Data Realms Fan Forums http://868000.nnhp.asia/ |
|
Lua firing issue http://868000.nnhp.asia/viewtopic.php?f=73&t=46145 |
Page 1 of 1 |
Author: | Chiko [ Sat Feb 18, 2017 2:35 pm ] |
Post subject: | 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. |
Author: | Bad Boy [ Sat Feb 18, 2017 9:38 pm ] |
Post subject: | 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. |
Author: | Chiko [ Sat Feb 18, 2017 10:19 pm ] |
Post subject: | 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. |
Author: | Bad Boy [ Sun Feb 19, 2017 1:34 am ] |
Post subject: | 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. |
Author: | Chiko [ Mon Feb 20, 2017 12:36 pm ] |
Post subject: | 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 |
Author: | Bad Boy [ Mon Feb 20, 2017 5:28 pm ] |
Post subject: | 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? |
Author: | Chiko [ Mon Feb 20, 2017 6:42 pm ] |
Post subject: | 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 |
Author: | Bad Boy [ Mon Feb 20, 2017 8:49 pm ] |
Post subject: | 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. |
Page 1 of 1 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |