I want to add variable respawn times, depending on vehicle complexity, but hit a wall.
Although I've just started on this, I'm a bit unsure on how to solve it. Back in Dominatrix for Arma1 this was easy since each vehicle ran its own respawn script. Now "all" vehicles are handled by a central script. For land vehicles, I'm in init.sqf assigning a third array element (delay) that is sent to x_vrespawn2.sqf. This is stored on the vehicle as a variable, varying from 30 seconds from the sniper teams ATV to 300 seconds to the CSW/SF teams Stryker MC.
If I add variable sleeps in the main loop, the effect will be additive (the 30 second ATV respawn might have to wait for the 300 second Stryker MC respawn first), which I don't want. So I've tried spawning the creation process and added the delay there. For this I've made d_vec_array a global parameter.
x_server\x_respawn2.sqf at this point:
Code:
// by Xeno
#include "x_setup.sqf"
#define __Trans(tkind) _trans = getNumber(configFile >> #CfgVehicles >> typeOf _vehicle >> #tkind)
private ["_vehicle", "_camotype", "_camo", "_i", "_disabled", "_trans", "_empty", "_outb", "_hasbox"];
if (!isServer) exitWith{};
d_vec_array = [];
{
_vehicle = _x select 0;
_number_v = _x select 1;
_respawntimer = _x select 2;
d_vec_array set [count d_vec_array, [_vehicle,_number_v,position _vehicle,direction _vehicle,typeOf _vehicle,_respawntimer]];
_vehicle setVariable ["D_OUT_OF_SPACE", -1];
_vehicle setVariable ["d_vec", _number_v, true];
_vehicle setVariable ["d_respawntimer",_respawntimer];
_vehicle setAmmoCargo 0;
_vehicle setVariable ["d_vec_islocked", if (locked _vehicle) then {true} else {false}];
clearMagazineCargo _vehicle;
clearWeaponCargo _vehicle;
_kind = typeOf _vehicle;
switch (_kind) do {
case "HMMWV_Ambulance_DES_EP1": {_vehicle setVehicleInit "xxx = [this] execVM ""bat\Refill_MHQ.sqf"""; processInitCommands;};
case "HMMWV_Terminal_EP1": {_vehicle setVehicleInit "xxx = [this] execVM ""bat\Refill_MHQ.sqf"""; processInitCommands;};
case "MtvrRefuel_DES_EP1": {_vehicle setVehicleInit "xxx = [this] execVM ""bat\Refill_TruckAmmo.sqf"""; processInitCommands;};
case "MtvrRepair_DES_EP1": {_vehicle setVehicleInit "xxx = [this] execVM ""bat\Refill_TruckAmmo.sqf"""; processInitCommands;};
case "MtvrReammo_DES_EP1": {_vehicle setVehicleInit "xxx = [this] execVM ""bat\Refill_TruckAmmo.sqf"""; processInitCommands;};
case "MTVR_DES_EP1": {_vehicle setVehicleInit "xxx = [this] execVM ""bat\Refill_TruckSquad.sqf"""; processInitCommands;};
case "MtvrSupply_DES_EP1": {_vehicle setVehicleInit "xxx = [this] execVM ""bat\Refill_TruckEng.sqf"""; processInitCommands;};
case "M1129_MC_EP1": {_vehicle setVehicleInit "this addEventHandler [""fired"",{_this + [nearestObject [_this select 0,_this select 4]] spawn DOM_EH_Fired}]"; processInitCommands;}; //TODO: Change to precompiled spawn in due time.
};
#ifdef __TT__
if (_number_v < 100) then {
_vehicle addeventhandler ["killed", {_this call x_checkveckillwest}];
} else {
_vehicle addeventhandler ["killed", {_this call x_checkveckilleast}];
};
#endif
if (_number_v < 10 || (_number_v > 99 && _number_v < 110)) then {
_vehicle addeventhandler ["killed", {(_this select 0) setVariable ["D_MHQ_Deployed",false,true]}];
};
#ifndef __CARRIER__
_camotype = switch (getNumber (configFile >> "CfgVehicles" >> typeOf _vehicle >> "side")) do {
case 1: {if (__OAVer) then {"Land_CamoNetB_NATO_EP1"} else {"Land_CamoNetB_NATO"}};
case 0: {if (__OAVer) then {"Land_CamoNetB_EAST_EP1"} else {"Land_CamoNetB_EAST"}};
};
// _camo = createVehicle [_camotype, position _vehicle, [], 0, "NONE"];
// _camo setPos position _vehicle;
// _camo setDir (direction _vehicle) + 180;
// _vehicle setVariable ["d_camonet", _camo];
#endif
} forEach _this;
_this = nil;
sleep 65;
while {true} do {
sleep 8 + random 5;
__MPCheck;
__DEBUG_NET("x_vrespawn2.sqf",(call XPlayersNumber))
for "_i" from 0 to (count d_vec_array - 1) do {
_d_vec_a = d_vec_array select _i;
_vehicle = _d_vec_a select 0;
_disabled = false;
if (damage _vehicle > 0.9) then {
_disabled = true;
} else {
__Trans(transportAmmo);
if (_trans > 0) then {
_vehicle setAmmoCargo 1;
#ifdef __MANDO__
_msl = _vehicle getVariable "mando_source_level";
if (isNil "_msl") then {_msl = 0};
if (_msl < 20) then {
_vehicle setVariable ["mando_source_level", 100];
["d_man_r", _vehicle] call XNetCallEvent;
};
#endif
};
__Trans(transportRepair);
if (_trans > 0) then {
_vehicle setRepairCargo 1;
};
__Trans(transportFuel);
if (_trans > 0) then {
_vehicle setFuelCargo 1;
};
};
_empty = _vehicle call XfGetVehicleEmpty;
if (_empty && !_disabled && alive _vehicle && (_vehicle call XOutOfBounds)) then {
_outb = _vehicle getVariable "D_OUT_OF_SPACE";
if (_outb != -1) then {
if (time > _outb) then {_disabled = true};
} else {
_vehicle setVariable ["D_OUT_OF_SPACE", time + 600];
};
} else {
_vehicle setVariable ["D_OUT_OF_SPACE", -1];
};
sleep 0.01;
#ifdef __ACE__
_aliveve = if (!isNil {_vehicle getVariable "ace_canmove"}) then {_vehicle call ace_v_alive} else {alive _vehicle};
#else
_aliveve = alive _vehicle;
#endif
if ((_disabled && _empty) || (_empty && !_aliveve)) then {
_number_v = _d_vec_a select 1;
_hasbox = [_vehicle, "d_ammobox", false] call XfGetVar;
if (_hasbox) then {["ammo_boxes",__XJIPGetVar(ammo_boxes) - 1] call XNetSetJIP};
_respawntimer = _vehicle getVariable "d_respawntimer";
if (_number_v < 10 || (_number_v > 99 && _number_v < 110)) then {
_dhqcamo = [_vehicle, "D_MHQ_Camo", objNull] call XfGetVar;
if (!isNull _dhqcamo) then {deleteVehicle _dhqcamo};
};
#ifndef __CARRIER__
_camo = _vehicle getVariable "d_camonet";
if (!isNil "_camo") then {deleteVehicle _camo;_camo = objNull} else {_camo = objNull};
#endif
_isitlocked = _vehicle getVariable "d_vec_islocked";
sleep 0.1;
deletevehicle _vehicle;
sleep 0.5;
[_vehicle,_d_vec_a,_number_v,/*d_vec_array,*/_respawntimer,_isitlocked,_i] spawn {
_vehicle = _this select 0;
_d_vec_a = _this select 1;
_number_v = _this select 2;
// d_vec_array = _this select 3;
_respawntimer = _this select 3;
_isitlocked = _this select 4;
_i = _this select 5;
["d_v_rs",[0,[(_d_vec_a select 4),0] call XfGetDisplayName,_respawntimer/60]] call XNetCallEvent;
_vehicle = objNull;
sleep _respawntimer;
_vehicle = createVehicle [(_d_vec_a select 4), (_d_vec_a select 2), [], 0, "NONE"];
#ifndef __CARRIER__
_vehicle setpos (_d_vec_a select 2);
#else
if (_number_v > 9) then {
_vehicle setPos (_d_vec_a select 3);
} else {
_vehicle setPosASL [(_d_vec_a select 2) select 0, (_d_vec_a select 2) select 1, 15.9];
};
#endif
_vehicle setdir (_d_vec_a select 3);
if (_number_v < 10 || (_number_v > 99 && _number_v < 110)) then {
_vehicle addeventhandler ["killed", {(_this select 0) setVariable ["D_MHQ_Deployed",false,true]}];
};
_d_vec_a set [0, _vehicle];
d_vec_array set [_i, _d_vec_a];
_vehicle setVariable ["D_OUT_OF_SPACE", -1];
_vehicle setVariable ["d_vec", _number_v, true];
_vehicle setVariable ["d_respawntimer", _respawntimer];
_vehicle setAmmoCargo 0;
clearMagazineCargo _vehicle;
clearWeaponCargo _vehicle;
_vehicle setVariable ["d_vec_islocked", _isitlocked];
if (_isitlocked) then {_vehicle lock true};
["d_n_v", _vehicle] call XNetCallEvent;
["d_v_rs",[1,[typeOf _vehicle,0] call XfGetDisplayName,(round(_respawntimer * (call XPlayersNumber) / 600)) max 1]] call XNetCallEvent;
#ifdef __TT__
if (_number_v < 100) then {
_vehicle addeventhandler ["killed", {_this call x_checkveckillwest}];
} else {
_vehicle addeventhandler ["killed", {_this call x_checkveckilleast}];
};
#endif
#ifndef __CARRIER__
/*
if (isNull _camo) then {
_camotype = switch (getNumber (configFile >> "CfgVehicles" >> typeOf _vehicle >> "side")) do {
case 1: {if (__OAVer) then {"Land_CamoNetB_NATO_EP1"} else {"Land_CamoNetB_NATO"}};
case 0: {if (__OAVer) then {"Land_CamoNetB_EAST_EP1"} else {"Land_CamoNetB_EAST"}};
};
_camo = createVehicle [_camotype, position _vehicle, [], 0, "NONE"];
_camo setPos position _vehicle;
_camo setDir (direction _vehicle) + 180;
_vehicle setVariable ["d_camonet", _camo];
};
*/
#endif
_kind = typeOf _vehicle;
switch (_kind) do {
case "HMMWV_Ambulance_DES_EP1": {_vehicle setVehicleInit "xxx = [this] execVM ""bat\Refill_MHQ.sqf"""; processInitCommands;};
case "HMMWV_Terminal_EP1": {_vehicle setVehicleInit "xxx = [this] execVM ""bat\Refill_MHQ.sqf"""; processInitCommands;};
case "MtvrRefuel_DES_EP1": {_vehicle setVehicleInit "xxx = [this] execVM ""bat\Refill_TruckAmmo.sqf"""; processInitCommands;};
case "MtvrRepair_DES_EP1": {_vehicle setVehicleInit "xxx = [this] execVM ""bat\Refill_TruckAmmo.sqf"""; processInitCommands;};
case "MtvrReammo_DES_EP1": {_vehicle setVehicleInit "xxx = [this] execVM ""bat\Refill_TruckAmmo.sqf"""; processInitCommands;};
case "MTVR_DES_EP1": {_vehicle setVehicleInit "xxx = [this] execVM ""bat\Refill_TruckSquad.sqf"""; processInitCommands;};
case "MtvrSupply_DES_EP1": {_vehicle setVehicleInit "xxx = [this] execVM ""bat\Refill_TruckEng.sqf"""; processInitCommands;};
case "M1129_MC_EP1": {_vehicle setVehicleInit "this addEventHandler [""fired"",{_this + [nearestObject [_this select 0,_this select 4]] spawn DOM_EH_Fired}]"; processInitCommands;};
};
};
};
sleep 8 + random 5;
};
};
Relevant part of init.sqf:
Code:
// editor varname, unique number
//0-9 = MHQ, 10-19 = Medic vehicles, 20-29 = Fuel, Repair, Reammo trucks, 30-39 = Engineer Salvage trucks, 40-49 = Transport trucks
[
[xvec1,0,60],[xvec7,1,60],
[xmedvec,10,240],
[xvec3,20,120],[xvec4,21,120],[xvec5,22,120],
[xvec6,30,180],
[xvec9,40,60],[xvec10,41,30],[xvec11,42,90],[xvec12,43,90],[xvec2,44,300]
] execVM "x_server\x_vrespawn2.sqf";
And the text event, in x_client\x_setupplayer.sqf:
Code:
[2, "d_v_rs", { //short for d_vehicle_respawn
switch (_this select 0) do {
case 0: {format ["A %1 has been destroyed. A new one will be delivered at base in about %2 minutes.", _this select 1, _this select 2] call XfHQChat};
case 1: {format ["A %1 has been delivered to your base. Keep this one alive! NIP worth %2 points.", _this select 1, _this select 2] call XfHQChat}; //NIP - Not Implemented Punishment :p
}
}] call XNetAddEvent;
I'm aware that new "d_v_rs" should probably be merged with "d_n_v", and that my processInitCommands should probably be executed there (in another way) instead, but I just want to keep things simple for now.
Problem: Sometimes my NIP value comes up with scalar, and when that happens I get respawn message even if the vehicle was already respawned. Seems to me the main loop sees the destroyed vehicle and spawns yet another process.
Question: How do I prevent this from taking place?

Originally Posted by
Sisko!
Why don't people like Team V Team Domination?
Whats wrong with people?
I enjoy coop. I can't stand PvP where most players tweak the settings to be most efficient instead of giving them the most immersion. So when I go for immersion, that is obviously going to put me in a disadvantage and get me killed.
I guess that's what's wrong with me...
Seeing zach72's post... Am I the only one going for less conveniences? The game mode is already far too convenient already. Why don't we just give everyone a nuke? That way we don't have to do anything at all and just watch the fireworks. Yikes...