Jump to content

Recommended Posts

Hi guys, ive been considering a way to implement a series of small objectives that players can activate attempt to complete and then weather succeeded or failed run the scenario again.
What I have to far is an addiction that runs a few scripts.
first it runs this SFHVTSpawn.sqf

[ "t1" ] call BIS_fnc_deleteTask;
 _SFHVTMarker = Selectrandom ["HVT1_1"];
 _HVT = [getmarkerpos _SFHVTMarker, East, ["CUP_C_R_Functionary_01"],[],[],[],[],[],116] call BIS_Fnc_spawnGroup;//spawn my HVT
	{
		removeAllWeapons _x; //remove HVT gear
		removeAllWeapons _x;
		removeUniform _x;
		removeHeadgear _x;
		removeBackpack _x;
		_x addUniform "U_O_T_Officer_F"; //add specific gear
		_x addHeadgear "CUP_H_TK_Beret";
		_x addbackpack "CUP_B_SLA_Medicbag";
		_x addItemToBackpack "ACE_Flashlight_XL50";
		_x addItemToBackpack "MCC_butanetorch";
		_x addItemToBackpack "ACE_IR_Strobe_Item";
		_x addItemToBackpack "ACE_Cellphone";
		_x addaction ["CAPTURE","capture.sqf"]; //addaction (potential condition check)
	} forEach (units _HVT);
{
	["ACE_captives_setSurrendered", [_x, true], _x] call CBA_fnc_targetEvent; //hands up
} forEach (units _HVT);


[west,["t1"],["A group of operatives have captured a CSAT Officer inside enemy territory code name Judas. Safely extract Judas and bring them back to base for interrogation.","Vengeful God","HVT1_1"],getmarkerpos "HVT1_1",1,3,true] call BIS_fnc_taskCreate; //create the task
"t1" call BIS_fnc_taskSetCurrent; //set the task as current

And for Capture.sqf

_HVT = _this select 0;
removeallactions _HVT;
["t1", getMarkerPos "marker_63"] call BIS_fnc_taskSetDestination;

marker_63 is the position I want them to bring the HVT to.
what is the best way to implement the checks I need?
I need to check if HVT is brought to marker_63 (maybe within 10m).

I need to check if the HVT has been killed.
I tried using triggers in the eden editor but I'm not sure I'm using the right variable reference?
Should I add an evenhandler to the Capture.sqf script.
Just getting back into arma coding so any help is greatly appreciated!

Share this post


Link to post
Share on other sites
5 hours ago, Cockheaven said:

I need to check if HVT is brought to marker_63 (maybe within 10m).

_nul = [ _HVT ] spawn {
	params[ "_HVT" ];
  
	waitUntil{
		_HVT inArea "marker_63" ||
		[ "t1" ] call BIS_fnc_taskState == "FAILED"
	};
	if !( [ "t1" ] call BIS_fnc_taskState == "FAILED" ) then {
		[ "t1", "SUCCEEDED" ] call BIS_fnc_taskSetState;
		_HVT removeEventHandler ( _HVT getVariable "killedEH" );
	};
};

 

5 hours ago, Cockheaven said:

I need to check if the HVT has been killed.

_HVT setVariable[ "killedEH", _HVT addEventHandler [ "Killed", {
	params[ "_killed" ];
	
	[ "t1", "FAILED" ] call BIS_fnc_taskSetState;
	_killed removeEventHandler _thisEventHandler;
}]];

Untested but should provide some pointers to think about.

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

@Larrow Your code is incredibly plug and play, thanks for that.
I added both of those check to the Capture.SQF and changed the line
_HVT inArea "marker_63"

to _HVT inArea ["marker_63", 8, 8, 0, false, 8] 

 

When I use the code as is (as you prescribed it) it works but it wont detect weather or not _HVT has been brought to the marker, so I considered it needed a search distance (didn't seem to be baked into inArea) so I changed it to the array posted. however when I use this new line I get the error 

'...] spawn {

params[ "_hvt" ];

 

waitUntil{

|#|_HVT inArea ["marker_63", 8, 8, 0, fals...'
Error undefined variable in expression: _hvt

 

I don't get it, do I have to redefine _HVT , if so how do I do that? I don't really know how to reference objects spawned preciously are they stored in the script they are spawned from? do I need to pass them as a variable to other scripts that utilize them? how do I do this?

What I don't get is the EH to check if _hvt is alive works, when I shoot _hvt the task fails....

Thanks!

Share this post


Link to post
Share on other sites
1 hour ago, Cockheaven said:

I added both of those check to the Capture.SQF and changed the line
_HVT inArea "marker_63"

to _HVT inArea ["marker_63", 8, 8, 0, false, 8] 

Why? That should not work. The array version of inArea expects the first parameter as a position or object, not a string.

 

1 hour ago, Cockheaven said:

but it wont detect weather or not _HVT has been brought to the marker,

Is the marker an area marker? or just an empty?

If its not an area marker change the waitUntil condition in the code in the spoiler below to...

waitUntil{
	//If the task has been set as failed
	[ "t1" ] call BIS_fnc_taskState == "FAILED" ||
	//Or all units of group _HVT are in marker_63
	{ units _HVT findIf{ !( _x inArea [ getMarkerPos "marker_63", 8, 8, 0, false, 8 ] ) } isEqualTo -1 }
};

Uses inArea ARRAY but passing markers position rather than string name.

 

On 5/22/2019 at 5:56 AM, Cockheaven said:

_HVT = [getmarkerpos _SFHVTMarker, East, ["CUP_C_R_Functionary_01"],[],[],[],[],[],116] call BIS_Fnc_spawnGroup;//spawn my HVT

Sorry my mistake for not spotting that _HVT is a group not a unit

 

Spoiler

_nul = [ _HVT ] spawn {
	params[ "_HVT" ];
  
	waitUntil{
		//If the task has been set as failed
		[ "t1" ] call BIS_fnc_taskState == "FAILED" ||
		//Or all units of group _HVT are in marker_63
		{ units _HVT findIf{ !( _x inArea "marker_63" ) } isEqualTo -1 }
	};
	
	//If we didnt exit the waitUntil due to task failure
	if !( [ "t1" ] call BIS_fnc_taskState == "FAILED" ) then {
		//Succeed task
		[ "t1", "SUCCEEDED" ] call BIS_fnc_taskSetState;
	};
		
	//Remove killed events from each unit in _HVT group
	{
		//Get their killed EH ID
		_ehid = _x getVariable[ "killedEH", -1 ];
		//If they do have an ID
		if ( _ehid > -1 ) then {
			//Remove the killed EH
			_x removeEventHandler[ "killed", _ehid ];
			//Clear stored ID
			_x setVariable[ "killedEH", nil ];
		};
	}forEach units _HVT;
};


{
	//Store on each unit of _HVT the ID of a...
	_x setVariable[ "killedEH",
		//Add a killed event to the unit
		_x addEventHandler [ "Killed", {
			params[ "_killed" ];
			
			//Mark task as failed
			[ "t1", "FAILED" ] call BIS_fnc_taskSetState;
		}]
	];
}forEach units _HVT;

Also fixed removeEventHandler. Untested.

 

  • Thanks 1

Share this post


Link to post
Share on other sites

@Larrow Thank you for the clarification I wasn't making the distinction between and area marker and an empty. Using an Area marker now and everything is working.
However it doesn't seem to be repeatable. When I run SFHVTSpawn.sqf  a second time it does not create a new task and assign the new task. Is this because I have assigned a variable "t1" to the task and since it already had existed it cannot be created again? Do I need to use something that increments and assign that as the task I.D.

Thanks again!

Share this post


Link to post
Share on other sites
13 hours ago, Cockheaven said:

When I run SFHVTSpawn.sqf  a second time it does not create a new task and assign the new task. Is this because I have assigned a variable "t1" to the task and since it already had existed it cannot be created again? Do I need to use something that increments and assign that as the task I.D.

Yes either create a new task Id or delete the previous task.

Although from your OP code you are already deleting the task at the top of the function so should be OK.

For instance from the debug console executing this...

TAG_fnc_createTask = {
	if ( "t1" call BIS_fnc_taskExists ) then {
		"t1" call BIS_fnc_deleteTask
	};
	
	if ( getMarkerPos "HVT1_1" isEqualTo [0,0,0] ) then {
		createMarker[ "HVT1_1", player getPos[ 10, getDir player ] ];
	};
	[west,["t1"],["A group of operatives have captured a CSAT Officer inside enemy territory code name Judas. Safely extract Judas and bring them back to base for interrogation.","Vengeful God","HVT1_1"],getMarkerPos "HVT1_1",1,3,true] call BIS_fnc_taskCreate;
	
	sleep 5;
	
	[ "t1", "FAILED" ] call BIS_fnc_taskSetState;
	
	sleep 5;
	
	[] call TAG_fnc_createTask;
};

_nul = [] spawn TAG_fnc_createTask;

in a blank mission with just a player. Creates and then fails the mission over and over again.

  • Thanks 1

Share this post


Link to post
Share on other sites

Awesome, I've gotten this bit working reliably thanks @Larrow for your help!
I've gone ahead and implemented a lot of this functionality that you provided into some more addaction events that spawn enemies. My goal for these next few events being simple seek and destroy objectives and I'm trying to get a task marker that follows each leader of the group the addaction spawns. 

_myunitarray = ["O_PLANE_FIGHTER_02_F","CUP_O_SU25_DYN_CSAT_T","CUP_O_SU34_CSAT","cfp_o_syarmy_L39_AA"];
_myunit = selectRandom _myunitarray;
_FIGT =  _myunit createvehicle getMarkerPos "FighterSpawn1_1";
_FIGT setDir 90;
createVEHicleCrew _FIGT;
_FIGT2 =  _myunit createvehicle getMarkerPos "FighterSpawn1_2";
createvehicleCrew _FIGT2;
_FIGT2 setDir 90;


_FIGT2crew = crew _FIGT2; //this will give you an array which has the crew members.



_FIGTgrp = group driver _FIGT; //you get the convoy leader's group with this little command
_FIGT2crew join _FIGTgrp; //Array is needed for join command.


			[_FIGTgrp, getMarkerPos "HOSTILEAIRSPACE", 1200] call bis_fnc_taskPatrol;
			[_FIGTgrp, 1] setWaypointSpeed "NORMAL";
			[_FIGTgrp, 1] setWaypointCombatMode "WHITE";
			[_FIGTgrp, 1] setWaypointBehaviour "SAFE";
			[_FIGTgrp, 1] setWaypointFormation "WEDGE";


if ( "t2" call BIS_fnc_taskExists ) then {
		"t2" call BIS_fnc_deleteTask
	}; //delete any existing t2

[west,["t2"],["Two CSAT Fighters have been detected in close proximity of our airspace. Intercept and destroy the CSAT squadron.","The Rapture","FighterSpawn1_1"],getmarkerpos "FighterSpawn1_1",1,3,true] call BIS_fnc_taskCreate; //create the task
_Alpha = leader _FIGTgrp;
"t2" call BIS_fnc_taskSetCurrent; //set the task as current

	while { "t1" call BIS_fnc_taskExists } do {
		"FIGTmkr" setmarkerpos getpos leader _FIGTgrp;
		["t2",  getmarkerpos "FIGTmkr"] call BIS_fnc_taskSetDestination;
		if !(alive leader _FIGTgrp) then {
	[ "t1", "SUCCEEDED" ] call BIS_fnc_taskSetState;
	};//YOU WIN!
};//update Bogey leader to HUD in 3D

So I have task propagation and the marker placement, should i use an EH to "track" the enemy squadron leader, this while seems to not update and neither is the task succeeded argument

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

×