Game Development Community

Weapon State Sequence Variable?

by Zorro Davis · in Torque 3D Beginner · 03/05/2014 (10:29 am) · 8 replies

I was wondering if there was a way to change a state's name with a function or variable or something.
Heres a example of what I mean:


----on the State Sequence:

stateSequence[2] = "Draw";


----Could the name be changable with a variable like:

stateName[1] ="Fire";
stateSequence[1] = %StateSwitcher;
stateScript[1] ="onStateChange";

stateName[2] ="Bolt";
stateSequence[2] = %StateSwitcher;
stateScript[2] ="onStateChange";


////Function

function CarbineImage::onStateChange(%this,%obj,%slot)
{
if(%obj.client.quantity["State"] == 1)
{
%StateSwitcher = Fire;
}
else if(%obj.client.quantity["State"] == 0)
{
%StateSwitcher = Bolt;
}
}


If thats not possible at all, would there be a way to Hide weapon bones with script?

Im trying to make a weapon mount a silencer with animation and all but without having to create another datablock.
I was thinking I could use "StateTransitionOnLoaded / StateTransitionOnNotLoaded". But the problem is I already using that for Fire modes being "Safety On" and "Safety Off".

I wanted to try "StateTransitionGeneric0In" but I dont know how to get this to work. I put it in the Sequence and realized that there isnt way to activate that state with something like how "%obj.setImageAmmo(0,0)" works with the state
"stateTransitionOnAmmo[]".

How would "StateTransitionGeneric0In" and "StateTransitionGeneric0Out" work in a weapon?
If anyone could aid me on this idea, please show me a example.

#1
03/05/2014 (11:24 pm)
It's not possible to do just what you want, but you could emulate it by just encoding the logic of having two fire states in your state machine:
http://www.asciiflow.com/#Draw
                         +--------------+
                         |              |
 +---------------+       | add silencer |     +----------------+
 |               |+----->|              |+--->|                |
 |   ready loud  |       +--------------+     |   ready quiet  |
 |               |<-----+|              |<---+|                |
 +-----+---------+       |lose silencer |     +-----+----------+
       |   ^             |              |           |    ^
       v   |             +--------------+           v    |
 +---------+-----+                            +----------+-----+
 |               |                            |                |
 |    fire loud  |                            |    fire quiet  |
 |               |                            |                |
 +---------------+                            +----------------+

Not sure if you can hide bones in an image, I've not tried it.
#2
03/06/2014 (7:09 am)
Why all of the pains to avoid another datablock? Do you have thousands of then floating around? Trying to reduce client-side load times across a slow network?

Speaking of which - maybe we could use some sort of CRC to avoid copying datablocks on level load. As long as the checksum matches we could avoid the copy. Have to think on that one....
#3
03/06/2014 (7:19 am)
I think your solution is valid, Daniel, and I wouldn't see why you couldn't 'art it it' in reference to the actual 'silencer' geometry as a Visiblity animation to play during that particular 'State'...
#4
03/06/2014 (8:49 am)
Quote:
How would "StateTransitionGeneric0In" and "StateTransitionGeneric0Out" work in a weapon?
If anyone could aid me on this idea, please show me a example.

I use these quite extensively so I'm very familiar with them. The idea is focused around this function in shapebase:

setImageGenericTrigger (int slot, int trigger, bool state)

They're script triggered transitions, and complement stateScript. As an example, I use them as such: when you click to fire it transitions into "testfire" state that runs a function to evaluate whether the player can fire the weapon. If everything checks out I call:

%obj.setImageGenericTrigger(whatever, 0, true);

And it will transition to the state name specified by StateTransitionGeneric0In, otherwise I use stateTimeout to fall back into Ready, though I could technically use another generic trigger. In and Out represent True and False respectively.

I should note that you need to reset these triggers back to false when you're done with them, otherwise when torque switches to the state it will immediately transition because the generic trigger is still true.
#5
03/06/2014 (1:53 pm)
Well so far I have I think 300 datablocks going In my game and when I try adding 1 more datablock, my hame crashes so thats why im trying to avoid using so many datablocks by finding better ways to add features like adding a weapon attachment animation.

Andrew Mac, if you don't mind could you paste an example of what the script will look like? Ive tryed it myself but console says something like:

Unknown command setImageGenericTrigger

Thanks for you all being so helpful

#6
03/06/2014 (2:26 pm)
Quote:when I try adding 1 more datablock, my game crashes
Okay that shouldn't happen. I remember there is ahardcoded datablock limit but it's at like 4096, not 300. This probably shouldn't happen... what does the console say after a crash? Do you get an error message?
#7
03/06/2014 (2:28 pm)
stateName[0]                     = "FirstState";
stateTransitionOnTriggerDown[0]  = "SecondState";

stateName[1]                     = "SecondState";
stateScript[1]                   = "onSecondState";
stateTransitionGeneric1In[1]     = "FirstState";
function TestShapeBaseImageData::onSecondState(%this, %obj, %slot)
{
   %obj.setImageGenericTrigger(%slot, 1, true);
}

It starts in FirstState, you press a button to fire and it transitions to SecondState which then calls the onSecondState() function. This sets the generic trigger to true which causes it to transition back to FirstState. Note that if you fire it a second time it will immediately go back to FirstState without calling onSecondState() because the generic trigger is still set to true.
#8
03/06/2014 (9:00 pm)
It doesn't say anything, it just crash as soon as i launch the game