Jump to content
Sign in to follow this  
_qor

code instead of switch-trigger?

Recommended Posts

Hey there,

is there a code which I can use instead of a switch-trigger?

I want to free a captive mate by addAction and then setting him to setCpative false, setUnitPos "AUTO" and so on...

At first, I achieved this by a trigger when player is in a certain range, but it is very more comfortable having this on using an action!

Otherwise a code which checks if the action has been already used would help a lot as well!

Share this post


Link to post
Share on other sites

In single player or multiplayer? The trick with this in multiplayer is that ever client needs to have the action added to them and then removed after being used. So your script would have to do that kind of thing.

A trick for this is to go back to using triggers since those are executed on every PC. So you'll have four parts to this.

init of the unit named HVT:

hostageAction = this addAction ["Rescue Hostage", "rescue.sqf"]; this setCaptive true; this setUnitPos "DOWN"; removeAllWeapons this;

This adds the action to the unit on everyone's PC so anyone can rescue them.

script of the rescue.sqf:

hostageRescued = true;
publicVariable "hostageRescued";

This sets the variable hostageRescued to something which will be picked up by the trigger.

trigger condition:

!isNil "hostageRescued"

trigger onAct:

nul = [HVT] execVM "freehostage.sqf";

The trigger waits for the variable to be created then runs the script to free the HVT.

freehostage.sqf:

_unit = _this select 0;
_unit removeAction hostageAction;
_unit setCaptive false;
_unit setUnitPos "AUTO";
player sideChat "The hostage is free!";

This code is what will free the unit.

Share this post


Link to post
Share on other sites

Sorry for really not giving a good description of my problem!

I was asking because there are several enemy units which should move to the hostage's position when the action "Free hostage" has been used!

So I'd like to add a code to my script which is kind of a switch-trigger for a "HOLD" waypoint, or - for the trigger INGAME - something which fires when the action has been used!

For some other missions I am working on, I really would know if there is a code which checks if addAction has been used!

Share this post


Link to post
Share on other sites

It would be the same, simply synch (F5) the !isNil "hostageRescued" trigger to the HOLD waypoint that is keeping the enemy units in place. Once the trigger goes off the HOLD is released and they move to their next waypoint, presumably where the hostage was.

For some other missions I am working on, I really would know if there is a code which checks if addAction has been used!

addAction is "local" meaning everything happens only on the client which used it. This is why we used a combination of a trigger looking for a variable (since that will run on all clients) and the use of the publicVariable command which "broadcasts" the value of that variable to all clients. So to let other clients know an addAction was used really depends on what it's supposed to be doing.

If all you're doing is deleting something you don't have to do anything since the effect of deleteVehicle is global, so everyone will know about it. But if it's to send a message you'd need to have all clients display the message or else just one guy gets it.

Share this post


Link to post
Share on other sites

Aaaaah alright. I really need to get used to those work arounds!

But it also works when I add "hostageResucued = true" to the script and adding "hostageRescued" to the trigger which should switch a HOLD waypoint.

I am new to all of that scripting, so why do you use !isNil and what does this code do at all?

Share this post


Link to post
Share on other sites

Yup, that's how I used to do it. Put rescued = false in the init.sqf then have the trigger look for rescued (being set to true by the addAction) but the problem pointed out by neokika is that if someone joins the game late the init.sqf for them will set it back to false which might cause problems.

So instead you just leave the variable uninitiated (nil in otherwords) till you're ready to set it. So if someone comes in later they just get the current value (exists or not) instead of setting it back to default.

So the !isNil variable means "Is the value of 'variable' not nil" or "does the variable have a value". If not, as in never been set, it's false, but once you create it and give it a value then it's no longer "not nil" and becomes true.

So yeah your way does work usually, but in multiplayer might have some issues which is why I've tried to start using this trick. :)

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×