Jump to content
Sign in to follow this  
patpowercat

Trigger detect scripted task complete

Recommended Posts

I currently have a task that is assigned by a script. Basically, at some point in mission, you have to capture an HVT, then once captured a helicopter spawns and picks up the HVT. I want to make a new trigger in the editor that detects when the task assigned by the script are completed so I can thus assign new tasks or end the mission on that trigger. 

 

Here is the script I have (credit to davidoss, it's pirated and chopped from a script of his):

_heli = objNull;
_hPad = "Land_HelipadEmpty_F" createVehicle (getmarkerPos "pickup") ;
if (!isServer) exitWith {};
private ["_posArray", "_mrkSpawn", "_warlordgrp", "_marker","_grp1C", "_grp2C"];

	_posArray = ["m_1","m_2","m_3","m_4","m_5"];
	_mrkSpawn = getMarkerPos (_posArray select floor (random (count _posArray)));
	
	_warlordgrp = createGroup EAST;
	warlord = _warlordgrp createUnit ["I_Story_Colonel_F", _mrkSpawn, [], 0, "NONE"];
	[warlord] joinSilent _warlordgrp;
	warlord allowDamage false;
	warlord setCaptive false;
	warlord addaction ["Capture","rescue.sqf",[],0,true,true,"","_this distance _target < 3"];
	
	//creating the marker 

	_marker = createMarker ["capture", getpos warlord];
	_marker setMarkerShape "ellipse";
	_marker setMarkerColor "ColorRed";
	_marker setMarkerSize [100,100];

	[west, ["capture"], ["Find and arrest the Russian Commander.", "Capture", "Find and arrest"], getMarkerPos "capture", true] spawn BIS_fnc_taskCreate;
	["capture", "ASSIGNED",true] call BIS_fnc_taskSetState;
	
	sleep 5;

	_grp1C = [(getPos warlord), EAST, (configfile >> "CfgGroups" >> "Indep" >> "LOP_AM" >> "Infantry" >> "LOP_AM_Rifle_squad")] call BIS_fnc_spawnGroup;
	[_grp1C,getpos warlord] call BIS_fnc_taskDefend;
		
	_grp2C = [(getPos warlord), EAST, (configfile >> "CfgGroups" >> "Indep" >> "LOP_AM" >> "Infantry" >> "LOP_AM_Support_section")] call BIS_fnc_spawnGroup;
	[_grp2C,getpos warlord, 100] call BIS_fnc_taskPatrol;

waitUntil {{alive _x} count ((units _grp1C)+(units _grp2c)) <= 5};
	warlord setCaptive true;
	
waitUntil {warlord in units group player};
	warlord allowDamage true;
	["capture", "SUCCEEDED", true] call BIS_fnc_taskSetState;

//PICKUP
_extract_crew = creategroup WEST; 
_airframe1 = [getMarkerPos "pickup_spawn", markerDir "pickup_spawn", "RHS_UH1Y_d", _extract_crew] call BIS_fnc_spawnVehicle;
_heli = _airframe1 select 0;
_wp1 = _extract_crew addWaypoint [_hPad, 0];
_wp1 setWaypointType "LOAD";
_wp1 setWaypointSpeed "FAST";
_wp1 setwaypointstatements ["true", "(vehicle this) LAND 'GET IN';"];

[west, ["extract"], ["Extraction helicopter inbound. Get the Russian commander aboard it.", "Extract", ""], getMarkerPos "pickup", true] spawn BIS_fnc_taskCreate;
	["extract", "ASSIGNED",true] call BIS_fnc_taskSetState;

waitUntil {warlord in _heli}; 
[warlord] joinsilent _extract_crew;
["extract", "SUCCEEDED", true] call BIS_fnc_taskSetState;

_wp2 = _extract_crew addWaypoint [(getmarkerpos "pickup_spawn"), 100];
_wp2 setWaypointType "MOVE";
_wp2 setWaypointSpeed "FAST";
_wp2 setWaypointStatements ["true", "{deleteVehicle _x;} forEach crew (vehicle this) + [vehicle this];"]; 

The trigger I have set in the editor is set to a condition of 

taskCompleted extract;

But it doesn't fire, even once the task is completed. Any help appreciated. 

Share this post


Link to post
Share on other sites
(taskCompleted "extract")
//or
(["extract"] call BIS_fnc_taskCompleted)

Share this post


Link to post
Share on other sites
2 hours ago, davidoss said:

(taskCompleted "extract")
//or
(["extract"] call BIS_fnc_taskCompleted)

Hey man, I've been using this....

["Task_Name"] call BIS_fnc_taskState == "SUCCEEDED"// or whatever condition you like/need

(Just wanna learn here...)

What's the difference, beside the fact that you specify the state of the task?

Thank you!

 

Share this post


Link to post
Share on other sites

 

As long you want a boolean in your condition, you can do any "compareto"  to get the effect.

 

taskCompleted returns {true} if task is completed, no mater with which state. ( Succeeded, Failed or Canceled )

BIS_fnc_taskCompleted is doing the same thing to above.

BIS_fnc_taskState returns only current state of task, which you need to compare to something for boolean.

 

If you still want to check tasks complete  in this way i suggest you to use command instead function

((taskState "Task_Name") == "SUCCEEDED")

(taskCompleted "Task_Name")

is probably much more quicker.

Both doing the same thing  only if task was succeeded, otherwise first will return false,

and both will return false if the task is not complete

  • Like 1

Share this post


Link to post
Share on other sites
39 minutes ago, davidoss said:

 

As long you want a boolean in your condition, you can do any "compareto"  to get the effect.

 

taskCompleted returns {true} if task is completed, no mater with which state. ( Succeeded, Failed or Canceled )

BIS_fnc_taskCompleted is doing the same thing to above.

BIS_fnc_taskState returns only current state of task, which you need to compare to something for boolean.

 

If you still want to check tasks complete  in this way i suggest you to use command instead function

((taskState "Task_Name") == "SUCCEEDED")

(taskCompleted "Task_Name")

is probably much more quicker.

Both doing the same thing  only if task was succeeded, otherwise first will return false,

and both will return false if the task is not complete

GOTCHA!!!

Thank you.

Share this post


Link to post
Share on other sites

Alright I may have jumped the gun just a bit. Since the task is created by a script but this trigger is placed by the editor, until the script runs and the task is created at bottom of screen I get a

 

BIS_fnc_taskCompleted: No task "extract" exhists.

Is there something I am missing, or should I just write the trigger that activates on task completed into the script that creates the task?

Share this post


Link to post
Share on other sites

I just wrote the trigger into the script, and that works just fine. If anyone knows a different way?

Share this post


Link to post
Share on other sites

Read better davidoss post:

Spoiler

As long you want a boolean in your condition, you can do any "compareto"  to get the effect.

 

taskCompleted returns {true} if task is completed, no mater with which state. ( Succeeded, Failed or Canceled )

BIS_fnc_taskCompleted is doing the same thing to above.

BIS_fnc_taskState returns only current state of task, which you need to compare to something for boolean.

 

If you still want to check tasks complete  in this way i suggest you to use command instead function

((taskState "Task_Name") == "SUCCEEDED")

(taskCompleted "Task_Name")

is probably much more quicker.

Both doing the same thing  only if task was succeeded, otherwise first will return false,

and both will return false if the task is not complete

I'm not an expert as he's, but since you script the task and AFTER that you're using a editor placed trigger, I would use 

((taskState "Task_Name") == "SUCCEEDED")

so it not check for the task to be completed (which in your case is NOT,since you just started the mission) but it fire only when the scripted task is indeed completed! 

Share this post


Link to post
Share on other sites

Oh i am not an expert too for sure, but you can always use condition tree with lazy evaluation.

for example:

["Task_Name"] call BIS_fnc_taskExists

returns true if the task exist, false if not.

You can use this as first statement and for example:

taskCompleted "Task_Name"

  as second.

 

(["Task_Name"] call BIS_fnc_taskExists) && {(taskCompleted "Task_Name") }

The game engine will skip second condition if the first returns false and exit with false (trigger not fire)

The second condition will be evaluated if the first one returns true, and if the second one returns false exit with false (trigger not fire)

Last the last possibility: first condition returns true, then  evaluate second , second returns true, so we have both true (trigger fire)

 

Anyway get familiar with this framework. There are everything about tasks what you need to knew

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  

×