This is a quote from the OFP RespawningTutorial:
Q10
--
When my units respawn using base respawn, they don't respawn with the weapons they
started with, how can I fix this?
A10
--
The following will give the units the weapons it started with.
Unit's Init field - _this addEventHandler ["killed", {_this exec "unitspawn.sqs"}]
;MyRespawn.sqs
_unit = _this select 0
_unit removealleventhandlers "Killed"
_weapArray = weapons _unit
_magArray = magazines _unit
_primary = primaryweapon _unit
@ alive _unit
removeallweapons _unit
_unit addEventHandler ["killed", {_this exec "unitspawn.sqs"}]
{_unit addMagazine _x} forEach _magArray
{_unit addWeapon _x} forEach _weapArray
_unit selectWeapon _primary
Alternatively you can specify a different loadout:
@ alive _unit
removeallweapons _unit
_unit addmagazine "XXXXX"
_unit addmagazine "XXXXX"
_unit addmagazine "XXXXX"
_unit addweapon "XXXXX"
And this is my script:
;MyRespawn.sqs
_unit = _this select 0
_unit removealleventhandlers "Killed"
_weapArray = weapons _unit
_magArray = magazines _unit
_primary = primaryweapon _unit
@ alive _unit
removeallweapons _unit
_unit addEventHandler ["killed", {_this exec "unitspawn.sqs"}]
_unit addmagazine "jam_w556m_200mag"
_unit addmagazine "jam_w556m_200mag"
_unit addweapon "ukf_lmgsusat"
_unit addmagazine "blb_satchel"
_unit addmagazine "blb_satchel"
_unit addmagazine "blb_mine"
_unit addmagazine "blb_mine"
_unit addmagazine "blb_mine"
_unit addmagazine "blb_mine"
_unit addweapon "blb_satchel"
_unit addweapon "blb_mine"
_unit addweapon "binocular"
_unit addweapon "nvgoggles"
_unit addmagazine "jam_glocksdmag"
_unit addmagazine "jam_glocksdmag"
_unit addmagazine "jam_glocksdmag"
_unit addmagazine "jam_glocksdmag"
_unit addweapon "jam_glocksd"
_unit selectWeapon _primary
However, it doesn't work! I still spawn with just an AK with 1 magazine. Can you correct my mistakes? I tried in the unit's init field (as advised above):
_this addEventHandler ["killed", {_this exec "unitspawn.sqs"}]
But it came up with the error about local variable in global space, so I changed it to:
this addEventHandler ["killed", {_this exec "unitspawn.sqs"}]
Any idea why the whole thing won't work?
Thanks a lot,
Sabre
EDIT:I got it working: In the Init.sqs, I put:
player addEventHandler ["killed", {_this exec "respawn.sqs"}]
and I made the Respawn.sqs as this:
player removealleventhandlers "Killed"
_weapons = weapons player
_ammo = magazines player
_primary = primaryweapon player
@ alive player
removeallweapons player
player addEventHandler ["killed", {_this exec "respawn.sqs"}]
{player addMagazine _x} forEach _ammo
{player addWeapon _x} forEach _weapons
player selectWeapon _primary
The above script makes it so the player wakes up with the weapons they died with. Works a treat.