Jump to content
Sign in to follow this  
altis

Run script on spawned units [Alive]

Recommended Posts

I have asked this question over on the Alive thread and also want to ask here.

 

How might i be able to apply the script below to all Opfor units that may spawn during a mission. 

{
    if ((side _x == EAST) && (vehicle _x == _x)) then {
        _x unassignItem "NVGoggles_OPFOR";
        _x addGoggles "Mask_M50";
    }
} forEach allUnits;

Share this post


Link to post
Share on other sites

A bit of research of your own would make the solution obvious.

Just spawn this function and loop it to be executed every X seconds.

Share this post


Link to post
Share on other sites

Look at the alive wiki there is a snippet of script that can do exactly what you ask. I've used it to full loadouts on units spawned with alive.

Share this post


Link to post
Share on other sites

Look at the alive wiki there is a snippet of script that can do exactly what you ask. I've used it to full loadouts on units spawned with alive.

 

Perfect, thank you, i missed that.

 

For anyone else searching:

 

Adding Custom Inits to Spawned Units

The following is one method for adding custom scripts to every spawned unit or object of that class, for example running a script that adds custom gear to a class of units. This will work for units spawned with MP/MCP, the Profiles system and any other spawning method such as Zeus.

HEALTH WARNING: you will need to know the basics of scripting to setup the gear script so it only applies to AI (and not players) or specific factions. Place the following in description.ext and create my_code.sqf with whatever code you want to add to the spawned units. Also be aware that anything added to player units will duplicate if player persistence is on, so it's better to use regular methods for players (or include isPlayer check in your script).

 

class Extended_Init_EventHandlers {

class Man {

init = "_this call (compile preprocessFileLineNumbers 'my_script.sqf')";

};

};

This is an example my_script.sqf thanks to SpyderBlack723 on the BI Forums:

private "_this";

_this = _this select 0;

 

if ((side _this == west) and (!isPlayer _this)) then {

removeallweapons _this;

removeGoggles _this;removeHeadgear _this;removeVest _this;removeUniform _this;removeAllAssignedItems _this;removeBackpack _this;

_this addHeadgear 'Helmet_ACU';_this addUniform 'Uniform_ACU';_this addVest 'Vest_ACU';_this addBackPack 'ACU_Backpack';

{ _this addItemToBackpack"rhs_mag_30Rnd_556x45_M855A1_Stanag"; } forEach [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,18, 19, 20, 21];

{ _this addItemToBackpack "rhs_mag_m67"; } forEach [1, 2, 3, 4];

{ _this addItemToBackpack "SmokeShell"; } forEach [1, 2, 3, 4];

{ _this addItem "FirstAidKit"; } forEach [1, 2, 3, 4, 5];

_this addweapon 'rhs_m4_grip_acog';_this addPrimaryWeaponItem 'rhsusf_acc_ACOG';_this linkItem "ItemMap";

};

Share this post


Link to post
Share on other sites

Thanks again Spyderblack, the snippet works perfectly.  :)

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  

×