Jump to content
Sign in to follow this  
Zaptoman

AI Retain Loadout on Respawn

Recommended Posts

So here's the problem. I have AI guys with a custom loadout at the beginning of a mission. Then they respawn, and they go back to their default loadout. I want them to respawn with the loadout they started with. I'm currently using the following script for players, which works fine. I just don't know how to make it work with the AI.

if (hasInterface) then {
    [] spawn {
        waitUntil {alive player};
        player setVariable ["loadout",getUnitLoadout player,false];
        player addEventHandler ["Respawn", {
            player setUnitLoadout (player getVariable "loadout");
        }];
    };
};

Share this post


Link to post
Share on other sites

for Ais and players:

 

if (hasInterface) then { 
  [] spawn { 
    waitUntil {alive player}; 
    player setVariable ["loadout", getUnitLoadout player]; 
  }; 
};
if (isServer) then {
  addMissionEventHandler ["entityKilled", { 
    params ["_unit"]; 
    if (isNil {_unit getVariable "loadout"} && !isPlayer _unit) then {
      _unit setVariable ["loadout", getUnitLoadout _unit]
    };
  }];
  addMissionEventHandler ["entityRespawned", { 
    params ["_unit"];
    _unit setUnitLoadout (_unit getVariable "loadout")
  }]
};

You need both MEH because the respawned one doesn't grab the dropped weaponholder when the unit is killed, the MEH killed does.

 

feel free to add some filter for side or else.

  • Like 1

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  

×