Jump to content
Sign in to follow this  
mycatsaid

Addaction running code issue

Recommended Posts

Wondering if anyone can work this out. It says on the wiki that you can use addaction and run code straight from the line instead of calling a separate script file.

The script is spawning the AI (hostage) in a captive position waiting to be rescued. Once the player clicks the addaction button the hostage should be released and change animation.

I've seen people do this with triggers and if statements but this just seems an easier way if someone could work out the issue (if it is even possible). Maybe it is something simple and I haven't spotted it but I just can't get any code to run this way.

// Wait for BIS functions to load
waituntil {!isnil "BIS_fnc_init"};

// Hostage
_hostageSpawn = markerPos "hostageSpawn";
_hostageInit = [_hostageSpawn, 180, "Dr_Hladik_EP1", CIVILIAN] call bis_fnc_spawnvehicle;
hostage = _hostageInit select 0;

// Hostage Idle waiting for rescue
removeAllWeapons _hostage;
hostage disableAI "ANIM";
hostage switchmove "boundCaptive_loop";
hostage setCaptive true;
hostage setBehaviour "CARELESS";

// Hostage change to active after addaction
hostage addaction ["Release Hostage", {
hostage enableAI "ANIM";
hostage switchmove "boundCaptive_unaErc";
hostage setCaptive false;
hostage setBehaviour "CARELESS";
}];

Thanks.

Share this post


Link to post
Share on other sites

As far as I know, you cannot use addaction this way. It must call a script file.

Just copy that code into a script file and activate it.

Share this post


Link to post
Share on other sites

You can also make a funtion and let the addaction call the function. That way you do not have to make several SQF files and make a terrible lot of files in your mission. First of all you need to understand that the functions Always has to be loaded first in your init.sqf

The code in your INIT.sqf should look like this:

//First load the function.
fnc_hostage_action = {
private ["_hostage"];
_hostage = _this select 0

_hostage enableAI "ANIM";
_hostage switchmove "boundCaptive_unaErc";
_hostage setCaptive false;
_hostage setBehaviour "CARELESS";
};

// Hostage change to active after addaction
hostage addaction ["Release Hostage", "call fnc_hostage_action"];

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  

×