Jump to content
flymaker

Apply scripts to every unit on mission

Recommended Posts

How to load a script to all units on my mission? There is a way to run this to prelaced and script spawnable units?
I'm trying to use CBA preload eventhandler without sucess.
For example, if i want to replace the main weapon or add satchel to every unit, is that possible?
Maybe running this script to all man classes works. The problem is i'm so dumb to make this work ¬¬'
(If this works for defaut missions will be great)

Share this post


Link to post
Share on other sites
Just now, HazJ said:

Just put it in init.sqf or initPlayerLocal.sqf file? If you need to run the script after respawn. Use the EH:

https://community.bistudio.com/wiki/Arma_3:_Event_Handlers#Respawn


If i dosen't have acces to these files there is a way? For example change all default weapons on vanilla missions to modded weapons.
I can use this event handler to all units?

I guess this have to be a mod to work, right?

Share this post


Link to post
Share on other sites

No. There are multiple ways of doing this. It all depends on what you want/prefer. You can have separate function with switch block that you pass the loadout as var and it selects whatever. Directly in Respawn EH. You can also save loadout so it loads upon respawn.

https://community.bistudio.com/wiki/BIS_fnc_saveInventory

https://community.bistudio.com/wiki/BIS_fnc_loadInventory

Have a search around. You should find some stuff for custom loadouts. I am off to bed, I'll provide example tomorrow sometime. zZz

Share this post


Link to post
Share on other sites

Thx for the info.
I will dig looking for a solution. I dont have much ability to code but with some effort i will do it.
Examples should be good. Thanks again

Share this post


Link to post
Share on other sites
5 hours ago, flymaker said:

How to load a script to all units on my mission? There is a way to run this to prelaced and script spawnable units?
I'm trying to use CBA preload eventhandler without sucess.
For example, if i want to replace the main weapon or add satchel to every unit, is that possible?
Maybe running this script to all man classes works. The problem is i'm so dumb to make this work ¬¬'
(If this works for defaut missions will be great)

 

If you want to run something on every unit once, something like this might do:

 

//initServer.sqf

TAG_fnc_applyStuff = {

	TAG_fnc_applyStuffEnabled = true;//if you want to disable the loop mid-mission, set this to false
	
	while {TAG_fnc_applyStuffEnabled} do {
		
		_units = allUnits select {alive _x AND !(_x getVariable ["TAG_fnc_isStuffApplied",false])};
		systemchat str _units;
		{
			//apply your stuff here, also set flag that stuff has been applied so it only happens once
			_x setUnitPos "DOWN";//just an example
			_x setVariable ["TAG_fnc_isStuffApplied",true,true];
		} forEach _units;

		waitUntil {sleep 1;count (allUnits select {alive _x AND !(_x getVariable ["TAG_fnc_isStuffApplied",false])}) > 0};


	};

};

//spawn it
_init = [] spawn TAG_fnc_applyStuff;

Depends on what you want to apply you need to take command locality into account.

 

Cheers

  • Like 1

Share this post


Link to post
Share on other sites

Since you use CBA here is the proper way to do it. You need something like this in your description.ext file:

class CfgFunctions
{
    class FLY // flymaker
    {
        class Equipment
        {
            class ReplaceEquipment { file = "replaceEquipment.sqf"; };
        };
    };
};

class Extended_Init_EventHandlers
{
    class CAManBase
    {
        class ReplaceEquipment {
            init = "_this call FLY_fnc_ReplaceEquipment;";
        };
    };
};

Then in your script file, in this example it must be placed in the root of your mission folder and named 'replaceEquipment.sqf', you process each unit. The file will now run for all humanoids, regardless of how they are spawned in:

params ["_unit"];

// Do what you want here. I have an example here:

// Only run local to avoid duplicate stuff and ensure we can use local-only commands.
if (!local _unit) exitWith {};

// Let's not mess with human players
if (isPlayer _unit) exitWith {};

// Add the Satchel charge
_unit addMagazine "SatchelCharge_Remote_Mag";

// Switch the weapon
_unit removeWeapon (primaryWeapon _unit);
_unit addWeapon "LMG_Mk200_F";

// Adjust what you need. Don't forget to give new ammo. Recommend you do that before giving the weapon.

 

Share this post


Link to post
Share on other sites
On 08/04/2018 at 10:36 AM, Muzzleflash said:

Since you use CBA here is the proper way to do it. You need something like this in your description.ext file:


class CfgFunctions
{
    class FLY // flymaker
    {
        class Equipment
        {
            class ReplaceEquipment { file = "replaceEquipment.sqf"; };
        };
    };
};

class Extended_Init_EventHandlers
{
    class CAManBase
    {
        class ReplaceEquipment {
            init = "_this call FLY_fnc_ReplaceEquipment;";
        };
    };
};

Then in your script file, in this example it must be placed in the root of your mission folder and named 'replaceEquipment.sqf', you process each unit. The file will now run for all humanoids, regardless of how they are spawned in:


params ["_unit"];

// Do what you want here. I have an example here:

// Only run local to avoid duplicate stuff and ensure we can use local-only commands.
if (!local _unit) exitWith {};

// Let's not mess with human players
if (isPlayer _unit) exitWith {};

// Add the Satchel charge
_unit addMagazine "SatchelCharge_Remote_Mag";

// Switch the weapon
_unit removeWeapon (primaryWeapon _unit);
_unit addWeapon "LMG_Mk200_F";

// Adjust what you need. Don't forget to give new ammo. Recommend you do that before giving the weapon.

 



That is exactly what i need.

Look at this: https://github.com/FlyMakerBR/FM-UserWeaponReplace

I made this code a long ago. I tryed everything to apply this to all units

The script should take user config entries to replace default weapons into new ones
It worked on BIS default campaing but only for pre-placed units
A think my config.cpp is my mistake 

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

×