Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Create(self)
- self.detectlength = 300; -- length of detection
- self.detectradius = 100; -- radius (half the total height) of detection at the end
- self.pixspacing = 5; -- note: don't do 0 spacing, it does bad things. also, this is only horizontal spacing at the moment
- self.effectdamage = 2; -- per shot
- self.baseammocount = 5000; -- set this to the weapon's base RoundCount to avoid the rare chance of a weird problem
- self.detectlength = self.detectlength / self.pixspacing;
- --self.detectradius = self.detectradius / self.pixspacing;
- self.detectionslope = self.detectradius/self.detectlength;
- self.anglelength = math.sqrt( math.pow(self.detectlength,2) + math.pow(self.detectradius,2) ) / self.pixspacing;
- if self.Magazine ~= nil then
- self.baseammocount = self.Magazine.RoundCount;
- end
- self.ammocount = self.baseammocount;
- self.damagelist = {};
- end
- function Update(self)
- if self.Magazine ~= nil then
- if self.Magazine.RoundCount ~= self.ammocount then
- local negativenum = 1;
- if self.HFlipped then
- negativenum = -1;
- end
- local movelong = Vector(self.pixspacing*negativenum,0):RadRotate(self.RotAngle);
- local moveanglea = Vector(self.pixspacing*negativenum,self.detectionslope):RadRotate(self.RotAngle);
- local moveangleb = Vector(self.pixspacing*negativenum,-self.detectionslope):RadRotate(self.RotAngle);
- local checkpos = Vector(self.MuzzlePos.X,self.MuzzlePos.Y);
- for i = 1, self.detectlength do
- checkpos = checkpos + movelong;
- if SceneMan.SceneWrapsX == true then
- if checkpos.X > SceneMan.SceneWidth then
- checkpos = Vector(checkpos.X - SceneMan.SceneWidth,checkpos.Y);
- elseif checkpos.X < 0 then
- checkpos = Vector(SceneMan.SceneWidth + checkpos.X,checkpos.Y);
- end
- end
- if SceneMan:GetTerrMatter(checkpos.X,checkpos.Y) == 0 then
- -- DETECTING STUFF HERE
- --FrameMan:DrawLinePrimitive(checkpos + Vector(-1,0), checkpos + Vector(0,0), 120);
- --FrameMan:DrawLinePrimitive(checkpos + Vector(-1,1), checkpos + Vector(0,1), 120);
- local moCheck = SceneMan:GetMOIDPixel(checkpos.X,checkpos.Y);
- if moCheck ~= 255 then
- local mo = MovableMan:GetMOFromID( MovableMan:GetMOFromID(moCheck).RootID );
- self.damagelist[#self.damagelist+1] = mo;
- end
- --
- else
- break;
- end
- end
- local checkpos = Vector(self.MuzzlePos.X,self.MuzzlePos.Y);
- for i = 1, self.detectlength do
- checkpos = checkpos + moveanglea;
- if SceneMan.SceneWrapsX == true then
- if checkpos.X > SceneMan.SceneWidth then
- checkpos = Vector(checkpos.X - SceneMan.SceneWidth,checkpos.Y);
- elseif checkpos.X < 0 then
- checkpos = Vector(SceneMan.SceneWidth + checkpos.X,checkpos.Y);
- end
- end
- if SceneMan:GetTerrMatter(checkpos.X,checkpos.Y) == 0 then
- local checkpos2 = Vector(checkpos.X,checkpos.Y);
- if SceneMan.SceneWrapsX == true then
- if checkpos2.X > SceneMan.SceneWidth then
- checkpos2 = Vector(checkpos2.X - SceneMan.SceneWidth,checkpos2.Y);
- elseif checkpos2.X < 0 then
- checkpos2 = Vector(SceneMan.SceneWidth + checkpos2.X,checkpos2.Y);
- end
- end
- -- DETECTING STUFF HERE
- --FrameMan:DrawLinePrimitive(checkpos + Vector(-1,0), checkpos + Vector(0,0), 120);
- --FrameMan:DrawLinePrimitive(checkpos + Vector(-1,1), checkpos + Vector(0,1), 120);
- local moCheck = SceneMan:GetMOIDPixel(checkpos.X,checkpos.Y);
- if moCheck ~= 255 then
- local mo = MovableMan:GetMOFromID( MovableMan:GetMOFromID(moCheck).RootID );
- self.damagelist[#self.damagelist+1] = mo;
- end
- --
- for j = 1, self.detectlength - i do
- checkpos2 = checkpos2 + movelong;
- if SceneMan.SceneWrapsX == true then
- if checkpos2.X > SceneMan.SceneWidth then
- checkpos2 = Vector(checkpos2.X - SceneMan.SceneWidth,checkpos2.Y);
- elseif checkpos2.X < 0 then
- checkpos2 = Vector(SceneMan.SceneWidth + checkpos2.X,checkpos2.Y);
- end
- end
- if SceneMan:GetTerrMatter(checkpos2.X,checkpos2.Y) == 0 then
- -- DETECTING STUFF HERE
- --FrameMan:DrawLinePrimitive(checkpos2 + Vector(-1,0), checkpos2 + Vector(0,0), 120);
- --FrameMan:DrawLinePrimitive(checkpos2 + Vector(-1,1), checkpos2 + Vector(0,1), 120);
- local moCheck = SceneMan:GetMOIDPixel(checkpos.X,checkpos.Y);
- if moCheck ~= 255 then
- local mo = MovableMan:GetMOFromID( MovableMan:GetMOFromID(moCheck).RootID );
- self.damagelist[#self.damagelist+1] = mo;
- end
- --
- else
- break;
- end
- end
- else
- break;
- end
- end
- local checkpos = Vector(self.MuzzlePos.X,self.MuzzlePos.Y);
- for i = 1, self.detectlength do
- checkpos = checkpos + moveangleb;
- if SceneMan.SceneWrapsX == true then
- if checkpos.X > SceneMan.SceneWidth then
- checkpos = Vector(checkpos.X - SceneMan.SceneWidth,checkpos.Y);
- elseif checkpos.X < 0 then
- checkpos = Vector(SceneMan.SceneWidth + checkpos.X,checkpos.Y);
- end
- end
- if SceneMan:GetTerrMatter(checkpos.X,checkpos.Y) == 0 then
- local checkpos2 = Vector(checkpos.X,checkpos.Y);
- if SceneMan.SceneWrapsX == true then
- if checkpos2.X > SceneMan.SceneWidth then
- checkpos2 = Vector(checkpos2.X - SceneMan.SceneWidth,checkpos2.Y);
- elseif checkpos2.X < 0 then
- checkpos2 = Vector(SceneMan.SceneWidth + checkpos2.X,checkpos2.Y);
- end
- end
- -- DETECTING STUFF HERE
- --FrameMan:DrawLinePrimitive(checkpos + Vector(-1,0), checkpos + Vector(0,0), 120);
- --FrameMan:DrawLinePrimitive(checkpos + Vector(-1,1), checkpos + Vector(0,1), 120);
- local moCheck = SceneMan:GetMOIDPixel(checkpos.X,checkpos.Y);
- if moCheck ~= 255 then
- local mo = MovableMan:GetMOFromID( MovableMan:GetMOFromID(moCheck).RootID );
- self.damagelist[#self.damagelist+1] = mo;
- end
- --
- for j = 1, self.detectlength - i do
- checkpos2 = checkpos2 + movelong;
- if SceneMan.SceneWrapsX == true then
- if checkpos2.X > SceneMan.SceneWidth then
- checkpos2 = Vector(checkpos2.X - SceneMan.SceneWidth,checkpos2.Y);
- elseif checkpos2.X < 0 then
- checkpos2 = Vector(SceneMan.SceneWidth + checkpos2.X,checkpos2.Y);
- end
- end
- if SceneMan:GetTerrMatter(checkpos2.X,checkpos2.Y) == 0 then
- -- DETECTING STUFF HERE
- --FrameMan:DrawLinePrimitive(checkpos2 + Vector(-1,0), checkpos2 + Vector(0,0), 120);
- --FrameMan:DrawLinePrimitive(checkpos2 + Vector(-1,1), checkpos2 + Vector(0,1), 120);
- local moCheck = SceneMan:GetMOIDPixel(checkpos.X,checkpos.Y);
- if moCheck ~= 255 then
- local mo = MovableMan:GetMOFromID( MovableMan:GetMOFromID(moCheck).RootID );
- self.damagelist[#self.damagelist+1] = mo;
- end
- --
- else
- break;
- end
- end
- else
- break;
- end
- end
- local damageamount = self.ammocount - self.Magazine.RoundCount;
- for i = 1, #self.damagelist do
- if self.damagelist[i] ~= nil then
- if MovableMan:IsActor(self.damagelist[i]) and self.damagelist[i].Team ~= self.Team then
- ToActor(self.damagelist[i]).Health = ToActor(self.damagelist[i]).Health - (damageamount*self.effectdamage/self.damagelist[i].Mass);
- end
- -- remove duplicates
- for j = i+1, #self.damagelist do
- if self.damagelist[j] ~= nil and self.damagelist[i].ID == self.damagelist[j].ID then
- self.damagelist[j] = nil;
- end
- end
- end
- end
- self.damagelist = {};
- self.ammocount = self.Magazine.RoundCount;
- end
- else
- self.ammocount = self.baseammocount;
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement