Although my lua is pretty terrible I thought that this script would be easy to throw together, but am having unexplained problems with it. I am trying to make a gun which steadily fires faster and faster, and resets to the original speed when reloaded. I put together this:
Code:
function update(self) if self.RoundInMagCount <= 95 and self.RoundInMagCount > 80 then self.RateOfFire = 225 elseif self.RoundInMagCount <= 80 and self.RoundInMagCount > 75 then self.RateOfFire = 250 elseif self.RoundInMagCount <= 75 and self.RoundInMagCount > 60 then self.RateOfFire = 275 elseif self.RoundInMagCount <= 60 and self.RoundInMagCount > 55 then self.RateOfFire = 300 elseif self.RoundInMagCount <= 55 and self.RoundInMagCount > 50 then self.RateOfFire = 325 elseif self.RoundInMagCount <= 50 and self.RoundInMagCount > 45 then self.RateOfFire = 350 elseif self.RoundInMagCount <= 45 and self.RoundInMagCount > 40 then self.RateOfFire = 400 elseif self.RoundInMagCount <= 40 and self.RoundInMagCount > 35 then self.RateOfFire = 450 elseif self.RoundInMagCount <= 35 and self.RoundInMagCount > 30 then self.RateOfFire = 500 elseif self.RoundInMagCount <= 30 and self.RoundInMagCount > 25 then self.RateOfFire = 550 elseif self.RoundInMagCount <= 25 and self.RoundInMagCount > 20 then self.RateOfFire = 600 elseif self.RoundInMagCount <= 20 and self.RoundInMagCount > 15 then self.RateOfFire = 700 elseif self.RoundInMagCount <= 15 and self.RoundInMagCount > 10 then self.RateOfFire = 800 elseif self.RoundInMagCount <= 10 and self.RoundInMagCount > 5 then self.RateOfFire = 900 elseif self.RoundInMagCount <= 5 and self.RoundInMagCount > 0 then self.RateOfFire = 1250 end end
However this doesn't seem to be working in any meaningful way. I have changed many, many things about the script, and still can't get it to work in any form. I have put print lines in to check how far it gets, and none of the steps ever seem to trigger under any circumstances. Am I missing something obvious, or am I trying to do something that isn't actually possible?
I don't think what you're trying to do is possible in the way you're doing it.
What you're probably going to have to do is replace the magazine (because I'm pretty sure the rate of fire is denoted by the magazine) at those values, instead of trying to alter a variable that doesn't exist to Lua.
Fri Dec 23, 2011 6:27 pm
Zagzag
Joined: Tue Mar 22, 2011 9:26 pm Posts: 14
Re: Changing rate of fire via lua
RateOfFire is a property of the weapon, and no similar property exists for the magazine. I had begun to suspect that you can't simply overwrite it with a new value, but I was hoping you could. Does that mean that there is no way of dynamically altering the rate of fire via lua? I suppose that if this is the case you could swap the gun for an identical one with a higher rate of fire, and the appropriate number of bullets in the magazine every time it needs to speed up, then revert to the original when it is reloaded, but this is sadly beyod my lua skills at the moment, without some serious messing around anyway!
function update(self) self.RateOfFire = (100-self.RoundInMagCount)*5+200; print(self.RateOfFire); end
Tell me what that does for you.
Fri Dec 23, 2011 8:16 pm
Zagzag
Joined: Tue Mar 22, 2011 9:26 pm Posts: 14
Re: Changing rate of fire via lua
I've just seen your post about 10 second before I have to go. I'll try it as soon as I get back and then I'll let you know.
Thanks
EDIT: It doesn't change the rate of fire, nor does it actually print anything. There are no lua console errors either. Removing the "end" does produce a lua console error, so that confirms that it is actually loading the right script and atempting to do something with it. This would seem to suggest that RateOfFire can't actually be rewritten by lua, which is rather disappointing. I'm sure there is a good reason why (if?) this is the case, but I for one can't see it...
Fri Dec 23, 2011 8:33 pm
Kettenkrad
Joined: Mon Oct 25, 2010 5:51 am Posts: 1198 Location: Sydney
Re: Changing rate of fire via lua
Shook had a lovely Dakka script that I'm sure he'd let you use. Run it by him first.
Code:
function Create(self) self.baseROF = 250 self.modROF = 0 end
function Update(self) if self:IsActivated() then if self.modROF < 550 then self.modROF = self.modROF + 3; end else self.modROF = 0; end self.RateOfFire = (self.baseROF + self.modROF); end
Sat Dec 24, 2011 11:34 pm
Zagzag
Joined: Tue Mar 22, 2011 9:26 pm Posts: 14
Re: Changing rate of fire via lua
Thanks a lot for the help. Although that script wasn't exactly what I was trying to achieve, I have been able to use it for reference to create my own sctipt to do exactly what I originally wanted. It actually works better than my original script would have done!
I still have absolutely no idea why my new sctipt works and my old one doesn't, but in situations like this it isn't usually best to complain when things work...
Mon Dec 26, 2011 1:39 pm
Azukki
Joined: Sat Nov 03, 2007 9:44 pm Posts: 1916 Location: Flint Hills
Re: Changing rate of fire via lua
It looks like tossing in a self-existence-check made veg's script work. I dunno why.
Code:
function Update(self) if self.RootID ~= 255 then self.RateOfFire = (100-self.RoundInMagCount)*5+200 print(self.RateOfFire) end end
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