So I made a weapon using the Dummy Annihilator as base. It's less powerful and needs to be completely charged before it releases the beam.
The issue is the weapon continues to charge the shot when you fire another gun in your inventory. When you switch back to it, it will instantly release a beam, sometimes even damaging the gun itself. I have been unable to find the issue so far. Halp! D:
Here's the code:
Code:
function Create(self)
self.fireTimer = Timer();
self.blinkTimer = Timer();
self.chargeTimer = Timer();
self.effectTimer = Timer();
self.fireOn = false;
self.particleTable = {};
self.glowCount = 0;
self.glowIncrementCount = 0;
self.chargeCounter = 0;
self.glowChargeIncrement = 0.4;
self.maxCharge = 30;
self.chargesPerSecond = 15;
end
function Update(self)
if self:IsAttached() then
local actor = MovableMan:GetMOFromID(self.RootID);
if MovableMan:IsActor(actor) and ToActor(actor):IsPlayerControlled() == false then
ToActor(actor):GetController():SetState(Controller.BODY_CROUCH,false);
end
end
if self:IsActivated() then
if self.fireTimer:IsPastSimMS(2500) then
local actor = MovableMan:GetMOFromID(self.RootID);
if MovableMan:IsActor(actor) and ToActor(actor):IsPlayerControlled() == false then
ToActor(actor):GetController():SetState(Controller.WEAPON_FIRE,false);
end
end
if self.fireTimer:IsPastSimMS(2800) then
local actor = MovableMan:GetMOFromID(self.RootID);
if MovableMan:IsActor(actor) and ToActor(actor):IsPlayerControlled() == true then
ToActor(actor):GetController():SetState(Controller.WEAPON_FIRE,false);
end
end
if self.glowCount < 10 and self.effectTimer:IsPastSimMS(550-((self.chargeCounter/self.maxCharge)*500)) then
self.glowCount = self.glowCount + 1;
local effectPar = CreateMOPixel("Priest Effect Particle");
effectPar.Pos = self.MuzzlePos;
effectPar.PinStrength = 1000;
MovableMan:AddParticle(effectPar);
self.particleTable[#self.particleTable+1] = effectPar;
end
if self.chargeCounter <= self.maxCharge then
self.chargeCounter = math.min(self.chargeCounter + ((self.chargeTimer.ElapsedSimTimeMS/1000)*self.chargesPerSecond),self.maxCharge);
self.chargeTimer:Reset();
end
for i = 1, #self.particleTable do
if MovableMan:IsParticle(self.particleTable[i]) then
self.particleTable[i].ToDelete = false;
self.particleTable[i].ToSettle = false;
self.particleTable[i].PinStrength = 1000;
self.particleTable[i].Pos = self.MuzzlePos;
end
end
if self.effectTimer:IsPastSimMS(550-((self.chargeCounter/self.maxCharge)*500)) then
self.effectTimer:Reset();
local actor = MovableMan:GetMOFromID(self.RootID);
local effectPar = CreateMOPixel("Priest Effect Particle 2");
effectPar.Pos = self.MuzzlePos;
effectPar.Vel = Vector(40,0):RadRotate(math.random()*(math.pi*2));
effectPar:SetWhichMOToNotHit(MovableMan:GetMOFromID(self.RootID),-1);
if MovableMan:IsActor(actor) then
effectPar.Team = ToActor(actor).Team;
effectPar.IgnoresTeamHits = true;
end
MovableMan:AddParticle(effectPar);
end
else
if self.fireTimer:IsPastSimMS(2400) then
if self.HFlipped == false then
self.reverseNum = 1;
else
self.reverseNum = -1;
end
local actor = MovableMan:GetMOFromID(self.RootID);
for i = 1, self.chargeCounter do
local damagePar = CreateMOPixel("Priest Laser Particle");
damagePar.Pos = self.MuzzlePos + Vector(((i-1)*-1)*self.reverseNum,0):RadRotate(self.RotAngle);
damagePar.Vel = Vector(200*self.reverseNum,0):RadRotate(self.RotAngle);
damagePar:SetWhichMOToNotHit(MovableMan:GetMOFromID(self.RootID),-1);
if MovableMan:IsActor(actor) then
damagePar.Team = ToActor(actor).Team;
damagePar.IgnoresTeamHits = true;
end
MovableMan:AddParticle(damagePar);
end
for i = 1, #self.particleTable do
if MovableMan:IsParticle(self.particleTable[i]) then
self.particleTable[i].ToDelete = true;
end
end
self.particleTable = {};
local soundfx = CreateAEmitter("Priest Sound Fire");
soundfx.Pos = self.MuzzlePos;
MovableMan:AddParticle(soundfx);
self.chargeCounter = 0;
self.glowCount = 0;
end
for i = 1, #self.particleTable do
if MovableMan:IsParticle(self.particleTable[i]) then
self.particleTable[i].ToDelete = true;
end
end
self.fireTimer:Reset();
self.particleTable = {};
end
end
function Destroy(self)
for i = 1, #self.particleTable do
if MovableMan:IsParticle(self.particleTable[i]) then
self.particleTable[i].ToDelete = true;
end
end
end
I have been using lua a lot lately but to be honest, I understand like half of it.