Pretty much, as the title says. I've written a little script for respawning AI's, which is executed in the AI's init like this:
null = [this, 1] execVM "wasteland_code\spawning\ai_respawn.sqf";
Which sets the AI "this" to respawn after 1 second. I've done the same thing for an AI next to it, but set it to 10 minutes in the init, which works fine, but when I shoot the first AI, and then the second, they both respawn after 10 minutes, instead of 1 second, 10 minutes respectively, I'm assuming this because of some sort of mix up in the scope.
ai_respawn.sqf
_obj = _this select 0;
_delay = _this select 1;
_obj addEventHandler ["killed", Format["[_this select 0, _this select 1, 1, %1] execVM 'wasteland_code\utilities\removeBody.sqf'", _delay]];
removeBody.sqf:
_unit = _this select 0;
_attacker = _this select 1;
_respawn = _this select 2;
_weapons = null;
_magazines = null;
_pos = null;
_uType = null;
hideBodyDelay = 4;
deleteBodyDelay = 4;
respawnDelay = _this select 3;
//_wlDebugString =
//hint (Format ["Respawn: %1\nDelay: %2", _respawn, respawnDelay]);
if ( _respawn > 0 ) then
{
// The Unit must be respawned, copy things.
//_group = group _unit;
_weapons = weapons _unit;
_magazines = magazines _unit;
_pos = getPosATL _unit;
_uType = typeOf _unit;
_dir = direction _unit;
};
hint "Unit Dead";
sleep hideBodyDelay;
//hint "Hiding Body";
hideBody _unit;
sleep deleteBodyDelay;
//hint "Deleting Body";
//deleteVehicle _this;
if ( _respawn > 0 ) then
{
sleep respawnDelay;
hint "Respawning...";
_newUnit = (group player) createUnit [_uType, _pos, [], 0, "none"];
hint "Spawned, setting up";
_newUnit setDir _dir;
null = [_newUnit, respawnDelay] execVM "wasteland_code\spawning\ai_respawn.sqf";
removeAllWeapons _newUnit; removeAllItems _newUnit;
{_newUnit addMagazine _x} foreach _magazines;
{_newUnit addWeapon _x} foreach _weapons;
hint "Done setting up";
[_newUnit] join grpNull;
}
hint "Done!";
ADDITIONALLY: is there a way to get the unit to spawn without joining the players group? I've tried createGroup resistance and assigning the AI to that group, but it doesn't spawn :(