Jump to content
Sign in to follow this  
SD_BOB

Weapon Respawn

Recommended Posts

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...

EDIT:- After playing some more, i have had some success so call this solved for now.

Edited by Shadow.D. ^BOB^

Share this post


Link to post
Share on other sites

I can't test this right now, so I rely on feedback (PC out of action), but this may do the trick.

Respawn with weapons you die with

Players initialization line:

_xhandle = this addEventHandler ["killed", "_this execvm 'weaponRespawn.sqf'"];

weaponRespawn.sqf

_unit = _this select 0;
_weapons = weapons _unit;
_magazines = magazines _unit;

waituntil {alive player};

_unit = player;
removeallweapons _unit;
{_unit addmagazine _x} foreach _magazines;
{_unit addweapon _x} foreach _weapons;

And if you wanted a different preference:

Respawn with weapons you start with

Players initialization line:

_xhandle = this addEventHandler ["killed", format["[_this,%1] execvm 'weaponRespawn.sqf'",[weapons this, magazines this]]];

weaponRespawn.sqf

_unit = (_this select 0) select 0;
_weapons = (_this select 1) select 0;
_magazines = (_this select 1) select 1;

waituntil {alive player};

_unit = player;
removeallweapons _unit;
{_unit addmagazine _x} foreach _magazines;
{_unit addweapon _x} foreach _weapons;

Edited by Rommel

Share this post


Link to post
Share on other sites

Another approach...

This one also fixes the GL weapon bug and takes care of the new item system in A2.

Either start the script from another script on a client or place a trigger, condition local player and start it from the activation field: _handle = [] execVM "weaponrespawn.sqf".

weaponrespawn.sqf:

while {true} do {
   waitUntil {!alive player};
   _weapons = weapons player;
   _magazines = magazines player;
   waitUntil {alive player};
   _p = player;
   removeAllItems _p;
   removeAllWeapons _p;
   {_p addMagazine _x} forEach _magazines;
   {_p addWeapon _x} forEach _weapons;
   _primw = primaryWeapon _p;
   if (_primw != "") then {
       _p selectWeapon _primw;
       // Fix for weapons with grenade launcher
       _muzzles = getArray(configFile>>"cfgWeapons" >> _primw >> "muzzles");
       _p selectWeapon (_muzzles select 0);
   };
};

Xeno

Share this post


Link to post
Share on other sites

Hm, interesting I only changed this part:

#selectrifle
;// BUG WORKAROUND! - Added to compensate for selectweapon bug 
;// Any gun with more than one muzzle (grenadelaunchers) cannot be selected with selectweapon!
;// Default Grenadelaunchers supported - Add your own types if you need to.
_unit selectweapon _prigun
?_prigun == "M16A2GL":_unit selectweapon "M16Muzzle"
?_prigun == "M16A4_GL":_unit selectweapon "M16Muzzle"
?_prigun == "M16A4_ACG_GL":_unit selectweapon "M16Muzzle"
?_prigun == "M4A1_HWS_GL":_unit selectweapon "M4Muzzle"
?_prigun == "M4A1_HWS_GL_SD_Camo":_unit selectweapon "M4Muzzle"
?_prigun == "M4A1_HWS_GL_camo":_unit selectweapon "M4Muzzle"
?_prigun == "M4A1_RCO_GL":_unit selectweapon "M4Muzzle"
?_prigun == "M8_carbineGL":_unit selectweapon "M4Muzzle"

goto "respawnloop"

but It works...

Share this post


Link to post
Share on other sites
Another approach...

This one also fixes the GL weapon bug and takes care of the new item system in A2.

Either start the script from another script on a client or place a trigger, condition local player and start it from the activation field: _handle = [] execVM "weaponrespawn.sqf".

weaponrespawn.sqf:

while {true} do {
   waitUntil {!alive player};
   _weapons = weapons player;
   _magazines = magazines player;
   waitUntil {alive player};
   _p = player;
   removeAllItems _p;
   removeAllWeapons _p;
   {_p addMagazine _x} forEach _magazines;
   {_p addWeapon _x} forEach _weapons;
   _primw = primaryWeapon _p;
   if (_primw != "") then {
       _p selectWeapon _primw;
       // Fix for weapons with grenade launcher
       _muzzles = getArray(configFile>>"cfgWeapons" >> _primw >> "muzzles");
       _p selectWeapon (_muzzles select 0);
   };
};

Xeno

The best approach!!!

Thanks , great Xeno!!!:)

Share this post


Link to post
Share on other sites

Keep in mind xeno's script will keep giving you what you had when you died. It's generally a better idea to add an action to the ammo box where gear is picked that will save the loadout (aka save 2 variables - playerWeapons = weapons player; and playerMagazines = magazines player;) and use those to re-gear on every respawn. Of course if you want to give the player weapons in other ways (ex: pre-made loadouts or whatever), then set the playerWeapons and playerMagazines varaibles accordingly. Of course you'll also need to use global variables instead of local ones so that your other scripts can modify the saved loadout the way you want.

Also, Xeno's grenade launcher fix does work like a charm - use it ;)

Share this post


Link to post
Share on other sites
Keep in mind xeno's script will keep giving you what you had when you died. It's generally a better idea to add an action to the ammo box where gear is picked that will save the loadout (aka save 2 variables - playerWeapons = weapons player; and playerMagazines = magazines player;) and use those to re-gear on every respawn. Of course if you want to give the player weapons in other ways (ex: pre-made loadouts or whatever), then set the playerWeapons and playerMagazines varaibles accordingly. Of course you'll also need to use global variables instead of local ones so that your other scripts can modify the saved loadout the way you want.

Also, Xeno's grenade launcher fix does work like a charm - use it ;)

do you have a script example of ammobox save loadout?

The Xeno`s script fails on client side., I dont know why!....... :(

Share this post


Link to post
Share on other sites

Here's a script I made a while ago. Incorporates the above mentioned features. Gives you the code to add to ammo boxes to save loadout. Let's you define loadouts to spawn with.

/* tcp_arm.sqf v01
Author: tcp Support: <<http://violatorgaming.com>> 
Used examples from Hunt Waldo by Bon_Inf* 
Respawn with custom loadouts.  Preconfigure custom loads and/or enable saving at ammoboxes.
Init.sqf:
_player_armed = [true] execVM "tcp_arm.sqf"; //to enable saving only (when already using briefing gear selection or starting ammoboxes)
_player_armed = [true,true] execVM "tcp_arm.sqf"; //to enable saving and custom starting loadouts (needs to be configured below)
Ammobox init:
_saveloadout = this addAction ["Save Loadout", "tcp_arm.sqf",[],-3,false,true,"",""];
Ammo filler script:
_saveloadout = _this addAction ["Save Loadout", "tcp_arm.sqf",[],-3,false,true,"",""];
*/
sleep 1;
waitUntil{alive player};
if(typeName _this != "ARRAY") then {
removeAllWeapons player;
{player addMagazine _x} foreach (tcp_loadout select 1); {player addWeapon _x} foreach (tcp_loadout select 0);
if (primaryWeapon player != "") then {
		player selectWeapon (primaryWeapon player);
		_muzzles = getArray(configFile>>"cfgWeapons" >> _primw >> "muzzles"); // Fix for weapons with grenade launcher
		player selectWeapon (_muzzles select 0);
};
} else {
if(count _this < 3) then {
	player addEventHandler ["killed", {player execVM "tcp_arm.sqf";}];
	if(count _this == 2) then {
		switch (typeOf player) do{
			case "USMC_Soldier_Officer": {
			//an empty case leaves default loadouts alone, see "USMC_Soldier" case for custom example
			//<<http://www.ofpec.com/COMREF/index.php?action=read&id=209#Man>> for more Soldier types
			//http://www.ofpec.com/COMREF/index.php?action=read&id=210 for Weapon and Magazine types
			};
			case "USMC_Soldier_Pilot": {
			};
			case "USMC_Soldier_SL": {
			};
			case "USMC_Soldier_LAT": {
			};
			case "USMC_Soldier_AR": {
			};
			case "USMC_Soldier_Medic": {
			};
			case "USMC_SoldierM_Marksman": {
			};
			case "USMC_SoldierS_Sniper": {
			};	
			case "USMC_Soldier": {
				removeAllWeapons player;
				//8 secondary ammo slots
				{player addMagazine "15Rnd_9x19_M9SD"} forEach [1,2,3,4,5,6,7,8];
				//12 primary ammo slots
				{player addMagazine "30Rnd_556x45_StanagSD"} forEach [1,2,3,4,5,6,7,8];
				{player addMagazine "HandGrenade_West"} forEach [9,10];
				{player addMagazine "PipeBomb"} forEach [11+12];
				//Weapons
				player addWeapon "M4A1_AIM_SD_camo";
				player addWeapon "M9SD";
				player addweapon "ItemGPS"; 
				player addWeapon "NVGoggles";
				player addWeapon "Binocular";
			};
			case "USMC_SoldierS_Engineer": {
			};
			default {
			};
		};
		if (primaryWeapon player != "") then {
			player selectWeapon (primaryWeapon player);
			_muzzles = getArray(configFile>>"cfgWeapons" >> _primw >> "muzzles"); // Fix for weapons with grenade launcher
			player selectWeapon (_muzzles select 0);
		};
	};
};
tcp_loadout = [weapons player,magazines player];
if ( daytime < 4.0 ) then {player action ["NVGOGGLES",player]};
if ( daytime > 20.5 ) then {player action ["NVGOGGLES",player]};
if (count _this < 3) then {HintSilent "Loadout Saving Enabled."} else {HintSilent "Loadout Saved."};
};

Edited by tcp

Share this post


Link to post
Share on other sites

Thx!! Now, the Xeno's script run`s well. I fix a bug.. (my)... here....

Share this post


Link to post
Share on other sites

I have tried the sript made by Rommel and Xeno both of them gave different problems while running my mission on a deticated server. With Xeno's script the JIP players (maybe others as well) didn't have any weapons at all after spawning not even a map. With Rommels script (the one im using now) it sometimes happens that you are unable to fire your own weapon (no crosshair or aiming possible). If you get another weapon from the crate the problem is gone until you respawn again. Does anybody have an idea why this happens or what i am doing wrong.. :eek:

Share this post


Link to post
Share on other sites

The second one is probably you not selecting the weapon properly, so you are getting a grenade or something selected. This is solved by running:

if (local _unit) then
{
_primaryWeapon = primaryWeapon _unit;
_unit selectweapon _primaryWeapon;
// Fix for weapons with grenade launcher
_muzzles = getArray(configFile>>"cfgWeapons" >> _primaryWeapon >> "muzzles");
_unit selectWeapon (_muzzles select 0);
};

Share this post


Link to post
Share on other sites

I dont know how to run it from trigger like do i have to make it cover the respawn area or do i make special setting other than the change to the condition and on act field?

Share this post


Link to post
Share on other sites

Anything that will save the loadout when you want it to be saved. Could be addAction on the ammo box, trigger, or whatever.

Share this post


Link to post
Share on other sites

I've tried both these scripts, including the fixed versions and they still don't give me my grenades that I start with. I respawn with full ammo again but the grenades don't replinish. This is the init I have with Rommel's fixed one (by Galzohar):

removeAllWeapons Decerto; this addMagazine "30Rnd_556x45_Stanag"; this addWeapon "M4A3_CCO_EP1"; this addMagazine "30Rnd_556x45_Stanag"; this addMagazine "30Rnd_556x45_Stanag"; this addMagazine "30Rnd_556x45_Stanag"; this addMagazine "30Rnd_556x45_Stanag"; this addMagazine "30Rnd_556x45_Stanag"; this addMagazine "HandGrenade_West"; this addMagazine "HandGrenade_West"; _xhandle = this addEventHandler ["killed", format["[_this,%1] execvm 'weaponRespawn.sqf'",[weapons this, magazines this]]];

Share this post


Link to post
Share on other sites

With OA there seems to be an error causing the unit to spawn with its standard loadout.

I setup a CDF-medic with only a handgun and after respawn he got his whole equip back (AKS and everything else)

In his init I got the postet eventhandler from here. The code in the weaponrespawn.sqf is the following (and worked prior to OA):

while {true} do {
   waitUntil {!alive P1};
   _weapons = weapons P1;
   _magazines = magazines P1;
   waitUntil {alive P1};
   _p = P1;
   _p setVehicleVarName "P1";  
   removeAllItems _p;
   removeAllWeapons _p;
   {_p addMagazine _x} forEach _magazines;
   {_p addWeapon _x} forEach _weapons;
   _primw = primaryWeapon _p;
   if (_primw != "") then {
       _p selectWeapon _primw;
       // Fix for weapons with grenade launcher
       _muzzles = getArray(configFile>>"cfgWeapons" >> _primw >> "muzzles");
       _p selectWeapon (_muzzles select 0);
   };
};

In the *.rpt it says:

Error in expression <til {!alive P1};_weapons = weapons P1;_magazines = magazines P1;w>

Error position: <P1;_magazines = magazines P1;w>

Error Missing ;

Can anyone help me plz. I want the "you respawn with what you die with"-feature back;

Share this post


Link to post
Share on other sites

Since this thread deals with respawn /weaponrespawn, and not least

while {true} do {

waitUntil {!alive player};

_weapons = weapons player;

_magazines = magazines player;

waitUntil {alive player};

_p = player;

{_p addMagazine _x} forEach _magazines;

{_p addWeapon _x} forEach _weapons;

_primw = primaryWeapon _p;

if (_primw != "") then {

_p selectWeapon _primw;

// Fix for weapons with grenade launcher

_muzzles = getArray(configFile>>"cfgWeapons" >> _primw >> "muzzles");

_p selectWeapon (_muzzles select 0);

};

[player] execVM "do_Marker.sqf";

};

I have some questions about the text and summaries of get this to work on a deticated server. Have been searching all over this forum and other, can see that most of the same people are Q'ing there Q's in the other threads, but no answer for the big ''Q'' to find. And im talking about the same problem that larsiano have over here. And since this wrap'dtext(weaponrespawn.sqf) for getting weapons spawn does not work on a server. I've realized this is just something that applies to single-players (LocalSystem). What kind of script/func shall i use? No clue my self. Main reason i want to use this is to respawn the marker with the players after they have met death itself, and repsawn back in base. see? Unfortunately is Norrins script something i can't use in this mission. In terms of the healing part of his script.

To fix a good solution on weapons respawn is so far no challenge. But nice if included as done here in the weaponrespawn.sqf. As there are many ''ammobox/save gear'' script's out there, i dont see that as a major challenge.

do_marker.sqf:

//////////////////////////////////////////////////////////////////

// Function file for Armed Assault //

// Created by: Logitrust/twirly - Enchanced by kylania //

//////////////////////////////////////////////////////////////////

// Call by:

// poop = [object] execVM "do_marker.sqf";

private ["_markerType","_unit","_markerName","_markerText","_markerColor"];

// Grab unit object

_unit = _this select 0; //

// Create marker values

_markerName = "marker" + str(_unit); //

_markerText = if (isPlayer _unit) then {toUpper name _unit} else {""};

_markerType = ""; // "Man"

_markerColor = ""; // "ColorOrange"

// Assign marker type and color

if (_unit isKindOf "Man") then {_markerType = "Man"; _markerColor = "ColorOrange"};

if (_unit isKindOf "Tank") then {_markerType = "Tank"; _markerColor = "ColorGreen"};

if (_unit isKindOf "Air") then {_markerType = "Air"; _markerColor = "ColorYellow"};

if (_unit isKindOf "Car") then {_markerType = "Car"; _markerColor = "ColorBlue"};

// If non matching item, give defaults

if (_markerType == "") then {_markerType = "Dot"};

if (_markerColor == "") then {_markerColor = "ColorBlack"};

// Create the marker

createMarker[_markerName,[1,1,1]];

_markerName setMarkerShape "ICON";

_markerName setMarkerType _markerType;

_markerName setMarkerText _markerText;

_markerName setMarkerColor _markerColor;

// Maintain marker.

while {alive _unit} do

{

_markerName setMarkerPos getPos _unit;

sleep 2;

};

// Clean up.

deleteMarker _markerName;

[player] execVM "do_Marker.sqf";

My init.sqf

setViewDistance 5000;

execVM "briefing.sqf";

execVM "weaponrespawn.sqf";

skiptime (((paramsarray select 0) - daytime + 24) % 24);

if(!isServer) then {waitUntil{!isNull player}};

DAC_Zone = compile preprocessFile "DAC\Scripts\DAC_Init_Zone.sqf";

DAC_Objects = compile preprocessFile "DAC\Scripts\DAC_Create_Objects.sqf";

execVM "DAC\DAC_Config_Creator.sqf";

Hope someone can get me onto something here :notworthy:. been

sitting in the same place for a few days now with intense efforts to

try to find a solution to this without success.

Ps. I also use the do_markers.sqf in Simple Vehicle Respawn Script v1.7 by Tophe of Östgöta Ops [OOPS]. Works great on cars, air, tank etc..

can this be somthing?

http://forums.bistudio.com/showthread.php?t=91366

Edited by Logitrust

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×