Game Development Community

Weapon state transitions

by lineage · in Torque Game Engine · 07/18/2005 (4:15 pm) · 6 replies

Im having trouble finding where the weapon state transitions check whether to move on or not.

for instance, if you really have no ammo, and the stateTransitionOnNoAmmo = "NoAmmo", it then goes to "NoAmmo" state. Where does it check in the code that there is no ammo?

I've looked deeply in shapeImage.cc and shapeBase.h. I've had no luck. Any advice would be really helpful. Thanks

#1
07/19/2005 (6:11 am)
Have you looked in the Player classes?
#2
07/19/2005 (7:11 am)
Its in the script code not the engine code

function Ammo::onInventory(%this,%obj,%amount)
{
// The ammo inventory state has changed, we need to update any
// mounted images using this ammo to reflect the new state.
for (%i = 0; %i < 8; %i++) {
if ((%image = %obj.getMountedImage(%i)) > 0)
if (isObject(%image.ammo) && %image.ammo.getId() == %this.getId())
%obj.setImageAmmo(%i,%amount != 0);
}
}

onInventory gets called whenever you play with the inventory (which is 100% script)

Setting an Image state, will have it check to see if the state changes or not, which does the transition bit and what not.
#3
04/28/2006 (2:14 pm)
I know that this post is old, but I am going to ask a question anyway.

Why is 'i' limited to a maximum value of 7? Is it related to weapon slots of 0 through 7?

Also, I am trying to follow the code to see where the real state change happens. It looks to me like 'setImageAmmo' is actually a hook into the C++ code. Is that right? If so, why would you put the actual state change code in C++ and everything else in script? I am asking because I am trying to understand how to decide when something should be in c++ and when it should be in script.
#4
04/28/2006 (2:43 pm)
All the image state machine code is in c++, you just define all it's data in script. It has _three_ methods that let you change a state other than using the automated onTriggerUp/Down (this only works for slots 0/1 by incrementing MoveTrigger0/1) or onTimeout callback. Those are

setImageLoaded
setImageAmmo
setImageTrigger

which will trigger the state settings

stateTransitionOnLoaded[x]
stateTransitionOnAmmo/NoAmmo[x]
stateTransitionOnTriggerUp/Down[x]

Though I think setImageLoaded is called by default in source somewhere... have to look into that one.

And yeah it's for the 8 image slots you can have by default.
#5
04/28/2006 (3:30 pm)
Thanks for the quick response. I had most of it, but you cleared up a few points for me. Thanks.
#6
07/29/2008 (5:28 pm)
Ok old post but we'll see if I get a response

I have set up an RPG in my game and when I run out of ammo it displays the correct empty RPG with no ammo, but when I switch to another weapon and then switch back, the RPG displays as if I have a loaded rocket in it. Any suggestions on how to fix it so it will show the image without a rocket?

When I pull the trigger it acts as if I have no ammo which is correct, but the image is wrong. Every other state seems to be working properly except for when I switch off the weapon and then switch back to it