Jump to content
Sign in to follow this  
Chris_37

Random Gear Loadout On All Players

Recommended Posts

Hello, i am wondering if anyone is able to help me but i am struggling to be able to come up with something which, on the mission loading, will create a random load out and exec it on everyone on the server. I have looked around but haven't been able to find much. Any suggestions?

Share this post


Link to post
Share on other sites

Hello, you could try this in your mission initServer.sqf

private _class = [];
{_class pushback configName _x} forEach ("getText (_x >> 'simulation') isEqualTo 'soldier'" configClasses (configFile >> "CfgVehicles"));

missionNamespace setVariable ["gear", selectRandom _class, true];

and write this in your mission initPlayerLocal.sqf

[] spawn {waitUntil {!isNil "gear"}; player setUnitLoadout gear};

I hope this helps

  • Like 2

Share this post


Link to post
Share on other sites
9 hours ago, Nikander said:

Hello, you could try this in your mission initServer.sqf


private _class = [];
{_class pushback configName _x} forEach ("getText (_x >> 'simulation') isEqualTo 'soldier'" configClasses (configFile >> "CfgVehicles"));

missionNamespace setVariable ["gear", selectRandom _class, true];

and write this in your mission initPlayerLocal.sqf


[] spawn {waitUntil {!isNil "gear"}; player setUnitLoadout gear};

I hope this helps

 

Would this actually work?

getUnitloadout is needed to get the loadout from a classname.

Was setUnitLoadout changed to also use classnames to retrieve the loadout info? Wiki doesn't state it, that's why I'm asking.

 

Edit: Tested it, wiki is not up to date, setUnitLoadout accepts class names. Awesome!

Changed the examples below, one less check is always welcome, heh.

 

This could work if the OP wants to refer to default class loadouts:

initPlayerLocal.sqf:

 

 

_allClasses = ("getText (_x >> 'simulation') isEqualTo 'soldier'" configClasses (configFile >> "CfgVehicles")) apply {configName _x};
_rndClass = selectRandom _allClasses;
player setUnitLoadout _rndClass;

This works but also includes all loadouts from all sides, including civilian. Not sure if the OP wants that.

 

To limit it to loadouts from the players side, so only blufor loadouts will be available to blufor players:
 

_allClasses = ("getText (_x >> 'simulation') isEqualTo 'soldier' AND (getNumber (_x >> 'side') isEqualTo (side player call BIS_fnc_sideID))" configClasses (configFile >> "CfgVehicles")) apply {configName _x};
_rndClass = selectRandom _allClasses;
player setUnitLoadout _rndClass;

 

There are plenty of ways to achieve this if the OP is a bit more specific what exactly he wants to accomplish.

 

Cheers

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
Sign in to follow this  

×