Jump to content
Sign in to follow this  
norrin

toadlife's Weapon Respawn script updated for ArmA

Recommended Posts

I’ve just updated toadlifes Weapon Respawn script for ArmA.  This allows playable units to respawn with the weapons that they originally started the mission with or with the weapons that they died with.  There are a couple of ways to implement this script and instructions for both are within the script itself but the easiest way to do it is to give each of your playable units a name such as west_1 then put in its init line either:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> [west_1, 0] exec "weapons_respawn.sqs";

if you want the playable unit to respawn with the weapon it started the mission with; or <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> [west_1, 1] exec "weapons_respawn.sqs";

if you want the playable unit to respawn with the weapons it died with, where “west_1†is the units name.

You can get both the files you need to run this script as a zip file from here

This has only been tested on a local server so please let me know if you run into any problems.

Share this post


Link to post
Share on other sites

Really sorry Cheetah my bad.  Try here instead. If that doesn't work I'll try and get some other hosting

Share this post


Link to post
Share on other sites

Awesome norrin thumbs-up.gif I was tryin to do something like that for long time.

And it's working with the Revive Respawn too! biggrin_o.gif GREATE!!

Maybee someone can tell me is there a way to insert the weapons_respawn.sqs to my respawn.sqs?

respawn.sqs

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">;by Doolittle

;Updated by PRiME to work with multiply unit types.

_string = _this

_obj = call compile format ["%1", _string]

_leadr = leader _obj

_body = call compile format ["%1", _string]

~.05

;;ReviveList = ReviveList - [_obj]

;;PublicVariable "ReviveList"

#skipv

~.05

_pos = getPos _body

_pos = [_pos select 0, _pos select 1, 0]

~.05

_bodybag = "HeliHEmpty" createVehicle _pos

_dir = getDir _body

_dir = _dir - 90

_string setMarkerType "Marker"

_string setMarkerPos getPos _bodybag

?not alive _obj And _body == player : _bodybag exec "respawncam.sqs"

~3

#notalive

~1

_obj = call compile format ["%1", _string]

?not alive _obj : goto "notalive"

?not local _body : goto "list"

?_obj == player: _string setMarkerColor "ColorGreen"

enableRadio false;

_respawn = call compile format ["respawn%1", _string]

_respawn = _respawn + 1

call compile format ["respawn%1 = _respawn", _string]

deleteVehicle _body

~.05

_body = "Body" createVehicle _pos

_body setDir _dir

_body setpos [getpos _body select 0, getpos _body select 1, 0]

_ai = objNull

_maxt = 0

_ClosestUnits = []

_AIUnits = []

_Closest6 = []

_PG = 0

_PassGo = 0

_pos = getpos _body

#nearest

_ai = objNull

_i = 0

_Num1 = 0

_ReviveList = ReviveList

~.05

_Closest1 = Server

_Closest2 = Server

_Closest3 = Server

_Closest4 = Server

_Closest5 = Server

_Closest6 = Server

_Closest7 = Server

_Closest8 = Server

ReviveL = []

_Num1 = (count _ReviveList) - 1

#LoopCP1

?_i > _Num1: _i = 0; goto "CheckPass1"

~.002

_unitn = call compile (_ReviveList select _i)

?(not isNull _unitn): _ReviveL = _ReviveL + [_unitn]

~.002

_i = _i + 1

goto "LoopCP1"

#checkpass1

#LoopCP2

?_i > _Num1: _i = 0; goto "CheckPass2"

~.002

_unitn = call compile (_ReviveList select _i)

?_unitn distance _body < 5: _ClosestBitch = _unitn; _PG = 1; goto "CheckPass2"

~.002

_i = _i + 1

goto "LoopCP2"

#checkpass2

?_PG == 1: _PG = 0; _PassGo = 0; _soldier = _ClosestBitch; goto "BringAlive"

;;;;; Below Is the AICheck, if AI is found it will be told to move to bodybag.;;;;;

;;;;; Ranges are upto 200m, unlike nearest method which is limited to 50m. ;;;;;

;;;;; This method may look messy but it is very effective in comparison. ;;;;;

_AIUnit = []

#AIloop1

?_i > _Num1: _i = 0; _num1 = (count _AIUnit) - 1; goto "AIPass1"

~.002

_unitn = call compile (_ReviveList select _i)

?_ai != _unitn: _AIUnit = _AIUnit + [_unitn]

~.002

_i = _i + 1

goto "AIloop1"

#AIpass1

?_i > _Num1: _i = 0; goto "AIPass2"

~.002

_unitn = _AIUnit select _i

?(vehicle _unitn distance _body < 10) AND (vehicle _unitn distance _body > 4) AND (not isNull vehicle _unitn): _Closest1 = _unitn; _vehclo = vehicle _Closest1; AIORDERS = [_Closest1, _vehclo]; publicvariable "AIORDERS";

~.002

_i = _i + 1

goto "AIpass1"

#AIpass2

?_i > _Num1: _i = 0; goto "AIPass3"

~.002

_unitn = _AIUnit select _i

?(_unitn distance _body < 20) AND (_unitn distance _body > 9) AND (not isNull _unitn): _Closest2 = _unitn

~.002

_i = _i + 1

goto "AIpass2"

#AIpass3

?_i > _Num1: _i = 0; goto "AIPass4"

~.002

_unitn = _AIUnit select _i

?(_unitn distance _body < 30) AND (_unitn distance _body > 19) AND (not isNull _unitn): _Closest3 = _unitn

~.002

_i = _i + 1

goto "AIpass3"

#AIpass4

?_i > _Num1: _i = 0; goto "AIPass5"

~.002

_unitn = _AIUnit select _i

?(_unitn distance _body < 40) AND (_unitn distance _body > 29) AND (not isNull _unitn): _Closest4 = _unitn

~.002

_i = _i + 1

goto "AIpass4"

#AIpass5

?_i > _Num1: _i = 0; goto "AIPass6"

~.002

_unitn = _AIUnit select _i

?(_unitn distance _body < 70) AND (_unitn distance _body > 39) AND (not isNull _unitn): _Closest5 = _unitn

~.002

_i = _i + 1

goto "AIpass5"

#AIpass6

?_i > _Num1: _i = 0; goto "AIPass7"

~.002

_unitn = _AIUnit select _i

?(_unitn distance _body < 100) AND (_unitn distance _body > 69) AND (not isNull _unitn): _Closest6 = _unitn

~.002

_i = _i + 1

goto "AIpass6"

#AIpass7

?_i > _Num1: _i = 0; goto "AIPass8"

~.002

_unitn = _AIUnit select _i

?(_unitn distance _body < 150) AND (_unitn distance _body > 99) AND (not isNull _unitn): _Closest7 = _unitn

~.002

_i = _i + 1

goto "AIpass7"

#AIpass8

?_i > _Num1: _i = 0; goto "AIPass9"

~.002

_unitn = _AIUnit select _i

?(_unitn distance _body < 200) AND (_unitn distance _body > 149) AND (not isNull _unitn): _Closest8 = _unitn

~.002

_i = _i + 1

goto "AIpass8"

#AIpass9

~.002

_ClosestBitch = _Closest1

#ClosestPart1

?_i > _Num1: _i = 0; goto "ClosestPart2"

~.002

_unitn = _AIUnit select _i

?vehicle _ClosestBitch distance _body < 5: _PG = 1; goto "ClosestPart2"

~.002

_i = _i + 1

goto "ClosestPart1"

#ClosestPart2

?_PG == 1: _PG = 0; _soldier = _ClosestBitch; goto "BringAlive"

?Server == _ClosestBitch OR _ClosestBitch == player:_ClosestBitch = _Closest2; goto "skip1"

_ai = _ClosestBitch;

_ai doMove _pos;

~1

goto "nearest"

#skip1

?Server == _ClosestBitch OR _ClosestBitch == player: _ClosestBitch = _Closest3; goto "skip2"

_ai = _ClosestBitch;

_ai doMove _pos;

~1

goto "nearest"

~.05

#skip2

?Server == _ClosestBitch OR _ClosestBitch == player: _ClosestBitch = _Closest4; goto "skip3"

_ai = _ClosestBitch;

_ai doMove _pos;

~1

goto "nearest"

#skip3

?Server == _ClosestBitch OR _ClosestBitch == player: _ClosestBitch = _Closest5; goto "skip4"

_ai = _ClosestBitch;

_ai doMove _pos;

~1

goto "nearest"

~.05

#skip4

?Server == _ClosestBitch OR _ClosestBitch == player: _ClosestBitch = _Closest6; goto "skip5"

_ai = _ClosestBitch;

_ai doMove _pos;

~1

goto "nearest"

#skip5

?Server == _ClosestBitch OR _ClosestBitch == player: _ClosestBitch = _Closest7; goto "skip6"

_ai = _ClosestBitch;

_ai doMove _pos;

~1

goto "nearest"

#skip6

?Server == _ClosestBitch OR _ClosestBitch == player: _ClosestBitch = _Closest8; goto "nearest"

_ai = _ClosestBitch;

_ai doMove _pos;

~1

goto "nearest"

_Soldier = _ClosestSoldier

~.05

#BringAlive

_soldier = _soldier

~.05

_maxt = 0

;;

_obj = call compile format ["%1", _string]

?not alive _obj : exit

_soldier doWatch _obj

_obj setCaptive true

~.01

_obj setPos _pos

_obj setPos getpos _body

_obj setDir _dir

_obj setCaptive true

deletevehicle _body

;;ReviveList = ReviveList + [_obj]

;;PublicVariable "ReviveList"

;_obj switchMove "CombatToLying"

~.01

_obj switchMove "LyingToTreatedLying"

~.01

_soldier playMove "CombatToMedic"

~1

deletevehicle _bodybag

~4

_obj setCaptive false

#list

~1

_obj = call compile format ["%1", _string]

?not (_obj in list playeralive) : goto "list"

~.3

enableRadio true;

_string setMarkerColor "ColorRed"

_string setMarkerType "Empty"

~1

_obj switchMove "LyingToCombat"

exit

Share this post


Link to post
Share on other sites

I've just reposted a slightly cleaner version of the script as I've been having some bizarre problems with my host and I'm not 100% sure what version it has been sending you.  Either way the script will work it just may have some extra lines of code as comments that should have been deleted.  

This version gets rid of these working comments (the links above have been updated) and also hopefully explains a little better how to implement the script.

@SNKMAN I'd love to help but I don't have a lot of spare time at the moment and thats one pretty complex script. Lol, it would probably take me a few hours just to work out what its doing before I could even think of combining the two.  Maybe if I can find some time a bit later. smile_o.gif

Share this post


Link to post
Share on other sites

norrin the link's are dead... confused_o.gif

Could you plz reupload the Script?

Share this post


Link to post
Share on other sites

Thanks a million guys I'm just looking into the problem now.  I'm not sure whats happened as my links should still work as they are written.

Here's the code just in case any one runs into the same problem in future.  Just paste it into a .txt file and call it weapons_respawn.sqs.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

;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

I've just checked, you guys have got a slightly older version of my revised script that still contains some comments that can be deleted and has less explanation on how to execute it.  If you can be bothered just try redownloading my script from the link here and remirror the new files please.

Weapon_respawn.rar

Share this post


Link to post
Share on other sites

Am I doing something wrong? It works fine but all secondary stuff like mines and satchels are lost....

Or should it work only for main weaponry?

Share this post


Link to post
Share on other sites

To be perfectly honest I never checked for that.  I only checked for rifles, grenades, AT launchers and rockets.  I'm in the process of writing a sqf version of this script that may work better but we'll have to wait and see.

Share this post


Link to post
Share on other sites

Well i tested the Script and it work's fine for me.

With Mine's and Secoundary Weapon's too.

Share this post


Link to post
Share on other sites

I can get the (_method == 1) part working just fine.

But when I try it with 0 it gives me generic error in desription.........

I have only touched the "method" lines.

I run it from individual units init lines.

I'm doing it somehow wrong but I'm too dumb to figure it out... whistle.gif

Share this post


Link to post
Share on other sites

Can you post a link to your mission so I can d/l it and have a look at how you've got it set up?  I'll send you a PM with my email address so if you prefer you can send it to me that way.

@SNKMAN  Thanks m8 thats good to know. smile_o.gif

Share this post


Link to post
Share on other sites

Any one noticing this script causing bad FPS on the server?

Just trying to find out whether there is some rogue bit of code chewing up CPU cycles...

Share this post


Link to post
Share on other sites

You could be right Lt Damage as I've only ever used this code with a small number of playable units.  Maybe when you get over a critical number of users it starts putting a large burden on the cpu.

I translated this code pretty faithfully from toadlife's original script, just simplified a couple of lines of code and updated for the new weapon names in ArmA and where code usage has changed.

Just had another quick look at the code and if you find it is a problem you may want to slightly lengthen the sleeps/rests in the loops as this may seriously reduce cpu usage without really affecting the functioning of the script.

Anyway let us know what you find out.

Share this post


Link to post
Share on other sites

Thanks Norrin, I'm not naturally a scripter are you able to paste the code and highlight in red the sleeps that you think might help if lengthened?

Share this post


Link to post
Share on other sites

I know this is not related to the script, but...

am I the only person that thinks that there should be an addon that resembles "SnakeEyes" from GI Joe fame and called the "Toadlife" addon instead?

Its the only character I can think of that is as mysterious as his legacy here.

Share this post


Link to post
Share on other sites

CrashDome I don't know if I understand you right but there is a website http://toadlife.net/. Maybe it helps to understand or maybe not, I don't know because as I said I am not sure if I understand what you mean. The guys at www.ofpec.com know more about this character if you want to know more.

Share this post


Link to post
Share on other sites
CrashDome I don't know if I understand you right but there is a website http://toadlife.net/. Maybe it helps to understand or maybe not, I don't know because as I said I am not sure if I understand what you mean. The guys at www.ofpec.com know more about this character if you want to know more.

@Baddo

Oh, I know about toadlife. If you check the date I signed on you can see I was around that time. He was very talented and very devoted. No one is sure why he left (atleast I do not)... so I was trying to be funny and say we should do a "snakeyes" addon in tribute - and partly to confuse the newer people by creating a fictional and outrageous legacy about him. biggrin_o.gif

Anyways, I am not hijacking this thread. I am actually patiently waiting for the SQF version of this and thought I'd have some small talk.

Share this post


Link to post
Share on other sites

@Lt Damage

I'm not sure whether this will help but I've modified the rests/sleeps.  Just replace the code in the current weapons_respawn.sqs with the following code. As far as I can tell these changes don't affect the functioning of the script.  

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">

;Universal Weapons Respawn Script v1.04 (March 31, 2003) revised (March, 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

;

;

~(1 + (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

~(1 + (random 0.5))

_guncount = count _guns

_magcount = count _mags

?_unit hasweapon (primaryweapon _unit):_hasrifle = true;_prigun = primaryweapon _unit;goto _return

_hasrifle = false

goto _return

Share this post


Link to post
Share on other sites

@Victor its there already m8 smile_o.gif

Haven't been able to update my post with the latest version of the script though as I'm having trouble logging onto OFPEC at the mo.

Share this post


Link to post
Share on other sites

This is a noobish question- where do you place the .sqs file in the mission folder?

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  

×