Advertisement
Guest User

Untitled

a guest
Mar 29th, 2015
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.68 KB | None | 0 0
  1. function Create(self)
  2.  
  3. self.detectlength = 300; -- length of detection
  4. self.detectradius = 100; -- radius (half the total height) of detection at the end
  5. self.pixspacing = 5; -- note: don't do 0 spacing, it does bad things. also, this is only horizontal spacing at the moment
  6. self.effectdamage = 2; -- per shot
  7.  
  8. self.baseammocount = 5000; -- set this to the weapon's base RoundCount to avoid the rare chance of a weird problem
  9.  
  10. self.detectlength = self.detectlength / self.pixspacing;
  11. --self.detectradius = self.detectradius / self.pixspacing;
  12. self.detectionslope = self.detectradius/self.detectlength;
  13. self.anglelength = math.sqrt( math.pow(self.detectlength,2) + math.pow(self.detectradius,2) ) / self.pixspacing;
  14.  
  15. if self.Magazine ~= nil then
  16. self.baseammocount = self.Magazine.RoundCount;
  17. end
  18. self.ammocount = self.baseammocount;
  19.  
  20. self.damagelist = {};
  21.  
  22. end
  23.  
  24. function Update(self)
  25.  
  26. if self.Magazine ~= nil then
  27. if self.Magazine.RoundCount ~= self.ammocount then
  28.  
  29. local negativenum = 1;
  30. if self.HFlipped then
  31. negativenum = -1;
  32. end
  33.  
  34. local movelong = Vector(self.pixspacing*negativenum,0):RadRotate(self.RotAngle);
  35. local moveanglea = Vector(self.pixspacing*negativenum,self.detectionslope):RadRotate(self.RotAngle);
  36. local moveangleb = Vector(self.pixspacing*negativenum,-self.detectionslope):RadRotate(self.RotAngle);
  37.  
  38. local checkpos = Vector(self.MuzzlePos.X,self.MuzzlePos.Y);
  39.  
  40. for i = 1, self.detectlength do
  41.  
  42. checkpos = checkpos + movelong;
  43.  
  44. if SceneMan.SceneWrapsX == true then
  45. if checkpos.X > SceneMan.SceneWidth then
  46. checkpos = Vector(checkpos.X - SceneMan.SceneWidth,checkpos.Y);
  47. elseif checkpos.X < 0 then
  48. checkpos = Vector(SceneMan.SceneWidth + checkpos.X,checkpos.Y);
  49. end
  50. end
  51.  
  52. if SceneMan:GetTerrMatter(checkpos.X,checkpos.Y) == 0 then
  53.  
  54. -- DETECTING STUFF HERE
  55. --FrameMan:DrawLinePrimitive(checkpos + Vector(-1,0), checkpos + Vector(0,0), 120);
  56. --FrameMan:DrawLinePrimitive(checkpos + Vector(-1,1), checkpos + Vector(0,1), 120);
  57.  
  58. local moCheck = SceneMan:GetMOIDPixel(checkpos.X,checkpos.Y);
  59. if moCheck ~= 255 then
  60. local mo = MovableMan:GetMOFromID( MovableMan:GetMOFromID(moCheck).RootID );
  61. self.damagelist[#self.damagelist+1] = mo;
  62. end
  63.  
  64. --
  65.  
  66. else
  67. break;
  68. end
  69.  
  70. end
  71.  
  72. local checkpos = Vector(self.MuzzlePos.X,self.MuzzlePos.Y);
  73.  
  74. for i = 1, self.detectlength do
  75.  
  76. checkpos = checkpos + moveanglea;
  77.  
  78. if SceneMan.SceneWrapsX == true then
  79. if checkpos.X > SceneMan.SceneWidth then
  80. checkpos = Vector(checkpos.X - SceneMan.SceneWidth,checkpos.Y);
  81. elseif checkpos.X < 0 then
  82. checkpos = Vector(SceneMan.SceneWidth + checkpos.X,checkpos.Y);
  83. end
  84. end
  85.  
  86. if SceneMan:GetTerrMatter(checkpos.X,checkpos.Y) == 0 then
  87.  
  88. local checkpos2 = Vector(checkpos.X,checkpos.Y);
  89.  
  90. if SceneMan.SceneWrapsX == true then
  91. if checkpos2.X > SceneMan.SceneWidth then
  92. checkpos2 = Vector(checkpos2.X - SceneMan.SceneWidth,checkpos2.Y);
  93. elseif checkpos2.X < 0 then
  94. checkpos2 = Vector(SceneMan.SceneWidth + checkpos2.X,checkpos2.Y);
  95. end
  96. end
  97.  
  98. -- DETECTING STUFF HERE
  99. --FrameMan:DrawLinePrimitive(checkpos + Vector(-1,0), checkpos + Vector(0,0), 120);
  100. --FrameMan:DrawLinePrimitive(checkpos + Vector(-1,1), checkpos + Vector(0,1), 120);
  101.  
  102. local moCheck = SceneMan:GetMOIDPixel(checkpos.X,checkpos.Y);
  103. if moCheck ~= 255 then
  104. local mo = MovableMan:GetMOFromID( MovableMan:GetMOFromID(moCheck).RootID );
  105. self.damagelist[#self.damagelist+1] = mo;
  106. end
  107. --
  108.  
  109. for j = 1, self.detectlength - i do
  110. checkpos2 = checkpos2 + movelong;
  111.  
  112. if SceneMan.SceneWrapsX == true then
  113. if checkpos2.X > SceneMan.SceneWidth then
  114. checkpos2 = Vector(checkpos2.X - SceneMan.SceneWidth,checkpos2.Y);
  115. elseif checkpos2.X < 0 then
  116. checkpos2 = Vector(SceneMan.SceneWidth + checkpos2.X,checkpos2.Y);
  117. end
  118. end
  119.  
  120. if SceneMan:GetTerrMatter(checkpos2.X,checkpos2.Y) == 0 then
  121.  
  122. -- DETECTING STUFF HERE
  123. --FrameMan:DrawLinePrimitive(checkpos2 + Vector(-1,0), checkpos2 + Vector(0,0), 120);
  124. --FrameMan:DrawLinePrimitive(checkpos2 + Vector(-1,1), checkpos2 + Vector(0,1), 120);
  125.  
  126. local moCheck = SceneMan:GetMOIDPixel(checkpos.X,checkpos.Y);
  127. if moCheck ~= 255 then
  128. local mo = MovableMan:GetMOFromID( MovableMan:GetMOFromID(moCheck).RootID );
  129. self.damagelist[#self.damagelist+1] = mo;
  130. end
  131. --
  132.  
  133. else
  134. break;
  135. end
  136.  
  137. end
  138. else
  139. break;
  140. end
  141.  
  142. end
  143.  
  144. local checkpos = Vector(self.MuzzlePos.X,self.MuzzlePos.Y);
  145.  
  146. for i = 1, self.detectlength do
  147.  
  148. checkpos = checkpos + moveangleb;
  149.  
  150. if SceneMan.SceneWrapsX == true then
  151. if checkpos.X > SceneMan.SceneWidth then
  152. checkpos = Vector(checkpos.X - SceneMan.SceneWidth,checkpos.Y);
  153. elseif checkpos.X < 0 then
  154. checkpos = Vector(SceneMan.SceneWidth + checkpos.X,checkpos.Y);
  155. end
  156. end
  157.  
  158. if SceneMan:GetTerrMatter(checkpos.X,checkpos.Y) == 0 then
  159.  
  160. local checkpos2 = Vector(checkpos.X,checkpos.Y);
  161.  
  162. if SceneMan.SceneWrapsX == true then
  163. if checkpos2.X > SceneMan.SceneWidth then
  164. checkpos2 = Vector(checkpos2.X - SceneMan.SceneWidth,checkpos2.Y);
  165. elseif checkpos2.X < 0 then
  166. checkpos2 = Vector(SceneMan.SceneWidth + checkpos2.X,checkpos2.Y);
  167. end
  168. end
  169.  
  170. -- DETECTING STUFF HERE
  171. --FrameMan:DrawLinePrimitive(checkpos + Vector(-1,0), checkpos + Vector(0,0), 120);
  172. --FrameMan:DrawLinePrimitive(checkpos + Vector(-1,1), checkpos + Vector(0,1), 120);
  173.  
  174. local moCheck = SceneMan:GetMOIDPixel(checkpos.X,checkpos.Y);
  175. if moCheck ~= 255 then
  176. local mo = MovableMan:GetMOFromID( MovableMan:GetMOFromID(moCheck).RootID );
  177. self.damagelist[#self.damagelist+1] = mo;
  178. end
  179. --
  180.  
  181. for j = 1, self.detectlength - i do
  182. checkpos2 = checkpos2 + movelong;
  183.  
  184. if SceneMan.SceneWrapsX == true then
  185. if checkpos2.X > SceneMan.SceneWidth then
  186. checkpos2 = Vector(checkpos2.X - SceneMan.SceneWidth,checkpos2.Y);
  187. elseif checkpos2.X < 0 then
  188. checkpos2 = Vector(SceneMan.SceneWidth + checkpos2.X,checkpos2.Y);
  189. end
  190. end
  191.  
  192. if SceneMan:GetTerrMatter(checkpos2.X,checkpos2.Y) == 0 then
  193.  
  194. -- DETECTING STUFF HERE
  195. --FrameMan:DrawLinePrimitive(checkpos2 + Vector(-1,0), checkpos2 + Vector(0,0), 120);
  196. --FrameMan:DrawLinePrimitive(checkpos2 + Vector(-1,1), checkpos2 + Vector(0,1), 120);
  197.  
  198. local moCheck = SceneMan:GetMOIDPixel(checkpos.X,checkpos.Y);
  199. if moCheck ~= 255 then
  200. local mo = MovableMan:GetMOFromID( MovableMan:GetMOFromID(moCheck).RootID );
  201. self.damagelist[#self.damagelist+1] = mo;
  202. end
  203. --
  204.  
  205. else
  206. break;
  207. end
  208.  
  209. end
  210. else
  211. break;
  212. end
  213.  
  214. end
  215.  
  216. local damageamount = self.ammocount - self.Magazine.RoundCount;
  217. for i = 1, #self.damagelist do
  218. if self.damagelist[i] ~= nil then
  219. if MovableMan:IsActor(self.damagelist[i]) and self.damagelist[i].Team ~= self.Team then
  220. ToActor(self.damagelist[i]).Health = ToActor(self.damagelist[i]).Health - (damageamount*self.effectdamage/self.damagelist[i].Mass);
  221. end
  222. -- remove duplicates
  223. for j = i+1, #self.damagelist do
  224. if self.damagelist[j] ~= nil and self.damagelist[i].ID == self.damagelist[j].ID then
  225. self.damagelist[j] = nil;
  226. end
  227. end
  228. end
  229. end
  230. self.damagelist = {};
  231.  
  232. self.ammocount = self.Magazine.RoundCount;
  233. end
  234. else
  235. self.ammocount = self.baseammocount;
  236. end
  237.  
  238. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement