Advertisement
Guest User

Untitled

a guest
Oct 21st, 2018
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.42 KB | None | 0 0
  1. @name HoloDetailer V5.5
  2. @outputs Props:array Ops
  3. @persist [Base TProp]:entity
  4. @persist Int Go Key Alpha FinalInvalid Sounds TryDelete Version SwitchInterval Cycle SearchRadius
  5. @persist [Weapon FileName CustomName Append Tab]:string
  6. @persist [TVec Offset PreBase]:vector
  7. @persist TAng:angle
  8. @trigger none
  9. if(duped() | dupefinished()){reset()}
  10. ############################################
  11. #SETTINGS YOU CAN CHANGE####################
  12. ############################################
  13.  
  14. Key=owner():keyAttack2() #Key used to select/deselect props
  15. Offset=vec(0,0,200) #Offset of preview holos
  16. Weapon="weapon_crowbar" #Weapon/tool that must be used
  17. Alpha=120 #Transparency of selected objects
  18. Sounds=1 #Play sound effects: 1=on, 0=off
  19. SwitchInterval=40 #How often to start a new switch statement
  20. #Interval
  21. ###########################################
  22. ###########INSTRUCTIONS####################
  23. ###########################################
  24.  
  25. #Default tool to use this chip is the HL2 Crowbar, if unavailable, change it in the settings above.
  26. #Use the chat command !base to define a base prop which all others will be relative to.
  27. #If no base is set using the command, the first prop you select will become the base.
  28. #If you want to change your base, you must reset the process.
  29. #Default: Right click with the crowbar to add/remove props or entitities from the selection list.
  30. #Can also add all props/entities constrained to another to the list using the !constraints command.
  31. #Use the chat command !go to validate props and write a .txt file, the path to the file will be given after the process is complete.
  32. #Custom filename can be set with the !name command. Process can be reset with the !reset command.
  33. #Delete all highlighted props with the !delete command.
  34. #You can check the amount of props currently selected with the !check command
  35. #Conversion is not instant, approximate rate is 4 props per second.
  36.  
  37. #Correctly formatted E2 holo code in the form of a switch statement will be written to the .txt file, please note that Windows Notepad does not show the linebreaks, I recommend Notepad++.
  38. #In a new E2, create a "N" number variable, a "Cycle" variable and a "Base" entity variable. These are only default values and can be changed.
  39. #The "Base" variable must be set for the holos to appear correctly.
  40. #Holos use a incrementing value so as to not overwrite each other if new holos need to be added to an existing chip.
  41.  
  42. ###COMMANDS
  43. # !base = Select a Base
  44. # !go = Start Conversion Process
  45. # !name = Define a filename
  46. # !check = Check amount
  47. # !reset = Reset Process/E2
  48. ###########
  49.  
  50. ############################################ FILES OF THE SAME NAME WILL BE OVERWRITTEN ############################################
  51.  
  52. ############################################
  53. ############################################
  54. ############################################
  55. ############################################
  56. ############################################
  57. ############################################
  58. ############################################
  59. ############################################
  60. #STUFF YOU SHOULD NOT TOUCH#################
  61. ############################################
  62. ############################################
  63. ############################################
  64. ############################################
  65. ############################################
  66. ############################################
  67. ############################################
  68. ############################################
  69. ############################################
  70. ############################################
  71. ############################################
  72. ############################################
  73. ############################################
  74. ############################################
  75. ############################################
  76. ############################################
  77. ############################################
  78. ############################################
  79. ############################################
  80. ############################################
  81. ############################################
  82. ############################################
  83. ############################################
  84. ############################################
  85. ############################################
  86. ############################################
  87. ############################################
  88. ############################################
  89. Version=5.5
  90. setName("[Holo Detailer v"+Version+"]\n"+"Selected: "+Props:count()+(CustomName != "null" ? ("\n"+"Filename: "+CustomName) : ""))
  91. if(first())
  92. {
  93. entity():soundPlay("reset",0,"buttons/blip2.wav")
  94. runOnChat(1)
  95. runOnLast(1)
  96. hint("Holo Detailer: Version "+Version+"\nCreated by Ixil",3)
  97. hint("Open E2 for Instructions",3)
  98. printColor(vec(255,50,50),"[Your server holo limit may vary...]")
  99. printColor(vec(255,50,50),"[FILES OF THE SAME NAME WILL BE OVERWRITTEN]")
  100. holoDeleteAll()
  101. Int=1
  102. CustomName="null"
  103. Tab=toChar(9)
  104. SearchRadius=150 #Radius of Area to Search for Entities
  105. function number verifyEntity(E:entity)
  106. {
  107. local Errors=0
  108. local I=1
  109. for(I=1,Props:count())
  110. {
  111. if(E==Props[I,entity])
  112. {
  113. Errors++
  114. }
  115. }
  116. if(E==Base)
  117. {
  118. Errors++
  119. }
  120. if(Errors>0)
  121. {
  122. return 0
  123. }
  124. else
  125. {
  126. return 1
  127. }
  128. }
  129. function number validateArray(Arr:array)
  130. {
  131. local Invalid=0
  132. local I=1
  133. for(I=1,Arr:count())
  134. {
  135. if(!Arr[I,entity]:isValid())
  136. {
  137. Invalid++
  138. hint("Invalid Found",1)
  139. }
  140. }
  141. if(Invalid>0)
  142. {
  143. return Invalid
  144. }
  145. else
  146. {
  147. return 0
  148. }
  149. }
  150. function void removeEntity(E:entity)
  151. {
  152. local I=1
  153. for(I=1,Props:count())
  154. {
  155. if(E==Props[I,entity])
  156. {
  157. Props:remove(I)
  158. }
  159. }
  160. }
  161. function void resetProps()
  162. {
  163. local I=1
  164. for(I=1,Props:count())
  165. {
  166. Props[I,entity]:setAlpha(255)
  167. }
  168. Props=array()
  169. hint("Prop Array Cleared",2)
  170. Base:setColor(PreBase)
  171. Base=noentity()
  172. }
  173. function deleteProps()
  174. {
  175. local I=1
  176. local Prop=noentity()
  177. for(I=1,Props:count())
  178. {
  179. Prop=Props[I,entity]
  180. Prop:propDelete()
  181. }
  182. Props=array()
  183. }
  184.  
  185.  
  186. function number processProp(Num)
  187. {
  188. local TProp=Props[Num,entity]
  189. if(frac(Num/SwitchInterval)==0)
  190. {
  191. #hint("This interval is even: "+Num/2,2)
  192. Cycle++
  193. Append+=Tab+Tab+"Cycle++\n"+Tab+"break\n\n"+Tab+"case "+Cycle+",\n"
  194. }
  195. Append+=Tab+Tab+"###Beginning Loop: "+Num+"\n"
  196. Append+=Tab+Tab+"#############################\n"
  197.  
  198. local TVec=Base:toLocal(TProp:pos())#TProp:pos()-Base:pos()
  199. holoPos(Num,Base:toWorld(TVec)+Offset)
  200. Append+=Tab+Tab+"holoPos(N,Base:toWorld(vec("+round(TVec:x(),3)+","+round(TVec:y(),3)+","+round(TVec:z(),3)+")) )\n"
  201.  
  202. holoAng(Num,Base:toWorld( Base:toLocal(TProp:angles()) ))
  203. local TAng=Base:toLocal(TProp:angles())
  204. Append+=Tab+Tab+"holoAng(N,Base:toWorld( ang("+round(TAng:pitch())+","+round(TAng:yaw())+","+round(TAng:roll())+") ))\n"
  205.  
  206. holoModel(Num,TProp:model())
  207. Append+=Tab+Tab+"holoModel(N,"+toChar(34)+TProp:model()+toChar(34)+")\n"
  208.  
  209. holoMaterial(Num,TProp:getMaterial())
  210. Append+=Tab+Tab+"holoMaterial(N,"+toChar(34)+TProp:getMaterial()+toChar(34)+")\n"
  211.  
  212. holoColor(Num,TProp:getColor())
  213. local TVec=TProp:getColor()
  214. Append+=Tab+Tab+"holoColor(N,"+"vec("+round(TVec:x(),2)+","+round(TVec:y(),2)+","+round(TVec:z(),2)+"))\n"
  215.  
  216. holoParent(Num,1)
  217. Append+=Tab+Tab+"holoParent(N,Base)\n"
  218. Append+=Tab+Tab+"#############################\n"
  219. Append+=Tab+Tab+"N++\n"
  220. if(Num==Props:count())
  221. {
  222. Append+=Tab+Tab+"Cycle=0\n"+Tab+"break\n"
  223. }
  224. if(!holoEntity(Num):isValid())
  225. {
  226. FinalInvalid++
  227. }
  228. if(fileCanWrite())
  229. {
  230. return 1
  231. }
  232. else
  233. {
  234. return 0
  235. }
  236. }
  237. }
  238. if(Go)
  239. {
  240. interval(50)
  241. }
  242. else
  243. {
  244. interval(50)
  245. }
  246. if(chatClk(owner()))
  247. {
  248. local LS=owner():lastSaid()
  249. local Explode=LS:explode(" ")
  250. if(Explode:count()>1)
  251. {
  252. if(Explode[1,string]=="!name")
  253. {
  254. CustomName=Explode[2,string]
  255. printColor(vec(255,255,255),"Filename set to: "+CustomName)
  256. hideChat(1)
  257. }
  258. if(Explode[1,string]=="!radius")
  259. {
  260. SearchRadius=clamp(Explode[2,string]:toNumber(),32,512)
  261. printColor(vec(255,255,255),"Area Select radius set to: "+SearchRadius)
  262. hideChat(1)
  263. }
  264. }
  265. switch(LS)
  266. {
  267. case"!base",
  268. if(!Base)
  269. {
  270. Base=owner():aimEntity()
  271. PreBase=Base:getColor()
  272. Base:setColor(vec(255,0,0))
  273. hint("Base: "+Base:model(),2)
  274. }
  275. else
  276. {
  277. hint("Base already set, reset to change.",2)
  278. }
  279. hideChat(1)
  280. break
  281.  
  282. case"!go",
  283. local I=0
  284. printColor(vec(255,255,255),"Starting process...")
  285. if(Base:isValid()){I++}else{hint("Base not found",3)}
  286. if(Props:count()>0){I++}else{hint("No Props selected",3)}
  287. if(I==2)
  288. {
  289. holoDeleteAll()
  290. #Props=Base:getConstraints()
  291. timer("validate",500)
  292. if(CustomName!="null")
  293. {
  294. FileName=CustomName+".txt"
  295. }
  296. else
  297. {
  298. FileName="Holo Detailer-"+randint(1,999)+".txt"
  299. }
  300. Cycle=1
  301. Append="#############################\n####Holo Detailer by Ixil####\n#############################\n"
  302. Append+="@name "+FileName+"\n@persist Cycle N Max Phase Go Base:entity\n@trigger none\n
  303. if(first())\n
  304. {\n"
  305. +Tab+"Max="+Props:count()+"\n"
  306. +Tab+"if(entity():hasConstraints("+toChar(34)+"Weld"+toChar(34)+")){Base=entity():isWeldedTo()}else{Base=entity():isConstrainedTo(1):isConstrainedTo(1)}\n"
  307. +Tab+"N=1\n"
  308. +Tab+"Cycle=1"
  309. +Tab+"Phase=1\n"
  310. +Tab+"timer("+toChar(34)+"Go"+toChar(34)+",2500)\n
  311. }\n if(clk("+toChar(34)+"Go"+toChar(34)+")){Go=1,hint("+toChar(34)+"Building..."+toChar(34)+",2)}\n"+
  312. "if(Phase==1 & Go)\n
  313. {\n"
  314. +Tab+"interval(75)\n"
  315. +Tab+"if(N<=Max)\n"
  316. +Tab+"{\n"
  317. +Tab+Tab+"local E=holoCreate(N)\n"
  318. +Tab+Tab+"holoParent(N,Base)\n"
  319. +Tab+Tab+"N++\n"
  320. +Tab+"}\n"
  321. +Tab+"else\n"
  322. +Tab+"{\n"
  323. +Tab+Tab+"N=1\n"
  324. +Tab+Tab+"Phase=2\n"
  325. +Tab+"}\n
  326. }\n"
  327. Append+="if(Cycle!=0 & Go & Phase==2)\n
  328. {\n"
  329. +Tab+"interval(80)\n"
  330. +Tab+"switch(Cycle)\n"
  331. +Tab+"{\n"
  332. Append+=Tab+Tab+"case 1,\n"+Tab+Tab+"N=1\n"
  333. }
  334. hideChat(1)
  335. break
  336.  
  337. case"!reset",
  338. hint("Resetting...",2)
  339. holoDeleteAll()
  340. Int=1
  341. if(Base:isValid())
  342. {
  343. Base:setColor(PreBase)
  344. Base=noentity()
  345. }
  346. resetProps()
  347. entity():soundPlay("reset",0.276,"buttons/blip2.wav")
  348. hideChat(1)
  349. break
  350.  
  351. case"!check",
  352. print(_HUD_PRINTCENTER,"Current Prop Count: "+Props:count())
  353. hideChat(1)
  354. break
  355. case"!area",
  356. findByClass("prop_physics")
  357. findIncludeClass("prop_physics")
  358. findInSphere(owner():aimPos(),SearchRadius)
  359. local Found = findToArray()
  360. local I=1
  361. local Added=0
  362. local TEnt=noentity()
  363. if(Base:isValid())
  364. {
  365. while(perf() & I<=Found:count())
  366. {
  367. #if(perf())
  368. #{
  369. TEnt=Found[I,entity]
  370. if(TEnt!=Base)
  371. {
  372. TEnt:setAlpha(Alpha)
  373. Props:pushEntity(TEnt)
  374. Added++
  375. }
  376. I++
  377. #}
  378. }
  379. if(Sounds)
  380. {
  381. print(_HUD_PRINTCENTER,"Added "+Added+" Props of "+Found:count()+"\nTotal Count: "+Props:count())
  382. owner():aimEntity():soundPlay(1,1.0,"buttons/button_synth_positive_01.wav")
  383. }
  384. }
  385. hideChat(1)
  386. break
  387. case"!constraints",
  388. local Constraints=owner():aimEntity():getConstraints()
  389. local I=1
  390. local Added=0
  391. local TEnt=noentity()
  392. if(Base:isValid())
  393. {
  394. for(I=1,Constraints:count())
  395. {
  396. if(perf())
  397. {
  398. TEnt=Constraints[I,entity]
  399. if(verifyEntity(TEnt)==1)
  400. {
  401. TEnt:setAlpha(Alpha)
  402. Props:pushEntity(TEnt)
  403. Added++
  404. }
  405. I++
  406. }
  407. }
  408. if(Sounds)
  409. {
  410. print(_HUD_PRINTCENTER,"Added "+Added+" Props of "+Constraints:count()+"\nTotal Count: "+Props:count())
  411. owner():aimEntity():soundPlay(1,1.0,"buttons/button_synth_positive_01.wav")
  412. }
  413. }
  414. else
  415. {
  416. hint("Please define a Base",3)
  417. }
  418. hideChat(1)
  419. break
  420. case"!delete",
  421. if(Base:isValid() & Props:count()>0)
  422. {
  423. printColor(vec(255,0,0),"This function will delete all highlighted props, cannot be undone.")
  424. printColor(vec(255,0,0),"Type !confirm to delete.")
  425. TryDelete=1
  426. timer("resetDelete",10000)
  427. }
  428. hideChat(1)
  429. break
  430. case"!confirm",
  431. if(TryDelete)
  432. {
  433. printColor(vec(255,0,0),"Removing highlighted props.")
  434. deleteProps()
  435. }
  436. else
  437. {
  438. printColor(vec(255,0,0),"Request timed out.")
  439. }
  440. hideChat(1)
  441. break
  442. default,
  443. hideChat(0)
  444. break
  445. }
  446. }
  447. if(clk("resetDelete"))
  448. {
  449. TryDelete=0
  450. }
  451. if(clk("validate"))
  452. {
  453. printColor(vec(255,255,255),"Please wait, validating prop array...")
  454. local Invalid=validateArray(Props)
  455. if(Invalid==0)
  456. {
  457. timer("start",500)
  458. }
  459. else
  460. {
  461. printColor(vec(255,0,0),Invalid+" Invalid Props Found. Type !reset to start over")
  462. }
  463. }
  464. if(clk("start"))
  465. {
  466. printColor(vec(0,255,0),"Props Validated, process started")
  467. Go=1
  468. }
  469. if(changed(Key) & Key & owner():weapon():type()==Weapon )
  470. {
  471. local TEnt=owner():aimEntity()
  472. if(TEnt:isValid() & Base:isValid() & TEnt!=Base & TEnt!=entity())
  473. {
  474. if(!TEnt:isPlayer() & TEnt:owner()==entity():owner())
  475. {
  476. if(verifyEntity(TEnt)==1)
  477. {
  478. TEnt:setAlpha(Alpha)
  479. Props:pushEntity(TEnt)
  480. print(_HUD_PRINTCENTER,"Added...\nTotal Count: "+Props:count())
  481. if(Sounds)
  482. {
  483. TEnt:soundPlay(1,1.0,"buttons/button_synth_positive_01.wav")
  484. }
  485. }
  486. else
  487. {
  488. TEnt:setAlpha(255)
  489. removeEntity(TEnt)
  490. print(_HUD_PRINTCENTER,"Removed...\nTotal Count: "+Props:count())
  491. if(Sounds)
  492. {
  493. TEnt:soundPlay(2,1.0,"buttons/button_synth_negative_02.wav")
  494. }
  495. }
  496. }
  497. else
  498. {
  499. hint("Invalid Selection",1)
  500. }
  501. }
  502. else
  503. {
  504. if(!Base:isValid())
  505. {
  506. Base=owner():aimEntity()
  507. PreBase=Base:getColor()
  508. Base:setColor(vec(255,0,0))
  509. hint("Base: "+Base:model(),2)
  510. }
  511. else
  512. {
  513. hint("Error",1)
  514. }
  515. }
  516. }
  517.  
  518.  
  519. if(Go & Base:isValid())
  520. {
  521. if(Int<=Props:count())
  522. {
  523. if(processProp(Int)==1)
  524. {
  525. Int++
  526. }
  527. }
  528. else
  529. {
  530. Append+="}\n}\n###PROCESS COMPLETE###"
  531. fileWrite(">e2shared/"+FileName,Append)
  532. printColor(vec(0,255,0),"Process Complete: "+(Props:count()-FinalInvalid)+" of "+Props:count()+" holos created")
  533. printColor(vec(255,93,0),"File Saved As: [STEAM DIRECTORY]/SteamApps/common/GarrysMod/garrysmod/data/Expression2/e2shss/"+FileName)
  534. printColor(vec(0,255,0),"Type !delete to remove selected props")
  535. printColor(vec(255,255,0),"Type !reset to begin again")
  536. Go=0
  537. Int=1
  538. }
  539. }
  540.  
  541. if(last())
  542. {
  543. resetProps()
  544. if(Base)
  545. {
  546. Base:setColor(PreBase)
  547. }
  548. holoDeleteAll()
  549. }
  550. Ops=ops()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement