OFPEC Forum
Editors Depot - Mission Editing and Scripting => Arma2 - Editing/Scripting Multiplayer => Topic started by: Shadow.D. ^BOB^ 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...
-
This answer (http://www.ofpec.com/forum/index.php?topic=33525.0) might be equally useful for you.
-
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.
-
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 (http://www.ofpec.com/forum/index.php?topic=28740.0).
-
Yeah, i've retried that route and have had some success....
Cheers for your input m8, always appreciated.
-
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):
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):
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).
-
This won't work if you have a weapon with multiple muzzles, such as any rifle with an underslung grenade launcher:
player selectWeapon (primaryWeapon player);
You can look in SPON Kits if you want to see the way to deal with that.
-
Whoops, you're quite right. I have an updated script somewhere (can't find it at present), but that obviously wasn't it! :D
-
Credits to Xeno, modified by me.
player addeventhandler ["killed","(_this select 0) execvm 'handles\playerkilled.sqf'"];
_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);
};