Jump to content

Photo
- - - - -

How to Randomise Game / Tasks to complete


  • Please log in to reply
40 replies to this topic
Thread Starter
1para{god-father}
1para{god-father}

    Sergeant Major

  • Members
  • 1794 posts

Posted 29 October 2010 - 09:26 #1

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 !

Shuko
Shuko

    Warrant Officer

  • Members
  • 2138 posts

Posted 29 October 2010 - 10:00 #2

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

Thread Starter
1para{god-father}
1para{god-father}

    Sergeant Major

  • Members
  • 1794 posts

Posted 29 October 2010 - 10:09 #3

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

-)rStrangelove
-)rStrangelove

    Sergeant Major

  • Members
  • 1760 posts

Posted 29 October 2010 - 10:10 #4

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.
Posted Image
Spoiler

Thread Starter
1para{god-father}
1para{god-father}

    Sergeant Major

  • Members
  • 1794 posts

Posted 29 October 2010 - 10:36 #5

Hmm so i am bugged then :)

Shuko
Shuko

    Warrant Officer

  • Members
  • 2138 posts

Posted 29 October 2010 - 11:21 #6

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.

Thread Starter
1para{god-father}
1para{god-father}

    Sergeant Major

  • Members
  • 1794 posts

Posted 29 October 2010 - 11:39 #7

OMG thank you soooooo much that is sooo Cool !!!!!!

It works great

Ill have a play with this now !!!

Cheers

Thread Starter
1para{god-father}
1para{god-father}

    Sergeant Major

  • Members
  • 1794 posts

Posted 01 November 2010 - 15:01 #8

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

Shuko
Shuko

    Warrant Officer

  • Members
  • 2138 posts

Posted 01 November 2010 - 15:09 #9

taskCount = paramsarray select 0;

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

Thread Starter
1para{god-father}
1para{god-father}

    Sergeant Major

  • Members
  • 1794 posts

Posted 01 November 2010 - 15:40 #10

opppsss many thanks that done the trick !

still learning !

Cheers

raptorko
raptorko

    Private First Class

  • Members
  • 11 posts

Posted 03 November 2010 - 20:17 #11

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 :)

Shuko
Shuko

    Warrant Officer

  • Members
  • 2138 posts

Posted 04 November 2010 - 09:47 #12

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

Shuko
Shuko

    Warrant Officer

  • Members
  • 2138 posts

Posted 04 November 2010 - 18:49 #13

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


raptorko
raptorko

    Private First Class

  • Members
  • 11 posts

Posted 04 November 2010 - 21:14 #14

Still no change, not showing up on dedicated server...

rstratton
rstratton

    Master Sergeant

  • Members
  • 644 posts

Posted 05 November 2010 - 02:07 #15

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

Shuko
Shuko

    Warrant Officer

  • Members
  • 2138 posts

Posted 05 November 2010 - 12:50 #16

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


raptorko
raptorko

    Private First Class

  • Members
  • 11 posts

Posted 05 November 2010 - 14:43 #17

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?

Shuko
Shuko

    Warrant Officer

  • Members
  • 2138 posts

Posted 05 November 2010 - 15:55 #18

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.

raptorko
raptorko

    Private First Class

  • Members
  • 11 posts

Posted 05 November 2010 - 19:51 #19

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

Thread Starter
1para{god-father}
1para{god-father}

    Sergeant Major

  • Members
  • 1794 posts

Posted 10 November 2010 - 20:56 #20

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