View Full Version : Vehicle Respawn Template
Ok Here is my Vehicle Respawn Template
Vehicle Respawn (http://www.surfacezero.com/uploads/MattRochelle/ArmA/Missions/Templates/VehicleRespawnTemplate.Intro.rar)
Place into your ArmA/Usermissions
All you need to do is place this into the Vehicles INIT
Quote[/b] ]vehicles = vehicles + [this]
any vehicle u want and it doesn't matter where u go the vehicle will spawn back to its original position.
[i]THE SPAWN ONLY WORKS IN MP! SO IF IT DOESNT WORK IN THE EDITOR DONT WORRY IT WILL IN MP!
Great! http://forums.bistudio.com/oldsmileys/biggrin_o.gif
Yeah this is the shit man. i got stressed walking all that way.
BTW: This Script was Originally made By Doolittle
Sniperwolf572
Dec 8 2006, 20:05
Errrrr, why doing it the long way when we now have a dedicated command to do that, respawnVehicle (http://community.bistudio.com/wiki/respawnVehicle).
Edit:
Just saw your other topic on this, and to say BIS way doesn't work, is complete BS. Here is a working example (ftp://surfacezero.com/uploads/Sniperwolf572/RespawnTest.rar) that it works.
Well there SPAWN IS CRAP! when the vehicle blows up it spawns on the spot that it blew up. Which is no good, At leaste with the one i posted the Vehicles spawn back at base.! http://forums.bistudio.com/oldsmileys/smile_o.gif
Sniperwolf572
Dec 8 2006, 21:13
Right, and I'm Bill Gates. Change the respawn type to base and Bob's your uncle. Need another example?
Big Dawg KS
Dec 8 2006, 21:22
Right, and I'm Bill Gates. Change the respawn type to base and Bob's your uncle.
What? lol
Gee Sniperwolf572, you seem a little irritated. http://forums.bistudio.com/oldsmileys/whistle.gif
So then, it does work right?
Right, and I'm Bill Gates. Change the respawn type to base and Bob's your uncle. Need another example?
Take a chill pill, what if you dont want them to spawn at the base marker. what if you want them to spawn at the place where the editor placed them .. U CANT. so guess what. My version is still better.
Go To Bed.
It's exactly the same as Doolittle's http://forums.bistudio.com/oldsmileys/whistle.gif
It's exactly the same as Doolittle's http://forums.bistudio.com/oldsmileys/whistle.gif
yeah check my 3rd post down or the readme
Sniperwolf572
Dec 10 2006, 08:07
Right, and I'm Bill Gates. Change the respawn type to base and Bob's your uncle.
What? lol
Gee Sniperwolf572, you seem a little irritated. http://forums.bistudio.com/oldsmileys/whistle.gif
So then, it does work right?
Yes, it does work, but as Matt noticed, it depends on the respawn type. INSTANT respawns the vehicle where it was destroyed, and BASE respawns it at the base marker. Maybe we can add a separate respawn entry for description.ext for vehicles, so we can have i.e GROUP respawn for infantry and BASE respawn for vehicles.
Also, I think you can always place a marker for that specific vehicle on where you want to respawn it, and setpos it back after a base respawn.
And, no, I wasn't irritated, I guess all that post was missing is a banana or something...
Goldenwings2002
Dec 11 2006, 08:44
Well i must be doing something wrong because I cannot for the life of me figure this out. What exactly do I type in the INIT field? I am trying to respawn helicopters. Any Ideas?
Well i must be doing something wrong because I cannot for the life of me figure this out. What exactly do I type in the INIT field? I am trying to respawn helicopters. Any Ideas?
Add the three scripts into your mission folder.
then add this into the helicopters init
Quote[/b] ]vehicles = vehicles + [this]
then it only works in MP so if you test it in the editor it wont work. so save the mission in MP and test it there http://forums.bistudio.com/oldsmileys/smile_o.gif
Hit_Sqd_Ack
Dec 11 2006, 13:53
Nice work Matt.
- Ack
Goldenwings2002
Dec 11 2006, 18:19
You are saying to add 3 scripts to my missions folder. I assume you mean to extract the file from the .rar folder and then pull out these 3 files from "VehicleRespawnTemplate.intro"
What I did was just place the "VehicleRespawnTemplate.intro" folder into the every mission folder I had just to be safe.
I added the INIT: "vehicles = vehicles VehicleRespawnTemplate;"
I assume that is wrong...
_
So to understand what you are saying there are 4 files in the "VehicleRespawnTemplate.intro" folder: mission.sqm, player.sqs, vehicles.sqs, and smoke.sqs.
Which of these 3 out of 4 do I place in my missions folder?
I feel really dumb for asking this question but I am not understanding something or am missing a step. Thanks!
You are saying to add 3 scripts to my missions folder. I assume you mean to extract the file from the .rar folder and then pull out these 3 files from "VehicleRespawnTemplate.intro"
What I did was just place the "VehicleRespawnTemplate.intro" folder into the every mission folder I had just to be safe.
I added the INIT: "vehicles = vehicles VehicleRespawnTemplate;"
I assume that is wrong...
_
So to understand what you are saying there are 4 files in the "VehicleRespawnTemplate.intro" folder: mission.sqm, player.sqs, vehicles.sqs, and smoke.sqs.
Which of these 3 out of 4 do I place in my missions folder?
I feel really dumb for asking this question but I am not understanding something or am missing a step. Thanks!
Just add the Script Files
Quote[/b] ]player.sqs, vehicles.sqs, and smoke.sqs
---------------------------------
If you overwite your mission.sqm it will overwite your mission bad idea.. so just copy the 3 script files. http://forums.bistudio.com/oldsmileys/smile_o.gif
Errrrr, why doing it the long way when we now have a dedicated command to do that, respawnVehicle (http://community.bistudio.com/wiki/respawnVehicle).
Edit:
Just saw your other topic on this, and to say BIS way doesn't work, is complete BS. Here is a working example (ftp://surfacezero.com/uploads/Sniperwolf572/RespawnTest.rar) that it works.
link not working
Ok I also can not seem to get it to work. I was able to get the other script to work by kyrillion but that requires a script per vehichle which I do not see myself liking.
The init field that they say ArmA supports that doesn't work for me either.
this on seems to be the only one I get to work
?!(local Server): Goto "end"
_vcl = _this select 0
_position=Getpos _vcl
_dir=Getdir _vcl
_respawndelay = 5
#mainloop
@<hidden> (damage _vcl >0.7)
~_respawndelay
deleteVehicle _vcl
_vcl = "UAZMG" createVehicle _position
_vcl setdir _dir
goto "mainloop"
#end
Exit
Now I am running some other scripts do you need to exec this in the description.ext?
I got it to work you need to add a game logic and a trigger to it like your mission contained
jerryhopper
Dec 22 2006, 18:05
Errrrr, why doing it the long way when we now have a dedicated command to do that, respawnVehicle (http://community.bistudio.com/wiki/respawnVehicle).
Edit:
Just saw your other topic on this, and to say BIS way doesn't work, is complete BS. Here is a working example (ftp://surfacezero.com/uploads/Sniperwolf572/RespawnTest.rar) that it works.
link not working
yep, his url is dead, but here is the right one....
http://www.surfacezero.com/uploads/Sniperwolf572/RespawnTest.rar
Doolittle
Dec 22 2006, 22:16
Hey... I'm surprised that still works. I'm sure there's better ways of doing it now?
Doolittle
Goldenwings2002
Dec 24 2006, 17:09
It still is not working and I have those 3 files in my folder.
jphilapy
Jan 2 2007, 01:12
Why not just use the respawnVehicle command and then move the vehicle to get it at the location where you want it? For example you can create an empty marker where the vehicle goes, then every time the vehicle is destroyed, move it as soon as it respawns.
Jeff
KaRRiLLioN
Jan 3 2007, 20:21
That script snippet from my vrs.sqs is ancient stuff. Just from looking at the credits, I can tell it came from before OFP 1.8 when they added the typeOf command, lol.
Anyway, for ArmA, I redid it as an SQF script. In the mission editor, simply put this in the init field of each vehicle:
s = [] execVM "vrs.sqf"
You MUST have a dummy variable, in this case 's', for the script, or the mission editor parser will error.
And copy the following code into a file named vrs.sqf and put the file in your mission folder.
What this does is monitor the vehicle until someone gets in it, or it's destroyed. Let's say Joe Player hops in a jeep, drives it across the map and abandons it at the enemy base. If no one hops into the jeep for 150 seconds, then it'll respawn it. You can adjust that with the _crewWait variable. Put it high if you don't want it automatically respawning even if it's not destroyed.
Then of course it'll respawn it once it's destroyed anyway. You can adjust the _respawndelay to change the timer on that.
I also will be adding a couple more things to this script later, such as the ability to change the respawn time depending on the type of vehicle, i.e. plane, helo, tank, etc. It'll only require a few extra lines of code, but I haven't put it in yet because I wanted to test some new script commands besides the age-old countType command that I used. Anyway, then if you want planes to take longer to spawn, you'll be able to do that.
I tried the BIS version of respawn, but it's sort of half-assed, TBH. The ONLY thing I want to have to put in the editor is the vehicle itself and the execVM command in the init field. Having to put markers and such simply to respawn a vehicle is a PITA. And I've used this script with hundreds of vehicles at once so I know it doesn't bog the server down at all.
I'll also be changing the while...do command to a for...do. Just haven't done it yet. That way it'll prevent the script from exiting after 10,000 loops. Seeing as how there's a lot of sleep commands, it'd only be an issue with very long missions.
Anyway, here it is.
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">
//BEGIN vrs.sqf
//By KaRRiLLioN
//IMPORTANT: ADD A GAMELOGIC NAMED Server
//to the mission to prevent multispawn
private ["_vcl","_respawndelay","_dir","_pos","_type","_run","_crewWait","_wait","_delay"];
if (!local Server) exitWith {};
_vcl = _this;
_respawndelay = 20;
_dir = Getdir _vcl;
_pos = Getpos _vcl;
_crewWait = 150;
_wait = 0;
_type = typeOf _vcl;
_run = TRUE;
sleep 1;
for [{}, {_run}, {_run}] do
{
while {canMove _vcl && count crew _vcl < 1} do
{
_wait = Time + _crewWait;
sleep 1;
};
while {Count crew _vcl > 0 && Alive _vcl} do
{
_wait = Time + _crewWait;
sleep 1;
};
while {canMove _vcl && count Crew _vcl < 1 && Time < _wait} do
{
sleep 1;
};
_delay = Time + _respawnDelay;
while {!canMove _vcl && count Crew _vcl < 1 && Time < _delay} do
{
sleep 1;
};
if (count Crew _vcl < 1) then
{
deleteVehicle _vcl;
_vcl = _type createVehicle _pos;
_vcl setdir _dir;
sleep 1;
_vcl setvelocity [0,0,0];
_vcl setpos _pos;
sleep 1;
_vcl setvelocity [0,0,0];
};
};
[/QUOTE]
SWAT_BigBear
Jan 3 2007, 22:48
You MUST have a dummy variable, in this case 's', for the script, or the mission editor parser will error.
Could you explain this a lil further? I'm getting the parse error.
On my 1st run, the vehicle spawned where it was destroyed?
KaRRiLLioN
Jan 4 2007, 02:00
1) Place a Game logic in the mission editor. Name it Server.
2) Place a vehicle in the mission editor.
3) In the init field of the vehicle put:
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">s = this execVM "vrs.sqf"[/QUOTE]
4) Copy the code from my earlier post into a file named vrs.sqf and put it in your mission directory.
Now it should work.
[DirTyDeeDs]-Ziggy-
Jan 4 2007, 02:41
great job as always, thanks Karr http://forums.bistudio.com/oldsmileys/notworthy.gif
Nice 1 mate http://forums.bistudio.com/oldsmileys/smile_o.gif
KaRRiLLioN
Jan 4 2007, 14:14
I made a small change to the script. The While{}...do{} loop has a hard-coded 10,000 loop limit and in longer games, there's always the possibility it could hit that limit and exit. I tweaked the script to use the for...do loop instead which AFAIK is infinite.
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">for [{}, {_run}, {_run}] do[/QUOTE]
is the only change I made. I edited my post with the change in case you want to update the script.
Does anyone else get an error while trying to use Kar's script?
_dir = |#|Getdir _vcl;
Error getdir: Type Array, expected Object (line 12 vrs.sqf)
When you start the game.
I'm hosting a game using the game client while testing this, is this ok, or do I need to PBO it and put it on a dedicated for it to work?
Thanks
KaRRiLLioN
Jan 5 2007, 15:35
Make sure in the init field you put:
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">s = this execVM "vrs.sqf"[/QUOTE]
It sounds like for some reason it's pulling an empty array into the script. You might have:
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">s = [] execVM "vrs.sqf"[/QUOTE]
Make sure the exec statement is correct and let me know.
This script can be used on dedicated or host servers--it'll work either way.
EDIT: I'd listed the exec statement incorrectly in my previous post. Corrected now.
SWAT_BigBear
Jan 5 2007, 23:02
Thank you so much. That fixed the error, and also has respawn working perfect. http://forums.bistudio.com/oldsmileys/notworthy.gif
http://forums.bistudio.com/oldsmileys/yay.gif
Thanks KaRRiLLioN! Works great and the vehicles respawn exactly where they are supposed to unlike in other scripts where they move slightly every time they spawn.
Loved all your missions for OFP, looking forward to some ArmA ones! http://forums.bistudio.com/oldsmileys/pistols.gif
@<hidden> KaRRiLLioN
I've been using your script in combination with some others (http://www.flashpoint1985.com/cgi-bin/ikonboard311/ikonboard.cgi?act=ST;f=71;t=57427) I have written that allow non-playable AI units to respawn and get in a respawning HMMWV50 before moving through waypoints to a destination and I have run into a fairly annoying and major bug where by if the gunner is killed enroute to the waypoint his corpse won’t disappear and this prevents the vehicle from respawning. I have tried scripting it so that the gunners corpse is deleted the moment he dies but for some reason his corpse just won’t disappear.
Have you ever experienced the same problem with your script?
I think it may occur in my case because even though the gunner is dead his body may be being counted as crew by your script.
I'm not sure if the syntax of this would work (cause I'm at work and can't try it) but do you think some sort of statement like this added to your script would fix this problem?
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">while {!alive gunner _vcl && canMove _vcl && count Crew _vcl < 2 } do
[/QUOTE]
KaRRiLLioN
Feb 1 2007, 20:29
I've never had that issue AFAIK. Count Crew Vehicle only counts living crew, I believe. In CTF's and such we've had many instances where players and AI were killed in vehicles and they respawned properly.
I suppose you could try to set up a debug statement, i.e.:
player groupchat format ["%1",count crew _vcl]
or something just to see if dead crew are counted as crew. If so, it's a change from OFP and something like your statement will probably work.
Let me start out by saying that this is not a problem if the gunner is a playable unit but if he is a non-playable AI unit and he's dead if I change the code to read this the vehicle will now respawn.
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">
// *****************************************************
//** Operation Flashpoint Script File
//*****************************************************
//BEGIN vrs.sqf
//By KaRRiLLioN
//IMPORTANT: ADD A GAMELOGIC NAMED Server
//to the mission to prevent multispawn
private ["_vcl","_respawndelay","_dir","_pos","_type","_run","_crewWait","_wait","_delay"];
if (!local Server) exitWith {};
_vcl = _this;
_respawndelay = 20;
_dir = Getdir _vcl;
_pos = Getpos _vcl;
_crewWait = 10;
_wait = 0;
_type = typeOf _vcl;
_run = TRUE;
sleep 1;
for [{}, {_run}, {_run}] do
{
while {canMove _vcl && count crew _vcl < 2} do
{
_wait = Time + _crewWait;
sleep 1;
};
while {Count crew _vcl > 1 && Alive _vcl} do
{
_wait = Time + _crewWait;
sleep 1;
};
while {canMove _vcl && count Crew _vcl < 2 && Time < _wait} do
{
sleep 1;
};
_delay = Time + _respawnDelay;
while {!canMove _vcl && count Crew _vcl < 2 && Time < _delay} do
{
sleep 1;
};
if (count Crew _vcl < 2)then
{
deleteVehicle _vcl;
_vcl = _type createVehicle _pos;
_vcl setdir _dir;
sleep 1;
_vcl setvelocity [0,0,0];
_vcl setpos _pos;
sleep 1;
_vcl setvelocity [0,0,0];
hint "respawn vehicle";
};
};[/QUOTE]
So it seems that there is a difference in the way the game treats dead playable and non playable units when they are in the gunner position in vehicles. I think what may be happening is that if the unit is playable when you shoot it its body falls out of the gunner position onto the ground and the script can continue but in the case of nonplayable AI its corpse doesn't disappear and as its still draped in the gunner position for some reason is being counted as a crew member.
This also explains why the script locks up the game if an non playable AI filled vehicle is destroyed while all are on board as the script thinks all the crew are alive but the vehicle is dead. Now how to deal with this is the next question.
After playing around with the vrs script for some time I've come up with this. As far as I can tell, on a local server anyway, if you modify your script like this it will work for both playable and non-playable AI units. The vehicle will now respawn if a non-playable AI corpse is present in the gunner's position and destroying the vehicle with a rocket while crewed by AI units no longer locks up the game.
Note this code was written initially for use with respawning non playable AI units, however as far as I can tell (with limited play testing on a local server) it will also work with playable units and therefore may be used as an alternative to KaRRiLLioN's original vrs code.
Please let me know if you run into any probs.
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">// *****************************************************
//** Operation Flashpoint Script File
//*****************************************************
//BEGIN vrs_AI.sqf
//Original script by KaRRiLLioN modified by norrin for AI units 4th Feb 2007
//IMPORTANT: ADD A GAMELOGIC NAMED Server
//to the mission to prevent multispawn
private ["_vcl","_respawndelay","_dir","_pos","_type","_unit","_run","_wait"];
if (!local Server) exitWith {};
_vcl = _this;
_respawndelay = 20;
_dir = Getdir _vcl;
_pos = Getpos _vcl;
_type = typeOf _vcl;
_unit = driver _vcl;
_run = TRUE;
sleep 5;
for [{}, {_run}, {_run}] do
{
while {_vcl distance _pos < 5 && canMove _vcl} do
{
sleep 1;
};
while {canMove _vcl && count crew _vcl > 0 && ({damage _x}forEach crew _vcl)!= 1} do
{
_wait = Time + _respawndelay;
sleep 1;
};
while {count crew _vcl < 1 && Time < _wait} do
{
sleep 1;
};
while {{damage _x} forEach crew _vcl >= 1 && Time < _wait} do
{
sleep 1;
};
if (count crew _vcl < 1) then
{
deleteVehicle _vcl;
_vcl = _type createVehicle _pos;
_vcl setdir _dir;
sleep 1;
_vcl setvelocity [0,0,0];
_vcl setpos _pos;
sleep 1;
_vcl setvelocity [0,0,0];
hint "respawn vehicle";
sleep 2;
};
if ({damage _x} forEach crew _vcl >= 1)then
{
deleteVehicle _vcl;
_vcl = _type createVehicle _pos;
_vcl setdir _dir;
sleep 1;
_vcl setvelocity [0,0,0];
_vcl setpos _pos;
sleep 1;
_vcl setvelocity [0,0,0];
hint "respawn vehicle";
sleep 1;
};
sleep 2;
};[/QUOTE]
EDIT: Updated script and text.
After a request from 169th_Ice I've revised my vrs_AI.sqf script so that you can specify different times for the length of respawn wait for when a vehicle is left empty or if a vehicle is destroyed much like KaRRiLLioN's original version of this script. You can d/l a copy of my revised vrs_AI.sqf script here (http://home.iprimus.com.au/simonnsl/norrinsArmA/Scripts/vrs_AI.sqf)
Here's the code of the revised script for anyone interested
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">
// *****************************************************
//** Operation Flashpoint Script File
//*****************************************************
//BEGIN vrs_AI.sqf
//Original script by KaRRiLLioN modified by norrin for AI units 7th Feb 2007
//IMPORTANT: ADD A GAMELOGIC NAMED Server
//to the mission to prevent multispawn
private ["_vcl","_respawndelay","_vclemptydelay","_dir","_pos","_type","_unit","_run","_wait","_delay"];
if (!local Server) exitWith {};
_vcl = _this;
//specify the respawn wait times for empty vehicles and destroyed vehicles in the following 2 lines
_vclemptydelay = 60;
_respawndelay = 20;
_dir = Getdir _vcl;
_pos = Getpos _vcl;
_type = typeOf _vcl;
_unit = driver _vcl;
_run = TRUE;
sleep 5;
for [{}, {_run}, {_run}] do
{
while {_vcl distance _pos < 5 && canMove _vcl} do
{
sleep 1;
};
while {canMove _vcl && count crew _vcl > 0 && ({damage _x}forEach crew _vcl)!= 1} do
{
_wait = Time + _vclemptydelay;
sleep 1;
};
while {canMove _vcl && count crew _vcl < 1 && Time < _wait} do
{
sleep 1;
};
while {canMove _vcl && {damage _x} forEach crew _vcl >= 1 && Time < _wait} do
{
sleep 1;
};
_delay = Time + _respawndelay;
while {!canMove _vcl && Time < _delay} do
{
sleep 1;
};
if (count crew _vcl < 1) then
{
deleteVehicle _vcl;
_vcl = _type createVehicle _pos;
_vcl setdir _dir;
sleep 1;
_vcl setvelocity [0,0,0];
_vcl setpos _pos;
sleep 1;
_vcl setvelocity [0,0,0];
hint "respawn vehicle";
sleep 2;
};
if ({damage _x} forEach crew _vcl >= 1)then
{
deleteVehicle _vcl;
_vcl = _type createVehicle _pos;
_vcl setdir _dir;
sleep 1;
_vcl setvelocity [0,0,0];
_vcl setpos _pos;
sleep 1;
_vcl setvelocity [0,0,0];
hint "respawn vehicle";
sleep 1;
};
sleep 2;
};
[/QUOTE]
Hi,
I think I've got it but I just have one small question... http://forums.bistudio.com/oldsmileys/biggrin_o.gif
I've exported my mission but I cant find it in the mulitplayer/host section.
I copied it to my mpmissions folder in my docs and the C:\ but it still doesnt show.
I renamed it earlier which may have caused a problem. http://forums.bistudio.com/oldsmileys/huh.gif
Should I change it back?
EDIT*
Nevamind, I have found that it is just in the mydocs/username/mission folder. (I had multiple versions saved all over)
Altho I found my map is not called what it is supposed to be called. Which is the best way to save and change name?
Rename it in the folder first and then in the editor?
I have a question about these respawn scripts.
I am using a veh respawn script but then I'm also using triggers that prevent non-pilots from piloting aircraft. The problem is that my triggers require me to name each separate aircraft. This all works fine until the first aircraft is destroyed-- when it respawns it seems to have lost its 'name' and thus anyone can fly it now, not just pilots.
How have some of you worked around this? Maybe I need a script for the pilot restrictions instead of triggers? Thanks.
Here some updated code for the VRS_AI.sqf. The changes will allow you to specify the vehicle empty respawn and vehicle destroyed respawn delays for each vehicle you place on the map.
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">
//BEGIN vrs_AI.sqf
//Original script by KaRRiLLioN modified by norrin for AI units March 2007
//IMPORTANT: ADD A GAMELOGIC NAMED Server
//to the mission to prevent multispawn
//to run this script place the following code in the init line of the vehicle:
// v = [this, x, y] execVM "vrs_AI.sqf"
//where x and y are the times you wish to set for the vehicle empty respawn delay and vehicle destroyed respawn delay
private ["_vcl","_respawndelay","_vclemptydelay","_dir","_pos","_type","_unit","_run","_wait","_delay"];
if (!local Server) exitWith {};
_vcl = _this select 0;
_vclemptydelay = _this select 1;
_respawndelay = _this select 2;
_dir = Getdir _vcl;
_pos = Getpos _vcl;
_type = typeOf _vcl;
_unit = driver _vcl;
_run = TRUE;
sleep 5;
for [{}, {_run}, {_run}] do
{
while {_vcl distance _pos < 5 && canMove _vcl} do
{
sleep 1;
};
while {canMove _vcl && count crew _vcl > 0 && ({damage _x}forEach crew _vcl)!= 1} do
{
_wait = Time + _vclemptydelay;
sleep 1;
};
while {canMove _vcl && count crew _vcl < 1 && Time < _wait} do
{
sleep 1;
};
while {canMove _vcl && {damage _x} forEach crew _vcl >= 1 && Time < _wait} do
{
sleep 1;
};
_delay = Time + _respawndelay;
while {!canMove _vcl && Time < _delay} do
{
sleep 1;
};
if (count crew _vcl < 1) then
{
deleteVehicle _vcl;
_vcl = _type createVehicle _pos;
_vcl setdir _dir;
sleep 1;
_vcl setvelocity [0,0,0];
_vcl setpos _pos;
sleep 1;
_vcl setvelocity [0,0,0];
sleep 2;
};
if ({damage _x} forEach crew _vcl >= 1)then
{
deleteVehicle _vcl;
_vcl = _type createVehicle _pos;
_vcl setdir _dir;
sleep 1;
_vcl setvelocity [0,0,0];
_vcl setpos _pos;
sleep 1;
_vcl setvelocity [0,0,0];
sleep 1;
};
sleep 2;
};
[/QUOTE]
@<hidden>
You could try sending the name of the unit directly to the script. Using the latest version of the script, if the unit’s name was dog and you wanted both respawn delays set at 10 seconds then in the init line you’d put this:
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">v = [this, 10, 10, “dog”] execVM "vrs_AI.sqf"[/QUOTE]
Then in the script you’d have to add
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> _name_vcl = _this select 3;[/QUOTE] at the start of the script and
when the vehicle is created toward the end of the script you need to add this line directly after the createVehicle line (this happens twice so you need to add this new line after each instance of createVehicle)
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> _vcl setVehicleVarName _name_vcl; [/QUOTE].
If you run into any probs send me your file to norrins_nook@<hidden> and I’ll fix it up for you.
@<hidden>
A couple of ways you can do this but you’re best to rename it in the MPmissions directory, the new folder will appear next time you log into your local server. If you change the mission name in the editor it creates a new folder but none of the scripts and additional files are sent across to the new folder.
Just to protect my older working versions I find it best to copy the mission folder and then paste it back into the MPmissions directory and rename it and then restart my local server.
Thanks Norrin. Will doo!
Just one thing. I copied your script exactly and added the init lines to a couple vehicles I wanted to test the respawn on.
When I run the map in MP I get an error on the top left corner, similar to the one you listed earlier.
ydelay = 20; (couldnt read beginning, Fraps FPS in way)
_respawndelay = 10;
_dir = l#lGetdir _vcl;
_pos = Getpos _vcl;
_type = ...'
Error getdir: Type Array, expected object
File MPmissions\__cur_mp.Sara\vrs.sqf, line 18
Any idea what it means?? http://forums.bistudio.com/oldsmileys/confused_o.gif
satexas69
Mar 13 2007, 16:52
Matt & Guys,
Do you know of a version that gets around a problem with respawning AH1Z's and other Aircraft from being able to reload FFARs and HellFire's?
I'm using this script, and it's awesome for everything but that bug above...
Not sure who wrote it, but it's called vehirespawn.sql
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">
; Call in initline with (120 for 120 seconds, 2 minutes) :
;
; [this, 120] exec "vehirespawn.sqs"
;
; Note - This script needs a "GameLogic" trigger named "SERVER" or else spawning will be nuts
;
?! (local server): exit
~3
_vehicle = _this select 0
_delay = _this select 1
_empty = true
_disabled = false
_moved = false
_startpos = getpos _vehicle
_startdir = getdir _vehicle
_type = typeof _vehicle
#waiting
~2
_newpos = getpos _vehicle
?! (_newpos select 0 in _startpos) or not (_newpos select 1 in _startpos): _moved = true
?! (isnull driver _vehicle) or not (isnull gunner _vehicle) or not (isnull commander _vehicle): _empty = false
? (isnull driver _vehicle) and (isnull gunner _vehicle) and (isnull commander _vehicle): _empty = true
?! (canmove _vehicle) or (canfire _vehicle): _disabled = true
? (canmove _vehicle) and (canfire _vehicle): _disabled = false
? (_disabled) and (_empty): goto "spawn"
? (_moved) and (_empty): goto "spawn"
goto "waiting"
#spawn
~_delay
?! (isnull driver _vehicle) or not (isnull gunner _vehicle) or not(isnull commander _vehicle): _empty = false
?! (_empty): goto "waiting"
deletevehicle _vehicle
~0.5
_newveh = _type createvehicle _startpos
_newveh setpos _startpos
_newveh setdir _startdir
[_newveh, _delay] exec "vehirespawn.sqs"
exit
[/QUOTE]
Hey props to you satexas69!!!
I copied your script and its working shweet!
Although, I'm now in the same boat as you with regards to the re-arm of choppers.
I remember reading that it is a glitch but if you keep one hellfire left then it will reload all. (Just have to be mindfull not use ALL your ammo until a fix comes out)
Later* http://forums.bistudio.com/oldsmileys/goodnight.gif
@<hidden> MeNeZ sounds like you may have mixed the init line execution code and the scripts. With all the changes to this script its not surprising.
I'll make some download links for the various versions of the vrs_AI script with some explanatory notes on how to use each version later today.
@<hidden>, I think I've got a fix for your reload problem as I've done something similar for Wedge for the harriers over at OPFEC which you can read about here: http://www.ofpec.com/index.p....28849.0 (http://www.ofpec.com/index.php?option=com_smf&Itemid=36&topic=28849.0)
I just need to add some code to the vrs script which I'll do a bit later today.
satexas69
Apr 5 2007, 16:52
Karrillion & Matt -
We have a problem! http://forums.bistudio.com/oldsmileys/smile_o.gif
My script (posted 2-3 posts above) doesn't give the vehicle the same "name" as it had in the editor before it respawned....
... I need the respawn process to somehow include putting the unit's name BACK on the vehicle - is this possible?http://forums.bistudio.com/oldsmileys/huh.gif?
Why? Because I have a "pilot can only pilot choppers" situation - but if I put a few rockets into a chopper and respawn it, it loses it's name and thus allows ANYONE to pilot it... bad bad bad.
Help? http://forums.bistudio.com/oldsmileys/smile_o.gif
Came across this post while I was looking for something else and I don't know if you still want this but here's the most recent version of my vrs_AI script that sets the name of the respawning vehicle to the name given in the editor. It also allows you to specify the empty and destroyed respawn times for individual vehicles.
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> //BEGIN vrs_AI_general.sqf
//Script by norrin March 2007
//Based upon KaRRiLLioN's original vrs.sqf script modified for use with playable and non-playable AI units
//Contact me at [EMAIL=norrins_nook@<hidden>]norrins_nook@<hidden>[/EMAIL]
//IMPORTANT: ADD A GAMELOGIC NAMED Server
//to the mission to prevent multispawn
//to run this script place the following code in the init line of the vehicle:
// v = [this, "vehicle name", x, y] execVM "vrs_AI_general.sqf"
//where x and y are the times you wish to set for the vehicle empty respawn delay and vehicle destroyed respawn delay
//Note: the vehicle name must be in quotation marks eg. if vehicle name Hmm1 it must appear in the init line as "Hmm1"
private ["_vcl","_respawndelay","_vclemptydelay","_dir","_pos","_type","_unit","_run","_wait","_delay"];
if (!local Server) exitWith {};
_vcl = _this select 0;
_name_vcl = _this select 1;
_vclemptydelay = _this select 2;
_respawndelay = _this select 3;
_dir = Getdir _vcl;
_pos = Getpos _vcl;
_type = typeOf _vcl;
_run = TRUE;
sleep 5;
for [{}, {_run}, {_run}] do
{
while {_vcl distance _pos < 5 && canMove _vcl} do
{
sleep 1;
};
while {canMove _vcl && count crew _vcl > 0 && ({damage _x}forEach crew _vcl)!= 1} do
{
_wait = Time + _vclemptydelay;
sleep 1;
};
while {canMove _vcl && count crew _vcl < 1 && Time < _wait} do
{
sleep 1;
};
while {canMove _vcl && {damage _x} forEach crew _vcl >= 1 && Time < _wait} do
{
sleep 1;
};
_delay = Time + _respawndelay;
while {!canMove _vcl && Time < _delay} do
{
sleep 1;
};
if (count crew _vcl < 1) then
{
deleteVehicle _vcl;
_vcl = _type createVehicle _pos;
_vcl setVehicleVarName _name_vcl;
_vcl setdir _dir;
sleep 1;
_vcl setvelocity [0,0,0];
_vcl setpos _pos;
sleep 1;
_vcl setvelocity [0,0,0];
sleep 2;
};
if ({damage _x} forEach crew _vcl >= 1)then
{
deleteVehicle _vcl;
_vcl = _type createVehicle _pos;
_vcl setVehicleVarName _name_vcl;
_vcl setdir _dir;
sleep 1;
_vcl setvelocity [0,0,0];
_vcl setpos _pos;
sleep 1;
_vcl setvelocity [0,0,0];
sleep 1;
};
sleep 2;
};
[/QUOTE]
You can down load the script from here: http://home.iprimus.com.au/simonns....tro.rar (http://home.iprimus.com.au/simonnsl/norrinsArmA/vrs_AI_general.Intro.rar)
In the init line of the unit you'll need to put something like this
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> v = [this, "vehicle name", x, y] execVM "vrs_AI_general.sqf"[/QUOTE]
where the vehicle name is the name given in the editor in quotation marks (eg "Hummer1", "Chopper2" etc) and x is the respawn time for the vehicle when empty and y is the respawn time after it has been destroyed.
Don't forget to add a gamelogic called server to stop multiple vehicle respawning.
Got a request for this and I thought it may be of use to other mission makers. Here's a version of the vrs script that only respawns vehicles if they are destroyed or cannot move.
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">/*
VEHICLE RESPAWN SCRIPT SQF
Respawns vehicles when they are destroyed or cannot move
© May 2007 - norrin (norrins_nook@<hidden>), based upon KaRRiLLioN's original vrs.sqf script.
Version: 1.0
******************************************************************************************
*********************************
IMPORTANT: ADD A GAMELOGIC NAMED Server to the mission to prevent multispawn
To run this script place the following code in the init line of the vehicle:
v = [this, "vehicle name", x] execVM "vrs_AI_general.sqf"
where x is the time you wish to set for the vehicle destroyed respawn delay
Note: the vehicle name must be in quotation marks eg. if vehicle name's Hmm1 it must appear in the init line as "Hmm1"
******************************************************************************************
**********************************
Start vrs_AI_general.sqf
*/
private ["_vcl","_respawndelay","_dir","_pos","_type","_run","_delay"];
if (!local Server) exitWith {};
_vcl = _this select 0;
_name_vcl = _this select 1;
_respawndelay = _this select 2;
_dir = Getdir _vcl;
_pos = Getpos _vcl;
_type = typeOf _vcl;
_run = TRUE;
sleep 5;
for [{}, {_run}, {_run}] do
{
while {canMove _vcl} do
{
sleep 1;
_delay = Time + _respawndelay;
};
_delay = Time + _respawndelay;
while {!canMove _vcl && Time < _delay} do
{
sleep 1;
};
if (!canMove _vcl && Time >= _delay) then
{
deleteVehicle _vcl;
_vcl = _type createVehicle _pos;
_vcl setVehicleVarName _name_vcl;
_vcl setdir _dir;
sleep 1;
_vcl setvelocity [0,0,0];
_vcl setpos _pos;
sleep 1;
_vcl setvelocity [0,0,0];
sleep 2;
};
};[/QUOTE]
ArMoGaDoN
May 23 2007, 09:08
I found that the name of the vehicle must be set on each client separately for some weird reason, sure the respawn works as above for the Server, but when you use crew-check code then that must run local on each client. So to get the client the name I had to fudge some publicVariables from the Server to the clients: one boolean that flags the new respawn, one 'hold' boolean that queues requests, and one object-variable set as the newly spawned object.
The client catches the flag-event in a trigger and locally sets the new object as named correctly.
Only problem is that sometimes this script locks up and stops respawning after some time but I can't for the life of me work out where or why it locks...
To see the vRD and vCC respawn and crewcheck scripts in action take a look inside the AirCav Onslaught map.
Probably a messy way to do it, if anyone has a better solution that does everything required then please give us a hint or three.
Onslaught Maps - using vRD and vCC SQS files with trigger catch on clients (http://vzone.virgin.net/wws.warwolf/CO_56_AirCavOnslaught.zip)
x7treme2001
May 28 2007, 14:39
I am using Karillions script for Vehicle Respawn, the vrs.sqf one. And I can get the respawn to work only if there are AI's in the vehicle...I dont want them in the vehicle. Any thoughts on how i can fix this?
I just updated the biki for vehicleRespawn (http://community.bistudio.com/wiki/respawnVehicle)
x7treme2001
May 28 2007, 15:51
I am using Karillions script for Vehicle Respawn, the vrs.sqf one. And I can get the respawn to work only if there are AI's in the vehicle...I dont want them in the vehicle. Any thoughts on how i can fix this?
thegunnysgt
Jun 6 2007, 06:18
I'm using this script, and it's awesome for everything but that bug above...
Not sure who wrote it, but it's called vehirespawn.sql
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">
; Call in initline with (120 for 120 seconds, 2 minutes) :
;
; [this, 120] exec "vehirespawn.sqs"
;
; Note - This script needs a "GameLogic" trigger named "SERVER" or else spawning will be nuts
;
?! (local server): exit
~3
_vehicle = _this select 0
_delay = _this select 1
_empty = true
_disabled = false
_moved = false
_startpos = getpos _vehicle
_startdir = getdir _vehicle
_type = typeof _vehicle
#waiting
~2
_newpos = getpos _vehicle
?! (_newpos select 0 in _startpos) or not (_newpos select 1 in _startpos): _moved = true
?! (isnull driver _vehicle) or not (isnull gunner _vehicle) or not (isnull commander _vehicle): _empty = false
? (isnull driver _vehicle) and (isnull gunner _vehicle) and (isnull commander _vehicle): _empty = true
?! (canmove _vehicle) or (canfire _vehicle): _disabled = true
? (canmove _vehicle) and (canfire _vehicle): _disabled = false
? (_disabled) and (_empty): goto "spawn"
? (_moved) and (_empty): goto "spawn"
goto "waiting"
#spawn
~_delay
?! (isnull driver _vehicle) or not (isnull gunner _vehicle) or not(isnull commander _vehicle): _empty = false
?! (_empty): goto "waiting"
deletevehicle _vehicle
~0.5
_newveh = _type createvehicle _startpos
_newveh setpos _startpos
_newveh setdir _startdir
[_newveh, _delay] exec "vehirespawn.sqs"
exit
[/QUOTE]
Can anyone help me with this script, I don't want empty vehicles to respawn, I only want them to respawn when destroyed or anything other than empty. I know about Norrin's recent respawn where they don't respawn empty vehicles, but all my vehicles don't have names and those that do, I need to know that they will keep their names as given in the editor due to other scripts that refer to that vehicles name.
@<hidden>[WWS]WarWolf...
you could just alter norrins scripts where...
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_vcl setVehicleVarName _name_vcl;[/QUOTE]
would become...
<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_vcl setVehicleVarName _name_vcl;
call compile format["%1 = _vcl;", (vehicleVarName _vcl)];[/QUOTE]
Why you ask?
'cause it's not enough to just set the 'vehicle name' on new versions of any vehicle you create, you've got to equate the 'vehicle name' to the 'object' as well. (that is if you want respawned vehicles to be 'testable' on all machines and not just the server)
thegunnysgt
Jun 8 2007, 15:45
Quote[/b] ]
Can anyone help me with this script, I don't want empty vehicles to respawn, I only want them to respawn when destroyed or anything other than empty. I know about Norrin's recent respawn where they don't respawn empty vehicles, but all my vehicles don't have names and those that do, I need to know that they will keep their names as given in the editor due to other scripts that refer to that vehicles name.
Can anyone help. I only want them to respawn when destroyed. Not respawn when empty or damaged.
--UPDATE--
Got it to work.
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.