Jump to content
Sign in to follow this  
Dr_Cox1911

[Dr_Cox1911] Hostage Script

Recommended Posts

I initialized my captives with setCaptive true and disableAI "Move" so they don't run all over the map. What I can't figure out is when the code executes for them to join the players group how to re enable them to move and to cancel their captive status.

I tried this:

_arrayPOWs = [p1,p2,p3,p4];{[_x] setCaptive false; enableAI "MOVE";} forEach _arrayPOWs;

p1 etc... are the names of my captives. I put this as the last line in the sqf file which only handles the join group action. I was hoping that when they joined the group these settings could be changed on all 4 of the captives. This isn't working though it says its expecting a ";".

Edited by JMOxx75

Share this post


Link to post
Share on other sites
I initialized my captives with setCaptive true and disableAI "Move" so they don't run all over the map. What I can't figure out is when the code executes for them to join the players group how to re enable them to move and to cancel their captive status.

I tried this:

_arrayPOWs = [p1,p2,p3,p4];{[_x] setCaptive false; enableAI "MOVE";} forEach _arrayPOWs;

p1 etc... are the names of my captives. I put this as the last line in the sqf file which only handles the join group action. I was hoping that when they joined the group these settings could be changed on all 4 of the captives. This isn't working though it says its expecting a ";".

Try

{_x setCaptive false; _x enableAI "MOVE"} forEach _arrayPOWs;

instead

Share this post


Link to post
Share on other sites

Thanks, that worked. I get it now as well.

Share this post


Link to post
Share on other sites

Thanks Dr_Cox1911. I found your script to be very helpful for a mission. I love the random spawns, animation, and the fact that the OPFOR will shoot the hostages after they join your group.

I am new to the Arma editing scene. I'm still learning new tricks but when I find a problem, I feel compelled to solve it and give back. I've registered here to assist.

I managed to find a couple issues when testing multiplayer/coop. After an long search, covering public variables, CBA, MPF, and Remote Execution to solve the problem, I had an Epiphany.

1. captivevars.sqf which is executed via the addaction changes the hostage's setcaptive status to false. This works perfectly when playing single player or in multiplayer if the host did the Untie action. Unfortunately addaction scripts like captivevars.sqf are executed locally by the person using the addaction. So if another client other than the host executes it, the server cannot update the captive status which does not allow captive.sqf to continue after the waitUntil{not(captive _cap)};. This essentially breaks the script for anyone that would rescue the hostages other than the host.

2. The player based animation was somewhat buggy in Multiplayer. If the host and another player are standing too close to the hostage the wrong player can be forced into the animation.

In order to get around these issues, I make the following suggestions.

Change captivevars.sqf to:

_unit = _this select 0;  // Hostage who had the addAction
_rescuer = _this select 1;  // Rescuer who used the addAction

//Animate the person using the untie action.
_rescuer attachto [_unit,[0,-0.9,0]];
_rescuer setdir 0;
_rescuer switchMove "MountSide";	//Animation while untieing 
sleep 5;
_rescuer switchmove "";
detach _rescuer;

// Join Hostage to rescuer's group, silently.
[_unit] joinsilent _rescuer;

joinSilent works from addaction client executed scripts. So we can use a different waitUntil condition to detect when the captive joins the players group. Then we can finish executing captive.sqf on the server and completing our objectives/tasks. I also removed the player animation from captive.sqf and added it to captivevars.sqf. This appears to work just fine executed from the addaction.

Change the last section of captive.sqf to:

//waitUntil{not(captive _cap)};
waitUntil{_cap in units group player};
_cap removeaction _captureact1;
_cap setcaptive false; 	// added from captivevars.sqf
_cap disableAI "MOVE";
_cap switchmove "SitStandUp";
sleep 2;
_cap enableAI "MOVE";
_cap enableAI "autoTarget";
_cap enableAI "ANIM";
_cap setBehaviour "COMBAT";

Finally we have the new waitUntil which fires when _cap joins the player group. Then we can reset _cap to not captive, remove the addaction, and allow them to move after joining the group.

So far this method has worked perfectly from a lan listen server. I bet it works just fine on dedicated servers.

I also want to share some trigger ideas for fellow hostage mission makers.

Example All Hostages Rescued trigger:

//Name your hostages and detect when all three are in the player's group. Then complete task_1.

//Condition
(civ1 in units group player) && (civ2 in units group player) && (civ3 in units group player);

//On Act.
task_1 setTaskState "Succeeded";
["TaskSucceeded",["Hostages Rescued!"]] call bis_fnc_showNotification;

Example Mission Failure Hostage killed trigger:

//Condition
!alive civ1 or !alive civ2

//On Act.
task_1 setTaskState "Failed";
task_3 setTaskState "Failed";
"obj1" setMarkerColor "ColorRed";
"obj3" setMarkerColor "ColorRed";
["TaskFailed",["A Hostage was killed! Mission Failed."]] call bis_fnc_showNotification;

Thank Kylania for one of the best ideas for Mission Complete with hostages trigger:

//name and array the hostages POWS = [civ1,civ2] on the player init.
//When all POWS are in the helicopter named rescue1 and alive, remove the hostages from the players group and end the mission.

//Condition
(({alive _x && (_x in rescue1)} count POWS == {alive _x} count POWS) && (alive civ1 && alive civ2 && alive civ3))
//On Act.
hint "POWs rescued!";{[_x] joinSilent grpNull} forEach POWS

One thing is for sure anyone searching for an Arma 3 hostage script has found the right place with Dr_Cox1911. Happy Editing!

Edited by Prathios

Share this post


Link to post
Share on other sites

in the captive.sqf where tdo I alter the settings.

I only have one hostage that I need to rescure but I cant figure it out being a noob to editing. IF some one would help I would be grateful.

Share this post


Link to post
Share on other sites

Hello i've modifyed this line:

//####################
//DON`T CHANGE ANY CODE BELOW UNLESS YOU KNOW WHAT YOU ARE DOING!
//####################
_cap = _this select 0;

if(isServer || isDedicated)then{
//_ranPos = _positions call BIS_fnc_selectRandom;
//hint _ranPos select 1;
_cap setPos [getMarkerPos (_position select 0) select 0, getMarkerPos (_position select 0) select 1, (getMarkerPos (_position select 0) select 2) + (_position select 1)];

};

with this:

//####################
//DON`T CHANGE ANY CODE BELOW UNLESS YOU KNOW WHAT YOU ARE DOING!
//####################
_cap = _this select 0;

if(isServer || isDedicated)then{
//_ranPos = _positions call BIS_fnc_selectRandom;
//hint _ranPos select 1;
_cap setPos [getMarkerPos (_position select 0) select 0, getMarkerPos (_position select 0) select 1, (getMarkerPos (_position select 0) select 2) + (_position select 1)];
       sleep1;
       _rOrig = getpos _cap;
       _rDir = round (random 360);
       _rDist = 4 + (ceil (random 5));
       _rPos = [(_rOrig select 0)+(sin _rDir)*_rDist,(_rOrig select 1)+(cos _rDir)*_rDist,0];
       sleep 2;
       guard = [_rPos, EAST, (configfile >> "CfgGroups" >> "East" >> "OPF_F" >> "Infantry" >> "OIA_InfTeam"),[], [],[0.3,0.6,0.3]] call BIS_fnc_spawnGroup;
       sleep 1;
       [guard1, _rOrig] call bis_fnc_taskDefend;
       sleep 1;
       _house = nearestbuilding _cap;
       _x = 0;
       while { format ["%1", _house buildingPos _x] != "[0,0,0]" } do {_x = _x + 1};
       _x = _x - 1;
       sleep 0.5;
       _eGrp = createGroup east;
       Guard1 = "O_Soldier_F" createUnit [_rPos ,_eGrp,"this setPos (_house buildingpos (random _x));"];
       Guard2 = "O_Soldier_F" createUnit [_rPos ,_eGrp,"this setPos (_house buildingpos (random _x));"];
       Guard3 = "O_Soldier_F" createUnit [_rPos ,_eGrp,"this setPos (_house buildingpos (random _x));"];
       Guard4 = "O_Soldier_F" createUnit [_rPos ,_eGrp,"this setPos (_house buildingpos (random _x));"];
       Guard5 = "O_Soldier_F" createUnit [_rPos ,_eGrp,"this setPos (_house buildingpos (random _x));"];
};

this creates some guards in the area and inside the building

Share this post


Link to post
Share on other sites

Hey guys!

Sorry for my long absence but it´s great to see that someone is using the script.

Also thanks for the additions! As said before I´m a real script-noob and glad to get tips for enhancing the code.

Is it OK if I implement the code-snippets from you Prathios and Simon1279? Or maybe you guys could upload a version with the changes so that everyone can use it more easily.

Share this post


Link to post
Share on other sites

Dr. Cox1911 have you had a chance to update this?

Share this post


Link to post
Share on other sites

Anyone have insight on the whereabouts of Dr. Cox and if this is a working script?

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  

×