MrCrazyDude115 132 Posted April 16, 2017 Hey folks! So throughout the time I spent working on my mod there was one thing I was quite unsure about, and that was randomizing anything from loadouts to music/sounds. When I found a way I personally find simple and useful I thought I should post it here to help other people who are new to modding/mission making. Let's begin. 1) You need to create an array of the things you need, in this tutorial's case, I want to spawn a unit with a random uniform and hat. //Loadout Array _CivSpawnUniform = selectRandom ["LOP_U_AFR_Civ_03","LOP_U_AFR_Civ_06","LOP_U_PMC_Fatigue_02","LOP_U_AFR_Civ_05"]; _CivSpawnHeadgear = selectRandom ["H_Bandanna_gry","H_Bandanna_cbr","H_Bandanna_khk","H_Bandanna_camo","H_Cap_blk","H_Cap_grn","H_Cap_oli","H_mas_afr_Bandana","H_mas_afr_c3","rhs_beanie_green"]; Now take a look at "_CivSpawnUniform", that's the name it'll use if you want to call everything after the "=" symbol on the same line, rather than individually In there, you should place the clothes/uniforms you want your unit to choose from. Your code should look something like this: _NAME = selectRandom ["CLASSNAME1","CLASSNAME2","CLASSNAME3"]; Now you have defined a basic randomize script. How does this work though? Lemme show you. The function below selectRandom; This basically tells the game to look at the class names you have and randomly pick one of them. Don't forget to put the function command BEFORE the class names. Your script should now look like this: _NAME = selectRandom ["CLASSNAME1","CLASSNAME2","CLASSNAME3"]; And voila! The randomization script is working, but how do we get it to actually randomize the unit's gear? I'll be giving the soldier a uniform in the following example: UNITNAME AddUniform _ARRAYname; To finalize it, I'll show you what a full working one looks like: //Loadout Array _CivSpawnUniform = selectRandom ["LOP_U_AFR_Civ_03","LOP_U_AFR_Civ_06","LOP_U_PMC_Fatigue_02","LOP_U_AFR_Civ_05"]; _CivSpawnHeadgear = selectRandom ["H_Bandanna_camo","H_Cap_blk","H_mas_afr_Bandana","H_mas_afr_c3","rhs_beanie_green"]; //Unit Init removeUniform UNITNAME; removeHeadgear UNITNAME; UNITNAME addUniform _CivSpawnUniform; UNITNAME addHeadgear _CivSpawnHeadgear; The above units will have uniforms and headgear randomly selected from the arrays we defined at the top. I really hope this helps some new guys here! If it wasn't easy to understand or if you have any issues, feel free to leave a comment below or contact me through PM. Kind regards, MrCrazyDude115 3 Share this post Link to post Share on other sites
sarogahtyp 1109 Posted April 16, 2017 thx for that dude. I think this will help some beginners. Could you explain why u r using BIS_fnc_selectRandom instead of selectRandom ? Is there any advantage or is this just ur preferential method? 1 Share this post Link to post Share on other sites
MrCrazyDude115 132 Posted April 16, 2017 1 minute ago, sarogahtyp said: thx for that dude. I think this will help some beginners. Could you explain why u r using BIS_fnc_selectRandom instead of selectRandom ? Is there any advantage or is this just ur preferential method? Honestly I'm not sure, by a quick look at the wiki page it seems selectRandom is the "latest", but I'm not sure how it might differ from BIS_fnc_selectRandom. Share this post Link to post Share on other sites
sarogahtyp 1109 Posted April 16, 2017 1 minute ago, MrCrazyDude115 said: Honestly I'm not sure, by a quick look at the wiki page it seems selectRandom is the "latest", but I'm not sure how it might differ from BIS_fnc_selectRandom. I think it doesnt differ. I use it instead of the BIS function. 1 Share this post Link to post Share on other sites
R3vo 2654 Posted April 16, 2017 1 hour ago, sarogahtyp said: I think it doesnt differ. I use it instead of the BIS function. It's faster, that's all. 3 Share this post Link to post Share on other sites
djotacon 190 Posted April 16, 2017 2 hours ago, R3vo said: It's faster, that's all. Not only that in selectRandom in hardcoded in the main game engine and isnt a coded function using sqf, probably is 100 times more faster than BIS_fnc_selectRandom 1 Share this post Link to post Share on other sites
MrCrazyDude115 132 Posted April 16, 2017 1 minute ago, djotacon said: Not only that in selectRandom in hardcoded in the main game engine and isnt a coded function using sqf, probably is 100 times more faster than BIS_fnc_selectRandom Ah, do you recommend I replace BIS_fnc_selectRandom with the other in all my scripts? Share this post Link to post Share on other sites
djotacon 190 Posted April 16, 2017 3 minutes ago, MrCrazyDude115 said: Ah, do you recommend I replace BIS_fnc_selectRandom with the other in all my scripts? Yes and I make a test about the using the "floor" command with floating point values using selectRandom and BIS_fnc_selectRandom to see how to make the rounding (up or down) to get integer values using both solutions. Share this post Link to post Share on other sites
djotacon 190 Posted April 16, 2017 Using selectRandom in array of string to me is the better solution. To understand the "harcoded" solutions vs scripted solutions you must think that the harcoded solution can be done using C++ or embebed assembler - the texture filler of quake engine is done using this -... Share this post Link to post Share on other sites
MrCrazyDude115 132 Posted April 16, 2017 Just now, djotacon said: Using selectRandom in array of string to me is the better solution. So will it look like this: FROM THIS _CivSpawnFood = ["kss_bread","kss_corn"] call BIS_fnc_selectRandom; TO THIS _CivSpawnFood = ["kss_bread","kss_corn"] call selectRandom; Or am I doing something wrong? Share this post Link to post Share on other sites
pierremgi 4906 Posted April 16, 2017 Easy to check in debug console. write your script, click on the little chrono instead of exec. note the iteration time, compare with the alternate script. 2 Share this post Link to post Share on other sites
djotacon 190 Posted April 16, 2017 No. _mibelovedprivatevariable = selectRandom ["kss_bread","kss_corn"]; 1 Share this post Link to post Share on other sites
MrCrazyDude115 132 Posted April 16, 2017 1 minute ago, pierremgi said: Easy to check in debug console. write your script, click on the little chrono instead of exec. note the iteration time, compare with the alternate script. Just now, djotacon said: No. _mibelovedprivatevariable = selectRandom ["kss_bread","kss_corn"]; Thanks for the tip guys! I'll update the main post with that function. Kind regards, MrCrazyDude115 Share this post Link to post Share on other sites
djotacon 190 Posted April 16, 2017 if you are using a vector matrix more than one time in your scripts and you want achive maximum speed you can create a sqf file with all your vector matrix and pre - process the file using public variables to store it, thats is one of the best use of the pre-processor. Example of an units container: Quote contenedor_unidades.sqf //// Unidades Opfor - Opfor units UnidadesapieOPFOR = ["OIA_InfSentry", "OIA_InfTeam", "OIA_InfTeam_AT", "OIA_InfSquad","OI_SniperTeam"]; // Matriz con las unidades a pie definido aqui por aislamiento del codigo UnidadesvehiOPFOR = ["O_MRAP_02_hmg_F","O_MRAP_02_gmg_F"]; UnidadesACOROPFOR = ["O_APC_Wheeled_02_rcws_F","O_MBT_02_cannon_F"]; UnidadesMECAOPFOR = ["O_APC_Tracked_02_cannon_F","O_APC_Tracked_02_AA_F"]; UnidadesAEREOPFOR = ["O_Heli_Attack_02_black_F","O_Heli_Light_02_v2_F","O_Plane_CAS_02_F"]; UnidadesMAROPFOR = ["O_Boat_Transport_01_F","O_Boat_Armed_01_hmg_F"]; after of create the file you can use: call compile preprocessfile "contenedor_unidades.SQF"; in the mission init.sqf and using this you have your vector matrix public and pre-processed using the Arma3 main engine at full speed. Excerpt from code optimization of Arma 3 wiki: Preprocessfilelinenumbers The preprocessFileLineNumbers command remembers what it has done, so loading a file once will load it into memory, therefore if wanted to refrain from using global variables for example, but wanted a function precompiled, but not saved, you could simply use: call compile preprocessfilelinenumbers "file" Remembering the only loss of performance will be the compile time of the string returned and then the call of the code itself. https://community.bistudio.com/wiki/Code_Optimisation 1 Share this post Link to post Share on other sites
MrCrazyDude115 132 Posted April 16, 2017 19 minutes ago, djotacon said: if you are using a vector matrix more than one time in your scripts and you want achive maximum speed you can create a sqf file with all your vector matrix and pre - process the file using public variables to store it, thats is one of the best use of the pre-processor. Example of an units container: after of create the file you can use: call compile preprocessfile "contenedor_unidades.SQF"; in the mission init.sqf and using this you have your vector matrix public and pre-processed using the Arma3 main engine at full speed. Excerpt from code optimization of Arma 3 wiki: Preprocessfilelinenumbers The preprocessFileLineNumbers command remembers what it has done, so loading a file once will load it into memory, therefore if wanted to refrain from using global variables for example, but wanted a function precompiled, but not saved, you could simply use: call compile preprocessfilelinenumbers "file" Remembering the only loss of performance will be the compile time of the string returned and then the call of the code itself. https://community.bistudio.com/wiki/Code_Optimisation That's gonna be very useful. Thank you! Share this post Link to post Share on other sites
killzone_kid 1333 Posted April 16, 2017 48 minutes ago, djotacon said: Not only that in selectRandom in hardcoded in the main game engine and isnt a coded function using sqf, probably is 100 times more faster than BIS_fnc_selectRandom Maybe even 1000 times faster! Seriouly though, there is built-in code performance button, so that there is no need to guess. 2 Share this post Link to post Share on other sites
Greenfist 1863 Posted April 16, 2017 The native command is faster, but not much I assume, since the function is only 3 lines long: #include "..\paramsCheck.inc" paramsCheck(_this,isEqualType,[]) selectRandom _this Share this post Link to post Share on other sites
Spatsiba 89 Posted May 1, 2017 I've noticed that at least one of the BIS_FNC_selecRandom or selecRandom tend to favour former values. So if you have 1, 2 ,3 and selectRandom you'll have a higher change of getting 1. Use the CBA counterpart if possible in my experience. Share this post Link to post Share on other sites
killzone_kid 1333 Posted May 1, 2017 1 hour ago, Spatsiba said: I've noticed that at least one of the BIS_FNC_selecRandom or selecRandom tend to favour former values. So if you have 1, 2 ,3 and selectRandom you'll have a higher change of getting 1. Use the CBA counterpart if possible in my experience. Nonsense! And you should be ashamed of posting such rubbish 1 Share this post Link to post Share on other sites
Grumpy Old Man 3548 Posted May 1, 2017 Might as well add BIS_fnc_selectRandomWeighted which is freaking awesome. Cheers 1 Share this post Link to post Share on other sites
MrCrazyDude115 132 Posted May 1, 2017 3 hours ago, Grumpy Old Man said: Might as well add BIS_fnc_selectRandomWeighted which is freaking awesome. Cheers Woah! Never heard of that one before! I'll look into it, seems like it'll be useful! Share this post Link to post Share on other sites
Spatsiba 89 Posted May 2, 2017 (edited) On 2017-05-01 at 4:07 AM, killzone_kid said: Nonsense! And you should be ashamed of posting such rubbish I'd never be ashamed of anything I'd post on BIS forums. I'll test it and come back to you then. :) EDIT: It was "BIS_fnc_arrayShuffle". Edited May 2, 2017 by Spatsiba Tested Share this post Link to post Share on other sites
killzone_kid 1333 Posted May 2, 2017 4 hours ago, Spatsiba said: I'd never be ashamed of anything I'd post on BIS forums. I'll test it and come back to you then. :) EDIT: It was "BIS_fnc_arrayShuffle". This is even worse. CBA suffle is practically identical to BIS one. Please do not misinterpret this as an invitation to further dialog. Share this post Link to post Share on other sites
Spatsiba 89 Posted May 3, 2017 On 2017-05-02 at 7:54 PM, killzone_kid said: This is even worse. CBA suffle is practically identical to BIS one. Please do not misinterpret this as an invitation to further dialog. Nonsense and you should be ashamed!! Share this post Link to post Share on other sites
MrCrazyDude115 132 Posted May 3, 2017 Alright there seems to be some hostility here.... let's tone it down a bit... Share this post Link to post Share on other sites