Robustcolor 31 Posted October 25, 2019 Hi, I try to learn abit about passing arguments/params through scripts when spawning ai. This code below is just one of my attempts of doing so. What would you change to make it better? Initserver.sqf call compileFinal preprocessFileLineNumbers "Functions\Units.sqf"; [5,getMarkerpos "Marker1",500] spawn Patrol; My function Patrol = { params ["_howmanyai","_markerpos","_spawndistance"]; private _pos = [_markerpos, 0, _spawndistance, 5, 0, 0.4, 0, [],_markerpos] call BIS_fnc_findSafePos; for "_i" from 1 to _Howmanyai do { private ["_grp1","_unit"]; _grp01 = grpNull; _grp01 = createGroup [east, true]; _unit = _grp01 createUnit [selectRandom ["uns_men_VC_mainforce_AS1","uns_men_VC_mainforce_HMG","uns_men_VC_mainforce_LMG"], _pos, [], 0, "FORM"]; _unit setSkill 1; _unit setSkill ["AimingAccuracy",0.01]; _unit allowFleeing 0; _grp01 enableDynamicSimulation true; _grp01 setSpeedMode "LIMITED"; _grp01 setBehaviour "SAFE"; _grp01 setCombatMode "Red"; {_x addCuratorEditableObjects [units _grp01, true];} foreach allCurators; sleep 2; }; }; Seems to work pretty good, but is it a correct way of spawning them this way? How could i improve it? If you spot useless code lines please point it out. 1 Share this post Link to post Share on other sites
engima 328 Posted October 25, 2019 _grp01 = grpNull; 1 Share this post Link to post Share on other sites
wogz187 1086 Posted October 26, 2019 There's no sense to writing a new spawn soldiers script every time we begin a new mission... With MMF_fnc you can add your soldiers to the configurable array or just add a custom array and spawn however many you want, wherever you want, whenever you want, with half a dozen other options, all with a single function call. Yours would look like this, MMF_custom=["uns_men_VC_mainforce_AS1","uns_men_VC_mainforce_HMG","uns_men_VC_mainforce_LMG"]; [_pos, 3, INDEPENDENT, MMF_custom, "SAFE", _pos, 0, 0, 0, 1] call MMF_fnc_soldiers; Have fun! 1 Share this post Link to post Share on other sites
Robustcolor 31 Posted October 26, 2019 Thanks. Is it possible to change group size through param? Since my spawngroup already have 5 units in the group. [2,getMarkerpos "Marker1",500] spawn Patrolgroup; Patrolgroup = { params ["_patrol","_markerpos","_spawndistance"]; for "_i" from 1 to _patrol do { private ["_grp1"]; private _pos = [_markerpos, 0, _markerSize, 5, 0, 0.4, 0, [],_markerpos] call BIS_fnc_findSafePos; _grp01 = [_pos, east, ["uns_men_NVA_65_MGS","uns_men_NVA_65_LMG","uns_men_NVA_65_AT","uns_men_NVA_65_AA","uns_men_NVA_65_HMG"],[],[],[1,1],[1,1]] call BIS_fnc_spawnGroup; sleep 2; }; }; What's the difference in using Cfgfunctions library - class Unithandler{preinit = 1;}; and call compileFinal preprocessFileLineNumbers "Functions\Unithandler.sqf"; What is the best way to activate the fnc that have all the variables of units? Share this post Link to post Share on other sites
wogz187 1086 Posted October 26, 2019 Quote Is it possible to change group size through param? [_pos, 5, INDEPENDENT, MMF_custom, "SAFE", _pos, 0, 0, 0, 1] call MMF_fnc_soldiers; 😄 Share this post Link to post Share on other sites
Robustcolor 31 Posted October 27, 2019 When is it good to [] spawn a compile like this vs a regular call compile. [] spawn {_this call compileFinal preprocessFileLineNumbers "Functions\fn_Units.sqf";}; Share this post Link to post Share on other sites
Mr H. 402 Posted October 27, 2019 1 hour ago, Robustcolor said: When is it good to [] spawn a compile like this vs a regular call compile. Never. Declare it in cfg functions and then spawn it. Share this post Link to post Share on other sites
Robustcolor 31 Posted October 28, 2019 8 hours ago, Mr H. said: Never. Declare it in cfg functions and then spawn it. Ok, so if i have a script with alot of other functions inside of it that i want to call. How would i activate that function through cfg functions? Since this won't find my functions inside that script called Aihandler. Should i use preinit? class CfgFunctions { class Robust { class Mission { file = "functions"; class Aihandler{}; }; }; }; Example _m1 = [_inf,_markerpos,_range] spawn Test; waitUntil {scriptDone _m1}; _m2 = [_inf,_markerpos,_range] spawn Test2; waitUntil {scriptDone _m2}; Aihandler.sqf Test = { code }; Test2 = { code }; Share this post Link to post Share on other sites
Mr H. 402 Posted October 28, 2019 But why to you do that since you have a cfg functions? Why not just declare them along the others? Share this post Link to post Share on other sites
Robustcolor 31 Posted October 28, 2019 7 minutes ago, Mr H. said: But why to you do that since you have a cfg functions? Why not just declare them along the others? Could you explain more, maybe a example? 🙂 Share this post Link to post Share on other sites
Mr H. 402 Posted October 28, 2019 class CfgFunctions { class Robust { class Mission { file = "functions"; class Aihandler{}; class test; }; }; }; [Some params] spawn Test Share this post Link to post Share on other sites
Robustcolor 31 Posted October 28, 2019 18 minutes ago, Mr H. said: class CfgFunctions { class Robust { class Mission { file = "functions"; class Aihandler{}; class test; }; }; }; [Some params] spawn Test Gives error, can't find test.sqf. So apparently it does not search inside the Aihandler.sqf for the test function. Share this post Link to post Share on other sites
Mr H. 402 Posted October 28, 2019 Your file has to be named fn_test.sqf and placed in the directory named functions Same for your aihandler the sqf has to be prefixed with fn_ Share this post Link to post Share on other sites
Robustcolor 31 Posted October 28, 2019 So using Inline functions is not a way to go? Instead i should be doing Functions-as-files with everything? Share this post Link to post Share on other sites
Mr H. 402 Posted October 28, 2019 Depends on what you aim for. Security wise it's better to have them declared in the cfgFunctions. I also find that separate files for each function is clearer and easier to maintain Share this post Link to post Share on other sites