Home   Help Search Login Register  

Author Topic: Choosing Weapons At Respawn  (Read 1796 times)

0 Members and 1 Guest are viewing this topic.

Offline SaBrE

  • Members
  • *
  • I was once a Llama
    • www.Armed-Assault-Zone.com
Choosing Weapons At Respawn
« on: 02 Apr 2007, 13:01:16 »
This is a quote from the OFP RespawningTutorial:
Code: [Select]
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:
Code: [Select]
;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):
Quote
_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:
Quote
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:
Code: [Select]
player addEventHandler ["killed", {_this exec "respawn.sqs"}]and I made the Respawn.sqs as this:
Code: [Select]
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.
« Last Edit: 03 Apr 2007, 11:49:30 by SaBrE »
Can you HELP?

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
Re: Choosing Weapons At Respawn
« Reply #1 on: 05 Apr 2007, 19:07:51 »
I have not looked at the above code, but there are respawn scripts in the Editors Depot Script section. There is one there by toadlife that should do what you want.
The problem is that once the player dies, the variable _unit which is local to the script, refers to the dead body, not the newly spawned player. Using player as you have done is the best solution.

In the tute, Q10 is referring (I think) to AI, not players.
urp!