Game Development Community

Reloading Fun

by Chris "C2" Byars · in Torque Game Engine · 11/27/2005 (5:19 pm) · 12 replies

I have a fancy little reloading system going on, and you hit R to call the reloading function, which will in turn call the function XM8Image::ReloadAmmoClip(%this, %obj) { in this weapon case. There's a little bug though I'd like to squash and am having a bit of trouble trying to figure out how to go about doing it.

If you're holding down the fire button and firing, and hit R to reload, well, it "glitches", and doesn't show the reload animation and well doesn't really work well with the image state system.

I need help figuring out a way to disallow the function XM8Image::ReloadAmmoClip to work (or its contents to work, actually) if the trigger is down. (Or basically just in the Fire or Refire states).

Here's my weapon script.

Any aid is greatly appreciated.

#1
11/27/2005 (7:56 pm)
You probably want to query the image state and just error out if they're shooting (ie, if state==firing)?
#2
11/28/2005 (1:45 pm)
Yeah, but I'm at a loss as to how to query the image state. :/
#3
11/28/2005 (2:08 pm)
Did you try checking for methods with names like getImageState getSlotState? (dump() would help here).
#4
11/28/2005 (3:21 pm)
You dont get the slot number here check the script.
function XM8Image::ReloadAmmoClip(%this, %obj[b],%slot[/b]) {
..

%obj.manualSetImageState(%slot, Reload);

..

}

%slot in bold doesnt exist
#5
11/28/2005 (4:11 pm)
Okay... I added the %slot there. (Didn't affect anything though, but I know that should optimize things or make it more logical)

Tried the dump(), didn't provide anything seemingly useful:

Methods:
AutoReload() -
delete() -
dump() -
getClassName() -
getGroup() -
getId() -
getName() -
getType() -
onFire() -
onMount() -
onReload() -
ReloadAmmoClip() -
save() -
schedule() -
setHud() -
setName() -
#6
11/28/2005 (5:37 pm)
You should set the image ammo to 0 when reloading. It's not like the clip would be in the gun anyway.
#7
11/28/2005 (6:07 pm)
Though that does work some of the time, the states will still glitch if you hit the reload at a certain time during firing.

If only there were a way to allow the reload to work "if not in states Fire or ReFire".
#8
11/28/2005 (6:19 pm)
My system seems to work great. I don't think I've ever run into any state bugs(I have 16 weapons ATM).

Edit: Of course they need to be fully tested sometime. ;)
#9
11/28/2005 (6:20 pm)
I just seem to have a problem when the player is holding down the fire button while simultaneously deciding to reload.
#10
11/29/2005 (5:28 pm)
Well I've gotten it to work perfectly fine by throwing in a global saying you can't reload (in the functions that are called by the states of Fire and ReFire), and putting a global saying you can reload in the functions of the states that you can, as such:

function XM8Image::ReloadAmmoClip(%this, %obj, %slot) {

   if ( %obj.getInventory(%this.clip) > 0 && $CanReload $= "true" ) {

However, a nice dollar sign like that really won't work right in a networked game with more than one person, will it?
#11
11/29/2005 (6:44 pm)
Have you tried setting a %obj.canreload = true/false
in the other functions and check this one in your reloadAmmoClip function.
#12
11/29/2005 (7:08 pm)
Excellent. Works perfectly. Thanks Billy. Will test over networked play tomorrow. (though I'm sure it will work fine)