Home   Help Search Login Register  

Author Topic: Weapon Respawn  (Read 2897 times)

0 Members and 1 Guest are viewing this topic.

Offline Shadow.D. ^BOB^

  • Members
  • *
Weapon Respawn
« on: 27 Jun 2009, 19:19:25 »
Hey guys, i was wondering if anyone has or knows how to make a weapon respawn script that works in ArmA 2?

I have previously used this (in ArmA):-

http://www.ofpec.com/forum/index.php?topic=28740.0

Which was originally done by Toadlife and updated for ArmA by norrin.  But i cannot seem to get it to work in ArmA 2.  I would really like to use the script for my CTF map pack, as limiting players to certain weapons adds a great deal to the fun.  Though at the moment, on respawn, you get defaulted back to the normal loadout for each soldier type.

If anyone could help me on this matter it would be greatly appreciated, as this is the only thing holding me up.

Cheers...

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Weapon Respawn
« Reply #1 on: 27 Jun 2009, 20:37:06 »
This answer might be equally useful for you.
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Shadow.D. ^BOB^

  • Members
  • *
Re: Weapon Respawn
« Reply #2 on: 27 Jun 2009, 21:41:47 »
Cheers Spooner, i would like to use a "respawn with what you had when you died type script".

I'm still looking around for something that works in ArmA 2, but no look as of yet. If you could point me in the direction of any you know know of, i would be grateful.

If that fails i will look into requiping using the eventhandler method, thanks.
« Last Edit: 27 Jun 2009, 21:43:38 by Shadow.D. ^BOB^ »

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Weapon Respawn
« Reply #3 on: 27 Jun 2009, 22:46:56 »
The big problem with "respawn with what you died with" scripts is that you slowly run out of ammo, so you have to re-equip manually anyway. I've not really paid any attention to these, since I don't like them at all.

I think Toadlife/Norrin have the solution.
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Shadow.D. ^BOB^

  • Members
  • *
Re: Weapon Respawn
« Reply #4 on: 27 Jun 2009, 23:09:36 »
Yeah, i've retried that route and have had some success....

Cheers for your input m8, always appreciated.

Offline JamesF1

  • Editors Depot Staff
  • *****
    • JamesBurgess.co.uk
Re: Weapon Respawn
« Reply #5 on: 28 Jun 2009, 17:36:23 »
Cheers Spooner, i would like to use a "respawn with what you had when you died type script".
Something simple I whipped up a while back that I use very frequently (for "respawn with what you died with"-style) is this (untested in A2... but works a charm in A1 and there is no reason why it shouldn't work):
Code: (respawnGear.sqf) [Select]
private ["_preventLooting", "_hideBodies", "_sWeaps", "_sMags", "_oldPlayer"];

_preventLooting = _this select 0;
_hideBodies = _this select 1;

while { true } do
{
waitUntil {not alive player};

// Save weapons
_sWeaps = weapons player;
_sMags  = magazines player;

if(_preventLooting) then { removeAllWeapons player; };

// In case we need to delete the body on respawn
_oldPlayer = player;

waitUntil {alive player};

// Hide body
if(_hideBodies) then { hideBody _oldPlayer; };

// Re-add weapons
removeAllWeapons player;
{ player addMagazine _x; } foreach _sMags;
{ player addWeapon _x; } foreach _sWeaps;

player selectWeapon (primaryWeapon player);

};

Call it as such (from init.sqf):
Code: [Select]
dummy = [true,true] execVM "respawnGear.sqf";
The first param. is whether to prevent looting by removing the weapons from the body when the player dies... this prevents getting more ammo simply by going back to your body.

The second param. is whether or not to hide the dead body when the player respawns.  This can save some system resource if you have a lot of players dying repeatedly.

I set both params to true, most of the time, as I use this script in all of my squad's missions (to prevent us having to restart our rather long missions every time someone dies... but ensure that people still need to conserve ammo, etc.  It's really only for 'accidental' deaths).

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Weapon Respawn
« Reply #6 on: 28 Jun 2009, 18:52:13 »
This won't work if you have a weapon with multiple muzzles, such as any rifle with an underslung grenade launcher:
Code: [Select]
player selectWeapon (primaryWeapon player);
You can look in SPON Kits if you want to see the way to deal with that.
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline JamesF1

  • Editors Depot Staff
  • *****
    • JamesBurgess.co.uk
Re: Weapon Respawn
« Reply #7 on: 29 Jun 2009, 00:08:10 »
Whoops, you're quite right.  I have an updated script somewhere (can't find it at present), but that obviously wasn't it! :D

Offline Rommel92

  • Members
  • *
Re: Weapon Respawn
« Reply #8 on: 07 Jul 2009, 06:19:34 »
Credits to Xeno, modified by me.

player addeventhandler ["killed","(_this select 0) execvm 'handles\playerkilled.sqf'"];

Code: [Select]
_weapons = weapons _this;
_magazines = magazines _this;

waituntil {alive player};
removeAllWeapons player;
{player addMagazine _x} forEach _magazines;
{player addWeapon _x} forEach _weapons;

_primary = primaryWeapon player;

if (_primary != "") then {
player selectWeapon _primary;
// Grenade launcher Fix
_muzzles = getArray(configFile>>"cfgWeapons" >> _primary >> "muzzles");
player selectWeapon (_muzzles select 0);
};