Advertisement
Starkkz

Starkkz's Gyropod V3.0 (E2 Chip)

Dec 17th, 2013
2,927
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
E 6.10 KB | None | 0 0
  1. @name Gyropod V3 by Starkkz
  2.  
  3. #Basic inputs
  4. @inputs EyePod:wirelink Core:entity Active Unfreeze Level RollLock Boost
  5.  
  6. #Movement inputs
  7. @inputs Forward Back MoveLeft MoveRight MoveUp MoveDown
  8.  
  9. #Angle inputs
  10. @inputs PitchUp PitchDown PitchAbs YawLeft YawRight YawAbs RollLeft RollRight RollAbs
  11.  
  12. #Multiplier inputs
  13. @inputs PitchMult YawMult RollMult SpeedMult
  14.  
  15. #Gyropod outputs
  16. @outputs Angle:angle Velocity:vector AngularVelocity:angle
  17. @outputs Mass
  18.  
  19. #Global variables
  20. @persist Initialized LastEnv:string
  21. @persist Control ControlIndex
  22. @persist CurrentMass
  23. @persist Parent:entity Parts:array
  24. if (dupefinished()){reset()}
  25.  
  26. function setName2(Text:string){
  27.     setName("Gyropod V3 by Starkkz\n"+Text)
  28. }
  29.  
  30. function normal pitchMult(){
  31.     if (PitchMult){
  32.         return PitchMult
  33.     }
  34.     return 1
  35. }
  36.  
  37. function normal yawMult(){
  38.     if (YawMult){
  39.         return YawMult
  40.     }
  41.     return 1
  42. }
  43.  
  44. function normal rollMult(){
  45.     if (RollMult){
  46.         return RollMult
  47.     }
  48.     return 1
  49. }
  50.  
  51. function normal speedMult(){
  52.     if (SpeedMult){
  53.         return SpeedMult
  54.     }
  55.     return 1
  56. }
  57.  
  58. function updateParent(){
  59.     Parent = entity():parent()
  60.     if (!Parent){Parent = entity():isConstrainedTo()}
  61.     if (!Parent){Parent = entity()}
  62.     Parts = Parent:getConstraints()
  63.     Parts[Parts:count() + 1, entity] = Parent
  64.     LastEnv = Parent:lsName()
  65. }
  66.  
  67. function controlParts(){
  68.     if (Control > 0){
  69.         while (ControlIndex <= Parts:count()){
  70.             if (minquota() <= 100){
  71.                 timer("controlParts", 1)
  72.                 exit()
  73.             }
  74.             local Part = Parts[ControlIndex, entity]
  75.            
  76.             if (Control == 1){
  77.                 #Check constraints
  78.                 if (Part != Parent & !Part:isVehicle()){
  79.                     if (Part:isWeldedTo() == Parent){
  80.                         Part:unConstrain()
  81.                         Part:deparent()
  82.                         Part:noCollide(Parent)
  83.                         if (Core){Part:weld(Core)}
  84.                         Part:parentTo(Parent)
  85.                     }elseif (Part:isWeldedTo() != Core){
  86.                         Part:unWeld()
  87.                         Part:weld(Core)
  88.                     }
  89.                 }
  90.             }elseif (Control == 2){
  91.                 #Calculate mass
  92.                 CurrentMass = CurrentMass + Part:mass()
  93.             }elseif (Control == 3){
  94.                 #Freeze
  95.                 Part:propFreeze(1)
  96.             }elseif (Control == 4){
  97.                 #Unfreeze
  98.                 Part:propFreeze(0)
  99.             }elseif (Control == 5){
  100.                 #Disable gravity
  101.                 Part:propGravity(0)
  102.             }elseif (Control == 6){
  103.                 #Enable gravity
  104.                 Part:propGravity(1)
  105.             }
  106.             ControlIndex = ControlIndex + 1
  107.         }
  108.     }
  109.        
  110.     if (ControlIndex > Parts:count()){
  111.         if (Control == 1){
  112.             timer("checkConstraints", 20000)
  113.             if (Parent == entity()){
  114.                 setName2("Using E2 as parent")
  115.             }else{
  116.                 setName2("Found parent\nCached "+Parts:count()+" entities")
  117.             }
  118.             Initialized = 1
  119.         }elseif (Control == 2){
  120.             Mass = CurrentMass
  121.             CurrentMass = 0
  122.             timer("calculateMass", 10000)
  123.         }
  124.        
  125.         ControlIndex = 0
  126.         Control = 0
  127.     }
  128. }
  129.  
  130. function update(){
  131.     if (Active){
  132.         local Pitch = PitchUp - PitchDown + PitchAbs
  133.         local Yaw = YawLeft - YawRight + YawAbs
  134.         local Roll = RollLeft - RollRight + RollAbs
  135.        
  136.         local AngleVel = ang(Pitch, Yaw, Roll) * 15
  137.         if (EyePod){
  138.             AngleVel = AngleVel - ang(EyePod["Y", normal], EyePod["X", normal], 0):setRoll(0) * 10
  139.         }
  140.         if (Level){
  141.             AngleVel = -Parent:angles():setYaw(0) * 3
  142.         }elseif (RollLock){
  143.             AngleVel = -Parent:angles():setYaw(0):setPitch(0) * 3
  144.         }
  145.         AngleVel = ang(AngleVel:pitch() * pitchMult(), AngleVel:yaw() * yawMult(), AngleVel:roll() * rollMult())
  146.        
  147.         local MoveX = Forward - Back
  148.         local MoveY = MoveRight - MoveLeft
  149.         local MoveZ = MoveUp - MoveDown
  150.         local VelMult = 600
  151.         if (Boost){VelMult = 5000}
  152.         local Vel = (Parent:forward() * MoveX + Parent:right() * MoveY + Parent:up() * MoveZ) * speedMult() * VelMult
  153.        
  154.         Parent:setVel(Vel)
  155.         Parent:setAngVel(shiftR(AngleVel))
  156.     }
  157. }
  158.  
  159. if (first()){
  160.     #Initialize
  161.     runOnLast(1)
  162.    
  163.     updateParent()
  164.     timer("checkConstraints", 1)
  165.     timer("calculateMass", 1000)
  166.     timer("update", 1000)
  167. }elseif (last()){
  168.     #End
  169. }
  170.  
  171. if (Parent & Parent:lsName() != LastEnv){
  172.     LastEnv = Parent:lsName()
  173.     if (Active){timer("Activate", 1)}
  174. }
  175.  
  176. if (~Active){
  177.     if (Active){
  178.         timer("Activate", 1)
  179.     }else{
  180.         timer("Deactivate", 1)
  181.     }
  182.     EyePod["Enable", normal] = Active
  183. }elseif (~Unfreeze){
  184.     if (Unfreeze){
  185.         timer("Unfreeze", 1)
  186.     }else{
  187.         timer("Freeze", 1)
  188.     }
  189. }elseif (clk("controlParts")){
  190.     controlParts()
  191. }elseif (clk("update")){
  192.     if (Initialized){
  193.         update()
  194.     }
  195.     timer("update", 200)
  196. }elseif (clk("Activate")){
  197.     if (Control == 0){
  198.         Control = 5
  199.         controlParts()
  200.     }else{
  201.         timer("Activate", 100)
  202.     }
  203. }elseif (clk("Deactivate")){
  204.     if (Control == 0){
  205.         Control = 6
  206.         controlParts()
  207.     }else{
  208.         timer("Dectivate", 100)
  209.     }
  210. }elseif (clk("Freeze")){
  211.     if (Control == 0){
  212.         Control = 3
  213.         controlParts()
  214.     }else{
  215.         timer("Freeze", 100)
  216.     }
  217. }elseif (clk("Unfreeze")){
  218.     if (Control == 0){
  219.         Control = 4
  220.         controlParts()
  221.     }else{
  222.         timer("Unfreeze", 100)
  223.     }
  224. }elseif (clk("checkConstraints")){
  225.     if (Control == 0){
  226.         Control = 1
  227.         updateParent()
  228.         controlParts()
  229.     }else{
  230.         timer("checkConstraints", 100)
  231.     }
  232. }elseif (clk("calculateMass")){
  233.     if (Control == 0){
  234.         Control = 2
  235.         controlParts()
  236.     }else{
  237.         timer("calculateMass", 100)
  238.     }
  239. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement