armatoday 12 Posted December 20, 2016 Hi there, I have following scripts running on: initServer.sqf missions = [1,2,3]; nul = []execVM "RandomTasks.sqf"; RandomTasks.sqf if ((count missions) == 0) then {[call bis_fnc_endMission] call bis_fnc_MP}; _selectedmission = missions select (floor(random(count missions))); if (_selectedmission == 1) then {[] execVM "tasks\task1.sqf"}; if (_selectedmission == 2) then {[] execVM "tasks\task2.sqf"}; if (_selectedmission == 3) then {[] execVM "tasks\task3.sqf"}; missions = missions - [_selectedmission]; It is running for selecting random task but returns the following error on mission end Image of error Thank you for your help in advance. Share this post Link to post Share on other sites
davidoss 550 Posted December 20, 2016 its because count is counting from 1 and select is selecting array index from 0. use if (missions isEqualTo []) exitWith {"EveryoneWon" call BIS_fnc_endMissionServer}; _selectedmission = selectRandom missions; instead Share this post Link to post Share on other sites
armatoday 12 Posted December 20, 2016 Thank you davidoss once again :) Edited : But it is not repeating tasks , right? Edited : Tested and that's OK. Thank you :) To sum up for anyone would need this: initServer.sqf missions = [1,2,3]; nul = []execVM "RandomTasks.sqf"; RandomTasks.sqf if (missions isEqualTo []) exitWith {"EveryoneWon" call BIS_fnc_endMissionServer}; _selectedmission = selectRandom missions; if (_selectedmission == 1) then {[] execVM "tasks\task1.sqf"}; if (_selectedmission == 2) then {[] execVM "tasks\task2.sqf"}; if (_selectedmission == 3) then {[] execVM "tasks\task3.sqf"}; missions = missions - [_selectedmission]; Share this post Link to post Share on other sites
davidoss 550 Posted December 20, 2016 no its cant repeat task because the selected index are removed on each loop missions = missions - [_selectedmission]; Share this post Link to post Share on other sites
Larrow 2779 Posted December 20, 2016 Quote its because count is counting from 1 and select is selecting array index from 0. This is not true, count missions = 3 random 3 = value between(0-2.99999) floor value = 0 1 or 2 Which is fine. //initServer.sqf missions = [ "tasks\task1.sqf", "tasks\task2.sqf", "tasks\task3.sqf" ]; nul = []execVM "RandomTasks.sqf"; //randomTasks.sqf if ( missions isEqualTo [] ) exitWith {[ "EveryoneWon" ] call BIS_fnc_endMissionServer}; [] execVM ( missions deleteAt floor random count missions ); 1 Share this post Link to post Share on other sites
armatoday 12 Posted December 20, 2016 Thank you both of you for your valuable help. I really hope to see you at my next question :) The topic is now changed to solved. 1 Share this post Link to post Share on other sites