Jump to content
Sign in to follow this  
dale0404

Vehicle respawn script

Recommended Posts

Gents I have tried everything, been on Ofpec, Armaholic, Armedassault.info and all the vehicle respawn scripts I try do not work in Arma2, can someone help me please!

What I am after is a simple script that respawns the vehicles back at their start positions after say 2 minutes.

Thanks in advance

Dale

Share this post


Link to post
Share on other sites

That would be helpful. I tried Mr. Murray's from arma1 and I could get it to delete but could not get it to respawn. The method I'm referring to is

"Beause the default variant doesn't offer many features, so I worked around a little bit with
that subject and recreated the following solution. The special thing is that this one doesn’t
need an entry in the Description.ext.
At first one needs place a vehicle on the map which is to be used for the vehicle respawn.
This vehicle has to be named Veh1 so it further needs a fixed respawn point which will
be represented by a game logic, named Veh1Pos. Now we have a vehicle with defined
spawn point. What we further need now is a checking trigger which is checking whether
the vehicle is still alive or not or has the ability to drive (depends on level of damage).
Each vehicle which shall be resapwnable receives it's own positions point (Logic) and
it's own checking trigger with the respective name of the vehicle.
Checking trigger (Vehicle guard)
Name: Veh1Guard
Condition: !Canmove Veh1
on Activation: [Veh1,"M1Abrams",Veh1Pos,360,2,10,1,0,0]
exec "vehicle-respawn.sqs"
Axis a/b: 0/0
Logic (Positions point)
Name: Veh1Pos"

Share this post


Link to post
Share on other sites

Really depends on what exactly you want that vehiclerespawnscript to do.

When should the respawn happen ? Only when the vehicle is destroyed ?

In this case, default command might be enough for you.

vehicle respawnVehicle [delay, count]

Share this post


Link to post
Share on other sites

If you know the exact location where you want to spawn them then you shall use a Killed eventHandler on the vehicles that you want to spawn back.

Init:

//adapt to your own path.
VehicleRespawn = Compile PreprocessFile "funcVehicleRespawn.sqf";

//modify the _vehicleRespawnLocation variable and the _vehicle one.
Call Compile Format ["_vehicle addEventHandler [""Killed"",{[_this select 0,%1]Spawn VehicleRespawn}];",_vehicleRespawnLocation];

funcVehicleRespawn.sqf:

_killed = _this select 0;
_pos = _this select 1;
_type = typeOf _killed;
_delay = 120;

sleep _delay;

_vehicle = _type createVehicle _pos;

//we handle the vehicle respawn after that the new vehicle is spawned.
Call Compile Format ["_vehicle addEventHandler [""Killed"",{[_this select 0,%1]Spawn VehicleRespawn}];",_pos];

Edited by Benny.

Share this post


Link to post
Share on other sites

I want the vehicles to respawn at the base if and when they get destroyed and I am sorry I dont undetstand the above code. :(

Share this post


Link to post
Share on other sites

Put this section of code in the Init.sqf:

//adapt to your own path.
VehicleRespawn = Compile PreprocessFile "funcVehicleRespawn.sqf";

//modify the _vehicleRespawnLocation variable and the _vehicle one.
Call Compile Format ["_vehicle addEventHandler [""Killed"",{[_this select 0,%1]Spawn VehicleRespawn}];",_vehicleRespawnLocation];

Copy this code into a text document and then name it

funcVehicleRespawn.sqf and then place it in your mission folder:

_killed = _this select 0;
_pos = _this select 1
_type = typeOf _killed;
_delay = 120;

sleep _delay;

_vehicle = _type createVehicle _pos;

//we handle the vehicle respawn after that the new vehicle is spawned.
Call Compile Format ["_vehicle addEventHandler [""Killed"",{[_this select 0,%1]Spawn VehicleRespawn}];",_pos];

Remember Dale you still need modify the _vehicleRespawnLocation variable and the _vehicle one in the init.sqf

P.S Awesome Benny, fixed a problem of mine aswell :) :yay::yay:

Share this post


Link to post
Share on other sites

Is there any chance you guys could use this in an example? e.g:

+Vehicle to respawn: Hind-D that's named chopper1

+Vehicle respawn location: a Helipad named Ch1

-Danke :D

Share this post


Link to post
Share on other sites

Forgot a few syntax errors there Jan. Also simplified the code a little bit.

vehicle Init Line

this addEventHandler ["Killed","[_this select 0, POSITION] spawn compile preprocessfile 'funcVehicleRespawn.sqf'"]

//Examples for variable "POSITION"
//getpos player - returns position of player
//getpos logic1 - returns position of unit named logic1 (ie a game logic placed at a respawn at base)
//getmarkerpos respawn_west - returns position of the marker named respawn_west
//getpos _this select 0 - returns its own position
//[0,0,0] - returns the position 0,0,0

funcVehicleRespawn.sqf

#define RESPAWN_DELAY 120 //in seconds

//DO NOT EDIT CODE BELOW THIS
_killed = _this select 0;
_pos = _this select 1;
_type = typeOf _killed;

sleep RESPAWN_DELAY;

_veh = _type createVehicle _pos;
_veh addeventhandler ["Killed",format["[_this select 0, %1]", _pos] + "spawn compile preprocessfile 'funcVehicleRespawn.sqf'"];

Edited by Rommel

Share this post


Link to post
Share on other sites
Forgot a few syntax errors there Jan. Also simplified the code a little bit.

vehicle Init Line

this addEventHandler ["Killed","[_this select 0, POSITION] spawn compile preprocessfile 'funcVehicleRespawn.sqf'"]

//Examples for variable "POSITION"
//getpos player - returns position of player
//getpos logic1 - returns position of unit named logic1 (ie a game logic placed at a respawn at base)
//getmarkerpos respawn_west - returns position of the marker named respawn_west
//getpos _this select 0 - returns its own position
//[0,0,0] - returns the position 0,0,0

funcVehicleRespawn.sqf

#define RESPAWN_DELAY 120 //in seconds

//DO NOT EDIT CODE BELOW THIS
_killed = _this select 0;
_pos = _this select 1;
_type = typeOf _killed;

sleep RESPAWN_DELAY;

_veh = _type createVehicle _pos;
_veh addeventhandler ["Killed",format["[_this select 0, %1]", _pos] + "spawn compile preprocessfile 'funcVehicleRespawn.sqf'"];

I don't understand, that code won't work at all. You're not grabbing the gamelogic marker positions in either of those code blocks, nor are you grabbing the name of the specified vehicle ON that gamelogic marker. Am i missing something, because your comments for the first code block don't match up with the code you wrote :confused:?

---------- Post added at 08:45 PM ---------- Previous post was at 08:21 PM ----------

Using the recently published domination's wreck chopper respawn script, I've reverse engineered my own vehicle respawn scipt out of that (woot thanks dude for the examples in your map!)

My problem now is, how do I get ANY aircraft/tank/truck etc etc's ID?

Example:

#ifdef __TT__

// chopper varname, type (0 = lift chopper, 1 = wreck lift chopper, 2 = normal chopper), marker name, placeholder for heli lift types

d_choppers_west = [["HR1",0,"chopper1"], ["HR2",0,"chopper2"], ["HR3",0,"chopper3"], ["HR4",1,"chopper4"]];

d_choppers_racs = [["HRR1",0,"chopperR1"], ["HRR2",0,"chopperR2"], ["HRR3",0,"chopperR3"], ["HRR4",1,"chopperR4"]];

#else

// chopper varname, type (0 = lift chopper, 1 = wreck lift chopper, 2 = normal chopper), marker name, placeholder for heli lift types

d_choppers = [["HH1",0,"choppa1"], ["HH2",0,"choppa2"], ["HH3",0,"choppa3"], ["HH4",0,"choppa4"], ["HH5",0,"choppa5"], ["HH6",0,"choppa6"], ["HH7",0,"choppa7"]];

#endif

The above code is assigning ANY chopper into said array of 0-6 a value based (for the else statement) on it's current name to a spawn location ("HH1" = a hind named chop1 on my map, and choppa1 being a simple marker)

Updated :)

Edited by =DraGa=

Share this post


Link to post
Share on other sites

Hello, just spotted this and realised I might be able to help!

I've been using KaRRiLLioN's wonderful vehicle respawning script for years and have found it to be the most elegant and easy-to-implement solution to use. I've just updated it to feature all the latest classnames to save everyone the pain!

Simply copy this code into a file called vrs.sqs and place it in your mission directory. In the init field for each vehicle you wish to respawn, place the line [this] exec "vrs.sqs"

Simple as that. Now when the vehicle is broken, it will respawn after a short period close to where it was originally placed. Tada!

;;BEGIN vrs.sqs
;;By KaRRiLLion
;;Modified by cragtek (2009) to function in ArmaII
;;
;;IMPORTANT: ADD A GAMELOGIC NAMED Server
;;to the mission to prevent multispawn

?!(local Server): Goto "end"
_vcl = _this select 0
_respawndelay = 5
_dir=Getdir _vcl
_position=Getpos _vcl
_Vehicles=[]

_aircraft=["A10","AH1Z","AV8B","AV8B2","BIS_Steerable_Parachute","C130J","Chukar","CruiseMissile1","CruiseMissile2","F35B","Ka52","Ka52Black","MH60S","MQ9PredatorB","MV22","Mi17_CDF","Mi17_Civilian","Mi17_Ins","Mi17_medevac_CDF","Mi17_medevac_Ins","Mi17_medevac_RU","Mi17_rockets_RU","Mi24_D","Mi24_P","Mi24_V","ParachuteBigEast","ParachuteBigWest","ParachuteC","ParachuteEast","ParachuteG","ParachuteMediumEast","ParachuteMediumWest","ParachuteWest","Pchela1T","Su25_CDF","Su25_Ins","Su34","Su39","UH1Y"]

_tracked=["2S6M_Tunguska","AAV","BMP2_Ambul_CDF","BMP2_Ambul_INS","BMP2_CDF","BMP2_Gue","BMP2_HQ_CDF","BMP2_HQ_INS","BMP2_INS","BMP3","M1A1","M1A2_TUSK_MG","MLRS","T34","T72_CDF","T72_Gue","T72_INS","T72_RU","T90","ZSU_CDF","ZSU_INS"]


_boats=["Fishing_Boat","PBX","RHIB","RHIB2Turret","SeaFox","Smallboat_1","Smallboat_2","Zodiac"]

_wheeled=["BRDM2_ATGM_CDF","BRDM2_ATGM_INS","BRDM2_CDF","BRDM2_Gue","BRDM2_HQ_Gue","BRDM2_INS","BTR90","BTR90_HQ","GAZ_Vodnik","GAZ_Vodnik_HMG","GAZ_Vodnik_MedEvac","GRAD_CDF","GRAD_INS","GRAD_RU","HMMWV","HMMWV_Ambulance","HMMWV_Armored","HMMWV_Avenger","HMMWV_M2","HMMWV_MK19","HMMWV_TOW","Ikarus","Kamaz","KamazOpen","KamazReammo","KamazRefuel","KamazRepair","LAV25","LAV25_HQ","Lada1","Lada2","LadaLM","M1030","MMT_Civ","MMT_USMC","MTVR","MtvrReammo","MtvrRefuel","MtvrRepair","Skoda","SkodaBlue","SkodaGreen","SkodaRed","TT650_Civ","TT650_Gue","TT650_Ins","TowingTractor","UAZ_AGS30_CDF","UAZ_AGS30_INS","UAZ_AGS30_RU","UAZ_CDF","UAZ_INS","UAZ_MG_CDF","UAZ_MG_INS","UAZ_RU","UAZ_SPG9_INS","UralCivil","UralCivil2","UralOpen_CDF","UralOpen_INS","UralReammo_CDF","UralReammo_INS","UralRefuel_CDF","UralRefuel_INS","UralRepair_CDF","UralRepair_INS","Ural_CDF","Ural_INS","Ural_ZU23_CDF","Ural_ZU23_Gue","Ural_ZU23_INS","V3S_Civ","V3S_Gue","VWGolf","car_hatchback","car_sedan","datsun1_civil_1_open","datsun1_civil_2_covered","datsun1_civil_3_open","hilux1_civil_1_open","hilux1_civil_2_covered","hilux1_civil_3_open","tractor"]

_Vehicles=_aircraft+_tracked+_boats+_wheeled

_i = 0
#Loop
? (_i > (Count _Vehicles)) : Goto "Skip"
_VehicleType = _Vehicles Select _i
_VehicleTypeDoesMatch = ((_VehicleType CountType _this) == 1)
? _VehicleTypeDoesMatch : _type = _VehicleType
? _VehicleTypeDoesMatch : Goto "Skip"
_i = _i + 1
Goto "Loop"

#Skip

#start
~1
@!(Canmove _vcl)
~_respawndelay
deleteVehicle _vcl
_vcl = _type createVehicle _position
_vcl setdir _dir

Goto "start"

#end
Exit
;;END vrs.sqs 

:)

Cragtek.

Edited by cragtek

Share this post


Link to post
Share on other sites
I don't understand, that code won't work at all. You're not grabbing the gamelogic marker positions in either of those code blocks, nor are you grabbing the name of the specified vehicle ON that gamelogic marker. Am i missing something, because your comments for the first code block don't match up with the code you wrote :confused:?

I've tested that code over and over; it works I assure you.

Game logic marker positions. This is not possible. You have either a game logic, or a marker, not both.

this addEventHandler ["Killed","[_this select 0, getpos player] spawn compile preprocessfile 'funcVehicleRespawn.sqf'"]

spawns at position of player

this addEventHandler ["Killed","[_this select 0, getpos logic1] spawn compile preprocessfile 'funcVehicleRespawn.sqf'"]

spawns position of unit named logic1 (ie a game logic placed at a respawn at base)

this addEventHandler ["Killed","[_this select 0, getmarkerpos respawn_west] spawn compile preprocessfile 'funcVehicleRespawn.sqf'"]

respawns at position of the marker named respawn_west

this addEventHandler ["Killed","[_this select 0, getpos _this select 0] spawn compile preprocessfile 'funcVehicleRespawn.sqf'"]

spawns at its own position

this addEventHandler ["Killed","[_this select 0, [0,0,0]] spawn compile preprocessfile 'funcVehicleRespawn.sqf'"]

spawns at the position 0,0,0

Is that more clear of how you should use it?

Share this post


Link to post
Share on other sites

Hey Rommel using that script now with the position variable set to "getpos _this select 0"

Please bare in mind that im new to this game series, and to creating missions in general, but

The issue I'm having is the Humvee still existing? and so a new one doesn't seem to appear. For example I laid down a sachel charge and blew it up, then after a while decided to lay another, but still it exists, though its wrecked? Should your script still respawn a Humvee in this case?

Share this post


Link to post
Share on other sites
Hey Rommel using that script now with the position variable set to "getpos _this select 0"

Please bare in mind that im new to this game series, and to creating missions in general, but

The issue I'm having is the Humvee still existing? and so a new one doesn't seem to appear. For example I laid down a sachel charge and blew it up, then after a while decided to lay another, but still it exists, though its wrecked? Should your script still respawn a Humvee in this case?

Yes.

I will upload my example mission later today if possible as it seems there's some issues with how people are piecing it together.

Share this post


Link to post
Share on other sites

Cragtek's script works good. Might need some tweaking for optimal performance, but hey.. It's easy and works really well!

Share this post


Link to post
Share on other sites

I just made a new script that will respawn any vehicle to it's original position (downloaded addons as well).

I think it does the same thing as what KaRRiLLioN's script does, but it is much shorter and works on any vehicle.

Also it's made in SQF.

Very easy to use, just run it from the INIT field of any vehicle.

You can find it here:

http://forums.bistudio.com/showthread.php?t=76445

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  

×