function Create(self) self.Mass = 60 --The timer that will detonate the revolver shot once 1.6 seconds have passed. self.mapwrapx = SceneMan.SceneWrapsX; self.LTimer = Timer(); self.DTimer = Timer(); self.RetardAirResistance = 0.15 self.NormalAirResistance = 0.01 self.Retarded = false --Find out who shot the weapon by finding the closest actor within 150 pixels. self.curdist = 150; for i = 1,MovableMan:GetMOIDCount()-1 do self.gun = MovableMan:GetMOFromID(i); local range = SceneMan:ShortestDistance(self.Pos,self.gun.Pos,self.mapwrapx).Magnitude if self.gun.PresetName == "Revolver Cannnon" and self.gun.ClassName == "HDFirearm" and range < self.curdist then self.curdist = range self.actor = MovableMan:GetMOFromID(self.gun.RootID); if MovableMan:IsActor(self.actor) then self.parent = ToActor(self.actor); end end end --If the weapon has no firer, make it go after anyone. Otherwise, set its team to that of the firer. if MovableMan:IsActor(self.parent) == false then self:GibThis(); end local aimAngle = self.parent:GetAimAngle(true) --print(string.format("aim: %.2f", aimAngle)) if aimAngle > math.pi / 4 and aimAngle < math.pi / 4 * 3 then self.loftMode = true else self.loftMode = false end clampedStrength = 15 if self.parent:IsPlayerControlled() then --aimPos = SceneMan:GetOffset(0) + Vector(320, 240) aimPos = self.parent.ViewPoint strength = SceneMan:ShortestDistance(self.parent.EyePos, aimPos, self.mapwrapx).Magnitude print(string.format("strength: %.2f", strength)) print(string.format("view offset: %.2f %.2f", (self.parent.ViewPoint - self.parent.EyePos).X, (self.parent.ViewPoint - self.parent.EyePos).Y)) if strength > 500 then clampedStrength = clampedStrength + 80 else if strength > 50 then clampedStrength = clampedStrength + ((strength - 50) / 450) * 80 end end else clampedStrength = 60 end originalVel = math.sqrt(self.Vel.X ^ 2 + self.Vel.Y ^ 2) self.Vel = self.Vel * (clampedStrength / originalVel) end function Update(self) if self.Retarded == false then if self.parent:GetController():IsState(Controller.WEAPON_FIRE) == true then self.AirResistance = self.NormalAirResistance else self.Retarded = true self.AirResistance = self.RetardAirResistance end end local deltaTime = self.DTimer.ElapsedSimTimeMS; self.DTimer:Reset(); local velDirection = math.atan2(self.Vel.Y, self.Vel.X); --print(string.format("veldir: %.2f", velDirection / math.pi * 180.0)); local dragDirection = Vector(-math.cos(velDirection), -math.sin(velDirection)); local velocity = math.sqrt(self.Vel.X ^ 2 + self.Vel.Y ^ 2); local drag = self.AirResistance * velocity local dragForce = Vector(drag * dragDirection.X, drag * dragDirection.Y) --print(string.format("drag: %.2f, %.2f", dragForce.X, dragForce.Y)) local accX = dragForce.X / self.Mass * deltaTime local accY = dragForce.Y / self.Mass * deltaTime --print(string.format("vel: %.2f, %.2f accl: %.2f, %.2f", self.Vel.X, self.Vel.Y, accX, accY)) self.Vel.X = self.Vel.X + accX self.Vel.Y = self.Vel.Y + accY local fuzeDistance = 45; if self.LTimer:IsPastSimMS(100) then for actor in MovableMan.Actors do local dist = SceneMan:ShortestDistance(self.Pos, actor.Pos, self.mapwrapx).Magnitude if dist < fuzeDistance and actor.ID ~= self.parent.ID and actor.Team ~= self.parent.Team then self:GibThis(); end end end --print(string.format("vel: %.2f, %2f", self.Vel.X, self.Vel.Y)) if self.loftMode == true then if math.abs(self.Vel.X) < 0.5 and self.Vel.Y > 0 and self.LTimer:IsPastSimMS(100) then --print(string.format("alt: %.2f", self:GetAltitude(100, 5))) if self:GetAltitude(100, 5) <= 50 then self:GibThis(); end end end if self.LTimer:IsPastSimMS(10000) then self:GibThis(); end end