Advertisement
Guest User

Parenting

a guest
Apr 3rd, 2011
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.98 KB | None | 0 0
  1. # Author: Steeveeo
  2. # Updated: Aug 6, 2010 @ 9:10 AM PST (-8 GMT)
  3.  
  4. # Use and Purpose:
  5. # Place this chip on the main prop of your ship and say
  6. # '!parent' in chat. This will do all the work for you
  7. # to have a properly working and non-laggy parented ship.
  8. # Note that this does auto-weight props, so if your gyropod
  9. # is setup for a different weight, you may have to adjust.
  10. #
  11. # To share this chip, just say 'share mode' in chat before placing.
  12.  
  13. # Fair Use and Legality:
  14. # This chip is provided as is and is designed to work only
  15. # as instructed. This is provided under Creative Commons and
  16. # may be modified and/or shared with anyone as long as proper
  17. # credit is given to the original author (Steeveeo). Failure to
  18. # give credit by plagiarising or removing this header is subject
  19. # to administrative punishment.
  20.  
  21. @name E2 Tool - Autoparenter
  22. @inputs In:number
  23. @outputs
  24. @persist Parts:array Parent:entity Step CommandStack:array
  25. #Options
  26. @persist Option_Constrain Option_Weight Option_GravPlate
  27. @trigger
  28.  
  29. runOnChat(1)
  30.  
  31. #Startup
  32. if(first())
  33. {
  34. #Check if constrained
  35. if(!entity():isConstrained() & owner():lastSaid():lower() != "share mode")
  36. {
  37. print("Please place this on a contraption to begin")
  38. selfDestruct()
  39. }
  40. elseif(entity():isConstrained())
  41. {
  42. print("Caching structure parts, say '!parent' to begin.")
  43. Parent = entity():isConstrainedTo()
  44. Parts = entity():getConstraints()
  45. }
  46.  
  47. #Option Defaults
  48. Option_Constrain = 0
  49. Option_Weight = 0
  50. Option_GravPlate = 0
  51. }
  52.  
  53. #Begin parenting
  54. if(chatClk(owner()) & owner():lastSaid():lower() == "!parent")
  55. {
  56. #------------
  57. hideChat(1)
  58. # Derma Menu
  59. #------------
  60.  
  61. #Panel
  62. dPanel("Main_Control_Panel",vec2(scrW()*0.05,scrH()*0.15),vec2(300,200))
  63. dText("Main_Control_Panel","E2 Autoparenter")
  64.  
  65. #Instructions
  66. dLabel("Check each option to perform, then hit Start.","Main_Control_Panel",vec2(10,30))
  67.  
  68. #Contraint Checkbox
  69. dCheckBox("Optimize_Constraints","Main_Control_Panel",vec2(15,60))
  70. dText("Optimize_Constraints","Optimize Constraints")
  71. dRunOnChange("Optimize_Constraints",1)
  72.  
  73. #Weight Checkbox
  74. dCheckBox("Optimize_Weights","Main_Control_Panel",vec2(15,80))
  75. dText("Optimize_Weights","Optimize Weights")
  76. dRunOnChange("Optimize_Weights",1)
  77.  
  78. #Gravplating Checkbox
  79. dCheckBox("Apply_Gravplate","Main_Control_Panel",vec2(15,100))
  80. dText("Apply_Gravplate","Apply GravPlate")
  81. dRunOnChange("Apply_Gravplate",1)
  82.  
  83. #Apply Button
  84. dButton("Start","Main_Control_Panel",vec2(215,155),vec2(75,35))
  85.  
  86. #Capture Mouse
  87. enableMouse(1)
  88.  
  89. #--End of Derma Menu--
  90. }
  91.  
  92. #---------------------
  93. # Derma Functionality
  94. #---------------------
  95.  
  96. #Constraint Option
  97. if(dClk("Optimize_Constraints"))
  98. {
  99. Option_Constrain = dNval("Optimize_Constraints")
  100. }
  101.  
  102. #Weighting Option
  103. if(dClk("Optimize_Weights"))
  104. {
  105. Option_Weight = dNval("Optimize_Weights")
  106. }
  107.  
  108. #GravPlate Option
  109. if(dClk("Apply_Gravplate"))
  110. {
  111. Option_GravPlate = dNval("Apply_Gravplate")
  112. }
  113.  
  114. #Start
  115. if(dClk("Start") | (~In & In))
  116. {
  117.  
  118. if (In) {
  119. Option_GravPlate = 1
  120. Option_Weight = 1
  121. Option_Constrain = 1
  122. }
  123. print("Initializing AutoParent, DO NOT TOUCH YOUR SHIP UNTIL THIS IS COMPLETE!")
  124.  
  125. #Close Derma
  126. enableMouse(0)
  127. dShow("Main_Control_Panel",0)
  128.  
  129. #Compile Commands onto stack, then start (will always freeze first and parent last)
  130. CommandStack[1,string] = "Freeze"
  131. if(Option_Constrain) { CommandStack[CommandStack:count()+1,string] = "Unconstrain" }
  132. if(Option_Weight) { CommandStack[CommandStack:count()+1,string] = "Weights" }
  133. if(Option_GravPlate) { CommandStack[CommandStack:count()+1,string] = "GravPlate" }
  134. CommandStack[CommandStack:count()+1,string] = "Parent"
  135.  
  136. #printTable(CommandStack)
  137.  
  138. timer("CallStack",100)
  139. }
  140.  
  141. #--End of Derma--
  142.  
  143. #--------------------------
  144. # Command Stack Controller
  145. #--------------------------
  146.  
  147. if(clk("CallStack"))
  148. {
  149. if(CommandStack:count())
  150. {
  151. Call = CommandStack:removeString(1)
  152. #print("Calling " + Call)
  153.  
  154. Step = 0
  155. timer(Call,100)
  156. }
  157. else
  158. {
  159. print("[PARENTER] - Error! Got to end of stack before parenting!")
  160. selfDestruct()
  161. }
  162. }
  163.  
  164. #--End of Stack Control--
  165.  
  166.  
  167. #---------------
  168. # Functionality
  169. #---------------
  170.  
  171. #Freeze all props
  172. if(clk("Freeze"))
  173. {
  174. #From here on out, these are expensive processes, so we need to do this in chunks
  175. Index = 1+(10*Step)
  176. End = 0
  177. while(Index <= 10+(10*Step))
  178. {
  179. if(Index != Parts:count()+1)
  180. {
  181. Parts[Index,entity]:freeze()
  182. Index++
  183. }
  184. else
  185. {
  186. #Back to the Stack
  187. timer("CallStack",100)
  188.  
  189. print("Freezing finished.")
  190. End = 1
  191. break
  192. }
  193. }
  194.  
  195. #Check if we did not hit the end, start next step
  196. if(!End)
  197. {
  198. Step++
  199. timer("Freeze",100)
  200. }
  201. }
  202.  
  203. #Unconstrain everything
  204. if(clk("Unconstrain"))
  205. {
  206. Index = 1+(10*Step)
  207. End = 0
  208. while(Index <= 10+(10*Step))
  209. {
  210. if(Index != Parts:count()+1)
  211. {
  212. Parts[Index,entity]:unConstrain()
  213. Index++
  214. }
  215. else
  216. {
  217. #Call the Rewelder
  218. Step = 0
  219. timer("Reweld",100)
  220.  
  221. print("Unconstrain finished, welding to parent.")
  222. End = 1
  223. break
  224. }
  225. }
  226.  
  227. #Check if we did not hit the end, start next step
  228. if(!End)
  229. {
  230. Step++
  231. timer("Unconstrain",100)
  232. }
  233. }
  234.  
  235. #ReWeld everything to Parent
  236. if(clk("Reweld"))
  237. {
  238. Index = 1+(10*Step)
  239. End = 0
  240. while(Index <= 10+(10*Step))
  241. {
  242. if(Index != Parts:count()+1)
  243. {
  244. if(Parts[Index,entity] != Parent)
  245. {
  246. Parts[Index,entity]:weld(Parent)
  247. }
  248. Index++
  249. }
  250. else
  251. {
  252. #Back to the Stack
  253. timer("CallStack",100)
  254.  
  255. print("Constraint Optimizations Complete.")
  256. End = 1
  257. break
  258. }
  259. }
  260.  
  261. #Check if we did not hit the end, start next step
  262. if(!End)
  263. {
  264. Step++
  265. timer("Reweld",100)
  266. }
  267. }
  268.  
  269. #Weight everything dynamically
  270. if(clk("Weights"))
  271. {
  272. Index = 1+(10*Step)
  273. End = 0
  274.  
  275. while(Index <= 10+(10*Step))
  276. {
  277. if(Index != Parts:count()+1)
  278. {
  279. Part = Parts[Index,entity]
  280. if(Part == Parent)
  281. {
  282. Part:setMass(50000)
  283. }
  284. elseif(Part:type() == "prop_physics" | Part:type() == "prop_physics_multiplayer")
  285. {
  286. Part:setMass(200)
  287. }
  288. else
  289. {
  290. Type = Part:type():lower()
  291. if(Type:find("resource") | Type:find("storage") | Type:find("gen") | Type:find("regulator") | Type:find("gyropod"))
  292. {
  293. Part:setMass(50)
  294. }
  295. else
  296. {
  297. Part:setMass(1)
  298. }
  299. }
  300. Index++
  301. }
  302. else
  303. {
  304. #Back to the Stack
  305. timer("CallStack",100)
  306.  
  307. print("Weighting finished.")
  308. End = 1
  309. break
  310. }
  311. }
  312.  
  313. #Check if we did not hit the end, start next step
  314. if(!End)
  315. {
  316. Step++
  317. timer("Weights",100)
  318. }
  319. }
  320.  
  321. #GravPlate all props
  322. if(clk("GravPlate"))
  323. {
  324. Index = 1+(10*Step)
  325. End = 0
  326. while(Index <= 10+(10*Step))
  327. {
  328. if(Index != Parts:count()+1)
  329. {
  330. Parts[Index,entity]:setGravPlate(1)
  331. Index++
  332. }
  333. else
  334. {
  335. #Back to the Stack
  336. timer("CallStack",100)
  337.  
  338. print("GravPlating finished.")
  339. End = 1
  340. break
  341. }
  342. }
  343.  
  344. #Check if we did not hit the end, start next step
  345. if(!End)
  346. {
  347. Step++
  348. timer("Freeze",100)
  349. }
  350. }
  351.  
  352. #Parenting time
  353. if(clk("Parent"))
  354. {
  355. Index = 1+(10*Step)
  356. End = 0
  357. while(Index <= 10+(10*Step))
  358. {
  359. if(Index != Parts:count()+1)
  360. {
  361. if(Parts[Index,entity] != Parent & !Parts[Index,entity]:isVehicle())
  362. {
  363. Parts[Index,entity]:parentTo(Parent)
  364. }
  365. Index++
  366. }
  367. else
  368. {
  369. #End it
  370. print("Parenting complete, you may now fly this ship.")
  371. End = 1
  372. break
  373. }
  374. }
  375.  
  376. #Check if we did not hit the end, start next step
  377. if(!End)
  378. {
  379. Step++
  380. timer("Parent",100)
  381. }
  382. else
  383. {
  384. selfDestruct()
  385. }
  386. }
  387.  
  388. #--End of Functions--
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement