function Create(self) self.reloaded = false; self.ammoCounter = 0; self.recoilTimer = Timer(); self.AIreset = false; self.recoil = 0; end function Update(self) if self.Magazine ~= nil then -- if we have a mag if self.ammoCounter ~= self.Magazine.RoundCount then -- and we've fired self.recoil = self.recoil + RangeRand(0.05,0.1)*(self.ammoCounter - self.Magazine.RoundCount); -- add recoil corresponding to the number of bullets fired end self.ammoCounter = self.Magazine.RoundCount; -- make sure we don't count any shot more than once if self.HFlipped then -- whether facing left or right self.RotAngle = self.RotAngle - self.recoil; -- recoil towards 90 else self.RotAngle = self.RotAngle + self.recoil; -- recoil towards 90 end -- AI fires in bursts, because the Grineer do. And because I'm too lazy to find some other way local actor = ToActor(MovableMan:GetMOFromID(self.RootID)); if self.recoil > 0.15 then -- if we've got too much recoil if actor and actor:IsPlayerControlled() == false then -- and we're AI self.AIreset = true; -- stop shooting end else if self.recoil < 0.00001 then -- if we've got the recoil under control self.AIreset = false; -- keep shooting end end if actor and self.AIreset then ToActor(actor):GetController():SetState(Controller.WEAPON_FIRE,false); -- don't shoot end if self:IsActivated() then self.recoil = math.max(self.recoil - self.recoilTimer.ElapsedSimTimeMS/1337,0); -- recoil decays else self.recoil = math.max(self.recoil - self.recoilTimer.ElapsedSimTimeMS/1000,0); -- recoil decays end self.recoilTimer:Reset(); else self.recoil = 0; end end