Replacing Weapons from ALiVE spawned Units (solved)

  1. 7 years ago

    Hello,
    I have tried to run a script on my dedicated ALiVE server which forces a certain Loadout for the defined Soldiers classes (Just replacing the Gun from the Soldier).
    So far it does work on Editor placed units but I had no luck with ALiVE spawned units.
    Sadly I couldnt figure it out myself and with the help of the Interwebs, so I hope you guys can help me out.

    I've tried using the following in description.ext based on what I found from others:

    class Extended_Init_EventHandlers {
    class Man {
    init = "_this call (compile preprocessFileLineNumbers 'ForceLoadouts.sqf')";
    };
    };

    ForceLoadouts.sqf:

    private "_this";
    _this = _this select 0;
    {
    
    if (typeof  _x == "CUP_O_TK_Soldier_AR") then { [_x] execVM "RpkLoadout.sqf"};
    
    } forEach units group _this;

    RpkLoadout.sqf:

    //Rpk Loadout
    
    waitUntil {!isNull player};
    _unit = _this select 0;
    
    removeAllWeapons _unit;
    _unit addMagazines ["hlc_45Rnd_545x39_t_rpk", 4];
    _unit addWeapon "Weapon_hlc_rifle_rpk74n";
    
    if(true) exitWith{};

    Any help is greatly appreciated!

  2. @Mumen Rider
    Did you take a look at:Script Snippets ?
    There is one example how to add Custom Inits to Spawned Units.
    With a "if class == grenadier" and such things you should be able to put those to work.

  3. @Murdock
    Thank you for replying!
    I did take a look at the Script Snippets and since im running multiple factions I try to use the class names of the units directly (e.g "CUP_O_TK_Soldier") rather than their role (Grenadier, Medic etc.).
    Still had no luck with it.

  4. Edited 7 years ago by SpyderBlack723

    Hi,
    try this

    params ["_unit"];
    
    {
    	if (typeof  _x == "CUP_O_TK_Soldier_AR") then {
    		[_x] execVM "RpkLoadout.sqf";
    
    		// debug
    		systemchat format ["Replacing unit loadout: %1", _x];
    	};
    } forEach units group _unit;

    Also the

    waitUntil {!isNull player};

    line can be removed since if used on a server it will cause the script to never run.

    if(true) exitWith{};

    is also not needed

    Let me know how it works out

  5. @SpyderBlack723
    Thanks it works now!
    But I do have another Question, when I copy and paste this code
    { if (typeof _x == "CUP_O_TK_Soldier_AR") then { [_x] execVM "RpkLoadout.sqf"; // debug systemchat format ["Replacing unit loadout: %1", _x]; }; } forEach units group _unit;
    into the Loadouts.sqf to add another Unit, the Script doesnt work anymore at all.
    Here is my Loadouts.sqf at it its atm (apologize my code structure):

    params ["_unit"];
    
    if (typeof  _x == "CUP_O_TK_Soldier_AA","CUP_O_TK_Soldier_AAT","CUP_O_TK_Soldier_AMG","CUP_O_TK_Soldier_HAT","CUP_O_TK_Commander",
    			"CUP_O_TK_Engineer","CUP_O_TK_Medic","CUP_O_TK_Soldier","CUP_O_TK_Soldier_Backpack","CUP_O_TK_Soldier_LAT",
    			"CUP_O_TK_Soldier_AT","CUP_O_TK_Soldier_FNFAL_Night","CUP_O_TK_Spotter","CUP_O_TK_Soldier_SL","CUP_O_TK_SpecOps_TL",
    			"CUP_O_TK_Story_Aziz") then { [_x] execVM "FalLoadout.sqf"};
    
    } forEach units group _unit;
    
    {
    
    if (typeof  _x == "CUP_I_TK_GUE_Soldier_AA","CUP_I_TK_GUE_Soldier_AR","CUP_I_TK_GUE_Demo","CUP_I_TK_GUE_Soldier",
    			"CUP_I_TK_GUE_Soldier_AAT","CUP_I_TK_GUE_Soldier_AT","CUP_I_TK_GUE_Mechanic","CUP_I_TK_GUE_Soldier_TL",
    			"CUP_I_TK_GUE_Commander") then { [_x] execVM "AkmLoadout.sqf"};
    
    } forEach units group _unit;
    
    {
    
    if (typeof  _x == "CUP_O_TK_Crew","CUP_O_TK_Officer","CUP_O_TK_Pilot") then { [_x] execVM "ak74uLoadout.sqf"};
    
    } forEach units group _unit;
    
    {
    
    if (typeof  _x == "CUP_I_TK_GUE_Soldier_GL","CUP_I_TK_GUE_Soldier_AK_47S") then { [_x] execVM "AkmGlLoadout.sqf"};
    
    } forEach units group _unit;
    
    {
    
    if (typeof  _x == "CUP_O_TK_Soldier_AR") then { [_x] execVM "RpkLoadout.sqf"};
    
    } forEach units group _unit;
    

    I tried to define multiple classes for the "x_ == " but that messed the whole script up.
    Is there a way to define mutiple soldier classes who use the same loadout without having to CnP everything with just one changed string?

  6. Edited 7 years ago by SpyderBlack723

    When testing to see if the unit is of multiple classes, you need to group your classes that you are testing (typeof _x) against inside an array and then use the in command like so

    if (typeof _x in ["CUP_I_TK_GUE_Soldier_GL","CUP_I_TK_GUE_Soldier_AK_47S"]) then { [_x] execVM "AkmGlLoadout.sqf"};

    Here is the reformatted script

    https://gist.github.com/SpyderBlack723/fe41eff0aa7aaad4582c1a8eab8e5bb7

  7. Edited 7 years ago by Mumen Rider

    Hi tried your code and still ran into the issue that no Units were spawning with the preset loadout.
    I looked into the RPT file too see whats going on and found these 2 lines multiple times:

    Error in expression < then { [_x] execVM "FalLoadout.sqf"};
    
    } forEach units group _unit;
    
    {
    
    if (typ>
      Error position: <} forEach units group _unit;
    
    {
    
    if (typ>
      Error Missing {
    File mpmissions\__cur_mp.lingor3\ForceLoadouts.sqf, line 8
    Error in expression < then { [_x] execVM "FalLoadout.sqf"};
    
    } forEach units group _unit;
    
    {
    
    if (typ>
      Error position: <} forEach units group _unit;
    
    {
    
    if (typ>
      Error Missing {
  8. Should work now
    https://gist.github.com/SpyderBlack723/fe41eff0aa7aaad4582c1a8eab8e5bb7

    :)

  9. Thanks for helping people you dont know.
    Sharing knowledge is a very honorable thing to do.
    Everything works as expected and I can finally go to sleep without having to google "Arma 3 Loadout scripts" :P
    Best wishes and thank you again very much

  10. highhead

    25 Apr 2016 Administrator

    Happy, that it works for you mate! I will mark this thread as solved!

  11. Hi guys, I've got a quick question regarding this:
    If I use this to spawn units with hlc/niarms weapons instead of their standard weapons, will it effect fps more than if I change their weapons directly in the units mod?
    I would assume this, because everytime a unit spawns, an additional script will be executed.
    If this is does not have a larger effect on fps than spawning units without an additional loadout script, I would gladly use this method since it will save me some work.

  12. It is a rather fast execution so they're usually isn't a huge concern with performance (as long as you arent executing a ton of code on each unit). Changing the weapons of the unit's with a config patch would be better but probably not worth the work.

  13. That sounds great. Then I will try this method first.
    Thanks for the quick answer!

  14. Sorry for reopening this thread. I have found that Spyder's original solution works well when spawned with Zeus, however the units are not spawning from ALiVE with the custom loadout. The link with the final solution from Spyder appears to be broken/old. Would it be possible to relink or post the final solution in this thread. Thank you.

  15. This should still be relevant

    Although, here is a bit more modernized version of the my_script.sqf

    params ["_unit"];
    
    if !(isPlayer _unit) then {
    
    	switch (str side _unit) do {
    		case "EAST": {
    			// unit is not a player
    			// and belongs to opfor side
    		};
    		case "WEST": {
    			// unit is not a player
    			// and belongs to blufor side
    		};
    		case "GUER": {
    			// unit is not a player
    			// and belongs to independant side
    		};
    	};
    
    };

    Should work just fine on all units regardless of spawn method.

  16. Thank you very much. Your assistance is greatly appreciated.

 

or Sign Up to reply!