Official Example Mission:
Note: ALiVE users need to select "Virtualize synced units only" in the ALiVE Virtual AI system module.
Official fn_vehRespawn.sqf
/* ----------------------------------------------------------------------------------------------------
File: fn_vehRespawn.sqf
Author: Iceman77
Description:
- Monitor a vehicle and "respawn" it if it's destroyed or abandoned
- Can be used on vehicles
- Set vehicle init upon respawn (optional)
- Store and keep the vehicle's variable name automatically
Parameter(s):
- _this select 0: < OBJECT > - VEHICLE
- _this select 1: < NUMBER > - ABANDONED DELAY IN SECONDS
- _this select 2: < NUMBER > - DESTROYED DELAY IN SECONDS
- _this select 3: < CODE > - FUNCTION THE VEHICLE CALLS UPON RESPAWN (OPTIONAL)
Usage (Vehicle init Line):
_nul = [ this, 120, 60, LVR_fnc_hunterInit ] spawn LVR_fnc_vehRespawn << have the vehicle call the custom LVR Function upon respawn
_nul = [this, 20, 10, {_this setVehicleAmmo 0; _this setDammage 0.5;}] spawn LVR_fnc_vehRespawn; << Run code directly on the vehicle when it respawns
_nul = [ this, 120, 60 ] spawn LVR_fnc_vehRespawn; << Default usage
---------------------------------------------------------------------------------------------------- */
// SERVER CODE
if ( ! ( isServer ) ) exitWith {};
// SET SCOPE OF LOCAL VARIABLES
private ["_veh","_abandonDelay","_destroyedDelay","_vehInit","_vehName","_vehDir","_vehPos","_vehtype","_abandoned","_dead"];
// PASSED ARGUMENTS ( OBJECT, ABANDONED DELAY, DESTROYED DELAY )
_veh = [_this, 0, objNull, [objNull]] call BIS_fnc_param;
_abandonDelay = [_this, 1, 60, [0]] call BIS_fnc_param;
_destroyedDelay = [_this, 2, 60, [0]] call BIS_fnc_param;
_vehInit = [_this, 3, {}, [{}] ] call BIS_fnc_param;
// STORE THE VEHICLES NAME, DIRECTION, POSITION AND TYPE
_vehName = vehicleVarName _veh;
_vehDir = getDir _veh;
_vehPos = getPos _veh;
_vehtype = typeOf _veh;
// START LOOP TO MONITOR THE VEHICLE
while { true } Do {
sleep 1;
// IF THE VEHICLE IS ALIVE AND CAN MOVE AND IS EMPTY THEN THE VEHICLE IS ABANDONED
if ( ( alive _veh ) && { ( canMove _veh ) && { { ( alive _x ) } count ( crew _veh ) == 0 } } ) then {
_abandoned = true;
// COUNTDOWN THE ABANDONED DELAY - STALL SCRIPT HERE
for "_i" from 0 to _abandonDelay do {
// IF THE VEHICLE ISN'T EMPTY, OR IS DESTROYED, OR IF IT CAN'T MOVE THEN IT'S NOT ABANDONED SO EXIT THE COUNTDOWN EARLY - CONTINUE THE SCRIPT
if ( { ( alive _x ) } count (crew _veh) > 0 || { !( alive _veh ) || { !( canMove _veh ) } } ) exitWith { _abandoned = false; };
sleep 1;
};
// IF THE VEHICLE IS ABANDONED AND ISN'T CLOSE TO IT'S STARTING POSITION THEN DELETE IT AND CREATE A NEW ONE AT THE STARTING POSITION
if ( ( _abandoned ) && { _veh distance _vehPos > 10 } ) then {
deleteVehicle _veh;
sleep 1;
_veh = createVehicle [ _vehtype, _vehPos, [], 0, "CAN_COLLIDE" ];
_veh setPos [ ( _vehPos select 0 ), ( _vehPos select 1 ), 0 ];
_veh setDir _vehDir;
_veh call _vehInit;
if (_vehName != "") then {
missionNamespace setVariable [_vehName, _veh];
publicVariable _vehName;
};
};
};
// IF THE VEHICLE IS DESTROYED OR IF IT CAN'T MOVE THEN ITS DEAD
if ( !( alive _veh ) || { !( canMove _veh ) } ) then {
_dead = true;
// COUNTDOWN THE DEAD DELAY - STALL SCRIPT HERE
for "_i" from 0 to _destroyedDelay do {
// IF THE VEHICLE ISN'T EMPTY, OR IF IT CAN MOVE ( HAS BEEN REPAIRED ) THEN IT'S NOT DEAD SO EXIT THE COUNTDOWN EARLY - CONTINUE THE SCRIPT
if ( { ( alive _x ) } count ( crew _veh ) > 0 || { ( canMove _veh ) } ) exitWith { _dead = false; };
sleep 1;
};
// IF THE VEHICLE IS DEAD THEN DELETE IT AND CREATE A NEW ONE AT THE STARTING POSITION
if ( _dead ) then {
deleteVehicle _veh;
sleep 1;
_veh = createVehicle [ _vehtype, _vehPos, [], 0, "CAN_COLLIDE" ];
_veh setPos [ ( _vehPos select 0 ), (_vehPos select 1 ), 0 ];
_veh setDir _vehDir;
_veh call _vehInit;
if (_vehName != "") then {
missionNamespace setVariable [_vehName, _veh];
publicVariable _vehName;
};
};
};
};
-------------------------------------------------------------- ALL CONTENT BELOW IS OPTIONAL ----------------------------------------------------------
Bonus LVR script (Not required)
For Dynamic Sector Control Vehicle Respawns
- Assign each vehicle to a sector
- Vehicles respawn into the appropriate vehicle type based on which side owns the sector that the vehicle belongs to.
- Think BF2 / BF3 vehicle respawn in conquest mode.
- I can provide an example mission if needed.
Installation & suggested usage:
-Installation is essentially the same as normal LVR. Place a vehicle, and the usage code into it's init line.
- Requires one empty marker per sector with the location's name as custom marker text. This is used to notify the players at which sector the vehicle has respawned,
via notification message. So.. if I've a sector deemed power plant, I would place one empty marker near that sector's center, with any variable name,
but with the text power plant.
Personal Suggestions:
-To be fair to all participants, the initial vehicle should be a civ vehicle. It can then respawn into a NATO/CSAT/INDEP vehicle (if applicable).
- Follow the comment's instructions carefully and see how to assign a vehicle to a sector and more.
- Keep it fair. Don't have an MRAP spawning for one side and an MBT for another. Take a look at the vehicle type array and the usage example in the comment.
Options:
- If you would like the vehicles to "refresh" even if they are at their initial spawn position (at the sector), remove && {(_veh distance _vehPos > 10)} from the _abandoned check. Otherwise, vehicle's that aren't damaged, and sitting at their initial spawn point, will not resapwn. Player's will need to A) Move the vehicle away or B) destroy the vehicle before a new one will respawn. It's really up to you. I personally like the distance check over the "refresh" option. Though the "refresh" option is nice too.
Notes:
-This version of LVR doesn't retain the vehicle's variable name. It doesn't support vehicle init respawn. It's essentially "old" style LVR, but converted for sectors.
description.ext
class CfgNotifications
{
class BCM_GENERIC_DEFAULT_MSG
{
color[] = {1,1,1,0.75};
colorIconPicture[] = {1,1,1,0.75};
colorIconText[] = {1,1,1,0.75};
title = "%1";
description = "%2";
iconPicture = "%3";
iconText = "%4";
duration = 7;
};
};
sector_fn_vehrespawn.sqf
/* ----------------------------------------------------------------------------------------------------
File: fn_vehRespawn.sqf
Author: Iceman77
Description:
- MODIFIED version of my LVR to accomodate dynamic vehicle spawning at sectors based on current owner's side
- Monitor a vehicle and "respawn" it if it's destroyed or abandoned
- Can be used on multiple vehicles
Parameter(s):
- _this select 0: < OBJECT > - VEHICLE TO MONITOR.
- _this select 1: < NUMBER > - ABANDONED DELAY IN SECONDS.
- _this select 2: < NUMBER > - DESTROYED DELAY IN SECONDS.
- _this select 3: < OBJECT > - SECTOR THE VEHICLE BELONGS TO.
- _this select 4: < ARRAY > - ARRAY OF STRINGS. VEHICLE CLASSNAMES. UPON REFRESH, ONE WILL BE CREATED BASED ON WHO OWNS THE SECTOR.
SELECT 0 - DEFAULT VEHICLE TYPE
SELECT 1 - OPFOR VEHICLE TYPE
SELECT 2 - BLUFOR VEHICLE TYPE
SELECT 3 - INDEPENDENT VEHICLE TYPE
e.g.:
["defaultVehicleClassName","bluforVehicleclassName","opforVehicleClassName","independentVehicleClassName"]
Usage Example (Vehicle init Line): _nul = [ this, 60, 60, sector1, [ typeOf this,"B_MRAP_01_hmg_F","O_MRAP_02_hmg_F","I_MRAP_03_hmg_F" ] ] spawn ICE_fnc_vehRespawn
---------------------------------------------------------------------------------------------------- */
if ( ! ( isServer ) ) exitWith {};
private ["_veh","_abandonDelay","_destroyedDelay","_sector","_vehArray","_defaultVehicle","_bluforVehicle","_opforVehicle","_independentVehicle","_vehDir","_vehPos","_vehType","_abandoned","_dead","_markerText","_displayName","_picture"];
_veh = [ _this, 0, objNull, [ objNull ] ] call BIS_fnc_param;
_abandonDelay = [ _this, 1, 60, [ 0 ] ] call BIS_fnc_param;
_destroyedDelay = [ _this, 2, 60, [ 0 ] ] call BIS_fnc_param;
_sector = [ _this, 3, objNull, [ objNull ] ] call BIS_fnc_param;
_vehArray = [ _this, 4, [ ], [ [ ] ] ] call BIS_fnc_param;
_defaultVehicle = ( _vehArray select 0 );
_bluforVehicle = ( _vehArray select 1 );
_opforVehicle = ( _vehArray select 2 );
_indepVehicle = ( _vehArray select 3 );
_vehDir = getDir _veh;
_vehPos = getPos _veh;
_abandoned = false;
_dead = false;
while { true } Do {
sleep 1;
if ( ( alive _veh ) && { ( canMove _veh ) && { { ( alive _x ) } count ( crew _veh ) == 0 } } ) then {
_abandoned = true;
for "_i" from 0 to _abandonDelay do {
if ( { ( alive _x ) } count (crew _veh) > 0 || { !( alive _veh ) || { !( canMove _veh ) } } ) exitWith {
_abandoned = false;
};
sleep 1;
};
if ( _abandoned && {(_veh distance _vehPos > 10)}) then {
deleteVehicle _veh;
_vehType = switch ( _sector getVariable "owner" ) do {
case West:{ _bluforVehicle; };
case East:{ _opforVehicle; };
case Independent:{ _indepVehicle; };
default { _defaultVehicle; };
};
sleep 1;
_veh = createVehicle [ _vehtype, _vehPos, [], 0, "CAN_COLLIDE" ];
_veh addEventHandler ["getIn","_null=call BCM_fnc_crewRestrictions"];
_veh setDir _vehDir;
_veh setPos [ ( _vehPos select 0 ), (_vehPos select 1 ), 0 ];
_displayName = getText (configFile >> "CfgVehicles" >> _vehType >> "displayName");
_picture = getText (configFile >> "CfgVehicles" >> _vehType >> "picture");
{
if ((markerPos _x) distance _sector < 25 && (markerType _x == "EMPTY")) then {
_markerText = markerText _x;
};
} forEach allMapMarkers;
[
[
"BCM_GENERIC_DEFAULT_MSG",
[
"Vehicle Respawn",
format ["A %1 has spawned at the %2", _displayName, _markertext],
_picture,
""
]
],
"BIS_fnc_showNotification",
_sector getVariable "owner"
] call BIS_fnc_MP;
};
};
if ( !( alive _veh ) || { !( canMove _veh ) } ) then {
_dead = true;
for "_i" from 0 to _destroyedDelay do {
if ( { ( alive _x ) } count ( crew _veh ) > 0 || { ( canMove _veh ) } ) exitWith { _dead = false; };
sleep 1;
};
if ( _dead ) then {
deleteVehicle _veh;
_vehType = switch ( _sector getVariable "owner" ) do {
case West:{ _bluforVehicle; };
case East:{ _opforVehicle; };
case Independent:{ _indepVehicle; };
default { _defaultVehicle; };
};
sleep 1;
_veh = createVehicle [ _vehtype, _vehPos, [], 0, "CAN_COLLIDE" ];
_veh addEventHandler ["getIn","_null=call BCM_fnc_crewRestrictions"];
_veh setDir _vehDir;
_veh setPos [ ( _vehPos select 0 ), (_vehPos select 1 ), 0 ];
_displayName = getText (configFile >> "CfgVehicles" >> _vehType >> "displayName");
_picture = getText (configFile >> "CfgVehicles" >> _vehType >> "picture");
{
if ((markerPos _x) distance _sector < 25 && (markerType _x == "EMPTY")) then {
_markerText = markerText _x;
};
} forEach allMapMarkers;
[
[
"BCM_GENERIC_DEFAULT_MSG",
[
"Vehicle Respawn",
format ["A %1 has spawned at the %2", _displayName, _markertext],
_picture,
""
]
],
"BIS_fnc_showNotification",
_sector getVariable "owner"
] call BIS_fnc_MP;
};
};
};
nil
-------------------------------------------------------------- Other projects related to LVR ----------------------------------------------------------
Not So Light Vehicle Respawn Framework ( BY LARROW )
- Tons of features