View unanswered posts | View active topics It is currently Wed Sep 20, 2017 1:23 am



Reply to topic  [ 8 posts ] 
 Lua firing issue 
Author Message
User avatar

Joined: Thu Oct 04, 2012 9:21 pm
Posts: 85
Location: Chile
Reply with quote
Post Lua firing issue
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. :P


Sat Feb 18, 2017 2:35 pm
Profile

Joined: Fri Sep 10, 2010 1:48 am
Posts: 625
Location: Halifax, Canada
Reply with quote
Post Re: Lua firing issue
You can probably check to be sure it's equipped - if actor.EquippedItem == self - before charging. I think that's what you want.


Sat Feb 18, 2017 9:38 pm
Profile
User avatar

Joined: Thu Oct 04, 2012 9:21 pm
Posts: 85
Location: Chile
Reply with quote
Post Re: Lua firing issue
Hmm... I've been giving that I try but it doesn't seem to work.

I just tried the original weapon and this doesn't happen with that one. I think I probably broke the code somewhere. I'll do more searching once I get home from work.


Sat Feb 18, 2017 10:19 pm
Profile

Joined: Fri Sep 10, 2010 1:48 am
Posts: 625
Location: Halifax, Canada
Reply with quote
Post Re: Lua firing issue
Sure thing, if you can't get it working I'd suggest putting conditions in (such as checking equipped item) and dropping prints to see if they ever stop being true and stuff. Equipped item should work I think, but it's been a while since I've done cc stuff so I may be mis-remembering.


Sun Feb 19, 2017 1:34 am
Profile
User avatar

Joined: Thu Oct 04, 2012 9:21 pm
Posts: 85
Location: Chile
Reply with quote
Post Re: Lua firing issue
I've been unable to find the issue. I tried with your suggestion plus some other stuff like self:IsAttached() using true/false conditions but it would either do nothing or stop the weapon from firing. D:

Edit: Scratch that, I just managed it, finally. Phew!
Only the firing flash set in the ini of the gun would sporadically appear but that's not as game breaking.

I noticed the script has some unused pieces of code. I used them and managed to fix it. The original script almost feel like it was unfinished. :O


Mon Feb 20, 2017 12:36 pm
Profile

Joined: Fri Sep 10, 2010 1:48 am
Posts: 625
Location: Halifax, Canada
Reply with quote
Post Re: Lua firing issue
I'm no help with ini stuff so I can't say anything about the muzzle flash, but I hope you figure that out too.

Glad you got it working and cleaned up. What was causing the problem?


Mon Feb 20, 2017 5:28 pm
Profile
User avatar

Joined: Thu Oct 04, 2012 9:21 pm
Posts: 85
Location: Chile
Reply with quote
Post Re: Lua firing issue
I actually couldn't find the issue causing it but I put a condition, as you suggested and it worked.

As you can see in the code I posted in the OP, there is an unused condition called "self.fireOn = false;" in the function Create(self) of the lua.

I made that one go true when the weapon is activated and go false after the beam is created. With that I could add it as a condition to create the beam in the first place. Thanks for the suggestion. :3


Mon Feb 20, 2017 6:42 pm
Profile

Joined: Fri Sep 10, 2010 1:48 am
Posts: 625
Location: Halifax, Canada
Reply with quote
Post Re: Lua firing issue
Haha yeah, looks like someone might have forgotten to finish up or clean up the original weapon script. Glad I could vaguely be of help.


Mon Feb 20, 2017 8:49 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 8 posts ] 

Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.047s | 17 Queries | GZIP : Off ]