Home   Help Search Login Register  

Author Topic: Respawn with same weapons you had before dying using while "" do {} command  (Read 5337 times)

0 Members and 1 Guest are viewing this topic.

Hamdinger

  • Guest
I'm having trouble accessing this post, too.  Very weird.

Anyway, I thought about a way to do toadlife's script just once.  It's a bit messy, but I tested it in MP and it seems to work.  Here's how I changed his first script:

Code: [Select]
_name = _this select 0

_guns = []
_mags = []
_guncount = 0
_magcount = 0

#respawnloop
@(call format [ "!alive %1", _name ])
call format [ "_guns = weapons %1", _name ]
player globalChat format [ "guns = %1", _guns ]
call format [ "_guncount = count weapons %1", _name ]
call format [ "_mags = magazines %1", _name ]
player globalChat format [ "guns = %1", _mags ]
call format [ "_magcount = count magazines %1", _name ]
@(call format [ "alive %1", _name ])
call format [ "%1 removeWeapon ""m16""", _name ]
call format [ "%1 removeMagazines ""m16""", _name ]
_c = 0
while "_c <= (_magcount - 1)" do {call format [ "%1 addmagazine (_mags select _c)", _name ]; _c = _c + 1}
_c = 0
while "_c <= (_guncount - 1)" do {call format [ "%1 addweapon (_guns select _c)", _name]; _c = _c + 1}
call format [ "%1 selectweapon primaryweapon %2", _name, _name ]
goto "respawnloop"
exit

To call it, you would put something like this in the unit's init field:  [ "W1" ] exec "respawn.sqs"
Since you don't need the pointer to the object, you could also just call this script from the init.sqs.

One note: I had to add a few dummy initializations at the top of the script to make sure that the variables existed at that scope.

Offline toadlife

  • OFPEC Old Skool
  • Former Staff
  • ****
  • Official OFP Editing Center Toad
    • toadlife.net
your right SUI. The damn things DO run on everyone's machine!
:o


@Hamdinger
Very clever. I hadn't read about the call comamnd yet. :) I thought about declaring the name at the start of the script, as you did but never did try it, and it wouldn't have worked without the call command anyway. I'll modify mine (it is slightly different than the one I posted) and try that out tonight and see how it goes.


Here's how my new script would look. I made two major changes from your version. I delcare the player only at critical parts of the script to reduce the amount of code. It should still work, but I haven't tried it yet.

Also, I added a slow loop at the beggining that checks if the player is local. The reason I don't want it to exit, is because if a player gets disconencted from the server, their unit is taken over by either the server or the group leader, and the script still needs to be running for whoever has control of the unit.

Code: [Select]
;weapon respawn script (TESTED AND WORKS)
;by toadlife and Hamdinger
;intialize like this: ["unitname",0] exec "thisscript.sqs"
;
;"unitname" = The name of the player the script runs on (must be enclosed by quotes!)
;method = method of repleneshing weapons
;   **if method is 0, the player gets the same weapons he stated out with every time
;   **if method is 1, the player gets the same weapons he had when he died

_name = _this select 0
_method = _this select 1

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


#choosemethod
?(_method  == 0):_guns = weapons _unit;_mags = magazines _unit;_guncount = count weapons _unit;_magcount = count magazines _unit


#respawnloop
@!alive _unit
?(_method  == 1):_guns = weapons _unit;_mags = magazines _unit;_guncount = count weapons _unit;_magcount = count magazines _unit
@alive call format["%1",_name]
_unit = call format["%1",_name]
_unit removemagazines (magazines player select 0)
_unit removeweapon (weapons player select 0)
_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}
_unit selectweapon primaryweapon _unit
?_unit == player:titlecut["","black in",0.5]
goto "respawnloop"
« Last Edit: 08 Nov 2002, 06:12:54 by toadlife »
"Whenever you want information on the 'net, don't ask a question; just post a wrong answer." -- Cancer Omega.

Offline toadlife

  • OFPEC Old Skool
  • Former Staff
  • ****
  • Official OFP Editing Center Toad
    • toadlife.net
I've tested and fixed the 10,000 syntax errors that riddled the above code. It works perfectly. I changed it, so that it will remove the weapons from any unit, regardless of what gun they respawn with by default.

Perhaps I can submit this as a code snippet.

Thanks guys. I learned something new.  ;)
"Whenever you want information on the 'net, don't ask a question; just post a wrong answer." -- Cancer Omega.

DoomedSoldier

  • Guest
how can i get that to work for all the AI that are WW2 people. and i got me confusted. can you explain it better or icq me at 123434439.
im very lost on what to do. i trying to make a WW2 multiplayer map. no its not going to historcal just something to have fun with. plz help me out.

say i name a player BOB. can you put the name BOB and there things i need to make him respawn.
« Last Edit: 01 Apr 2003, 04:12:52 by DoomedSoldier »

Offline toadlife

  • OFPEC Old Skool
  • Former Staff
  • ****
  • Official OFP Editing Center Toad
    • toadlife.net
http://www.ofpec.com/editors/resource_view.php?id=301  <-- go here dude, read the comments at the top of the script.
"Whenever you want information on the 'net, don't ask a question; just post a wrong answer." -- Cancer Omega.