View unanswered posts | View active topics It is currently Sat Apr 27, 2024 11:33 am



Reply to topic  [ 9 posts ] 
 Changing rate of fire via lua 
Author Message
User avatar

Joined: Tue Mar 22, 2011 9:26 pm
Posts: 14
Reply with quote
Post Changing rate of fire via lua
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:

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?


Fri Dec 23, 2011 6:13 pm
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Tue May 25, 2010 8:27 pm
Posts: 4521
Location: Constant motion
Reply with quote
Post Re: Changing rate of fire via lua
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
Profile
User avatar

Joined: Tue Mar 22, 2011 9:26 pm
Posts: 14
Reply with quote
Post 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!


Fri Dec 23, 2011 6:56 pm
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Tue May 25, 2010 8:27 pm
Posts: 4521
Location: Constant motion
Reply with quote
Post Re: Changing rate of fire via lua
Code:
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
Profile
User avatar

Joined: Tue Mar 22, 2011 9:26 pm
Posts: 14
Reply with quote
Post 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
Profile
User avatar

Joined: Mon Oct 25, 2010 5:51 am
Posts: 1198
Location: Sydney
Reply with quote
Post 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
Profile
User avatar

Joined: Tue Mar 22, 2011 9:26 pm
Posts: 14
Reply with quote
Post 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
Profile
User avatar

Joined: Sat Nov 03, 2007 9:44 pm
Posts: 1916
Location: Flint Hills
Reply with quote
Post 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


Mon Dec 26, 2011 10:11 pm
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Tue May 25, 2010 8:27 pm
Posts: 4521
Location: Constant motion
Reply with quote
Post Re: Changing rate of fire via lua
That never even crossed my mind, nice catch azukki.


Thu Dec 29, 2011 4:21 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 9 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.358s | 15 Queries | GZIP : Off ]