Jump to content
iV - Ghost

Delete value from array after selectRandom

Recommended Posts

 

Why not test yourself?

 

_task1 = {execVM "scripts\taskmanager\tasks\Girna.sqf";};
_task2 = {execVM "scripts\taskmanager\tasks\Mike-26.sqf";};
_task3 = {execVM "scripts\taskmanager\tasks\Airbase.sqf";};
_task4 = {execVM "scripts\taskmanager\tasks\Kamino.sqf";};
_task5 = {execVM "scripts\taskmanager\tasks\CampRogain.sqf";};
_task6 = {execVM "scripts\taskmanager\tasks\AgiaMarina.sqf";};

_tasks = [_task1,_task2,_task3,_task4,_task5,_task6];

// select random task and remove it from array

_selectedTask = _tasks deleteAt floor random (count _tasks);

hintC format ["_selectedTask:\n %1\n\n_tasks:\n %2",_selectedTask,_tasks];

 

Share this post


Link to post
Share on other sites

OK. Tested but it DON'T DELETE _task1, _task2 or another.

Everytime I interact (addaction on laptop) I get my hintC with ALL 6 _tasks.

Normally the script should only be started 6 times. But I can start it infinitely.

 

 

:-(

 

Whats going wrong?

 

Share this post


Link to post
Share on other sites
5 hours ago, dedmen said:

Problem though is that you overwrite the _tasks list everytime so even if you remove it you always add it back to the list. Ofc that's not gonna work. Make it a global variable and only set it once (init.sqf). Then use the deleteAt way that 2 or 3 people recommended to you

^^

This is your problem...

 

initServer.sqf:

tag_mytasks=
[	{execVM "scripts\taskmanager\tasks\Girna.sqf"},
	{execVM "scripts\taskmanager\tasks\Mike-26.sqf"},
	{execVM "scripts\taskmanager\tasks\Airbase.sqf"},
	{execVM "scripts\taskmanager\tasks\Kamino.sqf"},
	{execVM "scripts\taskmanager\tasks\CampRogain.sqf"},
	{execVM "scripts\taskmanager\tasks\AgiaMarina.sqf"}
];
publicVariable "tag_mytasks";

in your script:

_selectedTask = tag_mytasks deleteAt floor random (count tag_mytasks);
publicVariable "tag_mytasks";

hintC format ["_selectedTask:\n %1\n\n_tasks:\n %2",_selectedTask,tag_mytasks];

Pay attention for MP!

 

Share this post


Link to post
Share on other sites

As @Lucullus said, just avoid to "rearm" all your tasks each time you fire the addAction. Simple as that!

You can delete the active task/all tasks on addAction also to make something clean on your map.

The Lucullus way is a little bit a "hammer to crush a nut", because tasks are already "public". You don't need to broadcast variables and the network will be happy.

Why?:

 

- the lapTop is on server;

 

- the arrays of tasks (sqf path and id) can be in initPlayerLocal.sqf (so each player gets them and manages them) (say taskArray and taskCode see below) , and all the scripts (taskCode) are on mission folder, so known by all PCs.

 

- all players can addAction on laptop; The addAction is simple as:

this addAction ["JUST TRY IT!", {(selectRandom taskcode) call BIS_fnc_taskCreate},nil, 5,false, true,"","vehicle _this == _this"];

in init field of your laptop.

 

- Now, the selectRandom inside addAction is fired locally (on player's PC who acted it), but you are using a powerful createTask or bis_fnc_taskCreate which is public for all the "task owners" you decide (see the function parameters).

- then, manage your array of tasks locally when a task is created (same for all owners). In initPlayerLocal:


 

taskcode = [
    [west,"task1",["Good luck finding this cookie","Find Cookie","cookiemarker1"],"cookiemarker1",1,3,true] ,
    [west,"task2",["Good luck finding this cookie","Find Cookie","cookiemarker2"],"cookiemarker2",1,3,true] ,
    [west,"task3",["Good luck finding this cookie","Find Cookie","cookiemarker3"],"cookiemarker3",1,3,true]
];

taskArray = ["task1","task2","task3"];
[] spawn {
  while {true} do { taskArray = taskArray - (player call BIS_fnc_tasksUnit);
  sleep 2
  }
};

Remarks:

- The taskCode is an example, you can place your paths for sqf here.

- You can use the EH "TaskSetAsCurrent" if all added task is assigned to all players,instead of the spawned loop.

 

Share this post


Link to post
Share on other sites

Now all becames a bit more logical. I think I've understood.

I have to take a look into this two options and will test it and give a feedback.

 

 

Thx a lot to all!

 

Share this post


Link to post
Share on other sites

Question 1:

If I add 100 tasks on the "Lucullus way" is it bad for the performance?

Or what exactly is the reason for using the "pierremgi way"?

 

 

Question 2:

I wanna handle some more like "if is leader group", "check if a task is assigned", ... .

All this would be handled in the ..\taskManager.sqf before loading the selected task.

Is it possible to make it on the "pierremgi way"?

Share this post


Link to post
Share on other sites

Use a forEach loop, like so:

{
	execVM (format ["scripts\taskmanager\tasks\%1.sqf");
} forEach ["Girna", "Mike-26", "Airbase", "Kamino", "CampRogain", "AgiaMarina"];
{
	[west, (format ["task%1", (_forEachIndex + 1)]), ["Good luck finding this cookie", "Find Cookie", (format ["cookiemarker%1", (_forEachIndex + 1)])], (format ["cookiemarker%1", (_forEachIndex + 1)]), 1, 3, true]
} forEach ["Girna", "Mike-26", "Airbase", "Kamino", "CampRogain", "AgiaMarina"];

I don't think you need to store any of this information as mentioned above. Except for maybe task index, task name, etc... Anything that you really need. Not the whole code.

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

×