Jump to content
Sign in to follow this  
jollem

Help with two thing; random loadout and join command!.

Recommended Posts

Hello!

I'm messing around trying to make myself an enjoyable arma 2 mission for me and my friends. But I have now run into trouble with two things I would like to achieve:

Problem 1: I would like to have a script, trigger or whatever works assign 1 of 5 different loadouts to each playable unit in the mission randomly. Would also be nice if I could vary the number of each loadout available for distribution.

Problem 2: And the second thing would be a simple join script or something that allows two players that are close to each other (within X meters) and belong to different groups to join each others groups. Via an added action maybe?

I'm worthless at scripting myself and figuring this out would take ages. Tried searching the net and forums for solutions, but mosly ended up with stuff regarding regular changing of loadouts (which I'm able to achieve myself) and join commands when saving hostages or POWs. Or solutions to similar problems which I wasn't capable of adapting.

Any help is appreciated!

/JM

Share this post


Link to post
Share on other sites

I think I have a solution to your first problem (sorry, as my multiplayer scripting skills aren't very good, I prefered to write it in singleplayer version, though it shouldn't be too hard to convert to multiplayer):

Try this script in single player. Best run via init.sqf (I haven't tested it):

private ["_type", "_position", "_unit"];

_type = floor (random 6);
_position = <Insert your desired position of spawning here>;

switch (_type) do {
case 0: {_unit = "Ins_Soldier_1" createUnit [_position, grpNull, "addSwitchableUnit this"];};
case 1: {_unit = "Ins_Soldier_2" createUnit [_position, grpNull, "addSwitchableUnit this"];};
case 2: {_unit = "Ins_Soldier_Medic" createUnit [_position, grpNull, "addSwitchableUnit this"];};
case 3: {_unit = "Ins_Soldier_AT" createUnit [_position, grpNull, "addSwitchableUnit this"];};
case 4: {_unit = "Ins_Soldier_Sniper" createUnit [_position, grpNull, "addSwitchableUnit this"];};
case 5: {_unit = "Ins_Soldier_MG" createUnit [_position, grpNull, "addSwitchableUnit this"];};
};

It should create one of six different types of units, and it's pretty easy to change the unit types (by changing the unit class) or how many random types to choose from by decreasing/increasing the number "6" and changing the number of "cases".

As I said, I haven't tested this, but I can see a possible problem, as the units created join "grpNull" (a non-existant group), which may cause issues with the "createUnit" command. If it does, try the procedure bellow:

1. Create a gameLogic and group a unit with 0 probability of presence to it.

2. In the init line of the logic type, "grp1 = group this".

3. Replace the "grpNull" in the script with "grp1".

4. Just before you end the script, add the line:

_unit join grpNull

5. Then you can choose which group to place the units in by (after the first code):

_unit join <Insert group here>

Hope it helps

Share this post


Link to post
Share on other sites

In such simple cases where only one thing is random you can work without switch do:

_classarray = ["Ins_Soldier_1","Ins_Soldier_2","Ins_Soldier_Medic","Ins_Soldier_AT","Ins_Soldier_MG"];
_type = _classarray select (floor(random(count _classarray)));
_unit = _type createUnit [_position, grpNull, "addSwitchableUnit this"];

Now by simply adding or removing classnames to/from the array you can expand/reduce it pretty easy. And if you want a certain class be more likely to be spawned, just enter the it's classname a second or even third time to the array.

Share this post


Link to post
Share on other sites

Indeed. Maybe an even simpler version could be:

waitUntil {!isNil "BIS_fnc_init"};
_type = ["Ins_Soldier_1","Ins_Soldier_2","Ins_Soldier_Medic","Ins_Soldier_AT","Ins_Soldier_MG"] call BIS_fnc_selectRandom;
_unit = _type createUnit [_position, grpNull, "addSwitchableUnit this"];

... Actually I don't think this is any "simpler". Just a different variation.

Share this post


Link to post
Share on other sites
Indeed. Maybe an even simpler version could be:

waitUntil {!isNil "BIS_fnc_init"};
_type = ["Ins_Soldier_1","Ins_Soldier_2","Ins_Soldier_Medic","Ins_Soldier_AT","Ins_Soldier_MG"] call BIS_fnc_selectRandom;
_unit = _type createUnit [_position, grpNull, "addSwitchableUnit this"];

... Actually I don't think this is any "simpler". Just a different variation.

Sure this should work aswell. And if the functions module is already used for others functions aswell, sure why not.

But IIRC this approach needs the function module to be placed and if this is the only function used i don't see the point to load all functions by placing the module.

Furthermore, i guess (no prove so far) it is less effective to call a external function compared to a similar solution in the script itself.

_classarray = ["Ins_Soldier_1","Ins_Soldier_2","Ins_Soldier_Medic","Ins_Soldier_AT","Ins_Soldier_MG"];
_unit = (_classarray select (floor(random(count _classarray)))) createUnit [_position, grpNull, "addSwitchableUnit this"];

Shortened by one line.

Share this post


Link to post
Share on other sites

Suppose I would like to make the loadouts I distribute among a array of lets say 5 units custom? Done with different lists of add and remove weapon?

Would that be much different?

Share this post


Link to post
Share on other sites

I too am new to mission editing and recently asked this question.

The situation was i was rescuing prisoners, i named the rescuer "sas" and the prisoner "pow".

The i created a trigger in the editor, with the following:

condition "pow distance sas < 10"

acvtivation "pow join sas"

thanks to a user called Zigzag who helped me figure this out

Share this post


Link to post
Share on other sites

Or use this script to give pre-set units random loadouts based on unit class :) Won't mean some will be medics, some will be engineers, but it will randomize their weaponry!

Regards,

Wolfrug

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  

×