Jump to content
Sign in to follow this  
1para{god-father}

How to Randomise Game / Tasks to complete

Recommended Posts

I have 5 markers on my map and at the moment they are 5 tasks to complete before end of game.

However what I would like to do is randomise this little but have no idea how.

What I am after is as follows:-

At start of the game in server settings be able to select how many tasks’ to complete 1-5 before end of the game - it does not matter which order but it would show them tasks. Then it would randomly select any of the 5 tasks to complete once x number of task’s have been completed end game

Any idea how I could do this?

In my Briefing I have

//objective 2

tskobj_2 = player createSimpleTask["Clear Shanbaz"];

tskobj_2 setSimpleTaskDescription ["Take out all enemies located in and around <marker name=shahbaz'>this</marker> tower to complete the objective", "Clear Shahbaz", "Clear Shahbaz];

tskobj_2 setSimpleTaskDestination (getMarkerPos "shahbaz");

In my trigger I have

"2" objStatus "DONE"; tskobj_2 setTaskState "SUCCEEDED"; player setCurrentTask tskobj_3 ; obj_2 = true; publicVariable "obj_2";

Any help would be most welcome !

Share this post


Link to post
Share on other sites

1. Place all the task stuff into a switch case structure

2. Make server randomly select and broadcast the new task number

3. Create an PVEH to catch the number and run the right case in the switch

Share this post


Link to post
Share on other sites

Hi SHk,

Sorry but I am very new to this it is my first mission so very much still learning and have no idea how to do that ?!

Any help would be grateful!

Thanks

Share this post


Link to post
Share on other sites

Switch-case is hard to use when you dont want any task to repeat randomly.

An array with tasknumbers might be better. An entry is chosen randomly, used for the task to be created and is deleted from the array.

If task is aborted, add the number into the array again.

EDIT:

@psvialli: without scripting this is hard to do imo.

Share this post


Link to post
Share on other sites

description.ext

class Params {
 class TaskCount {
   title = "Number of Tasks";
   values[] = {1,2,3,4,5};
   texts[] = {"1","2","3","4","5"};
   default = 3;
 };
};

init.sqf

fncAddTask = {
 switch _this do {
   case 0: {
     tskobj_1 = player createsimpletask ["task1"];
     tskobj_1 setsimpletaskdescription ["1","1","1"];
     player setcurrenttask tskobj_1;
   };
   case 1: {
     tskobj_2 = player createsimpletask ["task2"];
     tskobj_2 setsimpletaskdescription ["2","2","2"];
     player setcurrenttask tskobj_2;
   };
   case 2: {
     tskobj_3 = player createsimpletask ["task3"];
     tskobj_3 setsimpletaskdescription ["3","3","3"];
     player setcurrenttask tskobj_3;
   };
   case 3: {
     tskobj_4 = player createsimpletask ["task4"];
     tskobj_4 setsimpletaskdescription ["4","4","4"];
     player setcurrenttask tskobj_4;
   };
   case 4: {
     tskobj_5 = player createsimpletask ["task5"];
     tskobj_5 setsimpletaskdescription ["5","5","5"];
     player setcurrenttask tskobj_5;
   };
 };
 if (isserver && (count tasks == 0)) then {
   call compile format ["lastTask = tskobj_%1",(_this + 1)];
   publicvariable "lastTask";
 };
};
fncPickTask = {
 if isserver then {
   addTask = tasks select (floor random count tasks);
   tasks = tasks - [addTask];
   publicvariable "addTask";
   if !isdedicated then {
     addTask call fncAddTask;
   };
 };
};

taskCount = paramsarray select 0;
tasks = [];

if isserver then {
 for "_i" from 0 to (taskCount - 1) do {
   tasks set [_i,_i];
 };
};
"addTask" addpublicvariableeventhandler {
 (_this select 1) call fncAddTask;
};

call fncPickTask; // add first task for briefing

test/example mission

Someone else can fix possible bugs, I gotta go so can't reply in next few hours.

Share this post


Link to post
Share on other sites

Hi Shk,

I can get this to work but as soon as I start adding anything to description.ext for some reson no taks show ?

my description.ext is as follows:-

// Mission Header

class Header

{

gameType = Coop;

minPlayers = 1;

maxPlayers = 8;

};

// description.ext settings for revive

///////////////////////////////////////////////////////////////////////////////////////////

respawn = "Start";

respawndelay = 4;

disabledAI = 1;

#include "revive_sqf\dialogs\config.cpp"

#include "revive_sqf\dialogs\define.hpp"

#include "revive_sqf\dialogs\rev_cam_dialog.hpp"

#include "revive_sqf\dialogs\respawn_button_1.hpp"

#include "revive_sqf\dialogs\respawn_button_2.hpp"

#include "revive_sqf\dialogs\respawn_button_3.hpp"

#include "revive_sqf\dialogs\respawn_button_4.hpp"

#include "revive_sqf\dialogs\respawn_button_1b.hpp"

#include "revive_sqf\dialogs\respawn_button_1c.hpp"

#include "revive_sqf\dialogs\respawn_button_2b.hpp"

#include "revive_sqf\dialogs\respawn_button_3b.hpp"

#include "revive_sqf\dialogs\respawn_button_4b.hpp"

#include "revive_sqf\dialogs\respawn_button_1map.hpp"

#include "revive_sqf\dialogs\respawn_button_2map.hpp"

#include "revive_sqf\dialogs\respawn_button_3map.hpp"

#include "revive_sqf\dialogs\respawn_button_4map.hpp"

#include "revive_sqf\dialogs\OK_map.hpp"

#include "revive_sqf\dialogs\dead_cam_dialog.hpp"

#include "revive_sqf\dialogs\rev_cam_dialog_blank.hpp"

///////////////////////////////////////////////////////////////////////////////////////////

class Params

{

class DayTime

{

//paramsArray[0]

title = "Time Of Day";

values[] = {-6, 0, 8, 13};

texts[] = {"Morning", "Clear day", "Sundown", "Night"};

default = 0;

};

class Revive

{

// paramsArray[1]

title = "Number of Revives:";

values[] = {2000,1000,20,10,7,5};

texts[] = {"No Revive","Infinite - Cadet","20 - Easy ","10 - Normal","7 - Hard","5 - Extreme"};

default = 10;

};

class TaskCount

{

// paramsArray[2]

title = "Number of Tasks";

values[] = {1,2,3,4,5};

texts[] = {"1","2","3","4","5"};

default = 3;

};

};

Any idea why it stops working ? if i just put your code in it works fine

Thanks

Share this post


Link to post
Share on other sites

taskCount = paramsarray select 0;

Change that to 2 or whatever is correct one. ;)

Share this post


Link to post
Share on other sites

Hi shk, I tried to implement this code to a mission, my goal is to create only one of six tasks, randomly selected, without need for selecting number of tasks from parameters. When I create the game locally, it all works perfectly, however, when I put it onto dedicated server, the random task does not show up.

Also I did not put the code to init.sqf but into briefing.sqf like this:

   fncAddTask = {
 switch _this do {
   case 0: {
     OBJ_WAREHOUSE1 = player createsimpletask ["OBJ_WAREHOUSE1"];
     OBJ_WAREHOUSE1 setsimpletaskdescription ["blahblah <marker name='wh1'>here</marker> .","blah","blah"];
 };

[color="DarkRed"]this repeats 5 times the same, only with different name and marker name[/color]

 if (isserver && (count tasks == 0)) then {
   call compile format ["lastTask = OBJ_WAREHOUSE%1",(_this + 1)];
   publicvariable "lastTask";
 };
};
fncPickTask = {
 if isserver then {
   addTask = tasks select (floor random count tasks);
   tasks = tasks - [addTask];
   publicvariable "addTask";
   if !isdedicated then {
     addTask call fncAddTask;
   };
 };
};

taskCount = paramsarray select 1;
tasks = [];

if isserver then {
 for "_i" from 0 to 5 do {
   tasks set [_i,_i];
 };
};
"addTask" addpublicvariableeventhandler {
 (_this select 1) call fncAddTask;
};

call fncPickTask; // add first task for briefing

What did I do wrong? I tried changing the paramsarray without any effect. I am only an amateur (even that is strong word :D ) so I don´t really understand whole part, especially not the one after adding tasks :icon_rolleyes:

Thank you for help and the code :)

Share this post


Link to post
Share on other sites

There seems to be something making the PVEH not fire. I'll take a look later today.

Share this post


Link to post
Share on other sites

Server sent PV too fast / Client didn't add PVEH fast enough.

Better luck this time:

fncAddTask = {
 switch _this do {
   case 0: {
     tskobj_1 = player createsimpletask ["task1"];
     tskobj_1 setsimpletaskdescription ["1","1","1"];
     player setcurrenttask tskobj_1;
   };
   case 1: {
     tskobj_2 = player createsimpletask ["task2"];
     tskobj_2 setsimpletaskdescription ["2","2","2"];
     player setcurrenttask tskobj_2;
   };
   case 2: {
     tskobj_3 = player createsimpletask ["task3"];
     tskobj_3 setsimpletaskdescription ["3","3","3"];
     player setcurrenttask tskobj_3;
   };
   case 3: {
     tskobj_4 = player createsimpletask ["task4"];
     tskobj_4 setsimpletaskdescription ["4","4","4"];
     player setcurrenttask tskobj_4;
   };
   case 4: {
     tskobj_5 = player createsimpletask ["task5"];
     tskobj_5 setsimpletaskdescription ["5","5","5"];
     player setcurrenttask tskobj_5;
   };
   case 5: {
     tskobj_6 = player createsimpletask ["task6"];
     tskobj_6 setsimpletaskdescription ["6","6","6"];
     player setcurrenttask tskobj_6;
   };
 };
 if (isserver && (count tasks == 0)) then {
   call compile format ["lastTask = tskobj_%1",(_this + 1)];
   publicvariable "lastTask";
 };
};
fncPickTask = {
 if isserver then {
   addTask = tasks select (floor random count tasks);
   tasks = tasks - [addTask];
   publicvariable "addTask";
   if !isdedicated then {
     addTask call fncAddTask;
   };
 };
};

taskCount = 6;
//taskCount = paramsarray select 0;
tasks = [];

if isserver then {
 for "_i" from 0 to (taskCount - 1) do {
   tasks set [_i,_i];
 };
};
[] spawn {
 waituntil {!isnil "addTask"};
 if !isserver then {addTask call fncAddTask};
 if !isdedicated then {
   "addTask" addpublicvariableeventhandler {
     (_this select 1) call fncAddTask;
   };
 };
};

call fncPickTask; // add first task for briefing

Share this post


Link to post
Share on other sites

how do i ensure that after the number of tasks set in the params is finished, do i end the mission?

Share this post


Link to post
Share on other sites

Tested in both MP host and on dedi. Tasks showed up and mission ended (script sets variable "theEnd" to true, so you can use that as condition in an end trigger).

Here's the mission I used for testing: _randomTasks.utes.rar

taskCount = paramsarray select 0;
//taskCount = 6;

fncAddTask = {
 switch _this do {
   case 0: {
     tskobj_1 = player createsimpletask ["task1"];
     tskobj_1 setsimpletaskdescription ["1","1","1"];
     player setcurrenttask tskobj_1;
   };
   case 1: {
     tskobj_2 = player createsimpletask ["task2"];
     tskobj_2 setsimpletaskdescription ["2","2","2"];
     player setcurrenttask tskobj_2;
   };
   case 2: {
     tskobj_3 = player createsimpletask ["task3"];
     tskobj_3 setsimpletaskdescription ["3","3","3"];
     player setcurrenttask tskobj_3;
   };
   case 3: {
     tskobj_4 = player createsimpletask ["task4"];
     tskobj_4 setsimpletaskdescription ["4","4","4"];
     player setcurrenttask tskobj_4;
   };
   case 4: {
     tskobj_5 = player createsimpletask ["task5"];
     tskobj_5 setsimpletaskdescription ["5","5","5"];
     player setcurrenttask tskobj_5;
   };
   case 5: {
     tskobj_6 = player createsimpletask ["task6"];
     tskobj_6 setsimpletaskdescription ["6","6","6"];
     player setcurrenttask tskobj_6;
   };
 };
};
fncPickTask = {
 if isserver then {
   if (count tasks == 0) then {
     theEnd = true;
     publicvariable "theEnd";
   } else {
     addTask = tasks select (floor random count tasks);
     tasks = tasks - [addTask];
     publicvariable "addTask";
     if !isdedicated then { addTask call fncAddTask };
   };
 };
};

theEnd = false;
if isserver then {
 tasks = [];
 for "_i" from 0 to (taskCount - 1) do {
   tasks set [_i,_i];
 };
} else {
 [] spawn {
   waituntil {!isnil "addTask"};
   addTask call fncAddTask;
   "addTask" addpublicvariableeventhandler {(_this select 1) call fncAddTask};
 };
};

call fncPickTask; // add first task for briefing

Share this post


Link to post
Share on other sites

If you don't kill any of the guys you *should* it still finishes the testing mission...and when I added that code to other tasks I have in mine, it stopped even showing up the random one in the local game...guess I should have mentioned that there are also fixed tasks and only one of them should be random :whistle: Could it be the problem?

Share this post


Link to post
Share on other sites

Ends if you don't kill even one of them?

As for fixed/mixed tasks, the OP asked for randoms only. Thus, you need to modify it for your needs.

Share this post


Link to post
Share on other sites

If you have 2 tasks to finish, it´s enough to kill random 2 guys. If you specifically kill the ones you are not supposed to, it still finishes the mission. Yes, modify, if I knew how :D

Share this post


Link to post
Share on other sites

Have been using your Random Takes which work great by the way but I have 1 problem and I am hoping you can fix it for me.

I am putting a marker on the map to show where the next task is it shows great on the first Task but when you complete the first task the next random task marker goes to the bottom left of the screen like it cannot find it , but I know it is there as it works when it is the first task.

I am using :- tskobj_1 = setSimpleTaskDestination (getmarkerPos "markername");

case 0: {

tskobj_1 = player createsimpletask ["task1"];

tskobj_1 setsimpletaskdescription ["1","1","1"];

player setcurrenttask tskobj_1;

tskobj_1 = setSimpleTaskDestination (getmarkerPos "markername");

};

Many thanks

Share this post


Link to post
Share on other sites

You've created a marker for each task/case, right?

Like: marker1, marker2, marker3...

Then do

tskobj_1 = setSimpleTaskDestination (getmarkerPos "marker1");

tskobj_2 = setSimpleTaskDestination (getmarkerPos "marker2");

etc

Share this post


Link to post
Share on other sites

Hi shk,

Yes I have them all set for each 6 Task with the correct Marker names and spelling.

They all work fine if it is the first task set, but as soon as you complete the first task the next task shoes but if you click on the task it just goes bottom left of screen , but if that task is first on restart it works fine so I know the marker is there and the correct spelling

Cheers

Share this post


Link to post
Share on other sites

Hi,

If I put something like the below under each of the Tasks, should that variable turn true ? What I am trying to do is when a task is active set a variable to true so I can trigger something. but it never turns ture it is allawys false ?

So i have added:-

myNameTask1 = true;

publicvariable "myNameTask1";

i.e

case 0: {

tskobj_1 = player createSimpleTask["1"];

tskobj_1 setSimpleTaskDescription ["1", "1", "1"];

tskobj_1 setSimpleTaskDestination (getMarkerPos "camara");

player setcurrenttask tskobj_1;

myNameTask1 = true;

publicvariable "myNameTask1";

};

case 1: {

tskobj_2 = player createSimpleTask["2"];

tskobj_2 setSimpleTaskDescription ["2", "2", "2"];

tskobj_2 setSimpleTaskDestination (getMarkerPos "pinley");

player setcurrenttask tskobj_2;

myNameTask2 = true;

publicvariable "myNameTask2";

};

etc....

Share this post


Link to post
Share on other sites

That works just fine. How are you detecting/using the variables?

Share this post


Link to post
Share on other sites

Ahh i think I see why in the condition I have

Cont - myNameTask1=true

act - spawn some men

It should just be myNameTask1 without the = true

Is that correct?

thanks

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  

×