OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting Multiplayer => Topic started by: toadlife on 04 Nov 2002, 09:47:07
-
Not really a question, but a tip. I'm not sure if this is worthy of being a code snippet, or if someone hasnt allready submitted it, so I figured I'd post it here.
I'm not a programmer by any means, so when I first heard about the new functions of OFP scripting, I didn't get too excited. Yesterday, the value of the new scripting abilities in 1.85 became evident to me when I wanted to write a script that would, upon respawning, give a unit the same weapons that they had when they died.
Using the new - while "" do {} - ability in 1.85 makes this much easier than writing a loop.
Here is the code that will give the unit named "w1" his weapons back when he respawns.
Note that you have to make a script for each player in a MP game with the player's name in the script, or the script will not be able to detect when he respawns.[/u]
#respawnloop
@!alive w1
_guns = weapons w1
_guncount = count weapons w1
_mags = magazines w1
_magcount = count magazines w1
@alive w1
w1 removeWeapon "m16";w1 removeMagazines "m16";
_c = 0
while "_c <= (_magcount - 1)" do {w1 addmagazine (_mags select _c); _c = _c + 1}
_c = 0
while "_c <= (_guncount - 1)" do {w1 addweapon (_guns select _c); _c = _c + 1}
w1 selectweapon primaryweapon w1
goto "respawnloop"
exit
-
Here is the same piece of code, modified to give the player the same weapons he started the game with every time, instead of the weapons he died with. See the post above for how to use the code in MP games.
_guns = weapons w1
_guncount = count weapons w1
_mags = magazines w1
_magcount = count magazines w1
#respawnloop
@!alive w1
@alive w1
w1 removeWeapon "m16";w1 removeMagazines "m16";
_c = 0
while "_c <= (_magcount - 1)" do {w1 addmagazine (_mags select _c); _c = _c + 1}
_c = 0
while "_c <= (_guncount - 1)" do {w1 addweapon (_guns select _c); _c = _c + 1}
w1 selectweapon primaryweapon w1
goto "respawnloop"
exit
-
This would be great exept for 2 things.
1. I really don't know how to exec this and if i just do this exec "a1.sqs" he doesn't have any weapons at the start!
2. I was using this for a WW2 level with the WW2 teams stuff and they respawn with a AK74 or M16!
Frosty Salamander
-
You have to run the script in Each players init field, and change w1 to the players name....
You might have to put a little delay (~0.1) in the start of the script for the second script it to pick up his weapons at the start.
For example, if your soldier is named "soldier1" you would put:
[] exec "thisscript.sqs" in his init field and change "w1" in the script to "soldier1".
Hope that helps.
-
Or you could do it this way toadlife:
in the init.sqs:
~1
_guns = weapons player
_guncount = count weapons player
_mags = magazines player
_magcount = count magazines player
#respawnloop
@!alive player
@alive player
Removeallweapons player
_c = 0
while "_c <= (_magcount - 1)" do {player addmagazine (_mags select _c); _c = _c + 1}
_c = 0
while "_c <= (_guncount - 1)" do {player addweapon (_guns select _c); _c = _c + 1}
player selectweapon primaryweapon player
goto "respawnloop"
exit
I put a one-second delay in there. Usually, I use init.sqs to launch a cutscene that runs while I do some MP housekeeping (negotiating viewdistance and such). This is one of those tasks that could be done during that time.
-
wouldn't this work better than making a million scripts:
;rearm.sqs
_player = _this select 0
~1
_guns = weapons _player
_guncount = count weapons _player
_mags = magazines _player
_magcount = count magazines _player
#respawnloop
@!alive _player
@alive _player
Removeallweapons _player
_c = 0
while "_c <= (_magcount - 1)" do {_player addmagazine (_mags select _c); _c = _c + 1}
_c = 0
while "_c <= (_guncount - 1)" do {_player addweapon (_guns select _c); _c = _c + 1}
_player selectweapon primaryweapon _player
goto "respawnloop"
exit
then exec for each player like...: [unitname] exec "rearm.sqs" ? ? atleast it would work for every unit on one side?...
-
wouldn't this work better than making a million scripts:
I wish, but it can't work that way. You really have to make one script for each player with the player's name explicitly defined in the script. :-[
When you say "_player = _this select 0" in the script, what "_player" refers to ceases to exist upon death. In MP, upon respawning, the player becomes a new object, the only things that are the same about the player after respawning are cosmetic, like player model, face, and name.
Once the initial object that "_player" stands for is gone, the script will just wait forever for the original object to come back alive.
That's why you have to declare the players name througout the script.
@Dinger
You're right, you could put it in the init.sqs, but then it would not work for AI units.
-
:tomato: I tried ;D
-
I do this:
Place a solder, make them Playable, and name them USA1 or whatever. They must have a name for reference.
Then make a Trigger that runs Repeatedly. Set its Condition to be not alive USA1 and local USA1. Then set it's OnDeactivation to be [USA1, "Steyr"] exec "weapons.sqs".
Put this weapons.sqs script in your mission directory:
(This only works with 1.85!!!!!!!!)
_obj = _this select 0
_type = _this select 1
goto _type
#Soldier
_mag = ["M16", "M16", "M16", "M16", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade"]
_weapon = ["M16"]
goto "exit"
#SoldierE
_mag = ["AK74", "AK74", "AK74", "AK74", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade"]
_weapon = ["AK74"]
goto "exit"
#G36
_mag = ["G36aMag", "G36aMag", "G36aMag", "G36aMag", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade"]
_weapon = ["G36a"]
goto "exit"
#Steyr
_mag = ["SteyrMag", "SteyrMag", "SteyrMag", "SteyrMag", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade"]
_weapon = ["Steyr"]
goto "exit"
#XMS
_mag = ["M4", "M4", "M4", "M4", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade"]
_weapon = ["XMS", "NVGoggles"]
goto "exit"
#AA
_mag = ["M16", "M16", "M16", "M16", "AALauncher"]
_weapon = ["M16", "AALauncher"]
goto "exit"
#EAA
_mag = ["AK74", "AK74", "AK74", "AK74", "9K32Launcher"]
_weapon = ["AK74", "9K32Launcher"]
goto "exit"
#AT
_mag = ["M16", "M16", "M16", "M16", "CarlGustavLauncher"]
_weapon = ["M16", "CarlGustavLauncher"]
goto "exit"
#EAT
_mag = ["AK74", "AK74", "AK74", "AK74", "AT4Launcher"]
_weapon = ["AK74", "AT4Launcher"]
goto "exit"
#SaboteurXMS
_mag = ["M4", "M4", "M4", "M4", "PipeBomb", "PipeBomb", "PipeBomb"]
_weapon = ["XMS", "Binocular"]
goto "exit"
#SaboteurHG
_mag = ["UZIMag", "UZIMag", "UZIMag", "UZIMag", "PipeBomb", "PipeBomb", "PipeBomb", "GlockMag", "GlockMag", "GlockMag", "GlockMag"]
_weapon = ["UZI", "NVGoggles", "Glock"]
goto "exit"
#SaboteurS
_mag = ["HK", "HK", "HK", "HK", "PipeBomb", "PipeBomb", "PipeBomb", "GlockSMag", "GlockSMag", "GlockSMag", "GlockSMag"]
_weapon = ["HK", "NVGoggles", "GlockS"]
goto "exit"
#ESaboteurBizon
_mag = ["BizonMag", "BizonMag", "BizonMag", "BizonMag", "PipeBomb", "PipeBomb", "PipeBomb"]
_weapon = ["Bizon", "NVGoggles"]
goto "exit"
#ESaboteurHG
_mag = ["AK74", "AK74", "AK74", "AK74", "PipeBomb", "PipeBomb", "PipeBomb", "SkorpionMag", "SkorpionMag", "SkorpionMag", "SkorpionMag"]
_weapon = ["AK74SU", "NVGoggles", "Skorpion"]
goto "exit"
#Crew
_mag = ["M4", "M4", "M4", "M4", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade"]
_weapon = ["M4", "NVGoggles"]
goto "exit"
#ECrew
#EPilot
_mag = ["AK74", "AK74", "AK74", "AK74", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade"]
_weapon = ["AK74SU", "NVGoggles"]
goto "exit"
#PilotHG
_mag = ["M4", "M4", "M4", "M4", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade", "RevolverMag", "RevolverMag", "RevolverMag", "RevolverMag"]
_weapon = ["M4", "NVGoggles", "Revolver"]
goto "exit"
#G
_mag = ["M16", "M16", "M16", "M16", "GrenadeLauncher", "GrenadeLauncher", "GrenadeLauncher"]
_weapon = ["M16GrenadeLauncher"]
goto "exit"
#EG
_mag = ["AK74", "AK74", "AK74", "AK74", "GrenadeLauncher", "GrenadeLauncher", "GrenadeLauncher"]
_weapon = ["AK74GrenadeLauncher"]
goto "exit"
#HeavyG
_mag = ["MM1Magazine", "SmokeShell", "SmokeShell"]
_weapon = ["MM1", "Binocular"]
goto "exit"
#EHeavyG
_mag = ["6G30Magazine", "6G30Magazine", "SmokeShell", "SmokeShell"]
_weapon = ["6G30", "Binocular"]
goto "exit"
#LAW
_mag = ["M16", "M16", "M16", "M16", "LAWLauncher", "LAWLauncher", "LAWLauncher"]
_weapon = ["M16", "LAWLauncher"]
goto "exit"
#ELAW
_mag = ["AK74", "AK74", "AK74", "AK74", "RPGLauncher", "RPGLauncher", "RPGLauncher"]
_weapon = ["AK74", "RPGLauncher"]
goto "exit"
#OfficerHG
_mag = ["M16", "M16", "M16", "M16", "BerettaMag", "BerettaMag", "BerettaMag", "BerettaMag", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade", "SmokeShell", "SmokeShell"]
_weapon = ["M16", "Binocular", "Beretta"]
goto "exit"
#OfficerEHG
_mag = ["AK74", "AK74", "AK74", "AK74", "TokarevMag", "TokarevMag", "TokarevMag", "TokarevMag", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade", "SmokeShell", "SmokeShell"]
_weapon = ["AK74", "Binocular", "Tokarev"]
goto "exit"
#Sniper
_mag = ["M21", "M21", "M21", "M21"]
_weapon = ["M21"]
goto "exit"
#ESniper
_mag = ["SVDDragunov", "SVDDragunov", "SVDDragunov", "SVDDragunov"]
_weapon = ["SVDDragunov"]
goto "exit"
#MG
_mag = ["M60", "M60", "M60", "M60", "M60"]
_weapon = ["M60"]
goto "exit"
#EMG
_mag = ["PK", "PK", "PK", "PK", "PK"]
_weapon = ["PK"]
goto "exit"
#Medic
_mag = ["M16", "M16", "M16", "M16"]
_weapon = ["M16"]
goto "exit"
#EMedic
_mag = ["AK74", "AK74", "AK74", "AK74"]
_weapon = ["AK74"]
goto "exit"
#Mortar
_mag = ["M16", "M16", "M16", "M16", "Mortar", "Mortar", "Mortar"]
_weapon = ["M16"]
goto "exit"
#exit
removeAllWeapons _obj
"_obj addMagazine _x" forEach _mag
"_obj addWeapon _x" forEach _weapon
_obj selectWeapon (_weapon select 0)
exit
Pick the appropriate #Label for each of your guys. So with this script each player will need a name (USA1, RUS1, etc.) and each will need their own Trigger!! This is as easy as it gets, I believe. You don't have to have 20 scripts all running as loops, instead you just have 20 triggers. :P
Doolittle
-
...You don't have to have 20 scripts all running as loops, instead you just have 20 triggers. :P
Err... that's not necessarily any better...
Why have 20 triggers, when all you need is one?
Trigger
Radius: 0,0
Condition: none (repeatedly)
Condition Field: Alive player
OnActivation Field: [] exec "Rearm.sqs"
Rearm.sqs
? player in [w1,w4,w5,w8]: goto "WGrenadier"
? player in [e1,e4,e5,e8]: goto "EGrenadier"
? player in [w2,w6]: goto "WMGunner"
.... etc.
That way you need only one script (that only activates when the each individual player dies) and one trigger. It'll save you a lot of CPU time, the only draw back being you have to name all your players. (And it won't work with group respawn).
-
Pick the appropriate #Label for each of your guys. So with this script each player will need a name (USA1, RUS1, etc.) and each will need their own Trigger!! This is as easy as it gets, I believe. You don't have to have 20 scripts all running as loops, instead you just have 20 triggers. :P
Doolittle
Woah there cowboy! That's a hefty piece of code there! When you put down 20 triggers on a MP map, each player has to process every trigger, regarless of weather or not he will ever meet the condition. If you put a script on the init feild of each player, then each player only has to run his own script, and doesn't have to process the other players' scripts.
The script I posted also allows for custom weapon loadouts (remember addon units!), not the just the standard soldier equipment.
-
If you put a script on the init feild of each player, then each player only has to run his own script, and doesn't have to process the other players' scripts.
:hmm:
Actually, toadie... every client will be running all player scripts as you have it there. Just because the script is executed in the player's init field doesn't mean other clients won't be running it. However it could be that way :D
Throw in a line:
? player != w1: exit
in there and it will work just as you've said ;)
-
Actually, toadie... every client will be running all player scripts as you have it there. Just because the script is executed in the player's init field doesn't mean other clients won't be running it. However it could be that way
I was, and still am under the impression that scripts that are executed in a unit's init field only execute on the machine that the unit is local to. I'm curious and will do a little test tonight just to make sure. If I'm wrong, then add that little line I will.
Your method of using one trigger would work great for human players, but I'm almost positive that it wouldn't work for AI units, because the server controls them and doesn't regard them as "players".
Not that people use AI that much in MP, but they do sometimes.
-
Sui, good point. I was making a mission as I posted that and having to edit 20 triggers for all the players got to be annoying. Here's a way to do it with NONE...
toadlife, yeah 20 triggers does suck and isn't clean/elegant. Here's a script that does allow for custom weapon loadouts, addon units, whatever. It is just one loop that is run by the server alone (???). Two .sqs files are needed, one Game Logic unit to start the loop, and nameing of each soldier (and editing of serverloop.sqs for each soldier). (I created this after last post above because of what you guys pointed out...thanks for the motivation.)
Pasted from http://www.flashpoint1985.com/cgi-bin/ikonboard301/ikonboard.cgi?s=3dca00b05181ffff;act=ST;f=7;t=22156;st=0 (http://www.flashpoint1985.com/cgi-bin/ikonboard301/ikonboard.cgi?s=3dca00b05181ffff;act=ST;f=7;t=22156;st=0)
Here's some script I wrote. It works with AI too. You need these two files...
weapons.sqs
;Reload a soldier when they respawn
;by Doolittle
_obj = _this select 0
_type = _this select 1
goto _type
#Soldier
_mag = ["M16", "M16", "M16", "M16", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade"]
_weapon = ["M16"]
goto "exit"
#SoldierE
_mag = ["AK74", "AK74", "AK74", "AK74", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade"]
_weapon = ["AK74"]
goto "exit"
#G36
_mag = ["G36aMag", "G36aMag", "G36aMag", "G36aMag", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade"]
_weapon = ["G36a"]
goto "exit"
#Steyr
_mag = ["SteyrMag", "SteyrMag", "SteyrMag", "SteyrMag", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade"]
_weapon = ["Steyr"]
goto "exit"
#XMS
_mag = ["M4", "M4", "M4", "M4", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade"]
_weapon = ["XMS", "NVGoggles"]
goto "exit"
#AA
_mag = ["M16", "M16", "M16", "M16", "AALauncher"]
_weapon = ["M16", "AALauncher"]
goto "exit"
#EAA
_mag = ["AK74", "AK74", "AK74", "AK74", "9K32Launcher"]
_weapon = ["AK74", "9K32Launcher"]
goto "exit"
#AT
_mag = ["M16", "M16", "M16", "M16", "CarlGustavLauncher"]
_weapon = ["M16", "CarlGustavLauncher"]
goto "exit"
#EAT
_mag = ["AK74", "AK74", "AK74", "AK74", "AT4Launcher"]
_weapon = ["AK74", "AT4Launcher"]
goto "exit"
#SaboteurXMS
_mag = ["M4", "M4", "M4", "M4", "PipeBomb", "PipeBomb", "PipeBomb"]
_weapon = ["XMS", "Binocular"]
goto "exit"
#SaboteurHG
_mag = ["UZIMag", "UZIMag", "UZIMag", "UZIMag", "PipeBomb", "PipeBomb", "PipeBomb", "GlockMag", "GlockMag", "GlockMag", "GlockMag"]
_weapon = ["UZI", "NVGoggles", "Glock"]
goto "exit"
#SaboteurS
_mag = ["HK", "HK", "HK", "HK", "PipeBomb", "PipeBomb", "PipeBomb", "GlockSMag", "GlockSMag", "GlockSMag", "GlockSMag"]
_weapon = ["HK", "NVGoggles", "GlockS"]
goto "exit"
#ESaboteurBizon
_mag = ["BizonMag", "BizonMag", "BizonMag", "BizonMag", "PipeBomb", "PipeBomb", "PipeBomb"]
_weapon = ["Bizon", "NVGoggles"]
goto "exit"
#ESaboteurHG
_mag = ["AK74", "AK74", "AK74", "AK74", "PipeBomb", "PipeBomb", "PipeBomb", "SkorpionMag", "SkorpionMag", "SkorpionMag", "SkorpionMag"]
_weapon = ["AK74SU", "NVGoggles", "Skorpion"]
goto "exit"
#Crew
_mag = ["M4", "M4", "M4", "M4", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade"]
_weapon = ["M4", "NVGoggles"]
goto "exit"
#ECrew
#EPilot
_mag = ["AK74", "AK74", "AK74", "AK74", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade"]
_weapon = ["AK74SU", "NVGoggles"]
goto "exit"
#PilotHG
_mag = ["M4", "M4", "M4", "M4", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade", "RevolverMag", "RevolverMag", "RevolverMag", "RevolverMag"]
_weapon = ["M4", "NVGoggles", "Revolver"]
goto "exit"
#G
_mag = ["M16", "M16", "M16", "M16", "GrenadeLauncher", "GrenadeLauncher", "GrenadeLauncher"]
_weapon = ["M16GrenadeLauncher"]
goto "exit"
#EG
_mag = ["AK74", "AK74", "AK74", "AK74", "GrenadeLauncher", "GrenadeLauncher", "GrenadeLauncher"]
_weapon = ["AK74GrenadeLauncher"]
goto "exit"
#HeavyG
_mag = ["MM1Magazine", "SmokeShell", "SmokeShell"]
_weapon = ["MM1", "Binocular"]
goto "exit"
#EHeavyG
_mag = ["6G30Magazine", "6G30Magazine", "SmokeShell", "SmokeShell"]
_weapon = ["6G30", "Binocular"]
goto "exit"
#LAW
_mag = ["M16", "M16", "M16", "M16", "LAWLauncher", "LAWLauncher", "LAWLauncher"]
_weapon = ["M16", "LAWLauncher"]
goto "exit"
#ELAW
_mag = ["AK74", "AK74", "AK74", "AK74", "RPGLauncher", "RPGLauncher", "RPGLauncher"]
_weapon = ["AK74", "RPGLauncher"]
goto "exit"
#OfficerHG
_mag = ["M16", "M16", "M16", "M16", "BerettaMag", "BerettaMag", "BerettaMag", "BerettaMag", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade", "SmokeShell", "SmokeShell"]
_weapon = ["M16", "Binocular", "Beretta"]
goto "exit"
#OfficerEHG
_mag = ["AK74", "AK74", "AK74", "AK74", "TokarevMag", "TokarevMag", "TokarevMag", "TokarevMag", "HandGrenade", "HandGrenade", "HandGrenade", "HandGrenade", "SmokeShell", "SmokeShell"]
_weapon = ["AK74", "Binocular", "Tokarev"]
goto "exit"
#Sniper
_mag = ["M21", "M21", "M21", "M21"]
_weapon = ["M21"]
goto "exit"
#ESniper
_mag = ["SVDDragunov", "SVDDragunov", "SVDDragunov", "SVDDragunov"]
_weapon = ["SVDDragunov"]
goto "exit"
#MG
_mag = ["M60", "M60", "M60", "M60", "M60"]
_weapon = ["M60"]
goto "exit"
#EMG
_mag = ["PK", "PK", "PK", "PK", "PK"]
_weapon = ["PK"]
goto "exit"
#Medic
_mag = ["M16", "M16", "M16", "M16"]
_weapon = ["M16"]
goto "exit"
#EMedic
_mag = ["AK74", "AK74", "AK74", "AK74"]
_weapon = ["AK74"]
goto "exit"
#Mortar
_mag = ["M16", "M16", "M16", "M16", "Mortar", "Mortar", "Mortar"]
_weapon = ["M16"]
goto "exit"
#exit
removeAllWeapons _obj
"_obj addMagazine _x" forEach _mag
"_obj addWeapon _x" forEach _weapon
_obj selectWeapon (_weapon select 0)
exit
serverloop.sqs
;Check to see when the soldier dies
;by Doolittle
;_obj = [USA1, USA2, RUS1]
;_obj must be after #Beginning
_type = ["OfficerHG", "XMS", "SoldierE"]
;This would mean USA1 is an OfficerHG, USA2 is an XMS dude, and RUS1 is a SoldierE
;Make up your own loadout for peeps and make up whatever name you want in the weapons.sqs file
_count = count _type
;_alive must be same length as _type and _obj and make it all zeros
_alive = [0, 0, 0]
#Beginning
_i = 0
;This MUST be here inside the loop
_obj = [USA1, USA2, RUS1]
~1
#Next
~0.01
_o = _obj select _i
? not alive _o : _alive set [_i, 0]
? _alive select _i == 0 and alive _o : [_o, _type select _i] exec "weapons.sqs"; _alive set [_i, 1]
_i = _i + 1
? _i == _count : goto "Beginning"
goto "Next"
Then make a Game Logic object and in its Initialization put [] exec "serverloop.sqs". Now, for the soldiers you want to get weapons on respawn, name them (like USA1, USA2, RUS1, etc.). Then edit serverloop.sqs and make the _obj, _type, and _alive what you want according to the soldiers' names and what type weapon configuration you want them to have.
Enjoy! :D
Doolittle
-
Wow for some reason it takes 10 years to load this post.
Anyways. HEY MY CODE ABOVE STINKS. IT DOESN'T WORK SO DON'T BOTHER WITH MY STUFF. I just tested it last night with my brother over multiplayer and it was giving weird results. :'(
Doolittle
-
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:
_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.
-
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.
;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"
-
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. ;)
-
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.
-
http://www.ofpec.com/editors/resource_view.php?id=301 <-- go here dude, read the comments at the top of the script.