Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.62 KB | None | 0 0
  1. if UnitDefs[Spring.GetUnitDefID(unitID)].name == "armcom" then
  2. base, lthigh, rthigh, rleg, lleg, lfoot, rfoot,ruparm, luparm, torso = piece ("pelvis", "lthigh", "rthigh", "rleg", "lleg", "lfoot", "rfoot","ruparm", "luparm","torso")
  3. piecetable = {
  4.     thighs = {
  5.         r = {
  6.             length = 20,
  7.             },
  8.         l = {
  9.             length = 20,
  10.             },
  11.         },
  12.     legs = {
  13.         r = {
  14.             length = 20,
  15.             },
  16.         l = {
  17.             length = 20,
  18.             },
  19.         },
  20.     foots = {
  21.         r = {
  22.             length = 5,
  23.             },
  24.         l = {
  25.             length = 5,
  26.             },
  27.         },
  28.     }
  29.     wantedstepfrequency = 0.5
  30. elseif UnitDefs[Spring.GetUnitDefID(unitID)].name == "armpw" then
  31. base, lthigh, rthigh, rleg, lleg, lfoot, rfoot,ruparm, luparm, torso = piece ("pelvis", "lthigh", "rthigh", "rleg", "lleg", "lfoot", "rfoot","ruparm", "luparm","torso")
  32. piecetable = {
  33.     thighs = {
  34.         r = {
  35.             length = 0.8,
  36.             },
  37.         l = {
  38.             length = 0.8,
  39.             },
  40.         },
  41.     legs = {
  42.         r = {
  43.             length = 3,
  44.             },
  45.         l = {
  46.             length = 3,
  47.             },
  48.         },
  49.     foots = {
  50.         r = {
  51.             length = 3,
  52.             },
  53.         l = {
  54.             length = 3,
  55.             },
  56.         },
  57.     }
  58.     wantedstepfrequency = 1.5
  59. elseif UnitDefs[Spring.GetUnitDefID(unitID)].name == "armbanth" then
  60. base, lthigh, rthigh, rleg, lleg, lfoot, rfoot = piece ("hips", "lthigh", "rthigh", "rleg", "lleg", "lfoot", "rfoot")
  61. piecetable = {
  62.     thighs = {
  63.         r = {
  64.             length = 7.64,
  65.             },
  66.         l = {
  67.             length = 7.64,
  68.             },
  69.         },
  70.     legs = {
  71.         r = {
  72.             length = 13,
  73.             },
  74.         l = {
  75.             length = 13,
  76.             },
  77.         },
  78.     foots = {
  79.         r = {
  80.             length = 0,
  81.             },
  82.         l = {
  83.             length = 0,
  84.             },
  85.         },
  86.     }
  87.     wantedstepfrequency = 1
  88. end
  89. local SIG_WALK = 2
  90. local PlaySoundFile     = Spring.PlaySoundFile
  91. local GetUnitPosition   = Spring.GetUnitPosition
  92. local GetGameFrame      = Spring.GetGameFrame
  93. common = include("headers/common_includes_lus.lua")
  94. piecest = {base, lthigh, rthigh, rleg, lleg, lfoot, rfoot}
  95. Step = {}
  96. Step[1] = {}
  97. Step[2] = {}
  98. Step[3] = {}   
  99.  
  100. function ProcessWalkParams()
  101. while (true) do
  102.  
  103. realstepfrequency = ((UnitDefs[Spring.GetUnitDefID(unitID)].speed/((Speed+0.01) * 30))/10 + 0.9)*wantedstepfrequency
  104. Spring.Echo((UnitDefs[Spring.GetUnitDefID(unitID)].speed/((Speed+0.01) * 30))/10 + 0.9)
  105.  
  106. --thighs
  107. AnimationTime = 1/realstepfrequency
  108. Step[1].animationtime = AnimationTime/3
  109. Step[2].animationtime = AnimationTime/3
  110. Step[3].animationtime = AnimationTime/3
  111.  
  112. StepLength = Speed * 30 * AnimationTime
  113. wholeleglength = piecetable.thighs.l.length + piecetable.legs.l.length + piecetable.foots.l.length
  114. halfleglegnth = piecetable.legs.l.length + piecetable.foots.l.length
  115. footlength = piecetable.foots.l.length
  116.  
  117.  
  118. thighfullangle = math.atan(StepLength/wholeleglength)
  119. thighfrontangle = -thighfullangle/2
  120. thighbackangle = thighfullangle/2
  121. pelvisangle = thighfrontangle/4
  122. uparmfrontangle = thighfrontangle
  123. uparmbackangle = thighbackangle
  124. torsofrontangle = thighbackangle/4
  125. Sleep(10)
  126. end
  127. end
  128.  
  129.  
  130. function GetAngleValues(angle,speed)
  131.  
  132. return newangle, newspeed
  133. end
  134.  
  135. function GetIsTerrainWater()
  136. x,y,z = Spring.GetUnitPosition(unitID)
  137. if Spring.GetGroundHeight(x,z)<= -8 then
  138. return true
  139. else
  140. return false
  141. end
  142. end
  143.  
  144. function Emit(pieceName, effectName)
  145. local x,y,z,dx,dy,dz    = Spring.GetUnitPiecePosDir(unitID, pieceName)
  146. dx, dy, dz = 1, 0, 1
  147. Spring.SpawnCEG(effectName, x,y,z, dx, dy, dz)
  148. end
  149.  
  150. function UnitTurns()
  151. t = 0
  152. heading = {}
  153. while (true) do
  154. difference = 0
  155. heading[t] = Spring.GetUnitHeading(unitID)
  156. if heading[t-1] then
  157.     if heading[t-1] ~= heading[t] then
  158.         difference = heading[t] - heading[t-1]
  159.  
  160.         else
  161.         difference = 0
  162.     end
  163.     if math.abs(difference * 8 * 360 / 65536) <= 15 then
  164.     difference = 0
  165.     end
  166.     difference = difference * 8 * 360 / 65536
  167.     if difference > 50 then
  168.     difference = 50
  169.     elseif difference < -50 then
  170.     difference = -50
  171.     end
  172.     if difference ~= 0 then
  173.         -- Spring.Echo("turning")
  174.         -- Spring.Echo(difference)
  175.     end
  176.  
  177.     if heading[t-2] then
  178.         heading[t-2] = nil
  179.     end
  180.     difference = difference + randomness/10
  181. end
  182. t = t+1
  183. Sleep (1)
  184. end
  185. end
  186.  
  187. function GetSurroundingTerrain(frontfoot)
  188. x,y,z = Spring.GetUnitPosition(unitID)
  189. dx, dy, dz = Spring.GetUnitDirection(unitID)
  190. GroundHeightUnderFoot = Spring.GetGroundHeight(x+8*dx, z+8*dz)
  191. GroundHeightUnderCom = Spring.GetGroundHeight(x, z)
  192. HeightDifference = GroundHeightUnderFoot - GroundHeightUnderCom
  193. if HeightDifference <= 0 then
  194. AdditiveAngle = -math.abs(math.atan(HeightDifference/math.sqrt(64*dx^2+64*dz^2)))*(300/currentSpeed)* 1/0.0174533 * 1/2
  195. else
  196. AdditiveAngle = math.abs(math.atan(HeightDifference/math.sqrt(64*dx^2+64*dz^2)))*(300/currentSpeed)* 1/0.0174533 * 1/2
  197. end
  198.  
  199. if y < 0 then
  200.     if y < -35 then
  201.         y = -35
  202.     end
  203.     AdditiveAngle = AdditiveAngle*2
  204. end
  205.  
  206. -- Spring.Echo(AdditiveAngle)
  207. if AdditiveAngle <= 0 or randomness*0.1 + AdditiveAngle  <= 0 then
  208. AdditiveAngle = (AdditiveAngle + randomness*0.1)/2
  209. else
  210. AdditiveAngle = AdditiveAngle + randomness*0.1
  211. end
  212. -- Spring.Echo(AdditiveAngle)
  213. return AdditiveAngle
  214. end
  215.  
  216. function walk()
  217.     if moving then
  218.         if not (alreadystartedmoving) then -- leftleg to front, from stopped to move
  219.         Turn (lthigh, 1, thighfrontangle, thighfrontangle/Step[1].animationtime)
  220.         Turn (rthigh, 1, thighbackangle, thighbackangle/Step[1].animationtime)
  221.         Turn (base, 2, pelvisangle, pelvisangle/Step[1].animationtime)
  222.        
  223.         Turn (luparm, 1, uparmbackangle, uparmbackangle/Step[1].animationtime)
  224.         Turn (ruparm, 1, uparmfrontangle, uparmfrontangle/Step[1].animationtime)
  225.  
  226.         Turn (torso, 1, torsofrontangle, torsofrontangle/Step[1].animationtime)
  227.        
  228.         Move (base, 3, 1, 1/Step[1].animationtime)                 
  229.         Turn (lleg, 1, 0, thighfrontangle/Step[1].animationtime)
  230.         Turn (rleg, 1, thighbackangle, thighbackangle/Step[1].animationtime)
  231.         alreadystartedmoving = true
  232.         Sleep(Step[1].animationtime * 1000)    
  233.         end
  234.     end
  235.     if moving then -- Default
  236.         Turn (lthigh, 1, 0, thighfrontangle/Step[2].animationtime)
  237.         Turn (rthigh, 1, 0, thighbackangle/Step[2].animationtime)
  238.         Turn (base, 2, 0, pelvisangle/Step[2].animationtime)
  239.         Turn (luparm, 1, 0, uparmbackangle/Step[2].animationtime)
  240.         Turn (ruparm, 1, 0, uparmfrontangle/Step[2].animationtime)
  241.         Turn (torso, 1, 0, torsofrontangle/Step[2].animationtime)
  242.         Move (base, 3, 0, 2/Step[1].animationtime)             
  243.         Turn (lleg, 1, 0, thighfrontangle/Step[2].animationtime)
  244.         Turn (rleg, 1, thighbackangle, thighbackangle/Step[2].animationtime)
  245.     Sleep(Step[2].animationtime * 1000)
  246.     end
  247.     if moving then -- Rightleg to front
  248.         Turn (lthigh, 1, thighbackangle, thighbackangle/Step[3].animationtime)
  249.         Turn (rthigh, 1, thighfrontangle, thighfrontangle/Step[3].animationtime)
  250.         Turn (base, 2, -pelvisangle, pelvisangle/Step[3].animationtime)
  251.         Turn (ruparm, 1, uparmbackangle, uparmbackangle/Step[3].animationtime)
  252.         Turn (luparm, 1, uparmfrontangle, uparmfrontangle/Step[3].animationtime)
  253.         Turn (torso, 1, torsofrontangle, torsofrontangle/Step[3].animationtime)
  254.         Move (base, 3, 2, 2/Step[3].animationtime)     
  255.         Turn (lleg, 1, thighbackangle, thighbackangle/Step[3].animationtime)
  256.         Turn (rleg, 1, 0, thighfrontangle/Step[3].animationtime)
  257.     Sleep(Step[3].animationtime * 1000)
  258.     end
  259.     if moving then--lleg to front from not moving to moving
  260.         if not (alreadystartedmoving) then
  261.         Turn (rthigh, 1, thighfrontangle, thighfrontangle/Step[1].animationtime)
  262.         Turn (lthigh, 1, thighbackangle, thighbackangle/Step[1].animationtime)
  263.         Turn (base, 2, pelvisangle, pelvisangle/Step[1].animationtime)
  264.         Turn (luparm, 1, uparmbackangle, uparmbackangle/Step[1].animationtime)
  265.         Turn (ruparm, 1, uparmfrontangle, uparmfrontangle/Step[1].animationtime)
  266.         Turn (torso, 1, torsofrontangle, torsofrontangle/Step[1].animationtime)
  267.         Move (base, 3, 1, 1/Step[1].animationtime)         
  268.         Turn (rleg, 1, 0, thighfrontangle/Step[1].animationtime)
  269.         Turn (lleg, 1, thighbackangle, thighbackangle/Step[1].animationtime)
  270.         alreadystartedmoving = true
  271.         Sleep(Step[1].animationtime * 1000)    
  272.         end
  273.  
  274.     end
  275.     if moving then -- default pos
  276.         Turn (rthigh, 1, 0, thighfrontangle/Step[2].animationtime)
  277.         Turn (lthigh, 1, 0, thighbackangle/Step[2].animationtime)
  278.         Turn (base, 2, 0, pelvisangle/Step[2].animationtime)
  279.         Turn (luparm, 1, 0, uparmfrontangle/Step[2].animationtime)
  280.         Turn (ruparm, 1, 0, uparmbackangle/Step[2].animationtime)
  281.         Turn (torso, 1, 0, torsofrontangle/Step[1].animationtime)
  282.         Move (base, 3, 0, 2/Step[2].animationtime)         
  283.         Turn (rleg, 1, 0, thighfrontangle/Step[2].animationtime)
  284.         Turn (lleg, 1, thighbackangle, thighbackangle/Step[2].animationtime)
  285.     Sleep(Step[2].animationtime * 1000)
  286.     end
  287.     if moving then -- left leg to front
  288.         Turn (rthigh, 1, thighbackangle, thighbackangle/Step[3].animationtime)
  289.         Turn (lthigh, 1, thighfrontangle, thighfrontangle/Step[3].animationtime)
  290.         Turn (base, 2, pelvisangle, pelvisangle/Step[3].animationtime)
  291.         Turn (ruparm, 1, uparmfrontangle, uparmfrontangle/Step[3].animationtime)
  292.         Turn (luparm, 1, uparmbackangle, uparmbackangle/Step[3].animationtime)
  293.         Turn (torso, 1, torsofrontangle, torsofrontangle/Step[1].animationtime)
  294.         Move (base, 3, 2, 2/Step[3].animationtime)         
  295.        
  296.         Turn (rleg, 1, thighbackangle, thighbackangle/Step[3].animationtime)
  297.         Turn (lleg, 1, 0, thighfrontangle/Step[3].animationtime)
  298.     Sleep(Step[3].animationtime * 1000)
  299.     end
  300. end
  301.  
  302. function walklegs()
  303.  
  304. end
  305.  
  306. function stopwalk()
  307. end
  308.  
  309. function UnitSpeed()
  310.         vx,vy,vz,Speed = Spring.GetUnitVelocity(unitID)
  311.     while (true) do
  312.         vx,vy,vz,Speed = Spring.GetUnitVelocity(unitID)
  313.         currentSpeed = Speed*100*60/moveSpeed
  314.         if (currentSpeed < 100) then currentSpeed = 100 end
  315.         randomness = math.random(-25,25)
  316.         currentSpeed = currentSpeed + randomness
  317.         Sleep (1)
  318.     end
  319. end
  320.  
  321. function MotionControl()
  322.  
  323.     justmoved = true
  324.     while (true) do
  325.         if (moving) then
  326.             dgunning = 0
  327.             if (aiming) then
  328.                 walklegs()
  329.             else
  330.                 walk()
  331.             end
  332.             justmoved = true
  333.         else
  334.             if( justmoved ) then
  335.                 -- Move (pelvis, 2, 0)
  336.                 if side == 0 then
  337.  
  338.                 else
  339.            
  340.                 end
  341.                 if not (aiming) then
  342.  
  343.                 end
  344.                 justmoved = false
  345.             end
  346.             Sleep (100)
  347.         end
  348.         Sleep (1)
  349.     end
  350. end
  351.  
  352. function script.Create()
  353.     side = math.random(0,1)
  354.     randomness = math.random(-25,25)
  355.     addheight = 0
  356.     moving = false
  357.     aiming = false
  358.     building = false
  359.     justfired = false
  360.     dgunning = false
  361.     buildy = 0
  362.     buildx = 0
  363.     moveSpeed = UnitDefs[Spring.GetUnitDefID(unitID)].speed
  364.     currentSpeed = 100
  365.     Spring.UnitScript.StartThread(MotionControl)
  366.     Spring.UnitScript.StartThread(UnitSpeed)
  367.     Spring.UnitScript.StartThread(UnitTurns)
  368.     Spring.UnitScript.StartThread(ProcessWalkParams)
  369.     -- Spring.SetUnitNanoPieces(unitID, {lfirept})
  370. end
  371.  
  372. function script.StartMoving()
  373.     building = false
  374.     moving = true
  375.     dgunning = false
  376. end
  377.    
  378. function script.StopMoving()
  379.     moving = false
  380. end
  381.  
  382.  
  383. function script.Killed()
  384. for count, piece in pairs(piecest) do
  385. Explode(piece, SFX.EXPLODE_ON_HIT)
  386. Hide(piece)
  387. end
  388. return 1
  389. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement