Jump to content
zagor64bz

Hot to randomize scripted Tasks?[SOLVED]

Recommended Posts

Ok...I have this list of tasks, as side missions, that is called by an add action. It used to give  player a list side missions on my mini-campaign. Now using  a "wait until" it give the tasks one at the time, to avoid cluttering the task list.

I would like to randomize the list of tasks, so every time you start a new campaign the task order is randomized. (future plan is to pick a list of side mission randomly from an array of side mission, so not only the order is random but the type too.

I'm aware of the  "call BIS_fnc_selectRandom" but how do I use it inside this code?

Spoiler

TexTask4 = false;
TexTask5 = false;
TexTask6 = false;
TexTask7 = false;
TexTask8 = false;
TexTask9 = false;
TexTask10 = false;
ParentTask02 = false;

[player,["ParentTask02"],["Agent Miller from DEA has been infiltrated in the island few weeks ago, giving us intels on valuable targets to reduce CERBERUS's operational capabilities.","SIDE MISSION",""], objNull,1,1,true,"target"] call BIS_fnc_taskCreate;

miller  removeAction 0;

[player,["Task04","ParentTask02"],["KILL an independant PILOT, a CIA double agent,he's the man responsable for the drug transport via aeroplane.","KILL THE DOUBLE AGENT",""], getMarkerPos "pilot_task",1,2,true,"kill"] call BIS_fnc_taskCreate;
waitUntil {sleep 0.5;!alive pilot};
["Task04", "SUCCEEDED",true] spawn BIS_fnc_taskSetState;
TexTask4 = true;
sleep 3;
saveGame;

waitUntil {TexTask4};
sleep (150 + (random 150));

[player,["Task05","ParentTask02"],["Destroy the ships used to transport weapons in and out of Altis.Best to approach unseen the targets using the SCUBA gear.When near the ships you'll be prompted to use explosive charges.","SINK THE CARGO SHIPS",""], getMarkerPos "boat_task",1,2,true,"kill"] call BIS_fnc_taskCreate;
waitUntil {sleep 0.5;!alive (boat_1) AND !alive (boat_2) AND !alive (boat_3)};
["Task05", "SUCCEEDED",true] spawn BIS_fnc_taskSetState;
TexTask5 = true;
sleep 3;
saveGame;

waitUntil {TexTask5};
sleep (150 + (random 150));

[player,["Task06","ParentTask02"],["Disable the powerplant to cut down enemy ability to use theyr assets in the area","DISABLE POWERPLANT",""], getPosATL pc_lumiere_off,1,2,true,"use"] call BIS_fnc_taskCreate;
waitUntil {sleep 0.5;(!Bouton_off1 && !Bouton_off2 && !Bouton_off3 && !Bouton_off4 && !Bouton_off5)};
["Task06", "SUCCEEDED",true] spawn BIS_fnc_taskSetState;
TexTask6 = true;
sleep 3;
saveGame;

waitUntil {TexTask6};
sleep (150 + (random 150));

[player,["Task07","ParentTask02"],["Thanks to a tip-off,we know where the main server of the island is. By UPLOADING a virus in the sistem, we will be able to track down every bank operation made, and to infect the sistem to make it slave to our SIGINT office main frame.Look for a data terminal box to upload the virus. ","UPLOAD VIRUS",""],getMarkerPos "virus_task",1,2,true,"download"] call BIS_fnc_taskCreate;
waitUntil {sleep 0.5;!hostageDemo_dataActive};
["Task10", "SUCCEEDED",true] spawn BIS_fnc_taskSetState;
TexTask7 = true;
sleep 3;
saveGame;

waitUntil {TexTask7};
sleep (150 + (random 150));

[player,["Task08","ParentTask02"],["A reported missing news reporter was ready to disclose some pictures proving mass graves and atrocities committed by the cartels. Search the HIDEOUTS to collect them to get media's support.","COLLECT PICTURE nr 1",""], objNull,1,2,true,"search"] call BIS_fnc_taskCreate;
[ missionNamespace, "objectInspected", {
	params[ "_leaflet", "_texture", "_text", "_sound", "_textureRatio" ];
	if ( _texture == "pictures\intel_A.jpg" ) then {
	[ "Task07", "SUCCEEDED", true ] call BIS_fnc_taskSetState;
	TexTask8 = true;
	sleep 3;
	};
}] call BIS_fnc_addScriptedEventHandler;
sleep 5;
[player,["Task09","ParentTask02"],["A reported missing news reporter was ready to disclose some pictures proving mass graves and atrocities committed by the cartels. Search the HIDEOUTS to collect them to get media's support.","COLLECT PICTURE nr 2",""], objNull,1,2,true,"search"] call BIS_fnc_taskCreate;
[ missionNamespace, "objectInspected", {
	params[ "_leaflet", "_texture", "_text", "_sound", "_textureRatio" ];
	
	if ( _texture == "pictures\intel_B.jpg" ) then {
	[ "Task08", "SUCCEEDED", true ] call BIS_fnc_taskSetState;
	TexTask9 = true;
	sleep 3;
	};
}] call BIS_fnc_addScriptedEventHandler;
sleep 5;
[player,["Task10","ParentTask02"],["A reported missing news reporter was ready to disclose some pictures proving mass graves and atrocities committed by the cartels. Search the HIDEOUTS to collect them to get media's support.","COLLECT PICTURE nr 3",""], objNull,1,2,true,"search"] call BIS_fnc_taskCreate;
[ missionNamespace, "objectInspected", {
	params[ "_leaflet", "_texture", "_text", "_sound", "_textureRatio" ];
	
	if ( _texture == "pictures\sticazzi.jpg" ) then {
	[ "Task10", "SUCCEEDED", true ] call BIS_fnc_taskSetState;
	TexTask10 = true;
	sleep 3;
	};
}] call BIS_fnc_addScriptedEventHandler;

waitUntil {sleep 1;(TexTask4 AND TexTask5 AND TexTask6 AND TexTask7 AND TexTask8 AND TexTask9 AND TexTask10)};

if (TexTask4 AND TexTask5 AND TexTask6 AND TexTask7 AND TexTask8 AND TexTask9 AND TexTask10) then {

	["ParentTask02", "SUCCEEDED",true] spawn BIS_fnc_taskSetState;
	systemchat "ALL SIDE MISSION COMPLETED";
	ParentTask02 = true;
	sleep 3;
	saveGame;
};

 

Thank you.

  • Like 1

Share this post


Link to post
Share on other sites

Hello there zagor64bz !

 

If you have every task in different  .sqf

then:

 

create an .sqf

_delay = 500 + (random 500);
_loopTimeout = 10 + (random 10);

_Task_List = selectRandom [
	"TexTask4",
	"TexTask5",
	"TexTask6",
	"TexTask7",
	"TexTask8",
	"TexTask9",
	"TexTask10",
	"ParentTask02"
];

	
while { true } do {

	{	
		_Current_Task = execVM format ["Task_List\%1.sqf", _Task_List];
	
		waitUntil {
			sleep 3;
			scriptDone _Current_Task
		};	
		sleep _delay;		
	};
	sleep _loopTimeout;
};

 

  • Thanks 1

Share this post


Link to post
Share on other sites
32 minutes ago, GEORGE FLOROS GR said:

If you have every task in different  .sqf

then:

 

create an .sqf

I kinda lost you here brother...what exactly do you meant?

I have a sqf where the tasks are called (see above) with an add action.

It's only one file (named task_handling.sqf).

Where should I put that snippet that you kindly provided?

At the end of my code ? Init.sqf?

:smiley-punched:

  • Haha 1

Share this post


Link to post
Share on other sites

Ok sorry , if i got you confused.

 

I thought that you had every task to a different .sqf , because i thought that there where more stuff in every task.!

hold on..! :f:

Share this post


Link to post
Share on other sites

ok check this:

(not tested!!)

 


TexTask4 = false;
TexTask5 = false;
TexTask6 = false;
TexTask7 = false;
TexTask8 = false;
TexTask9 = false;
TexTask10 = false;
ParentTask02 = false;


[player,["ParentTask02"],["Agent Miller from DEA has been infiltrated in the island few weeks ago, giving us intels on valuable targets to reduce CERBERUS's operational capabilities.","SIDE MISSION",""], objNull,1,1,true,"target"] call BIS_fnc_taskCreate;

miller  removeAction 0;


if (Task_List isEqualTo []) exitWith {ParentTask02 = true; publicvariable "ParentTask02";};
_Task = Task_List select (floor(random (count Task_List)));


// uncomment to a test certain Task
//_Task = Task_List select 0; //TexTask4
//_Task = Task_List select 1; //TexTask5
//_Task = Task_List select 2; //TexTask6
//_Task = Task_List select 3; //TexTask7
//_Task = Task_List select 4; //TexTask8
//_Task = Task_List select 5; //TexTask9
//_Task = Task_List select 6; //TexTask10


	
Task_List = Task_List - [_Task];
publicVariable "Task_List";
sleep 2;

switch (_Task) do
{
	case "TexTask4":
	{
	[player,["Task04","ParentTask02"],["KILL an independant PILOT, a CIA double agent,he's the man responsable for the drug transport via aeroplane.","KILL THE DOUBLE AGENT",""], getMarkerPos "pilot_task",1,2,true,"kill"] call BIS_fnc_taskCreate;
	waitUntil {sleep 0.5;!alive pilot};
	["Task04", "SUCCEEDED",true] spawn BIS_fnc_taskSetState;
	TexTask4 = true;
	sleep 3;
	saveGame;

	waitUntil {TexTask4};
	sleep (150 + (random 150));
	};
	
	case "TexTask5":
	{
	[player,["Task05","ParentTask02"],["Destroy the ships used to transport weapons in and out of Altis.Best to approach unseen the targets using the SCUBA gear.When near the ships you'll be prompted to use explosive charges.","SINK THE CARGO SHIPS",""], getMarkerPos "boat_task",1,2,true,"kill"] call BIS_fnc_taskCreate;
	waitUntil {sleep 0.5;!alive (boat_1) AND !alive (boat_2) AND !alive (boat_3)};
	["Task05", "SUCCEEDED",true] spawn BIS_fnc_taskSetState;
	TexTask5 = true;
	sleep 3;
	saveGame;

	waitUntil {TexTask5};
	sleep (150 + (random 150));
	};
	
	case "TexTask6":
	{
	[player,["Task06","ParentTask02"],["Disable the powerplant to cut down enemy ability to use theyr assets in the area","DISABLE POWERPLANT",""], getPosATL pc_lumiere_off,1,2,true,"use"] call BIS_fnc_taskCreate;
	waitUntil {sleep 0.5;(!Bouton_off1 && !Bouton_off2 && !Bouton_off3 && !Bouton_off4 && !Bouton_off5)};
	["Task06", "SUCCEEDED",true] spawn BIS_fnc_taskSetState;
	TexTask6 = true;
	sleep 3;
	saveGame;

	waitUntil {TexTask6};
	sleep (150 + (random 150));
	};
	
	case "TexTask7":
	{
	[player,["Task07","ParentTask02"],["Thanks to a tip-off,we know where the main server of the island is. By UPLOADING a virus in the sistem, we will be able to track down every bank operation made, and to infect the sistem to make it slave to our SIGINT office main frame.Look for a data terminal box to upload the virus. ","UPLOAD VIRUS",""],getMarkerPos "virus_task",1,2,true,"download"] call BIS_fnc_taskCreate;
	waitUntil {sleep 0.5;!hostageDemo_dataActive};
	["Task10", "SUCCEEDED",true] spawn BIS_fnc_taskSetState;
	TexTask7 = true;
	sleep 3;
	saveGame;

	waitUntil {TexTask7};
	sleep (150 + (random 150));
	};
	
	case "TexTask8":
	{
	[player,["Task08","ParentTask02"],["A reported missing news reporter was ready to disclose some pictures proving mass graves and atrocities committed by the cartels. Search the HIDEOUTS to collect them to get media's support.","COLLECT PICTURE nr 1",""], objNull,1,2,true,"search"] call BIS_fnc_taskCreate;
	[ missionNamespace, "objectInspected", {
	params[ "_leaflet", "_texture", "_text", "_sound", "_textureRatio" ];
	if ( _texture == "pictures\intel_A.jpg" ) then {
	[ "Task07", "SUCCEEDED", true ] call BIS_fnc_taskSetState;
	TexTask8 = true;
	sleep 3;
	};
	}] call BIS_fnc_addScriptedEventHandler;
	};
	
	case "TexTask9":
	{
	[player,["Task09","ParentTask02"],["A reported missing news reporter was ready to disclose some pictures proving mass graves and atrocities committed by the cartels. Search the HIDEOUTS to collect them to get media's support.","COLLECT PICTURE nr 2",""], objNull,1,2,true,"search"] call BIS_fnc_taskCreate;
	[ missionNamespace, "objectInspected", {
	params[ "_leaflet", "_texture", "_text", "_sound", "_textureRatio" ];
	
	if ( _texture == "pictures\intel_B.jpg" ) then {
	[ "Task08", "SUCCEEDED", true ] call BIS_fnc_taskSetState;
	TexTask9 = true;
	sleep 3;
	};
	}] call BIS_fnc_addScriptedEventHandler;
	};
	
	case "TexTask10":
	{
	[player,["Task10","ParentTask02"],["A reported missing news reporter was ready to disclose some pictures proving mass graves and atrocities committed by the cartels. Search the HIDEOUTS to collect them to get media's support.","COLLECT PICTURE nr 3",""], objNull,1,2,true,"search"] call BIS_fnc_taskCreate;
	[ missionNamespace, "objectInspected", {
	params[ "_leaflet", "_texture", "_text", "_sound", "_textureRatio" ];
	
	if ( _texture == "pictures\sticazzi.jpg" ) then {
	[ "Task10", "SUCCEEDED", true ] call BIS_fnc_taskSetState;
	TexTask10 = true;
	sleep 3;
	};
	}] call BIS_fnc_addScriptedEventHandler;
	};
	
};

if (true) exitWith {
//"Tasks_complete" call BIS_fnc_endMission;
	
	["ParentTask02", "SUCCEEDED",true] spawn BIS_fnc_taskSetState;
	systemchat "ALL SIDE MISSION COMPLETED";	
	sleep 2;
	saveGame;

};


/* 
waitUntil {sleep 1;(TexTask4 AND TexTask5 AND TexTask6 AND TexTask7 AND TexTask8 AND TexTask9 AND TexTask10)};

if (TexTask4 AND TexTask5 AND TexTask6 AND TexTask7 AND TexTask8 AND TexTask9 AND TexTask10) then {

	["ParentTask02", "SUCCEEDED",true] spawn BIS_fnc_taskSetState;
	systemchat "ALL SIDE MISSION COMPLETED";
	ParentTask02 = true;
	sleep 3;
	saveGame;
};

 

  • Like 1

Share this post


Link to post
Share on other sites

Hey George, thank you!!!

 

I'll test it and report ASAP.

  • Like 1

Share this post


Link to post
Share on other sites

Sorry bud..not working. It give you the parent Task and right after it complete it without even giving you all the sidemissions

  • Like 1

Share this post


Link to post
Share on other sites
15 hours ago, zagor64bz said:

Sorry bud..not working.

 

Test this also with including this :

waitUntil {sleep 1;(TexTask4 AND TexTask5 AND TexTask6 AND TexTask7 AND TexTask8 AND TexTask9 AND TexTask10)};

if (TexTask4 AND TexTask5 AND TexTask6 AND TexTask7 AND TexTask8 AND TexTask9 AND TexTask10) then {

	["ParentTask02", "SUCCEEDED",true] spawn BIS_fnc_taskSetState;
	systemchat "ALL SIDE MISSION COMPLETED";
	ParentTask02 = true;
	sleep 3;
	saveGame;
};

 

and excluding this:

if (true) exitWith {
//"Tasks_complete" call BIS_fnc_endMission;
	
	["ParentTask02", "SUCCEEDED",true] spawn BIS_fnc_taskSetState;
	systemchat "ALL SIDE MISSION COMPLETED";	
	sleep 2;
	saveGame;

};

 

 

and in this weekend i will have time to test this also and tell you.

  • Thanks 1

Share this post


Link to post
Share on other sites
On 18/4/2018 at 5:50 PM, zagor64bz said:

Ok

 

Finally have some time!

 

Grab the mission example from the link:

 

Download file

To download file click the link below:
+GF_Side_Missions_Script.VR.zip
Filesize: 0.008 MB
File upload date: 2018-04-22 10:36:16

 

  • Thanks 1

Share this post


Link to post
Share on other sites

Thank you George.I tested and it worked. Larrow also PM me a VERY good script that not only randomize the tasks, but it let you set up different "set" of child-tasks so every time you play the side missions not only they are random, but could be different ones. As soon as he give me permission I'll share with everyone.

 

EDIT: Here we go. THIS EXAMPLE MISSION will explain and help understand how to randomize tasks.

 

Thank you Larrow!

 

So for anyone coming here looking for help, just choose what suit yourselves better !

  • Thanks 2

Share this post


Link to post
Share on other sites

Nice. Thank you everyone for the share.

  • Like 2

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

×