Jump to content
Sign in to follow this  
KaRRiLLioN

Vehicle respawn

Recommended Posts

Since this has been asked many, many times, and I get many emails regarding it, here is how I respawn vehicles in multiplayer.  I checked this forum and the only thread I found regarding this, was a fossil of a thread with an old method that doesn't work well in it. There are other methods listed at www.ofpec.com but after running a search up to 1 year ago, I couldn't locate any of them so I'll just post how I do it.

Here's my method:

HOW TO USE:

Download the script vrs.sqs (link below) and place this file in your mission directory (where the mission.sqm file is)

*IMPORTANT*  In your mission create a GameLogic and name it Server.  This will prevent multi-spawns of vehicles because the script will only execute on the server with this.

Also, DO NOT use triggers to activate this, or the vehicle will respawn where it died.  Use the vehicle init field.

Create a vehicle.  In the init field of the vehicle put in this:

[this]exec "vrs.sqs"

Now copy and paste that vehicle and change it to any kind of vehicle you want (almost everything is covered in this script)

Whenever the vehicle can no longer move, it will be respawned.

Here's a link to the latest version:

http://www.aggression.org/karr/vrs.zip

Unzip the file and place it in your mission directory.  BTW, I left in some code that will do special re-arming on cessnas and Mi17's just so you can see how it can be done.

This script also has the new resistance vehicles in it.

Share this post


Link to post
Share on other sites

Hey KaRR,

I wanted to let you know that I use this script all the time. Thanks a lot...it has made my mission creation much simpler.

I use this script on some of my training missions, one of which is a LAW/RPG/AT4/Gustav range. I have certain vehicles move along predefined routes at changing speeds. This is to practice hitting moving vehicles. Problem is, once I kill the vehicle, it respawns without a crew. Is there a simple way I could modify this script to respawn the crew in the vehicle as well so I can continue practicing?

As always thanks for the help....keep up the excellent work!

Rock out.

Share this post


Link to post
Share on other sites

Backoff and Deadmeat, over at the OFPEC made an excellent flexible script for respawning and creating just about anything with crews, soldier squads, etc. I just need to dig it up and explain how to use it. Remind me to do so. =)

Basically you can even have APC's load up with soldiers, disembark etc. You define your squads and such in the init.sqs file and then you can place markers in the mission and have them go to the waypoints at different speeds.

I'll try to put together a tutorial for you since I've used that script a lot in my coops. That way I don't have to place items in the mission editor, except for markers that define where the squads start and go.

Share this post


Link to post
Share on other sites

i use that script to but sum probs i find is i use the jeep class fr respawns like a bus or motorbike, whathappens is after there first respawn when destroyed they then expload, before they just crumpled.

Share this post


Link to post
Share on other sites

I'm not sure I understand what you're saying Helltoupe.

Are you saying with my script they blow up after they respawn?

All my script does is delete the old vehicle and create a new one. The older methods where it did a SetDammage 0 on the destroyed vehicles would cause multiple explosions, but not this method.

Share this post


Link to post
Share on other sites

I discovered the Resistance BMP wasn't in the script, so I updated it.

Share this post


Link to post
Share on other sites

1) Thanks.

2) Any more info on getting repawned vehicles/men to do something after being respawned over and over as mentioned above?

3) Thanks.

Share this post


Link to post
Share on other sites

In order for crew to respawn into the vehicle after it's been respawned you just need to do your moveindriver, moveingunner,etc commands right after the vehicle is created and turned to it's correct direction. I would copy the vrespawn.sqs script and make a special one for crewed vehicle respawn.

When you specify vrespawn.sqs in the init field of the vehicle when it's first placed in the editor (or the 1st time via script) you would pass the unit IDs of the units that will be moved into the vehicle.

So, instead of [this] exec "vrespawn.sqs" for an m1a1 tank for example you might have [this,driver,gunner,commander] exec "vrespawn2.sqs" where driver, gunner, and commander are the unit names of the units you want crewing the tank.

Then in vrespawn2.sqs:

_vcl = _this select 0

_driver = _this select 1

_gunner = _this select 2

_commander = _this select 3

right after the vehicle is respawned just move the 3 units into their respective positions:

_driver moveindriver _vcl

_gunner moveingunner _vcl

_commander moveincommander _vcl

Something like that should do the trick

Share this post


Link to post
Share on other sites

This is a good respawn script but the unit will not spawn into the vehicle! I have tried so many ways to get ai to spawn in the vehicles but it will not. sad.gif. Plazmoid have you any succsess with respawning ai into respawned vehicles?

Share this post


Link to post
Share on other sites

for respawning units in a vehicle use

"SoldierECrew" createUnit [getMarkerpos "respawnpoint", GroupAlpha, "this moveInDriver RespawnVehicle", 1, "PRIVATE"]

Works for me

Share this post


Link to post
Share on other sites

I love having vehicle's respawn when they die or ALSO having them respawn if they are left all alone out in the woods somewhere.  (Drive a jeep out to battle, get out & go fight & don't worry about the jeep 'cause it'll respawn.)

Here's what I've scripted: (Cut and paste this code into a file named "vehicle.sqs" and put it in your mission's directory. Then for each vehicle you want to respawn, put [this] exec "vehicle.sqs" in that vehicle's Init.) (This code only works with OFP 1.91.) (And don't forget to put a Game Logic object on the map & set it's Name to "Server".)

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">;Script by Doolittle, dbircsak@earthlink.net

? not local Server : exit

_obj = _this select 0

_pos = getPos _obj

_dir = getDir _obj

_type = typeOf _obj

#clear

_t = 0

#alive

~3

? not alive _obj : _delay = 150; goto "notalive"

? fuel _obj == 1 : goto "clear"

? count crew _obj != 0 : goto "clear"

? _t == 0 : _t = _time + 110

? _t > _time : goto "alive"

"_obj removeMagazine _x" forEach magazines _obj

_obj setFuel 0

_obj setDamage 1

_delay = 10

#notalive

~_delay

deleteVehicle _obj

~1

_obj = _type createVehicle _pos

_obj setDir _dir

goto "clear"

<span id='postcolor'>

The first time of 150 seconds is how long the vehicle is left dead before it respawns.  The second time of 110 seconds is how long the vehicle needs to be left unattended/empty before it dies & respawns (10 seconds later).  Change these values to what you want.

If you use this code please mention me (Doolittle) in the mission notes as this encourages script authors to write & release more code...and it's also nice. smile.gif

Share this post


Link to post
Share on other sites

This is a good one Doolittle. biggrin.gif  Any chance you can write a script for players/ai to be in the respawned vehicles please?

I edited it a little but the players still cant respawn in the newly spawned vehicles:

;Script by Doolittle, dbircsak@earthlink.net

? not local Server : exit

_obj = _this select 0

_pos = getPos _obj

_dir = getDir _obj

_type = typeOf _obj

_

#clear

_t = 0

_vcl = _this select 0

_driver = _this select 1

_gunner = _this select 2

_commander = _this select 3

_driver moveindriver _vcl

_gunner moveingunner _vcl

_commander moveincommander _vcl

#alive

~3

? not alive _obj : _delay = 10; goto "notalive"

? fuel _obj == 1 : goto "clear"

? count crew _obj != 0 : goto "clear"

? _t == 0 : _t = _time + 22

? _t > _time : goto "alive"

"_obj removeMagazine _x" forEach magazines _obj

_obj setFuel 0

_obj setDamage 1

_delay = 10

#notalive

~_delay

deleteVehicle _obj

~1

_obj = _type createVehicle _pos

_obj setDir _dir

goto "clear"

Share this post


Link to post
Share on other sites

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (Chill @ Jan. 08 2003,01:11)</td></tr><tr><td id="QUOTE">This is a good respawn script but the unit will not spawn into the vehicle! I have tried so many ways to get ai to spawn in the vehicles but it will not. sad.gif. Plazmoid have you any succsess with respawning ai into respawned vehicles?<span id='postcolor'>

I have the same problem, in MP the soldiers(crew) just spawns outside the vehicle(tank whatever)

Here is my mission that won't work

1 empty M60 tank:

name=Tank1

1 west soldier:

init-field="WG0 = Group This;DeleteVehicle This"

2 west soldiers(playable)

1 Resistant soldier:

Name="Res", init-field="RemoveAllWeapons This"

2 GameLogics

[GameLogic1]

name=Server

[gameLogic2]

name=WSpawn

2 Triggers

[Trigger1]

a:0,b:0,activation:west,present

Condition=(Not Alive Res)

OnActivation=WPres=true

[Trigger2]

a:0,b:0,activation:west,present

Condition=WPres

OnActivation="SoldierWCrew" createUnit [(GetPos WSpawn), WG0, "This MoveInDriver Tank1", 0.5, "CAPTAIN"]

I also tried this

[Trigger2]

a:0,b:0,activation:west,present

Condition=WPres

OnActivation=[] exec "spawn.sqs"

[spawn.sqs]

?!(Local Server):Goto "End"

"SoldierWCrew" createUnit [(GetPos WSpawn), WG0, "This MoveInDriver Tank1", 0.5, "CAPTAIN"]

#End

exit

Please help us...

[edited]

Well My OPF-CD is very near destruction now!!

in MULTIPLAYER, the objects created with CreateVehicle does not get any ID's on the client machines.

As it is needed for the Server to only create one tank, instead of two(one for server, one for client) the CreateVehicle script do need the ?(Local Server):[] exec "tank.sqs"

in tank.sqs the game gives the "tank" object a reference to an variable(or something)

D1 = "M60" CreateVehicle GetPos GameLogic

D1 only lives ON the freaking server, and does not exist on the client machines!!1

example:

Trigger allways(at start)

[] exec "init.sqs"

[init.sqs]

;boolean used later

publicVariable "bM1"

;public reference to tank

publicVariable "vM1"

Trigger alpha (create Tank)

[] exec "create.sqs"

[create.sqs]

?(Local Server): [] exec "tank.sqs"

[] exec "send.sqs"

exit

[tank.sqs]

D1 = "M60" CreateVehicle GetPos T1

vM1 = D1

bM1 = True

[send.sqs]

@bM1

bM1=false

;Supposed to be transferring global variable

Hint Format["Global: %1",vM1]

_tInitStr1 = Format["This MoveInDriver D1"]

_tInitStr2 = Format["This MoveInGunner D1"]

_tInitStr3 = Format["This MoveInCommander D1"]

;~1

"SoldierWCrew" CreateUnit [GetPos T1,G1,_tInitStr1];

"SoldierWCrew" CreateUnit [GetPos T1,G1,_tInitStr2];

"SoldierWCrew" CreateUnit [GetPos T1,G1,_tInitStr3];

this works in SP ONLY!!1

the "Hint Format["Global: %1",vM1]" returns

202020F001# NOID m60

but in MP

"Hint Format["Global: %1",vM1]"

returns: array,bool, str (fuxxorz)

If i place an empty tank(M60) called D1

Presses the Bravo radio, the crew is spawned but not placed in the Tank in MP

They just hangs around, outside and look stoopid.

in SP, they do gets in the tank.

is it because the CreateVehicle does not work in MP?

or is it the CreateUnit String init that does not work in MP?

Please, if anyone has a sollution for this, help me out, until this week is over(January 30:th) or else mu OPF Cd get's it!

Share this post


Link to post
Share on other sites

PublicVariable is not a type of variable, it's a scripting command to broadcast a variable.

Too see what I mean, run a MP testbed on your machine with this script in the init.sqs file:

(be sure to put a gamelogic named "server" in the world)

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

?Local Server:goto serverside

#ClientSide

~5

#Shared

hint format ["Before: %1, After: %2", BeforePublic, AfterPublic]

exit

#serverside

BeforePublic = True

Publicvariable "BeforePublic"

PublicVariable "AfterPublic"

AfterPublic = True

BeforePublic = False

goto "Shared"

<span id='postcolor'>

The result will be on the server:

Before: False, After: True

and on the clients:

Before: True, After: scalar bool array

Also remember that when you're using createvehicle it can take up to a minute for it to register on all machines.

Share this post


Link to post
Share on other sites

Thanks Dinger wink.gif

I will try the script.

But the problem still exist, or?

So, is one minute max for the Created vehicle(CreateVehicle) to be recognized on all machines?

I mean, that moving the crew into the tank after 60 seconds would be a possible sollution?

Share this post


Link to post
Share on other sites

Hey Chill! Hey The_Taurus!  Ok I got it!  For AI that is...

This script will respawn vehicles if they are destroyed.  It will also respawn vehicles if they are abandoned.  It will also now respawn with AI if it had AI to begin with.  AND it will go on to it's waypoints if any are assigned.  Now you can have an enemy BMP on the map and once killed, it will respawn and charge at your Coop players again.  I'm sure they'll love that.

Place a GameLogic on the map far away and call it Server, then for each vehicle you want to respawn put [this] exec "vehicle.sqs" in the Initialization string.  Now make a script called vehicle.sqs and put this in it:

If you use this script please give me credit in your mission Notes or something.  Thanks!

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">;Vehicle (with AI) Respawn Script by Doolittle dbircsak@earthlink.net

requiredVersion "1.91"

? not local Server : exit

_obj = _this select 0

_pos = getPos _obj

_dir = getDir _obj

_type = typeOf _obj

_group = group _obj

_crew = []

"_crew = _crew + [typeOf _x]" forEach crew _obj

"_x addEventHandler [""Killed"", {(_this select 0) removeAllEventHandlers ""Killed""; deleteVehicle (_this select 0)}]" forEach crew _obj

#clear

_t = 0

#alive

~3

? not alive _obj : _delay = 150; goto "notalive"

? fuel _obj == 1 : goto "clear"

? count crew _obj != 0 : goto "clear"

? _t == 0 : _t = _time + 110

? _t > _time : goto "alive"

"_obj removeMagazine _x" forEach magazines _obj

_obj setFuel 0

_obj setDamage 1

_delay = 10

#notalive

~_delay

deleteVehicle _obj

~1

_obj = _type createVehicle _pos

_obj setDir _dir

? count _crew < 1 : goto "clear"

Soldier = []

_crew select 0 createUnit [_pos, _group, "Soldier = this"]

Soldier moveInDriver _obj

Soldier doMove getWPPos [_group, 1]

Soldier addEventHandler ["Killed", {(_this select 0) removeAllEventHandlers "Killed"; deleteVehicle (_this select 0)}]

? count _crew < 2 : goto "clear"

Soldier = []

_crew select 1 createUnit [_pos, _group, "Soldier = this"]

Soldier moveInGunner _obj

Soldier doMove getWPPos [_group, 1]

Soldier addEventHandler ["Killed", {(_this select 0) removeAllEventHandlers "Killed"; deleteVehicle (_this select 0)}]

? count _crew < 3 : goto "clear"

Soldier = []

_crew select 2 createUnit [_pos, _group, "Soldier = this"]

Soldier moveInCommander _obj

Soldier doMove getWPPos [_group, 1]

Soldier addEventHandler ["Killed", {(_this select 0) removeAllEventHandlers "Killed"; deleteVehicle (_this select 0)}]

goto "clear"

<span id='postcolor'>

I can't believe createUnit doesn't return the new unit as an object like createVehicle!!!  The only way to get around this (that I could figure) was to use a global variable (Soldier) almost like a temp variable to be able to do anything to the new unit (Temp variables like _obj don't work inside the Init string).  Also, so the battlefield doesn't get littered with bodies, the CREW of a vehicle will DISAPPEAR when they die.  This is because I didn't have a way to put a delay in there from the time of their death to the time their body disappears (I could have made a call to another script but I wanted to keep it simple).

Enjoy!

Doolittle

Share this post


Link to post
Share on other sites

</span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote </td></tr><tr><td id="QUOTE">Doolittle<span id='postcolor'>

I really like your effort, and your work on creating scripts.

and in other places and areas as well.

But, i'm sorry to say that this particular script is for no use to me, beacuse my version of OPF is: v 1.46(Cold war crisis)  sad.gif

I'm sorry for the inconvinence, but know that others will have use of your script.

So I will have to try the "wait 60 seconds until placing the AI in the vehicle" trick

[edited]

Which did not work ofcourse!! mad.gif

%insert swearwords here%

Share this post


Link to post
Share on other sites

My script is meant only for vehicle respawn in MP games where you aren't using AI. If you're playing coop and you want AI to respawn, then that could be best handled by something like a squad spawn script.

There are several methods for having AI and such moved into vehicles by simply scripting in a createunit command whenever the vehicle is respawned.

My newest version of my vrs.sqs script will respawn abandonded vehicles after 2-3 mins, can't remember off the top of my head.

If you're using 1.46 of Opflash, you should still be able to use my script for respawn, etc. If you want AI to respawn with vehicles, then I HIGHLY recommend you use the script at this link:

http://www.backoff.ch/ofp/script.php

Doolittle, one bad thing about using the typeOf command to get the type is that it might not work on dedicated servers since I don't think there is a 1.91 dedicated server version out there. I tested it on my dedicated server and the vehicles didn't respawn.

Even though it's an incredible pain, I'd recommend sticking with a looping method for the types until a dedicated 1.91 server comes out. I'm not sure why I haven't seen anything on it lately but I'd really like it so I can start using the typeOf command in my scripts and do some serious housecleaning. =)

Share this post


Link to post
Share on other sites

KaRRiLLioN, yeouch!! Very good point. I didn't even think of that...no 1.91 dedicated server. Rats rats....back to drawing board...

Doolittle

Share this post


Link to post
Share on other sites

KaRRiLLioN

Thanks, I've downloaded the script, and it works fine.

A bit to complex for my needs thou.

I will try to figure out how it works, and if I manage to do that, you will be on my "credit list".

[Edited(again)

I have now managed to "crop" down the script to suite my needs.

And the number 1 issue why my script did not work earlier is this "group creator dude" which I had placed in the mission

West Soldier

init:group1 = Group This;DeleteVehicle This

When removing

DeleteVehicle This

Even my lame script started to work, so....

Now I need to rebuild my mission, to have the "group creators" still in the game when it starts, and SetPos them to the right position

Many thanks to you people.

(and my OPF CD thanks you also wink.gif)

[Edited(again)]

The second reason for my earlier script did not work was the init field

e.g.

_strInit3 = Format["moveincommander %1", _vcl]

_pos = GetPos WR1

"SoldierWCrew" createUnit [_pos, _group2,_strInit1, 0.5, "Private"]

Share this post


Link to post
Share on other sites

Thankyou so much Doolittle! I have wanted this for so long!!! biggrin.gif

Share this post


Link to post
Share on other sites

Darn!

I've noticed that the script KaRRiLLioN created was not using groups as I want it to do.

[_newsld] join grpNull

Using it like that, I can't use waypoints as I want so, I rewrote it a little, and that worked fine, until some of the newly spawned units started to die, then the client machine crashed to desktop.

What could be wrong then?

My first thougt was that the groups did not exist on the client machine.

So I created a script like this:

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

_gLogN = _This Select 0

_gX = 0

_gAry = [WDG1,WDG2,WDG3,WDG4]

#NextGrp

_iX = 0

_gGrpN = _gAry Select _gX

;C1 SideChat Format["Group: %1",_gAry Select _gX]

#new

"SoldierWB" createUnit [(GetPos _gLogN), _gGrpN,"", 0.5, "PRIVATE"]

_uAry = Units _gGrpN

;(_uAry Select _iX) MoveInCargo WC1

;C1 SideChat Format["Unit: %1",_uAry Select _iX]

~0.5

_iX = _iX + 1

?(_iX < 12):Goto "New"

~0.5

_gX = _gX + 1

?(_gX < 4):Goto "NextGrp"

#End

exit<span id='postcolor'>

Works fine, the units are killed both on the server, and on the client(which this time is not crashing) is this because of the line

?(Local Server):baba

does not exist, I do not know.

BUT!

When asking the game(triggerwise using radio)

How many troops there are in the groups

e.g.

radio alpha

dude SideChat Format["Units in group %1", Count (Units WDG1)]

The client returns only 1, the server, 12

What's going on?

I'm started to get a bit fed up with this now...

Share this post


Link to post
Share on other sites

Ya got me, Taurus. The client/server differences in OFP has been one of the hardest things for me to understand. Especially because I personally have no way to see/test stuff! How can someone at home with one computer test if they are getting client/server stuff working?? Only way I see is to get someone to run your level on their server, which is a pain. Taurus, how exactly are you testing your scripts??

Doolittle

Share this post


Link to post
Share on other sites

Doolittle

I have the fortune to have three computers at home.

So I set up the server on my machine, and leaps over to the other machine and join from there.

I will now try to configure an dedicated server on the third machine, just to see what happens.

The server/client problem is, it seems.

But BIS should have done something about it in the later versions?

I hope to solve this problem shortly.

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  

×