Casio91Fin 31 Posted August 15, 2021 Is it possible for the AI team to randomly select their own mission? I'm feeling like a terribly long to write the script, because the AI group is created, however, in many cases again. What I’m looking for here AI randomly chooses a task for himself. a list of possibilities for what the AI could do 1. [New_AI_Group_3, _pos_1, 500] call lambs_wp_fnc_taskPatrol; 2.[New_AI_Group_3, _pos_1, 50] call lambs_wp_fnc_taskCamp; 3.[New_AI_Group_3, _pos_1, 50] call lambs_wp_fnc_taskGarrison; 4.[New_AI_Group_3, _pos_1, 50] spawn lambs_wp_fnc_taskCQB; 5.[New_AI_Group_3, _pos_1] call BIS_fnc_taskDefend; 6.[New_AI_Group_3, _pos_1, 1000] call BIS_fnc_taskPatrol; //Jalkaväki for "_x" from 0 to (1 * Multiplier) do { New_AI_Group_3 = createGroup [independent, true]; _AI_Spawn_Pos = [_Pos_1, 40, 160, 10 + random 15, 0, 20, 0] call BIS_fnc_findSafePos; _AI_Leader = New_AI_Group_3 createUnit [JalkavakiJohtajat select floor (random count JalkavakiJohtajat), _AI_Spawn_Pos, [], 0, "NONE"]; _AI_Leader setRank "SERGEANT"; [_AI_Leader, "SERGEANT"] call BIS_fnc_setUnitInsignia; _AI_Leader allowFleeing 0; _AI_Leader setSkill (0.75 + random 0.25); _AI_Leader enableAIFeature ["AUTOTARGET", false]; _AI_Leader enableAIFeature ["RADIOPROTOCOL", true]; _AI_Leader enableAIFeature ["COVER", true]; _AI_Leader enableAIFeature ["PATH", true]; sleep 2; for "_x" from 0 to (2 + (floor random 2 + 3 * Multiplier)) do { _NewAI = New_AI_Group_3 createUnit [JalkavakiSotilaat select floor (random count JalkavakiSotilaat), _AI_Spawn_Pos, [], 0 ,"NONE"]; _AINewRank = selectRandom ["PRIVATE","PRIVATE","PRIVATE","CORPORAL"]; _NewAI setRank _AINewRank; [_NewAI, _AINewRank] call BIS_fnc_setUnitInsignia; _NewAI allowFleeing 0; _NewAI setSkill (0.45 + random 0.55); _NewAI enableAIFeature ["AUTOTARGET", false]; _NewAI enableAIFeature ["RADIOPROTOCOL", true]; _NewAI enableAIFeature ["PATH", true]; _NewAI enableAIFeature ["SUPPRESSION", true]; }; sleep .5; New_AI_Group_3 setBehaviour "AWARE"; New_AI_Group_3 setCombatMode "RED"; [New_AI_Group_3, _pos_1, random 100 + 150] spawn lambs_wp_fnc_taskCQB; }; Share this post Link to post Share on other sites
UnDeaD. 82 Posted August 15, 2021 Something like this: _rand = round (random 5); switch (_rand) do { case 0: {[New_AI_Group_3, _pos_1, 500] call lambs_wp_fnc_taskPatrol;}; case 1: {[New_AI_Group_3, _pos_1, 50] call lambs_wp_fnc_taskCamp;}; case 2: {[New_AI_Group_3, _pos_1, 50] call lambs_wp_fnc_taskGarrison;}; case 3: {[New_AI_Group_3, _pos_1, 50] spawn lambs_wp_fnc_taskCQB;}; case 4: {[New_AI_Group_3, _pos_1] call BIS_fnc_taskDefend;}; case 5: {[New_AI_Group_3, _pos_1, 1000] call BIS_fnc_taskPatrol;}; }; 1 Share this post Link to post Share on other sites
mr_centipede 31 Posted August 16, 2021 5 hours ago, UnDeaD. said: Something like this: _rand = round (random 5); .... I think it should probably be (random 6) since its 0 to 5 ( 6 items ) 1 Share this post Link to post Share on other sites
Casio91Fin 31 Posted August 16, 2021 (edited) @UnDeaD. i am going to test and yes @mr_centipede is right it must be 6. Thank you, the script is working very well Edited August 16, 2021 by Casio91Fin thx... Share this post Link to post Share on other sites
sarogahtyp 1108 Posted August 16, 2021 4 hours ago, mr_centipede said: I think it should probably be (random 6) since its 0 to 5 ( 6 items ) This is nonsense. round random 5 produces integer values between 0 and 5 including 0 and 5. This is exactly what the 6 switch cases are handling. Using round random 6 means that 1/7th of all executions will do nothing because there is no case for 6 in the switch... 2 Share this post Link to post Share on other sites
mr_centipede 31 Posted August 16, 2021 5 minutes ago, sarogahtyp said: This is nonsense. round random 5 produces integer values between 0 and 5 including 0 and 5. This is exactly what the 6 switch cases are handling. Using round random 6 means that 1/7th of all executions will do nothing because there is no case for 6 in the switch... It seems you are indeed correct. My mistake. Sorry for the confusion that it might caused. Share this post Link to post Share on other sites
sarogahtyp 1108 Posted August 16, 2021 Also even if the switch solution works I would go with another solution which should be faster especially if you add more possible tasks: _tasks_array = [ {[New_AI_Group_3, _pos_1, 500] call lambs_wp_fnc_taskPatrol;}, {[New_AI_Group_3, _pos_1, 50] call lambs_wp_fnc_taskCamp;}, {[New_AI_Group_3, _pos_1, 50] call lambs_wp_fnc_taskGarrison;}, {[New_AI_Group_3, _pos_1, 50] spawn lambs_wp_fnc_taskCQB;}, {[New_AI_Group_3, _pos_1] call BIS_fnc_taskDefend;}, {[New_AI_Group_3, _pos_1, 1000] call BIS_fnc_taskPatrol;} ]; [] call ( selectRandom _tasks_array ); It's also simpler to add new tasks with that... 3 Share this post Link to post Share on other sites