Trying to create a charged shot sniper rifle
But it is failing. Epicly.
Everytime I think of shooting this it crashes. Plain old crash, with no messages and stuff. And the lua console is not giving me any kind of errors, so, help?
Code:
function Create(self)
self.ChargeTimer = Timer()
self.Shot = nil
end
function Update(self)
if self:IsActivated() then
if self.ChargeTimer:IsPastSimMS(1) and not self.ChargeTimer:IsPastSimMS(2499) then
self.Shot = 1
if self.Shot == 1 and not self.IsActivated() then
self.LowDamage = CreateMOPixel("Particle .22 Carbine")
self.LowDamage.Pos = self.MuzzlePos
self.LowDamage:SetWhichMOToNotHit(MovableMan:GetMOFromID(self.RootID),-1)
self.LowDamage.Vel = Vector(100,0):RadRotate(self.RotAngle)
MovableMan:AddParticle(self.LowDamage)
end
elseif self.ChargeTimer:IsPastSimMS(2500) and not self.ChargeTimer:IsPastSimMS(4999) then
self.Shot = 2
if self.Shot == 2 and not self.IsActivated() then
for i = 1, 3 do
self.NormalDamage = CreateMOPixel("Particle Carbine")
self.NormalDamage.Pos = self.MuzzlePos
self.NormalDamage:SetWhichMOToNotHit(MovableMan:GetMOFromID(self.RootID),-1)
self.NormalDamage.Vel = Vector(110,0):RadRotate(self.RotAngle)
MovableMan:AddParticle(self.NormalDamage)
end
end
elseif self.ChargeTimer:IsPastSimMS(5000) then
self.Shot = 3
if self.Shot == 3 and not self.IsActivated() then
self.ExplosiveDamage = CreateAEmitter("Particle HE Carbine")
self.ExplosiveDamage.Pos = self.MuzzlePos
self.ExplosiveDamage:SetWhichMOToNotHit(MovableMan:GetMOFromID(self.RootID),-1)
self.ExplosiveDamage.Vel = Vector(150,0):RadRotate(self.RotAngle)
MovableMan:AddParticle(self.ExplosiveDamage)
end
end
else
self.ChargeTimer:Reset()
end
end
I know there are a lot of charged-shot-type of script, but I never got any of them so I'm trying to create a more "simple" version.