Jump to content
Sign in to follow this  
JaFuzz

Respawn w/ Weapons + Ammo Script

Recommended Posts

Props to B. Young for making this script (Asked me to post the release for it)

Not sure if there is another script like this

Re spawn with the same weapons and ammo. He hasnt been able to do the same with clothing as of yet.

Download Here

to active it, in your Unit init add this

_handle = [] execVM "SWRepsawn_SRU.sqf"
Edited by JaFuzz

Share this post


Link to post
Share on other sites

try this init: _handle = [] execVM "weaponrespawn.sqf";

havent tryed this just what i saw straight away.

Share this post


Link to post
Share on other sites

My mistake, Fixed..

Edit - Also fixed the name (was last minute changes and wasnt really paying attention lol)

Edited by JaFuzz

Share this post


Link to post
Share on other sites
try this init: _handle = [] execVM "weaponrespawn.sqf";

havent tryed this just what i saw straight away.

Yeah, I saw what was wrong right away. Just thought I'd let him know.

Share this post


Link to post
Share on other sites

and im not the best as scripting but the file name is "SWRepsawn_SRU" not "weaponrespawn" so for a novice that think that they just can put in the file and then execute may have a problem.

But im not the best at scripting.

Share this post


Link to post
Share on other sites

Is there a way to initialize it across the board without having to add it to individual units such as

if(local player) then {

_handle = [] execVM "weaponrespawn.sqf";

};

Share this post


Link to post
Share on other sites

Try this script:

Universal Weapons Respawn Script

http://www.armaholic.com/page.php?id...RESPAWN+SCRIPT

Basically what it does it allows you to respawn with the same weapons you had when you started, or

you can set it up to where you can respawn with the same weapon you last had.

But the thing is you still need a basic respawn script, a description.ext script with 2 codes to respawn,

heres a tutorial I built in 2011 that explains what and how to set a basic respawn up:

http://forums.bistudio.com/showthrea...21#post1881921

Share this post


Link to post
Share on other sites

WTF sorry about that let me lay out the script, heres how it works:

1. Create a script and name it:

weapons_respawn

its originally SQS, but should work if you use SQF.

;Universal Weapons Respawn Script v1.04 (March 31, 2003) revised (February 1, 2007)
;Required Version: ArmA
;original by toadlife revised by norrin for ArmA
;toadlife@toadlife.net
;intialize like this: ["unitname",0] exec "weapons_respawn.sqs"
;            Or this: ["unitname",1] exec "weapons_respawn.sqs"
;
; * "unitname" = The name of the player the script runs on (must be enclosed by quotes!)
; * 0/1 = method of repleneshing weapons
;  **if method is 0, the player gets the same weapons he started out with every time
;  **if method is 1, the player gets the same weapons he had when he died
;
; Advanced example method of initializing script - put the following lines in your init.sqs,
; and replce the unit names with your own:
;_units = ["w1","w2","w3","w4","w5","w6","w7","w8","w9","w10","w11","w12","w13","w14","w15","w16","w17","w18"]
;{[_x,0] exec "weapons_respawn.sqs"} foreach _units
;
;

~(random 0.3)
_name = _this select 0
_method = _this select 1
_hasrifle = false
_unit = call compile format["%1",_name]
?(_method == 0):_return = "checklocal";goto "guncheck"

#checklocal
_unit = call compile format["%1",_name]
?(local _unit):goto "respawnloop"
~(1 + (random 3))
goto "checklocal"

#respawnloop
@!alive _unit
#checkmethod
?(_method == 1):_return = "waitforlife";goto "guncheck"

#waitforlife
@alive call compile format["%1",_name]
_unit = call compile format["%1",_name]
removeAllWeapons _unit
?_hasrifle:_guns = _guns - [_prigun];_guncount = count _guns
_c = 0
while {_c <= (_magcount - 1)} do {_unit addmagazine (_mags select _c); _c = _c + 1}
_c = 0
while {_c <= (_guncount - 1)} do {_unit addweapon (_guns select _c); _c = _c + 1}
?_hasrifle:_unit addweapon _prigun;_gun = _guns + [_prigun]
;//If unit has a rifle select it
?_hasrifle:goto "selectrifle"

;//No rifle - if unit has a pistol, select it
?_unit hasweapon ((weapons _unit - [secondaryweapon _unit,"Binocular","NVGoggles"]) select 0):_unit selectweapon ((weapons _unit - [secondaryweapon _unit,"Binocular","NVGoggles"]) select 0);goto "respawnloop"

;//No rifle or pistol, select secondary weapon
_unit selectweapon secondaryweapon _unit
goto "respawnloop"

#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 == "M16A4GL":_unit selectweapon "M16Muzzle"
?_prigun == "M16A4_ACG_GL":_unit selectweapon "M16Muzzle"
?_prigun == "M4GL":_unit selectweapon "M4Muzzle"
?_prigun == "M4A1GL":_unit selectweapon "M4Muzzle"
?_prigun == "AK74GL":_unit selectweapon "AK74Muzzle"

goto "respawnloop"


#guncheck
_guns = weapons _unit
_mags = magazines _unit
~(random 0.5)
_guncount = count _guns
_magcount = count _mags
?_unit hasweapon (primaryweapon _unit):_hasrifle = true;_prigun = primaryweapon _unit;goto _return
_hasrifle = false
goto _return

2. put the code:

["unitname",0] exec "weapons_respawn.sqs"

into the init line of the unit, and give him a name, something like w2 for example, so then the code will look like this:

["W2",0] exec "weapons_respawn.sqs"

take note the 2nd number:

if method is 0, the player gets the same weapons he started out with every time

if method is 1, the player gets the same weapons he had when he died

3. put the script into the same folder as your mission you created in the editor, (same place as the mission.sqm)

================

If you need the actual script then search on Armaholic for

Universal Weapons Respawn Script

and thats the script i had linked in my previous post, dont know how the link broke.

I take no credit for this script, its Toadlife's script.

hope that helps.

Share this post


Link to post
Share on other sites

Does not take into account optics or other attachments. Something I have tried and fail to do for the last 3 days.

Share this post


Link to post
Share on other sites

Hey guys, Ive been tackling this today. Ive used this save gear script from Armaholic as a baseline: http://www.armaholic.com/page.php?id=10785&highlight=WEAPONRESPAWN

The script works almost perfectly; the only issue is that every time you respawn, you lose 1 magazine for your primary, secondary and sidearm. This includes GL rounds. You keep everything else however; uniform, vest, attachments... even mines, hand grenades and med/tool kits. If someone could come up with a way to fix the losing mags issue, it would be very much appreciated.

Just one thing to bare in mind, every time you respawn, you have to save your gear. If you don't you'll lose it on repsawn. A way around this would be to run the script using an eventhandler also on "respawn" or "killed" in case you forget to save.

This is my first real attempt at scripting so, be gentle :D Apologies if the script is a bit messy.

I put this in the init line of a crate.

this addAction["Save Loadout","weaponrespawn.sqf"];

SQF file. I feel the section in red may be redundant, but it works with it in however.

_weapons = weapons player;
_magazines = magazines player;
_vest = vest player;
_uniform = uniform player;
_headgear = headgear player;
_backpack = backpack player;
_primacc = primaryWeaponItems player; //Primary Weapon Accessories
_secacc = secondaryWeaponItems player;//Secondary Weapon Accessories
_sideacc = handgunItems player; // Sidearm Accessories
_items = items player; // Medkits, ToolKits etc.
_assitems = assignedItems player; // NVG's, GPS etc.

hint "Loadout Saved";
waitUntil {!alive player};
waitUntil {alive player};

_p = player;

removeAllWeapons _p;

_p addVest _vest;
_p addUniform _uniform;
_p addHeadgear _headgear;
_p addBackpack _backpack;

{_p addItem _x} forEach _items;
{_p addMagazine _x} forEach _magazines;
{_p addWeapon _x} forEach _weapons;
{_p addPrimaryWeaponItem _x} forEach _primacc;
{_p addSecondaryWeaponItem _x} forEach _secacc;
{_p addHandgunItem _x} forEach _sideacc;
{_p addItem _x} forEach _assitems;
{_p assignItem _x} forEach _assitems;

[color="#FF0000"]_primw = primaryWeapon _p;
hint "Loadout Restored";
if (_primw != "") then {
   _p selectWeapon _primw;
   // Fix for weapons with grenade launcher
   _muzzles = getArray(configFile>>"cfgWeapons" >> _primw >> "muzzles");
   _p selectWeapon (_muzzles select 0);
};[/color]

Edited by MetaliX

Share this post


Link to post
Share on other sites
Hey guys, I've been tackling this today. I've been using this script as a baseline that I found on Armaholic: http://www.armaholic.com/page.php?id=10785&highlight=WEAPONRESPAWN

It works almost perfectly; It restores all weapon attachments etc. The only issue with it is that every time you respawn, you lose 1 magazine for your primary, secondary and sidearm, this includes GL rounds. Hand grenades and mines etc are not effected. If somebody could help me find a solution to this it would be very much appreciated.

This is my first real attempt at scripting so, be gentle :D Apologies if it is a bit messy.

Using this in the init line of a crate.

this addAction["Save Loadout","weaponrespawn.sqf"];

SQF file. I feel the code in red might be redundant, but it works fine with it in.

_weapons = weapons player;
_magazines = magazines player;
_vest = vest player;
_uniform = uniform player;
_headgear = headgear player;
_backpack = backpack player;
_primacc = primaryWeaponItems player; //Primary Weapon Accessories
_secacc = secondaryWeaponItems player;//Secondary Weapon Accessories
_sideacc = handgunItems player; // Sidearm Accessories
_items = items player; // Medkits, ToolKits etc.
_assitems = assignedItems player; // NVG's, GPS etc.

hint "Loadout Saved";
waitUntil {!alive player};
waitUntil {alive player};

_p = player;

removeAllWeapons _p;

_p addVest _vest;
_p addUniform _uniform;
_p addHeadgear _headgear;
_p addBackpack _backpack;

{_p addItem _x} forEach _items;
{_p addMagazine _x} forEach _magazines;
{_p addWeapon _x} forEach _weapons;
{_p addPrimaryWeaponItem _x} forEach _primacc;
{_p addSecondaryWeaponItem _x} forEach _secacc;
{_p addHandgunItem _x} forEach _sideacc;
{_p addItem _x} forEach _assitems;
{_p assignItem _x} forEach _assitems;

[color="#B22222"]_primw = primaryWeapon _p;
hint "Loadout Restored";
if (_primw != "") then {
   _p selectWeapon _primw;
   // Fix for weapons with grenade launcher
   _muzzles = getArray(configFile>>"cfgWeapons" >> _primw >> "muzzles");
   _p selectWeapon (_muzzles select 0);
};[/color]

Works for me but only for 1 respawn. After that it goes to the default loadout unless I save config each time. I tried adding just the saving portion to a separate sqf file then execvm that file at the conclusion of the script here... but I am really bad at scripting and I can't get it to work for any more than one respawn.

Share this post


Link to post
Share on other sites

Firstly, apologies for my double post. I was having some issues with the forums at the time. In the remaining post I mentioned that if you add an eventhandler with "killed" and execute the script, it will save the gear you die with.

For example, this in the player init line:

this addEventHandler ["killed", {_this execVM "weaponrespawn.sqf";}];

Ive not personally tried it yet but it should work.

*EDIT*

I have tested with the code above. It partially works. I respawn with the weapons i died with but nothing else. I also get the error "Bad vehicletype". Anyone got any ideas why?

*EDIT 2* FIXED SEE BELOW

---------- Post added at 17:54 ---------- Previous post was at 17:53 ----------

Well I have come up with a solution to not having to save every time you die. That is, if you want to spawn with the same gear every time and NOT what you had when you died. Ie. if during your mission you picked up a weapon you didnt have when you saved your gear, you will not have it when you respawn.

Firstly add this into the init line of each player:

this addEventHandler ["killed", {_this execVM "weaponrespawn.sqf";}];

then add this into the init of an object eg. a crate:

this addAction["Save Loadout","weaponsave.sqf"];

then make a file called weaponsave.sqf and paste this in:

weaponsvar = weapons player;
magazinesvar = magazines player;
vestvar = vest player;
uniformvar = uniform player;
headgearvar = headgear player;
backpackvar = backpack player;
primaccvar = primaryWeaponItems player; //Primary Weapon Accessories
secaccvar = secondaryWeaponItems player;//Secondary Weapon Accessories
sideaccvar = handgunItems player; // Sidearm Accessories
itemsvar = items player; // Medkits, ToolKits etc.
assitemsvar = assignedItems player; // NVG's, GPS etc.

hint "Loadout Saved";

then make another file and call it weaponrespawn.sqf and paste this in:

waitUntil {!alive player};
waitUntil {alive player};

_p = player;

removeAllWeapons _p;

_p addBackpack backpackvar;
_p addVest vestvar;
_p addUniform uniformvar;
_p addHeadgear headgearvar;

{_p addItem _x} forEach itemsvar;
{_p addMagazine _x} forEach magazinesvar;
{_p addWeapon _x} forEach weaponsvar;
{_p addPrimaryWeaponItem _x} forEach primaccvar;
{_p addSecondaryWeaponItem _x} forEach secaccvar;
{_p addHandgunItem _x} forEach sideaccvar;
{_p addItem _x} forEach assitemsvar;
{_p assignItem _x} forEach assitemsvar;

_primw = primaryWeapon _p;
hint "Loadout Restored";
if (_primw != "") then {
   _p selectWeapon _primw;
   // Fix for weapons with grenade launcher
   _muzzles = getArray(configFile>>"cfgWeapons" >> _primw >> "muzzles");
   _p selectWeapon (_muzzles select 0);
};

The difference here from my original script besides the obvious fact there there is now two scripts, is that the weaponsave.sqf script uses global variables as opposed to local variables.

Hope this helps guys. :)

Edited by MetaliX

Share this post


Link to post
Share on other sites
Firstly, apologies for my double post. I was having some issues with the forums at the time. In the remaining post I mentioned that if you add an eventhandler with "killed" and execute the script, it will save the gear you die with.

For example, this in the player init line:

this addEventHandler ["killed", {_this execVM "weaponrespawn.sqf";}];

Ive not personally tried it yet but it should work.

*EDIT*

I have tested with the code above. It partially works. I respawn with the weapons i died with but nothing else. I also get the error "Bad vehicletype". Anyone got any ideas why?

*EDIT 2* FIXED SEE BELOW

---------- Post added at 17:54 ---------- Previous post was at 17:53 ----------

Well I have come up with a solution to not having to save every time you die. That is, if you want to spawn with the same gear every time and NOT what you had when you died. Ie. if during your mission you picked up a weapon you didnt have when you saved your gear, you will not have it when you respawn.

Firstly add this into the init line of each player:

this addEventHandler ["killed", {_this execVM "weaponrespawn.sqf";}];

then add this into the init of an object eg. a crate:

this addAction["Save Loadout","weaponsave.sqf"];

then make a file called weaponsave.sqf and paste this in:

then make another file and call it weaponrespawn.sqf and paste this in:

The difference here from my original script besides the obvious fact there there is now two scripts, is that the weaponsave.sqf script uses global variables as opposed to local variables.

Hope this helps guys. :)

When I do this I get an error 'weaponrepawn.sqf' not found.

Triple checked everything including my spelling. Any suggestions.

EDIT: Problem solved - repacked mission a few times, works! Thanks!

Edited by Deceter
Problem Solved

Share this post


Link to post
Share on other sites

Been working on my set/get loadout functions almost since the release of public alpha.

See examples on how to use it for saving loadout and loading it on respawn.

set/get loadout functions

Edited by aeroson

Share this post


Link to post
Share on other sites
Firstly, apologies for my double post. I was having some issues with the forums at the time. In the remaining post I mentioned that if you add an eventhandler with "killed" and execute the script, it will save the gear you die with.

For example, this in the player init line:

this addEventHandler ["killed", {_this execVM "weaponrespawn.sqf";}];

Ive not personally tried it yet but it should work.

*EDIT*

I have tested with the code above. It partially works. I respawn with the weapons i died with but nothing else. I also get the error "Bad vehicletype". Anyone got any ideas why?

*EDIT 2* FIXED SEE BELOW

---------- Post added at 17:54 ---------- Previous post was at 17:53 ----------

Well I have come up with a solution to not having to save every time you die. That is, if you want to spawn with the same gear every time and NOT what you had when you died. Ie. if during your mission you picked up a weapon you didnt have when you saved your gear, you will not have it when you respawn.

Firstly add this into the init line of each player:

this addEventHandler ["killed", {_this execVM "weaponrespawn.sqf";}];

then add this into the init of an object eg. a crate:

this addAction["Save Loadout","weaponsave.sqf"];

then make a file called weaponsave.sqf and paste this in:

weaponsvar = weapons player;
magazinesvar = magazines player;
vestvar = vest player;
uniformvar = uniform player;
headgearvar = headgear player;
backpackvar = backpack player;
primaccvar = primaryWeaponItems player; //Primary Weapon Accessories
secaccvar = secondaryWeaponItems player;//Secondary Weapon Accessories
sideaccvar = handgunItems player; // Sidearm Accessories
itemsvar = items player; // Medkits, ToolKits etc.
assitemsvar = assignedItems player; // NVG's, GPS etc.

hint "Loadout Saved";

then make another file and call it weaponrespawn.sqf and paste this in:

waitUntil {!alive player};
waitUntil {alive player};

_p = player;

removeAllWeapons _p;

_p addBackpack backpackvar;
_p addVest vestvar;
_p addUniform uniformvar;
_p addHeadgear headgearvar;

{_p addItem _x} forEach itemsvar;
{_p addMagazine _x} forEach magazinesvar;
{_p addWeapon _x} forEach weaponsvar;
{_p addPrimaryWeaponItem _x} forEach primaccvar;
{_p addSecondaryWeaponItem _x} forEach secaccvar;
{_p addHandgunItem _x} forEach sideaccvar;
{_p addItem _x} forEach assitemsvar;
{_p assignItem _x} forEach assitemsvar;

_primw = primaryWeapon _p;
hint "Loadout Restored";
if (_primw != "") then {
   _p selectWeapon _primw;
   // Fix for weapons with grenade launcher
   _muzzles = getArray(configFile>>"cfgWeapons" >> _primw >> "muzzles");
   _p selectWeapon (_muzzles select 0);
};

The difference here from my original script besides the obvious fact there there is now two scripts, is that the weaponsave.sqf script uses global variables as opposed to local variables.

Hope this helps guys. :)

I've tried this method as for my PvP mission I need every player dies to be respawned with initial given weapons - magazines and items through his init line ... it is working except for grenades ... is it possible to fix this ?

Also my wish is a solution for auto-saving the loadout without using addAction but this to be by default (through init.sqf for example).

NOTE : I'm still getting the error "Bad vehicletype"

Edited by Aplion

Share this post


Link to post
Share on other sites

Nope ... it didn't because this is for A2 and in A2 there was not item optics (addPrimaryWeaponItem) to add on the weapons ... in any case I've try it and as I said it respawns only the weapon without optics.

Share this post


Link to post
Share on other sites

Hey guys. I did all these steps and it is still not working for me.

ASSUMPTIONS

1. When you approach the ammo crate it saves your current loadout.

2. When you die, the two .sqf files are referenced by the unit init script and you respawn - you will be armed with your last saved loadout.

Are my assumptions correct?

Share this post


Link to post
Share on other sites

There's so many different scripts referenced in this incredibly old thread that I'm not sure what scripts you're talking about.  Instead dredging up 3 year old posts and scripts from nine years ago, or even ported scripts from days after Arma 3 entered Alpha three years ago, you could look for more updated code.  There have been a lot of improvements over the years and new methods of doing things.

 

Perhaps use Arsenal?  You can attach it to an ammo box and players can have access to everything or only what you want them to and also save loadouts.  If they want to change their loadout or even just refresh what they have they just run to the box, adjust or load and enjoy.

 

Ammo box init:

0 = ["AmmoboxInit",[this,true]] spawn BIS_fnc_arsenal;

Or if you prefer a scripted option here's a post that uses the latest commands available.

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  

×