Data Realms Fan Forums http://45.55.195.193/ |
|
Finding if a gun shoots, without using self:IsActivated() http://45.55.195.193/viewtopic.php?f=73&t=25741 |
Page 1 of 1 |
Author: | Kettenkrad [ Thu Oct 06, 2011 11:57 am ] |
Post subject: | Finding if a gun shoots, without using self:IsActivated() |
Hello, brilliant, talented, wondrous .lua scripters of DRLFF. I seek guidance in the ways of .lua. So, what I've got is a gun that sort of overheats, thanks to snippets of Asklar and Coops's code. In order to efficiently achieve the desired effect, I need to find when the gun (emits? creates? the particle) shoots. self.IsActivated() has failed me, as the fire command can be held down for many, many frames. If any of you could point me in the right direction I'd love to go back and tinker with the script. EDIT: And if possible I would prefer the gun to retain it's unlimited ammo. I have tried: (In no particular order) - Using a 'break' (failed miserably) - Finding if the bullet itself is created and within range (partially worked) - Using IsActivated() (no dice) - Giving the mag 1 round and checking if the gun reloads. (nope) And various other methods. As you can clearly see, much of this script was made by me! I'm very proud of my horrible job. Thanks in advance. |
Author: | Xery [ Thu Oct 06, 2011 12:41 pm ] |
Post subject: | Re: Finding if a gun shoots, without using self:IsActivated() |
Quote: function_create originalroundcount = self.roundcount cooldowntimer = Timer() cooldowntime = 500 overheat = 0 overheatlimit = 50 function_update if self.roundcount < originalroundcount then <------fire checked overheat = overheat + originalroundcount - self.roundcount originalroundcount = self.roundcount cooldowntimer:Reset() elseif self.roundcount < originalroundcount then <------reload originalroundcount = self.roundcount end if cooldowntimer:IsPastSimMS(cooldowntime) and overheat >= 0 then overheat = overheat - 1 <------cooldown end if overheat >= overheatlimit then (make the gun unable to shoot) end how about this |
Author: | Kettenkrad [ Thu Oct 06, 2011 12:44 pm ] |
Post subject: | Re: Finding if a gun shoots, without using self:IsActivated() |
Oh right, and the gun has infinite ammo, sorry. Kidding, I'll give it a shot, thanks. EDIT: I'd prefer if it retained it's unlimited ammo. Any way to get around this? |
Author: | Xery [ Thu Oct 06, 2011 12:54 pm ] |
Post subject: | Re: Finding if a gun shoots, without using self:IsActivated() |
Oh, and how about the self.parent:GetController():IsState(14)? Is it the same as IsActivated()? |
Author: | Kettenkrad [ Thu Oct 06, 2011 12:59 pm ] |
Post subject: | Re: Finding if a gun shoots, without using self:IsActivated() |
From what I've seen, most likely. I'll have a look. EDIT: Nope, same effect. |
Author: | CaveCricket48 [ Thu Oct 06, 2011 2:51 pm ] |
Post subject: | Re: Finding if a gun shoots, without using self:IsActivated() |
You could just do complete Lua firing, instead of a hybrid between INI and Lua. That way, you'd have control over bullet spawning and you can use timers to make sure everything is synchornized nicely. But, if you don't want to go full Lua, you could set your gun's Sharpness to 0 in INI. Then, have a script on the bullets that find the parent gun and change that sharpness when they're first created. Then you can just check the gun's sharpness if it fired a bullet or not and reset the Sharpness back to 0 after you're done doing your stuff. |
Author: | akblabla [ Thu Oct 06, 2011 7:29 pm ] |
Post subject: | Re: Finding if a gun shoots, without using self:IsActivated() |
Look at my recoil script of the autocannon from the trapper mod, it uses the self.IsActivated(), but detects exactly when the particle is fired using timers and RateOfFire to find out when a shot is actually fired. Here is the code stripped to its basics Code: function Create(self) self.ShootTimer = Timer() self.Clicked = false end function Update(self) if self:IsActivated() then if self.ShootTimer:IsPastSimMS(60000/self.RateOfFire) and self.Clicked then self.ShootTimer:Reset() -- add stuff here self.Clicked = false end else self.Clicked = true end end Remove the "self.Clicked" part if the gun is full automatic |
Author: | Kettenkrad [ Fri Oct 07, 2011 1:52 am ] |
Post subject: | Re: Finding if a gun shoots, without using self:IsActivated() |
Thank you both, I ended up using akblabla's method, it required less work on my part Works wonderfully now. |
Author: | Azukki [ Tue Oct 11, 2011 12:25 am ] |
Post subject: | Re: Finding if a gun shoots, without using self:IsActivated() |
Edit: It seems I poorly skimmed through the thread and have made a fool of myself, whoops. |
Author: | CaveCricket48 [ Tue Oct 11, 2011 12:35 am ] |
Post subject: | Re: Finding if a gun shoots, without using self:IsActivated() |
Magazine RoundCount checking has already been suggested, but Kettenkrad wrote: EDIT: And if possible I would prefer the gun to retain it's unlimited ammo. |
Author: | robolee [ Sat Oct 15, 2011 4:27 pm ] |
Post subject: | Re: Finding if a gun shoots, without using self:IsActivated() |
What I ended up using in my portal gun script (edited for your own use): Code: self.Parent = MovableMan:GetMOFromID(MovableMan:GetRootMOID(self.RootID)); if MovableMan:IsActor(self.Parent) then self.Parent = ToActor(self.Parent); if (not(self.wait)) then if self.Parent:GetController():IsState(Controller.PRESS_PRIMARY) then self.fire=true; end end end if (self.wait) and (self.timer:IsPastSimMS(500)) then --change timer to match rate of fire self.wait=false; end if (self.fire) then self.timer:Reset(); self.wait=true; self.fire=false; end Basically there are two variables that control the shooting, self.fire and self.wait, both of them are initialized to false, so if the shoot button is pressed, self.fire is set to true and the firing code is run, then fire is set to false and wait is set to true, when wait is set the fire function cannot run until the timer has reached a threshold and it repeats. It's not the most accurate on timing but it's decent enough. You will have to change Controller.PRESS_PRIMARY to Controller.PRIMARY_HELD or something like that, I can't remember. |
Page 1 of 1 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |