Jump to content
Sign in to follow this  
A-SUICIDAL

Random Tasks (need help)

Recommended Posts

I am working on a new mission and I am using murk_spawn to spawn my enemy at the objective areas. I did this with another mission and it worked great, but my friends all told me the same thing... that they wished that the objectives were random. The mission takes several hours to complete and most times when I play it with my friends, we never finish it. Some of my friends have never even seen the last few objectives. In that mission there are 5 tasks. After completing task 1, task 2 is then assigned and the enemy in the task 2 location are then spawned using the murk_spawn method. What I would like to do is make it so that the 5 tasks are assigned randomly, so maybe task 1 is actually task 3. I've never done random scripting before, so I decided to ask for help here. I've done quite a bit of searching, but I have not found anything helpful at all, so I was hoping that maybe somebody could point me in the right direction and possibly post a link to a tutorial or sample mission that deals with random tasks or similar, then I could study it and learn from it. Thanks in advance.

Share this post


Link to post
Share on other sites

G'day Mate, so i noticed in one of your other missions u use shk taskmaster well that has a great random task selector built in so every task is selected at random every time. this is done as follows

in your init have

nul = [] execVM "task_init.sqf";

in task_init.sqf have

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//                                                                                                                   //////////////////////////////////////
//                       ----------      Set Up Random Task's    ----------                                          //////////////////////////////////////
//                                                                                                                   //////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
call compile preprocessfile "shk_taskmaster.sqf";
sleep .5;
SHK_addTask = {
 if isserver then {
   if (count SHK_Tasks == 0) then {
     TheEnd = true;
     publicvariable "TheEnd";
   } else {
     _this spawn {
       private "_t";
       if (count _this > 0) then {
         _t = _this select 0;
       } else {
         _t = SHK_Tasks select (floor random count SHK_Tasks);
       };
       SHK_Tasks = SHK_Tasks - [_t];
       switch _t do {
case 0: {
 		["Task1","taskname","task intell",true,["MissionAO",getmarkerpos "task1","flag","ColorRed"]] call SHK_Taskmaster_add;
               player sideChat "New Mission Updated.";

   		};
case 1: {
 		["Task2","taskname","task intell",true,["MissionAO",getmarkerpos "task2","flag","ColorRed"]] call SHK_Taskmaster_add;
               player sideChat "New Mission Updated.";

   		};
case 2: {
 		["Task3","taskname","task intell",,true,["MissionAO",getmarkerpos "task3","flag","ColorRed"]] call SHK_Taskmaster_add;
               player sideChat "New Mission Updated.";

   		};
case 3: {
 		["Task4","taskname","task intell",true,["MissionAO",getmarkerpos "task4","flag","ColorRed"]] call SHK_Taskmaster_add;
               player sideChat "New Mission Updated.";

   		};
case 4: {
 		["Task5","taskname","task intell",true,["MissionAO",getmarkerpos "task5","flag","ColorRed"]] call SHK_Taskmaster_add; 
               player sideChat "New Mission Updated.";

   		};

       };
     };
   };
 };
};
private "_selectedTask";
taskCount = 5;  //or use description i.e paramsarray select 4;
_selectedTask = 99; // or use description  i.e paramsarray select 5;
if isserver then {
 private ["_tmp","_t"];
 _tmp = [0,1,2,3,4];
 SHK_Tasks = [];
 for "_i" from 0 to (taskCount - 1) do {
   _t = _tmp select (floor random count _tmp);
   SHK_Tasks set [_i,_t];
   _tmp = _tmp - [_t];
 };
 // first task
 if (_selectedTask < 99) then {
   [_selectedTask] call SHK_addTask;
 } else {
   [] call SHK_addTask;
 };
};

now as normal with shk just end the task with

["task1","succeeded"] call SHK_Taskmaster_upd;

then add new task with

  [] call SHK_addTask;

thats it. if you whish to add more tasks to the list just edit the following on the task_init.sqf

[b]taskCount = 5;  //or use description i.e paramsarray select 4;[/b]
_selectedTask = 99; // or use description  i.e paramsarray select 5;
if isserver then {
 private ["_tmp","_t"];
[b]  _tmp = [0,1,2,3,4];[/b]

plus add more cases.

hope this helps let me know if you need any more info.

Share this post


Link to post
Share on other sites

Thanks I will give that a try.

I did manage to get my random tasks working well. I examined somebodys random script and then tried their script, but it gave me errors and did not work correctly, so then I tried to fix it and use my own tasks and this is what I came up with in the end that worked well for my mission. This same method of using randomness is applied to other things in my mission as well. I have not had any problems so far at all and I have tested online with friends, but not on a dedicated server.

randomize_tasks.sqf

if (! isServer) exitwith {};

sleep 60;  // 1 minute delay at mission start before tasks are assigned

taskscompletedcount = 0; 

while {taskscompletedcount < 10} do {
n1=round(random 10);

if (n1 == 1 AND !task1_completed) then
{
   sleep 20;
   task1_started = true;
   publicVariable "task1_started";
   waitUntil {task1_completed};
   sleep 2;
   taskscompletedcount = taskscompletedcount + 1;
};

if (n1 == 2 AND !task2_completed) then
{
   sleep 20;
   task2_started = true;
   publicVariable "task2_started";
   waitUntil {task2_completed};
   sleep 2;
   taskscompletedcount = taskscompletedcount + 1;    
};

if (n1 == 3 AND !task3_completed) then
{
   sleep 20;
   task3_started = true;
   publicVariable "task3_started";
   waitUntil {task3_completed};
   sleep 2;
   taskscompletedcount = taskscompletedcount + 1;
};

if (n1 == 4 AND !task4_completed) then
{
   sleep 20;
   task4_started = true;
   publicVariable "task4_started";
   waitUntil {task4_completed};
   sleep 2;
   taskscompletedcount = taskscompletedcount + 1;    
};

if (n1 == 5 AND !task5_completed) then
{
   sleep 20;
   task5_started = true;
   publicVariable "task5_started";
   waitUntil {task5_completed};
   sleep 2;
   taskscompletedcount = taskscompletedcount + 1;
};

if (n1 == 6 AND !task6_completed) then
{
   sleep 20;
   task6_started = true;
   publicVariable "task6_started";
   waitUntil {task6_completed};
   sleep 2;
   taskscompletedcount = taskscompletedcount + 1;    
};

if (n1 == 7 AND !task7_completed) then
{
   sleep 20;
   task7_started = true;
   publicVariable "task7_started";
   waitUntil {task7_completed};
   sleep 2;
   taskscompletedcount = taskscompletedcount + 1;
};

if (n1 == 8 AND !task8_completed) then
{
   sleep 20;
   task8_started = true;
   publicVariable "task8_started";
   waitUntil {task8_completed};
   sleep 2;
   taskscompletedcount = taskscompletedcount + 1;    
};

if (n1 == 9 AND !task9_completed) then
{
   sleep 20;
   task9_started = true;
   publicVariable "task9_started";
   waitUntil {task9_completed};
   sleep 2;
   taskscompletedcount = taskscompletedcount + 1;
};

if (n1 == 10 AND !task10_completed) then
{
   sleep 20;
   task10_started = true;
   publicVariable "task10_started";
   waitUntil {task10_completed};
   sleep 2;
   taskscompletedcount = taskscompletedcount + 1;    
};

};
sleep 4;
hintSilent composeText [parsetext format["<t size='1.4' align='center' color='#6698FF'>MISSION COMPLETED%1</t>"]];
sleep 6;
taskhint ["MISSION COMPLETE\nGood Job!", [1,1,1,1], "taskNew"];
sleep 6;
endMission "end1";

the "tasks#_started" condition triggers my other "taskmaster" triggers.

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  

×