|
Page 1 of 1
|
[ 10 posts ] |
|
Script: Recharging guns, no manual reloading
Author |
Message |
Gotcha!
Joined: Tue Apr 01, 2008 4:49 pm Posts: 1972 Location: The Netherlands
|
Script: Recharging guns, no manual reloading
Helloes, I wanted to make the laser weapons in UniTec have automatic recharging, like CaveCricket's T52. So far CaveCricket has been helping me, but he's a bit busy lately, so I'd like to ask others for help as well. Right now what I have is this: Code: function Create(self)
self.reloaded = false; self.ammoCounter = 0; self.rechargeTimer = Timer(); self.rechargeDelay = 100; self.Magazine.RoundCount = 30;
end
function Update(self)
if self.Magazine ~= nil then if self.reloaded == false then self.reloaded = true; self.ammoCounter = self.Magazine.RoundCount; else self.ammoCounter = self.Magazine.RoundCount; end if self:IsActivated() then self.rechargeTimer:Reset(); else if self.Magazine.IsFull == false and self.rechargeTimer:IsPastSimMS(self.rechargeDelay) then self.rechargeTimer:Reset(); local ammoCheck = self.Magazine.RoundCount + 1; self.Magazine.RoundCount = ammoCheck; end end else self.reloaded = false; end
end The automatic recharging works beautifully, but one thing that I'd like to have disabled is the ability to reload the gun. CaveCricket mentioned something about having the round to be fired through lua for this, since it isn't possible to stop the gun from reloading once you empty the clip. Are there brainiacs that can help me out?
|
Wed Sep 07, 2011 1:47 pm |
|
|
Azukki
Joined: Sat Nov 03, 2007 9:44 pm Posts: 1916 Location: Flint Hills
|
Re: Script: Recharging guns, no manual reloading
Code: if self.Magazine.RoundCount == 0 then self:Deactivate() end Just plop this on the end of the update function, and autoreloads upon emptying a mag don't happen, for player-controlled actors, at least. I started to try to stop other forms of reloading, but it didn't work out. Maybe some bits of my failed partial script will be useful to you, though. Code: self.y = MovableMan:GetMOFromID(self.RootID) if self.y.ID then if self.y:IsActor() then self.z = ToActor(MovableMan:GetMOFromID(self.RootID)) self.z:GetController():SetState(Controller.WEAPON_RELOAD,false) end end
Last edited by Azukki on Wed Sep 07, 2011 8:25 pm, edited 1 time in total.
|
Wed Sep 07, 2011 2:14 pm |
|
|
Gotcha!
Joined: Tue Apr 01, 2008 4:49 pm Posts: 1972 Location: The Netherlands
|
Re: Script: Recharging guns, no manual reloading
Thanks so far. Maybe other ideas will come up. I don't mind the manual reload button. (Heck, maybe it'll be easily disableable (is that a word?) when the pie menu thing works. No idea.) But the AI should definitely stop firing when running out of ammo. I could also go the easy way and make the laser guns have a ridiculously long manual reloading time as punishment for ignoring their natural recharge. >_>
|
Wed Sep 07, 2011 2:54 pm |
|
|
Asklar
Data Realms Elite
Joined: Fri Jan 07, 2011 8:01 am Posts: 6211 Location: In your office, earning your salary.
|
Re: Script: Recharging guns, no manual reloading
I'm making some charge-up weaponry with Miggles and I faced the problem of the auto reload thingie. The problem I had was that when I clicked it used the round but it didn't fire because the gun was charging it's power, and when I got to round 1 it automatically reloaded it, so the last round wasn't working.
What I did was remove one round from the magazine manually when I fired, more specifically, when the round was created, and to achieve it I gave the gun 0 RateOfFire and made the gun reload when the round count was 0.
Uh, I don't know if that is helping in anything, but still.
And if you make the magazine have only one round and make it have 30 with lua, so if you reload it will start from one again?
|
Wed Sep 07, 2011 10:40 pm |
|
|
Azukki
Joined: Sat Nov 03, 2007 9:44 pm Posts: 1916 Location: Flint Hills
|
Re: Script: Recharging guns, no manual reloading
Heeey, that also makes the AI not reload for mag counts of 1 or more. They still reload when they run dry to zero, but if I make the device 'run dry' at 1 and stop firing, then they never reload. Just add a delay so they charge up a few rounds, and we're golden! In .ini, make the magazine round count 1. Pop this in. The AI will stop reloading, and when they run dry, they'll wait for 6 rounds to charge up before firing again. You can change self.AIChargeRounds = 6 to whatever you like. 1 round of the mag won't be accessible, and the maximum capacity is now defined in Lua. I put it to 31, but in hindsight, that was dumb, because the whole point of 30 rounds isn't to have exactly 30 rounds, but rather to have a moderately large number in that range that's pretty looking, being rounded to the nearest ten and such.The player can still manually reload, but that doesn't really matter, it just delays them and depletes their charge. I took out your bits that avoid errors when you have no mag, just to tidy up the code, since those errors only really result in a needless console message, and they only happen when you pointlessly reload on purpose. Maybe needless reloading could be utilized for some kind of awesome special secondary function, though?
|
Wed Sep 07, 2011 11:35 pm |
|
|
Gotcha!
Joined: Tue Apr 01, 2008 4:49 pm Posts: 1972 Location: The Netherlands
|
Re: Script: Recharging guns, no manual reloading
Don't take this the wrong way, but... I love you.
|
Thu Sep 08, 2011 12:32 am |
|
|
Asklar
Data Realms Elite
Joined: Fri Jan 07, 2011 8:01 am Posts: 6211 Location: In your office, earning your salary.
|
Re: Script: Recharging guns, no manual reloading
Wait, so what I thought worked for something?
|
Thu Sep 08, 2011 1:44 am |
|
|
Gotcha!
Joined: Tue Apr 01, 2008 4:49 pm Posts: 1972 Location: The Netherlands
|
Re: Script: Recharging guns, no manual reloading
It seems so. Kudos for you.
|
Thu Sep 08, 2011 2:04 am |
|
|
Azukki
Joined: Sat Nov 03, 2007 9:44 pm Posts: 1916 Location: Flint Hills
|
Re: Script: Recharging guns, no manual reloading
Well, you apparently thought of it to make reloading functionally pointless at capacities higher than 0. Which it does. But that in and of itself wasn't a problem anyways. However, that form of making reloading pointless, unlike others discussed, makes the AI acknowledge that it's pointless. AI thinking they should reload was the main problem, and your form of making it pointless was the solution. So, you tried to solve problem b which was already solved in a new way, which accidentally made problem A a piece of cake to solve, thanks to your outside the box thinking. And then I solved problems c and d, which were pretty straightforward. Grif wrote: sometimes the only thing you really need is a little seed of an idea and you can work it out.
|
Thu Sep 08, 2011 2:09 am |
|
|
Asklar
Data Realms Elite
Joined: Fri Jan 07, 2011 8:01 am Posts: 6211 Location: In your office, earning your salary.
|
Re: Script: Recharging guns, no manual reloading
Well, I knew that it could probably work for something, but I didn't know what or how. Well, I'll just keep training the ways of lua scripting and see what happen, who knows, right?
|
Thu Sep 08, 2011 3:05 am |
|
|
|
|
Page 1 of 1
|
[ 10 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
|
|