Advertisement
Guest User

Untitled

a guest
Jun 17th, 2011
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.52 KB | None | 0 0
  1. local base = piece "base"
  2. local pelvis = piece "pelvis"
  3. local body = piece "body"
  4. local head = piece "head"
  5. local L_upper = piece "L_upper"
  6. local L_lower = piece "L_lower"
  7. local L_hand = piece "L_hand"
  8. local R_upper = piece "R_upper"
  9. local R_lower = piece "R_lower"
  10. local R_hand = piece "R_hand"
  11. local L_legupper = piece "L_legupper"
  12. local L_leglower = piece "L_leglower"
  13. local L_foot = piece "L_foot"
  14. local R_legupper = piece "R_legupper"
  15. local R_leglower = piece "R_leglower"
  16. local R_foot = piece "R_foot"
  17. local hammer = piece "hammer"
  18. local flare = piece "flare"
  19.  
  20. local SIG_REST = 1
  21. local SIG_WALK = 2   --signal for the walk animation thread
  22. local SIG_AIM = 4  --signal for the weapon aiming thread
  23. local SIG_SWING = 8
  24.  
  25. local leg_movespeed = 6
  26. local RESTORE_DELAY = 1 * 1000 * Spring.GetUnitWeaponState(unitID, 0, 'reloadTime')
  27.  
  28. ---REST---
  29. local function rest()
  30.    Signal(SIG_REST)
  31.    SetSignalMask(SIG_REST)
  32.    while (true) do
  33.     Move (body, 2, 0.5, 0.25)
  34.     Turn (body, 1 , math.rad(-2), math.rad(2))
  35.     Turn (head, 1 , math.rad(4), math.rad(4))
  36.     Turn (L_upper, 1, math.rad(4), math.rad(4))
  37.     Turn (R_upper, 1, math.rad(2), math.rad(2))
  38.     Sleep (1010)
  39.     Move (body, 2, 0, 0.25)
  40.     Turn (body, 1 , math.rad(0), math.rad(2))
  41.     Turn (head, 1 , math.rad(0), math.rad(4))
  42.     Turn (L_upper, 1, math.rad(0), math.rad(4))
  43.     Turn (R_upper, 1, math.rad(0), math.rad(2))
  44.     Sleep (1010)
  45.    end
  46. end
  47.  
  48. function script.Create()
  49. --rest arms
  50.    Turn(R_upper, 3, math.rad(-80))
  51.    Turn(L_upper, 3, math.rad(80))
  52.    Turn(R_lower, 3, math.rad(-10))
  53.    Turn(L_lower, 3, math.rad(10))
  54.    Turn(R_upper, 1, math.rad(10))
  55.    Turn(L_upper, 1, math.rad(10))
  56.    Turn(R_lower, 1, math.rad(-20))
  57.    Turn(L_lower, 1, math.rad(-20))
  58.    Turn(R_hand, 3, math.rad(-10))
  59.    Turn(hammer, 3, math.rad(90))
  60.    Turn(hammer, 2, math.rad(30))
  61. --rest legs
  62.    Turn(R_legupper, 1, math.rad(-5))
  63.    Turn(L_legupper, 1, math.rad(-10))
  64.    Turn(R_legupper, 3, math.rad(3))
  65.    Turn(L_legupper, 3, math.rad(-3))
  66.    Turn(R_leglower, 1, math.rad(15))
  67.    Turn(L_leglower, 1, math.rad(10))
  68.    Turn(R_foot, 1, math.rad(-10))
  69.    StartThread (rest)
  70. end
  71.  
  72.  
  73.  
  74. local function RestoreAfterDelay()
  75.    Sleep(RESTORE_DELAY)
  76.    Turn(body, 2, 0 ,math.rad(125))
  77.    Turn(L_upper, 2, 0, math.rad(75))
  78.    Turn(L_lower, 2, 0, math.rad(75))
  79.    Turn(head, 2, 0, math.rad(100))
  80.    Turn(L_upper, 1, 0, math.rad(50))
  81.    Turn(L_lower, 1, 0, math.rad(50))
  82.    Turn(L_hand, 1, 0, math.rad(200))
  83.    Turn(L_hand, 3, 0, math.rad(200))
  84. end
  85.  
  86. ---WALKING---
  87. local function walk()
  88.   Sleep (math.random(100))
  89.    Signal(SIG_WALK)
  90.    SetSignalMask(SIG_WALK)
  91.    while (true) do
  92.       --left leg up, right leg down
  93.       Turn (R_legupper, 1, math.rad(-3), math.rad(19)*leg_movespeed)
  94.       Turn (R_legupper, 3, math.rad(1), math.rad(1))
  95.       Turn (R_leglower, 1, math.rad(10), math.rad(0)*leg_movespeed)
  96.       Turn (R_foot, 1, math.rad(-8), math.rad(4)*leg_movespeed)
  97.       Turn (L_legupper, 1, math.rad(-16), math.rad(29)*leg_movespeed)
  98.       Turn (L_legupper, 3, math.rad(-1), math.rad(2))
  99.       Turn (L_leglower, 1, math.rad(58), math.rad(46)*leg_movespeed)
  100.       Turn (L_foot, 1, math.rad(12), math.rad(15)*leg_movespeed)
  101.       Turn (pelvis, 3, math.rad(0), math.rad(10))
  102.       Turn (body, 3, math.rad(0), math.rad(10))
  103.       Turn (R_upper, 1, math.rad(0), math.rad(10)*leg_movespeed)
  104.       Move (pelvis, 2, 0, 10)
  105.       Sleep (1010/leg_movespeed)
  106.       Turn (R_legupper, 1, math.rad(13), math.rad(16)*leg_movespeed)
  107.       Turn (R_legupper, 3, math.rad(3), math.rad(2))
  108.       Turn (R_leglower, 1, math.rad(12), math.rad(2)*leg_movespeed)
  109.       Turn (R_foot, 1, math.rad(-3), math.rad(5)*leg_movespeed)
  110.       Turn (L_legupper, 1, math.rad(-22), math.rad(6)*leg_movespeed)
  111.       Turn (L_legupper, 3, math.rad(0), math.rad(1))
  112.       Turn (L_leglower, 1, math.rad(10), math.rad(48)*leg_movespeed)
  113.       Turn (L_foot, 1, math.rad(-12), math.rad(24)*leg_movespeed)
  114.       Turn (pelvis, 3, math.rad(-4), math.rad(10))
  115.       Turn (body, 3, math.rad(4), math.rad(10))
  116.       Turn (R_upper, 1, math.rad(-10), math.rad(10)*leg_movespeed)
  117.       Move (pelvis, 2, -0.3, 10)
  118.       Sleep (1010/leg_movespeed)
  119.       Turn (R_legupper, 1, math.rad(-16), math.rad(29)*leg_movespeed)
  120.       Turn (R_legupper, 3, math.rad(1), math.rad(2))
  121.       Turn (R_leglower, 1, math.rad(58), math.rad(46)*leg_movespeed)
  122.       Turn (R_foot, 1, math.rad(12), math.rad(15)*leg_movespeed)
  123.       Turn (L_legupper, 1, math.rad(-3), math.rad(19)*leg_movespeed)
  124.       Turn (L_legupper, 3, math.rad(-1), math.rad(1))
  125.       Turn (L_leglower, 1, math.rad(10), math.rad(0)*leg_movespeed)
  126.       Turn (L_foot, 1, math.rad(-8), math.rad(4)*leg_movespeed)
  127.       Turn (pelvis, 3, math.rad(0), math.rad(10))
  128.       Turn (body, 3, math.rad(0), math.rad(10))
  129.       Turn (R_upper, 1, math.rad(0), math.rad(10)*leg_movespeed)
  130.       Move (pelvis, 2, 0, 10)
  131.       Sleep (1010/leg_movespeed)
  132.       Turn (R_legupper, 1, math.rad(-22), math.rad(6)*leg_movespeed)
  133.       Turn (R_legupper, 3, math.rad(0), math.rad(1))
  134.       Turn (R_leglower, 1, math.rad(10), math.rad(48)*leg_movespeed)
  135.       Turn (R_foot, 1, math.rad(-12), math.rad(24)*leg_movespeed)
  136.       Turn (L_legupper, 1, math.rad(13), math.rad(16)*leg_movespeed)
  137.       Turn (L_legupper, 3, math.rad(-3), math.rad(2))
  138.       Turn (L_leglower, 1, math.rad(12), math.rad(2)*leg_movespeed)
  139.       Turn (L_foot, 1, math.rad(-3), math.rad(5)*leg_movespeed)
  140.       Turn (pelvis, 3, math.rad(-4), math.rad(10))
  141.       Turn (body, 3, math.rad(4), math.rad(10))
  142.       Turn (R_upper, 1, math.rad(10), math.rad(10)*leg_movespeed)
  143.       Move (pelvis, 2, -0.3, 10)
  144.       Sleep (1010/leg_movespeed)
  145.  
  146.    end
  147. end
  148.  
  149. local function armswing()
  150.    Signal(SIG_SWING)
  151.    SetSignalMask(SIG_SWING)
  152.    while (true) do
  153.       Turn (L_upper, 1, math.rad(0), math.rad(20)*leg_movespeed)
  154.       Turn (L_lower, 1, math.rad(0), math.rad(10)*leg_movespeed)
  155.       Sleep (1010/leg_movespeed)
  156.       Turn (L_upper, 1, math.rad(20), math.rad(20)*leg_movespeed)
  157.       Turn (L_lower, 1, math.rad(10), math.rad(10)*leg_movespeed)
  158.       Sleep (1010/leg_movespeed)
  159.       Turn (L_upper, 1, math.rad(0), math.rad(20)*leg_movespeed)
  160.       Sleep (1010/leg_movespeed)
  161.       Turn (L_upper, 1, math.rad(-20), math.rad(20)*leg_movespeed)
  162.       Sleep (1010/leg_movespeed)
  163.    end
  164. end
  165.  
  166. local function legs_down ()
  167.    Turn (R_upper, 1, math.rad(0), math.rad(10)*leg_movespeed)
  168.    Turn (L_upper, 1, math.rad(0), math.rad(20)*leg_movespeed)
  169.    Turn (L_lower, 1, math.rad(0), math.rad(10)*leg_movespeed)
  170.    Turn(R_legupper, 1, math.rad(-5), math.rad(90)*leg_movespeed)
  171.    Turn(L_legupper, 1, math.rad(-10), math.rad(90)*leg_movespeed)
  172.    Turn(R_leglower, 1, math.rad(15), math.rad(90)*leg_movespeed)
  173.    Turn(L_leglower, 1, math.rad(10), math.rad(90)*leg_movespeed)
  174.    Turn(R_foot, 1, math.rad(-10), math.rad(90)*leg_movespeed)
  175.    Turn(L_foot, 1, math.rad(0), math.rad(90)*leg_movespeed)
  176.    Turn (pelvis, 3, math.rad(0), math.rad(10))
  177.    Turn (body, 3, math.rad(0), math.rad(10))
  178. end
  179.  
  180. function script.StartMoving()
  181. --    Spring.Echo ("starting to walk!")
  182.    StartThread (walk)
  183.    StartThread (armswing)
  184.    Signal(SIG_REST)
  185. end
  186.  
  187. function script.StopMoving()
  188. --    Spring.Echo ("stopped walking!")
  189.       StartThread (rest)
  190.       Signal(SIG_WALK)
  191.       Signal(SIG_SWING)
  192.       legs_down ()
  193. end
  194.  
  195. ---AIMING & SHOOTING---
  196. function script.AimFromWeapon1()
  197.    return body
  198. end
  199.  
  200. function script.QueryWeapon1()
  201.    return flare
  202. end
  203.  
  204. --must return true to allow the weapon to shot. return false denies the weapon from shooting
  205. --can be used delay the shooting until a "turn turret" animation is completed
  206. function script.AimWeapon1( heading, pitch )
  207.    --make sure the aiming animation is only run once
  208.    Signal(SIG_AIM)
  209.    Signal(SIG_SWING)
  210.    SetSignalMask(SIG_AIM)
  211.    if heading < math.rad(180) then
  212.       Turn(body, 2, heading/2, math.rad(150))
  213.       Turn(L_upper, 2, heading/4, math.rad(200))
  214.       Turn(L_lower, 2, heading/4, math.rad(200))
  215.       Turn(head, 2, heading/2, math.rad(200))
  216.       Turn(head, 1, -pitch, math.rad(200))
  217.       Turn(L_upper, 1, math.rad(280)-pitch, math.rad(200))
  218.       Turn(L_lower, 1, math.rad(350), math.rad(200))
  219.       Turn(L_hand, 1, math.rad(50), math.rad(200))
  220.       Turn(L_hand, 3, math.rad(-80), math.rad(200))
  221.       --wait until the weapon is pointed in the right direction
  222.       WaitForTurn (body, y_axis)
  223.       WaitForTurn (L_upper, x_axis)
  224.       StartThread(RestoreAfterDelay)
  225.       return true
  226.    else
  227.       headingdif = 2*math.pi-heading
  228.       Turn(body, 2, heading+headingdif/2, math.rad(150))
  229.       Turn(L_upper, 2, -headingdif/2, math.rad(200))
  230.       Turn(L_lower, 2, 0, math.rad(200))
  231.       Turn(head, 2, -headingdif/2, math.rad(200))
  232.       Turn(head, 1, -pitch, math.rad(200))
  233.       Turn(L_upper, 1, math.rad(280)-pitch, math.rad(200))
  234.       Turn(L_lower, 1, math.rad(350), math.rad(200))
  235.       Turn(L_hand, 1, math.rad(50), math.rad(200))
  236.       Turn(L_hand, 3, math.rad(-80), math.rad(200))
  237.       --wait until the weapon is pointed in the right direction
  238.       WaitForTurn (body, y_axis)
  239.       WaitForTurn (L_upper, x_axis)
  240.       StartThread(RestoreAfterDelay)
  241.       return true
  242.    end
  243.  
  244. end
  245.  
  246. --called after the weapon has fired
  247. function script.FireWeapon1()
  248.    Move(L_hand, 1, 0.5)
  249.    Move(L_upper, 3, -0.5)
  250.    Sleep(150)
  251.    Move(L_hand, 1, 0, 2)
  252.    Move(L_upper, 3, 0, 2)
  253. end
  254.  
  255. ----death animation: fall over & explode
  256. function script.Killed(recentDamage, maxHealth)
  257.    Turn (base, x_axis, math.rad(90),math.rad(150))
  258.    WaitForTurn (base, x_axis)  
  259.    Explode (body, SFX.SHATTER)  
  260.  
  261. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement