Guest User

Untitled

a guest
Jan 23rd, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 12.22 KB | None | 0 0
  1. local function drehMatrix (x, y, zx, zy, degree)
  2. x= x-zx
  3. y=y-zy
  4.  
  5.  
  6. x=(math.cos(degree)+ (-1*math.sin(degree)))*x
  7. y=(math.cos(degree)+ (math.sin(degree)))*y
  8.  
  9.     IntCastX=x%1
  10.     x=x-IntCastX
  11.     IntCastY=y%1
  12.     y=y-IntCastY
  13.  
  14. x=x+zx
  15. y=y+zy
  16. return x,y
  17. end
  18.  
  19.  
  20. --My BASE the unit does nothing
  21. local boolAllReadySpawnedNotYetKilled=false
  22. local nanoemit = piece "nanoemit"
  23. local sentrynelshield    = piece "sentrynelshield"
  24. local sentrynelshield2   = piece "sentrynelshield2"
  25. local   sentrynell       = piece "sentrynell"
  26. local   sentrynel0       = piece "sentrynel0"
  27. local   sentrynel1       = piece "sentrynel1"
  28. local   sentrynel2       = piece "sentrynel2"
  29. local   sentrynel3       = piece "sentrynel3"
  30. local   sentrynel4       = piece "sentrynel4"
  31. local   sentrynel5       = piece "sentrynel5"
  32. local   snfoot           = piece "snfoot"
  33. local   pivot            = piece "Pivot"
  34. local   pivot01              = piece "Pivot01"
  35. local boolStoped
  36. local boolIsItDeadYet=false
  37. local SIG_UNFOLD=8
  38. local SIG_FOLD=4
  39. local SIG_SPAM=16
  40. local SIG_TRACK=2
  41. local SIG_WALK=32
  42.  
  43. local spamfilterSTART=true
  44. local spamfilterSTOP=false
  45.  
  46. local boolFilterActive=false
  47. local spotOnTarget=false
  48.  
  49.  
  50. local boolActive
  51. local boolSTOP=false
  52. local boolLongSTOP=false
  53. local boolMoveStateStart=true
  54. local boolAllreadyMovin=false
  55.  
  56. function vectorBetrag(xv,yv,x2,y2)
  57. -- determiniere höheren Wert
  58. xv=xv-x2
  59. yv=yv-y2
  60.  
  61. local xv=xv*xv
  62. local yv=yv*yv
  63. local xyv=xv+yv
  64. local Betrag=math.sqrt(xyv)
  65.  
  66. return Betrag
  67. end
  68.  
  69. local function headingToDegree(heading)
  70. local degree=0
  71. local oneDegree=177.7
  72.  
  73.         if heading==0 then
  74.  
  75.         return degree
  76.         end
  77. if heading < 0 then
  78.  
  79. degree= (heading/oneDegree)
  80.  
  81. degree=degree+360
  82. return degree
  83. end
  84.  
  85. if heading >0 then
  86. degree=(heading/oneDegree)
  87. return degree
  88.  
  89. end
  90.  
  91.  
  92.  
  93. end
  94.  
  95. function motionTrack()
  96. Spring.Echo("MotionTrack Started")
  97. SetSignalMask(SIG_TRACK)
  98.  
  99. local x,y,z=Spring.GetUnitPosition(unitID)
  100. while (true) do
  101.  
  102.  
  103. Sleep(50)
  104. nearEnemyID=Spring.GetUnitNearestEnemy(unitID, 3000, false)
  105.             if nearEnemyID == nil  then
  106.             Distance =9000
  107.             else
  108.             local xe,ye,ze=Spring.GetUnitPosition(nearEnemyID)
  109.            
  110.             Distance = vectorBetrag(x,y,xe,ye)
  111.             end
  112.            
  113.  
  114.                        
  115.                        
  116. Spring.Echo(Distance)
  117.         if boolIsItDeadYet==false then
  118.                 for beep=0, 2, 1 do
  119.                 sleePer=666
  120.                      if Distance >1000 then
  121.                
  122.                      Spring.PlaySoundFile("sounds/mt/mtnocontact.wav")
  123.                     -- Spring.Echo("da")
  124.                      --Play Sound Plock
  125.                      Sleep(sleePer)
  126.                      end
  127.                              if Distance <=1000 and Distance>745 then
  128.  
  129.                               Spring.PlaySoundFile("sounds/mt/mtfarawaycontact.wav")
  130.                              --Play (DetectedNonHecticBeep)
  131.                               Spring.Echo("do")
  132.                              sleePer=303+ ((Distance/2.5)-100)
  133.                              Sleep(sleePer)
  134.                              end
  135.                                      if Distance <=745 and Distance >500 then
  136.                                      Spring.PlaySoundFile("sounds/mt/mtcloser.wav")
  137.                                      --Play (DetectedGettingHecticBeep)
  138.                                        --Spring.Echo("de")
  139.                                      sleePer=303 +((Distance/2.5)-100)
  140.                                      Sleep(sleePer)
  141.                                      end
  142.                                              if Distance <=500 then
  143.                                              Spring.PlaySoundFile("sounds/mt/mtclosecomb.wav")
  144.                                              --play shrill panicy sound
  145.                                                --Spring.Echo("di")
  146.                                              sleePer=303+((Distance/2.5)-100)
  147.                                                      if sleePer < 303 then
  148.                                                      sleePer=303
  149.                                                      end
  150.                                              Sleep(sleePer)
  151.                 end
  152.  
  153.             end
  154.            
  155.                                                     if boolIsItDeadYet==true then
  156.                                                 Spring.PlaySoundFile("sounds/mt/suddendeath2.wav")
  157.                                                 --play Soundfile beeping heartdead...
  158.                                                 Sleep(LenghtOfSoundfile)
  159.                                                 Signal(SIG_TRACK)  
  160.                                                     end
  161.                
  162.         end
  163. end
  164. end
  165.  
  166.  
  167. function faceConvert(degree)
  168. local aNumber=0
  169. if degree>=315 and degree<45 then
  170. aNumber=0
  171. return aNumber
  172. end
  173.  
  174. if degree>=45 and degree<135 then
  175. aNumber=1
  176. return aNumber
  177. end
  178.  
  179. if degree>=135 and degree<225 then
  180. aNumber=2
  181. return aNumber
  182. end
  183.  
  184. if degree>=225 and degree<315 then
  185. aNumber=3
  186. return aNumber
  187.  
  188. end
  189.  
  190. end
  191.  
  192.  
  193.  
  194.  
  195. function sentry_Spawn()
  196.     if boolAllReadySpawnedNotYetKilled==false then
  197.     boolAllReadySpawnedNotYetKilled=true
  198.  
  199.  
  200.        local xDistance=1500
  201.        local zx,zy,z=Spring.GetUnitPosition (unitID)
  202.        local teamID = Spring.GetUnitTeam (unitID)
  203.        local heading= Spring.GetUnitHeading(unitID)
  204.        local sentryDegree=headingToDegree(heading)
  205.        local face=faceOff(sentryDegree)
  206.        z1=z
  207.        Spring.Echo(z1)
  208.        x1,y1=drehMatrix (1500, 0, zx, zy, sentryDegree)
  209.        sentryID1 = Spring.CreateUnit("sentry", x1, y1, z1, face, teamID)
  210.        Spring.Echo(x1)
  211.        Spring.Echo(y1)
  212.        
  213.                    x2,y2=drehMatrix (1250, -450, zx, zy, sentryDegree)
  214.                    sentryID2 = Spring.CreateUnit("sentry", x2, y2, z1, face, teamID)
  215.                            x3,y3=drehMatrix (1250, 450, zx, zy, sentryDegree)
  216.                            sentryID3 = Spring.CreateUnit("sentry", x3, y3, z1, face, teamID)
  217.                              
  218.                                    x4,y4=drehMatrix (850, 950, zx, zy, sentryDegree)
  219.                                    sentryID4 = Spring.CreateUnit("sentry", x4, y4, z1, face, teamID)
  220.                                             x5,y5=drehMatrix (850, -950, zx, zy, sentryDegree)
  221.                                             sentryID5 = Spring.CreateUnit("sentry", x5, y5, z1, face, teamID)
  222.     --
  223.        
  224.     --calculate Position
  225.     --delivers x1,y1,z1
  226.  
  227.  
  228.     --getViewingVectory
  229.  
  230.     --flatten ground has to go for this
  231.  
  232.    
  233.     end
  234.  
  235. end
  236.  
  237. function sentry_Kill()
  238.  if (Spring.ValidUnitID (sentryID2)) then
  239.       Spring.DestroyUnit (sentryID2, false,true) --leave no wreck
  240.       end
  241.       if (Spring.ValidUnitID (sentryID1)) then
  242.       Spring.DestroyUnit (sentryID1, false,true) --leave no wreck
  243.       end
  244.       if (Spring.ValidUnitID (sentryID3)) then
  245.       Spring.DestroyUnit (sentryID3, false,true) --leave no wreck
  246.       end
  247.       if (Spring.ValidUnitID (sentryID4)) then
  248.       Spring.DestroyUnit (sentryID4, false,true) --leave no wreck
  249.       end
  250.       if (Spring.ValidUnitID (sentryID5)) then
  251.       Spring.DestroyUnit (sentryID5, false,true) --leave no wreck
  252.       end
  253.       boolAllReadySpawnedNotYetKilled=false
  254.      
  255. end
  256.  
  257. local function walk()
  258. SetSignalMask(SIG_WALK)
  259. StopSpin(sentrynel3,y_axis)
  260.  
  261.     while(true) do
  262.  --vorn rechts
  263. Move(sentrynel0,z_axis,2,2.5)
  264. Turn(sentrynel0,x_axis,math.rad(-7),3)
  265.  --hinten schub
  266.  
  267. Turn(sentrynell,x_axis,math.rad(4),0.5)
  268.  
  269. Turn(sentrynel1,x_axis,math.rad(-6),3)
  270. Turn(sentrynel2,x_axis,math.rad(12),4)
  271. Move(sentrynel1,z_axis,-1,1.5)
  272.  
  273. Turn(snfoot,x_axis,math.rad(9),3)
  274. Move(snfoot,x_axis,0,2)
  275.  
  276. --Various Waits
  277. WaitForMove(sentrynel0,z_axis)
  278. WaitForTurn(sentrynel0,x_axis)
  279. WaitForTurn(sentrynel1,x_axis)
  280. WaitForTurn(sentrynel2,x_axis)
  281. WaitForMove(sentrynel1,z_axis)
  282. WaitForTurn(snfoot,x_axis)
  283. WaitForTurn(snfoot,x_axis)
  284. Sleep(20)
  285. --vorne links
  286. Move(snfoot,z_axis,2,1.5)
  287. Turn(snfoot,x_axis,math.rad(-7),2)
  288.  
  289. Turn(sentrynel0,x_axis,math.rad(9),3)
  290. Move(sentrynel0,x_axis,0,2)
  291.  
  292. --hinten zug
  293. Turn(sentrynell,x_axis,math.rad(-4),0.5)
  294. Move(sentrynel1,z_axis,1,1.5)
  295. Turn(sentrynel1,x_axis,math.rad(8),2)
  296. Turn(sentrynel2,x_axis,math.rad(-28),6)
  297. WaitForMove(sentrynel0,z_axis)
  298. WaitForTurn(sentrynel0,x_axis)
  299. WaitForTurn(sentrynel1,x_axis)
  300. WaitForTurn(sentrynel2,x_axis)
  301. WaitForMove(sentrynel1,z_axis)
  302. WaitForTurn(snfoot,x_axis)
  303. WaitForTurn(snfoot,x_axis)
  304. Sleep(20)
  305.  
  306.     end
  307. end
  308.  
  309.  
  310.  
  311. ---------------------------------------------------------------------------------------------------------------------------------------------
  312. local function spamFilter()
  313.     SetSignalMask(SIG_SPAM)
  314.  
  315.  
  316.     while (true) do
  317.            
  318.             if spamfilterSTART==true and spamfilterSTOP==false then  
  319.                     for it=0,3,1 do
  320.                     Sleep(1024)
  321.                         if spamfilterSTOP==true then
  322.                         spamfilterSTART=false
  323.                         break                  
  324.                         end
  325.                     end
  326.                    
  327.                    
  328.                     if spamfilterSTART==true then
  329.                     --if spamfilterSTART is still ==true then
  330.                     Signal(SIG_FOLD)
  331.                    
  332.                     StartThread (fold)             
  333.                     end
  334.                    
  335.             end
  336.            
  337.             if spamfilterSTOP==true and spamfilterSTART==false then  
  338.                     for at=0,3,1 do
  339.                     Sleep(1024)
  340.                         if spamfilterSTART==true then
  341.                         spamfilterSTOP=false
  342.                         break                  
  343.                         end
  344.                     end
  345.                     if spamfilterSTOP==true then
  346.                     --if spamfilterSTOP is still ==true then
  347.                     Signal(SIG_FOLD)
  348.                     Signal(SIG_UNFOLD)
  349.                    
  350.                     StartThread(unfold)    
  351.                     if boolActive==true then
  352.                     sentry_Spawn()
  353.            
  354.                     end
  355.    
  356.                     end
  357.                    
  358.             end
  359.  
  360.             if spamfilterSTOP==false and spamfilterSTART==false then  
  361.                
  362.             Spring.Echo("No idea what you did, but you broke it. You gonna pay!")
  363.                
  364.             end
  365.  
  366.     end
  367. end
  368.  
  369.  
  370.  
  371.  
  372. function fold()
  373.  
  374. Signal(SIG_UNFOLD)
  375. SetSignalMask(SIG_FOLD)
  376. StopSpin(sentrynel3,y_axis)
  377. Move(sentrynell,y_axis,0,1.4)
  378. Turn(sentrynel5,x_axis,math.rad(0),5)
  379. Turn(sentrynel5,y_axis,math.rad(0),5)
  380. Turn(sentrynel5,z_axis,math.rad(0),5)
  381. WaitForTurn(sentrynel5,z_axis)
  382. WaitForTurn(sentrynel5,y_axis)
  383. WaitForTurn(sentrynel5,x_axis)
  384.  
  385. Turn(sentrynel4,x_axis,math.rad(0),5)
  386. Turn(sentrynel4,y_axis,math.rad(0),5)
  387. Turn(sentrynel4,z_axis,math.rad(0),5)
  388.  
  389. WaitForTurn(sentrynel4,z_axis)
  390. WaitForTurn(sentrynel4,y_axis)
  391. WaitForTurn(sentrynel4,x_axis)
  392.  
  393. Turn(sentrynel3,x_axis,math.rad(0),5)
  394. Turn(sentrynel3,y_axis,math.rad(0),5)
  395. Turn(sentrynel3,z_axis,math.rad(0),5)
  396.  
  397. WaitForTurn(sentrynel3,z_axis)
  398. WaitForTurn(sentrynel3,y_axis)
  399. WaitForTurn(sentrynel3,x_axis)
  400.  
  401. Turn(sentrynelshield2,z_axis,math.rad(-65),3)
  402. Turn(sentrynelshield,z_axis,math.rad(65),3)
  403. WaitForTurn(sentrynelshield2,z_axis)
  404. WaitForTurn(sentrynelshield,z_axis)
  405.  
  406. while(true) do 
  407. walk()
  408.  
  409. end
  410. end
  411.  
  412. function unfold()
  413.  
  414. Signal(SIG_FOLD)
  415.  
  416. SetSignalMask(SIG_UNFOLD)
  417.  
  418. Turn(sentrynelshield2,z_axis,math.rad(0),1)
  419. Turn(sentrynelshield,z_axis,math.rad(0),1)
  420. WaitForTurn(sentrynelshield2,z_axis)
  421. WaitForTurn(sentrynelshield,z_axis)
  422. Move(sentrynell,y_axis,-2,0.4)
  423. Turn(sentrynel0,x_axis,math.rad(28),7)
  424. Turn(snfoot,x_axis,math.rad(28),7)
  425. Turn(sentrynel1,x_axis,math.rad(-20),7)
  426. Sleep(890)
  427.  
  428. Turn(sentrynel3,y_axis,math.rad(160),1.25)
  429. Turn(sentrynel5,x_axis,math.rad(-61),3)
  430. WaitForTurn(sentrynel3,y_axis)
  431.  
  432. Turn(sentrynel4,x_axis,math.rad(-13),1)
  433. Turn(sentrynel3,y_axis,math.rad(270),1.25)
  434. WaitForTurn(sentrynel3,y_axis)
  435.  
  436. Turn(sentrynel4,x_axis,math.rad(59),0.5)
  437. Turn(sentrynel3,y_axis,math.rad(360),1.25)
  438. Turn(sentrynel5,x_axis,math.rad(-83),1)
  439. WaitForTurn(sentrynel3,y_axis)
  440. triforce=1
  441.     while(true) do
  442.     triforce=triforce+1
  443.     Sleep(4024)
  444.     Spring.Echo("Idle")
  445.             if triforce%3==0 then
  446.             --idle
  447.             IwantRandy=math.random(0,1)
  448.                 if IwantRandy==1 then
  449.                 giveMeFive=5*math.random(-1,1)
  450.                 Spin(sentrynel3,y_axis,math.rad(giveMeFive),1.5)
  451.                 Sleep(19192)
  452.                 StopSpin(sentrynel3,y_axis)
  453.                 end
  454.             end
  455.     triforce=triforce%4
  456.     end
  457.  
  458. end
  459.  
  460. function script.AimWeapon1(heading ,pitch) 
  461.     Signal(SIG_AIM)
  462.     SetSignalMask(SIG_AIM)
  463. Turn(sentrynel4,x_axis,math.rad(64),8)
  464. Turn(sentrynel3,y_axis,-heading,4)
  465. WaitForTurn(sentrynel3,y_axis)
  466. WaitForTurn(sentrynel4,x_axis)
  467. Turn(sentrynel5,x_axis,pitch,3)
  468. WaitForTurn(sentrynel5,x_axis)
  469.  
  470.  
  471.     return true
  472.  
  473.    
  474. end
  475.  
  476. function script.AimFromWeapon1()
  477.     return nanoemit  
  478. end
  479.  
  480. function script.QueryWeapon1()
  481.     return nanoemit
  482. end
  483.  
  484. function script.FireWeapon1()  
  485.  
  486.     return true
  487.  
  488.    
  489. end
  490.  
  491.  
  492.  
  493.  
  494.  
  495. function script.Killed()
  496.     boolIsItDeadYet=true
  497.     Sleep(420)
  498.     Signal(SIG_SPAM)
  499.     Signal(SIG_FOLD)
  500.     Signal(SIG_UNFOLD)
  501.    Explode(nanoemit, SFX.FIRE)
  502.     Explode(sentrynelshield2,SFX.FIRE)
  503.     Explode(sentrynelshield,SFX.FIRE)
  504.  
  505.  
  506. end
  507.  
  508. function script.StartMoving()
  509.         if boolFilterActive==false then
  510.         boolFilterActive=true
  511.         Signal(SIG_SPAM)
  512.         StartThread(spamFilter)
  513.  
  514. end
  515.  
  516.   sentry_Kill()
  517. spamfilterSTOP=false
  518. spamfilterSTART=true
  519.  
  520. end
  521.  
  522. function script.StopMoving()
  523. --    Spring.Echo ("stopped walking!")
  524. spamfilterSTART=false      
  525. spamfilterSTOP=true    
  526.  
  527. Turn(sentrynell,x_axis,math.rad(0),3)
  528.     boolSTOP=true
  529.     Signal(SIG_TRACK)
  530.     Signal(SIG_UNDEPLOY)
  531.     Signal(SIG_WALK)
  532.     StartThread(motionTrack)
  533.            
  534.  
  535. end
  536.  
  537.  
  538.  
  539. ---------------------------------------------------------------------------------------------------------------------------------------------
  540.  
  541.  
  542.  
  543.  
  544.  
  545.  
  546.  
  547. function script.StartBuilding(heading, pitch)  
  548. SetUnitValue(COB.INBUILDSTANCE, 1)
  549. end
  550.  
  551. function script.QueryNanoPiece()
  552.      return nanoemit
  553. end
  554.  
  555. function script.StopBuilding()
  556.     SetUnitValue(COB.INBUILDSTANCE, 0)
  557. end
  558.  
  559.  
  560.  
  561.  
  562.  
  563. function script.Activate()
  564.         boolActive=true
  565.        
  566.     return 1
  567.   end
  568.  
  569. function script.Deactivate()
  570. boolActive=false
  571.  
  572.  
  573.     return 0
  574.   end
  575.  
  576.  
  577. function script.Create()
  578. Hide(pivot01)
  579. Hide(pivot)
  580. Signal(SIG_SPAM)
  581. end
Add Comment
Please, Sign In to add comment