Jump to content

Scripting. How to check if a weapon has still ammo


Recommended Posts

I am trying to set up a cutscene that actually has alternative dialogue if i have used my only bomb for something, yes or no. 

My first thought was that the item can only be used by blowing something up (which works)  and then doing it via variables, which i can set in a cutscene or so, however, I was thinking of making the item a thermal detinator, which you should also be able to lob to an enemy. I been scrolling through behaved and I dont see really an option to check for ammunition. The closest thing i can get in an if statement if a weapon is set, but i have no clue how to check if the item excists or there is ammuntion for it.

Link to comment

...After some careful thought, I think this might just be possible.

Create a massive trigger_multiple that encompasses your entire map, target it at a target_scriptrunner with the runonactivator flag, and have it check for which weapon is equipped. If the thermal detonator is equipped, change a SET_PARM value on the NPC/Player that triggered the script.

From there, you'll need to transfer the value from the player's SET_PARMs to a global variable, but there are many easy tricks to do that, depending on how your level is set up, assuming this is single player.

The downside to this is that it might slow the game down, so you'll want to activate the trigger only when needed, and deactivate it as soon as it has served it's purpose.

Link to comment

 

I have been thinking it through, i may have a sub objective then on using the item, so i technically cant toss it or lob it to an enemy. not using the item then is easier to handle, by pushing it into a variable and then checking in the next level if you havent used it. if not you still have the item, and you can then use it somewhere else.

I am just curious how to check for it now. and if ammo is available... there should be a way to check it, imho

Link to comment

You can exploit the SET_VIDEO_PLAY here to make the player equip the weapon - then check if that succeeded:

//(BHVD)
set ( /*@SET_TYPES*/ "SET_VIDEO_PLAY", ";weapon 10" );

affect ( "player", /*@AFFECT_TYPE*/ FLUSH )
{

	if ( $get( STRING, "SET_WEAPON")$, $=$, "WP_THERMAL" )
	{
		print ( "!WP_THERMAL is equipped and thus still in inventory" );
	}


	if ( $get( STRING, "SET_WEAPON")$, $!$, "WP_THERMAL" )
	{
		print ( "!WP_THERMAL is NOT equipped because you are out of ammo" );
	}

}

If you  are using OpenJK, which can query and set cvars - there is a way to hide the .roq not found message temporarily, if you're interested...

 

If you want to overengineer this, you can even revert to the previously selected weapon - depending on whether this happens when the player still is in control or not.

Link to comment
On 6/22/2022 at 10:43 PM, mjt said:

You can exploit the SET_VIDEO_PLAY here to make the player equip the weapon - then check if that succeeded:

//(BHVD)
set ( /*@SET_TYPES*/ "SET_VIDEO_PLAY", ";weapon 10" );

affect ( "player", /*@AFFECT_TYPE*/ FLUSH )
{

	if ( $get( STRING, "SET_WEAPON")$, $=$, "WP_THERMAL" )
	{
		print ( "!WP_THERMAL is equipped and thus still in inventory" );
	}


	if ( $get( STRING, "SET_WEAPON")$, $!$, "WP_THERMAL" )
	{
		print ( "!WP_THERMAL is NOT equipped because you are out of ammo" );
	}

}

If you  are using OpenJK, which can query and set cvars - there is a way to hide the .roq not found message temporarily, if you're interested...

 

If you want to overengineer this, you can even revert to the previously selected weapon - depending on whether this happens when the player still is in control or not.

I am gonna play with it. I play via openJK, so it might aswell be for the message. This is just the end cutscene before level switch, so that over engineer part is not needed. Its a piece of dialogue that will be set in whenever you still have the thermal detinator. (but i may need to call on it again in a level further) So this would help yes.

mjt likes this
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...