Jump to content
Sign in to follow this  
tophe

Simple Vehicle Respawn Script [Arma3]

Recommended Posts

well actually not, I was using a new downloaded script

sorry, which thread are you referring to? did you forgot to set the link?

regards

Memphis

this same thread, look here http://forums.bistudio.com/showthread.php?147890-Simple-Vehicle-Respawn-Script-Arma3/page5

i'd doubt it is the lastest version though if it contain a setVehicleInit.

double check this. If I find a link I'll edit my post

---------- Post added at 20:49 ---------- Previous post was at 20:22 ----------

By the way, I have a suggestion to modify the script. I did that on my server and always tought to share but never did.

It is the order in which we do process the _hasinit and _hasname. I reversed it, precessing the name before the init. I use the name in my init to prevent having the "this" issue. but in my mind it has to be processed before the init. Am I ok thinking this?

also, minor issue, but has this never iritated anyone else to see the compare > 0.8 and later < 0.8 so what if it is equal to 0.8 ? I know it is improbable but murphy's told... maybe my thinking is wrong, let me know if it's the case.

regards,

Holo

Share this post


Link to post
Share on other sites

I'm trying to find the most recent version of this script that works on the beta. Could someone point me in the right direction.

thx

Share this post


Link to post
Share on other sites

First post, just to be able to post links... in the next one you'll find a solution.

---------- Post added at 16:42 ---------- Previous post was at 16:42 ----------

I dont want to take any credit, cause all of this is based in others post/work.

Here you have a modified version of the sample mission posted by BearBison in his post that works in today's beta. I just fixed the problems in that one and I tested that vehicles are respawning correctly.

To find the new entity names that were problematic I used info from this other post.

I hope it helps.

Share this post


Link to post
Share on other sites

How would I go about adding multiple scripts after the vehicle is respawned? I followed the instructions on Page 3, but that only pertains to one script and with my code only the first script listed goes off (no errors anywhere, the second and third simply don't do anything.

nul = [this] execVM "ghostDoorsReset.sqf";  
nul = [this,"H5",0.5] execVM "mark_unit.sqf";  
nul = [this] execVM "basic.sqf"; 
veh = [this, 60, 300, 0, FALSE, FALSE, "nul = [this] execVM ""ghostDoorsReset.sqf"";","nul = [this,""H5"",0.5] execVM ""mark_unit.sqf"";","nul = [this] execVM ""basic.sqf"";"] execVM "vehicle.sqf";

In the short term I just have the ghostDoorsReset.sqf (remote open/close door toggle) pulling double duty by launching basic.sqf (chopper cargo loadout) as well, but I can't use it to run the mark_unit script since it's dependent on a marker variable that changes for each bird.

Share this post


Link to post
Share on other sites

Kahna -

See chesko's post above. The mission file he links to has an example of a complex init.

Share this post


Link to post
Share on other sites

Is there something wrong with this? I Can't get it to work with the Arma 3 beta.. It says something like "Missing ;" in line 116 or something. I havnet done anything with the script. Ideas?

Share this post


Link to post
Share on other sites
First post, just to be able to post links... in the next one you'll find a solution.

---------- Post added at 16:42 ---------- Previous post was at 16:42 ----------

I dont want to take any credit, cause all of this is based in others post/work.

Here you have a modified version of the sample mission posted by BearBison in his post that works in today's beta. I just fixed the problems in that one and I tested that vehicles are respawning correctly.

To find the new entity names that were problematic I used info from this other post.

I hope it helps.

If I use your whole mission it works but if I try using the scripts on my own mission the car will not respawn and it also appears the script never activates. This is so confusing. :confused:

Share this post


Link to post
Share on other sites
Is there something wrong with this? I Can't get it to work with the Arma 3 beta.. It says something like "Missing ;" in line 116 or something. I havnet done anything with the script. Ideas?
Same issue here. Does anyone have a working version of this script?

Again, see chesko's post for the updated script set and an example mission.

Share this post


Link to post
Share on other sites
How would I go about adding multiple scripts after the vehicle is respawned? I followed the instructions on Page 3, but that only pertains to one script and with my code only the first script listed goes off (no errors anywhere, the second and third simply don't do anything.

nul = [this] execVM "ghostDoorsReset.sqf";  
nul = [this,"H5",0.5] execVM "mark_unit.sqf";  
nul = [this] execVM "basic.sqf"; 
veh = [this, 60, 300, 0, FALSE, FALSE, "nul = [this] execVM ""ghostDoorsReset.sqf"";","nul = [this,""H5"",0.5] execVM ""mark_unit.sqf"";","nul = [this] execVM ""basic.sqf"";"] execVM "vehicle.sqf";

In the short term I just have the ghostDoorsReset.sqf (remote open/close door toggle) pulling double duty by launching basic.sqf (chopper cargo loadout) as well, but I can't use it to run the mark_unit script since it's dependent on a marker variable that changes for each bird.

Cant you do it like this?:

add to init -> veh = [this, 60, 300, 0, FALSE, FALSE, "nul = [this,"H5"] execVM 'link.sqf'"] execVM "vehicle.sqf";[/php]

create a sqf file.

link.sqf

[_this select 0] execVM "ghostDoorsReset.sqf";

[_this select 0,_this select 1,0.5] execVM "mark_unit.sqf";

[_this select 0] execVM "basic.sqf";

Share this post


Link to post
Share on other sites

Since Beta i could not get this script to work with errors on line 116

However with a little hunting i was able to find the fix

Old version

if (_haveinit) then

{_unit setVehicleInit format ["%1;", _unitinit];

processInitCommands;};

if (_hasname) then

{_unit setVehicleInit format ["%1 = this; this setVehicleVarName ""%1""",_unitname];

processInitCommands;};

_dead = false;

New version

if (_haveinit) then

{

_unit call compile format ["%1=_This; PublicVariable '%1'",_unitinit];

};

if (_hasname) then

{

_unit setVehicleVarName _unitname;

_unit call compile format ["%1=_This; PublicVariable '%1'",_unitname];

};

_dead = false;

Hope this helps a few people out

Regards

Tradari

Share this post


Link to post
Share on other sites

I made a fix for it I will copy and paste the entire fix down below... Works the exact same way as the reguler one just need to add the "veh = [this] execVM "vehicle.sqf" to every vehicle....

if (!isServer) exitWith {};

// Define variables

_unit = _this select 0;

_delay = if (count _this > 1) then {_this select 1} else {30};

_deserted = if (count _this > 2) then {_this select 2} else {120};

_respawns = if (count _this > 3) then {_this select 3} else {0};

_explode = if (count _this > 4) then {_this select 4} else {false};

_dynamic = if (count _this > 5) then {_this select 5} else {false};

_unitinit = if (count _this > 6) then {_this select 6} else {};

_haveinit = if (count _this > 6) then {true} else {false};

_hasname = false;

_unitname = vehicleVarName _unit;

if (isNil _unitname) then {_hasname = false;} else {_hasname = true;};

_noend = true;

_run = true;

_rounds = 0;

if (_delay < 0) then {_delay = 0};

if (_deserted < 0) then {_deserted = 0};

if (_respawns <= 0) then {_respawns= 0; _noend = true;};

if (_respawns > 0) then {_noend = false};

_dir = getDir _unit;

_position = getPosASL _unit;

_type = typeOf _unit;

_dead = false;

_nodelay = false;

// Start monitoring the vehicle

while {_run} do

{

sleep (2 + random 10);

if ((getDammage _unit > 0.8) and ({alive _x} count crew _unit == 0)) then {_dead = true};

// Check if the vehicle is deserted.

if (_deserted > 0) then

{

if ((getPosASL _unit distance _position > 10) and ({alive _x} count crew _unit == 0) and (getDammage _unit < 0.8)) then

{

_timeout = time + _deserted;

sleep 0.1;

waitUntil {_timeout < time or !alive _unit or {alive _x} count crew _unit > 0};

if ({alive _x} count crew _unit > 0) then {_dead = false};

if ({alive _x} count crew _unit == 0) then {_dead = true; _nodelay =true};

if !(alive _unit) then {_dead = true; _nodelay = false};

};

};

// Respawn vehicle

if (_dead) then

{

if (_nodelay) then {sleep 0.1; _nodelay = false;} else {sleep _delay;};

if (_dynamic) then {_position = getPosASL _unit; _dir = getDir _unit;};

if (_explode) then {_effect = "M_AT" createVehicle getPosASL _unit; _effect setPosASL getPosASL _unit;};

sleep 0.1;

deleteVehicle _unit;

sleep 2;

_unit = _type createVehicle _position;

_unit setPosASL _position;

_unit setDir _dir;

if (_haveinit) then

{

_unit call compile format ["%1=_This; PublicVariable '%1'",_unitinit];

};

if (_hasname) then

{

_unit setVehicleVarName _unitname;

_unit call compile format ["%1=_This; PublicVariable '%1'",_unitname];

};

_dead = false;

// Check respawn amount

if !(_noend) then {_rounds = _rounds + 1};

if ((_rounds == _respawns) and !(_noend)) then {_run = false;};

};

};

[php]

Edited by Darkangel

Share this post


Link to post
Share on other sites

^ try adding

 tags around your code it makes it easier to read and copy/paste without errors

ie:

[code]if (!isServer) exitWith {};

// Define variables
_unit = _this select 0;
_delay = if (count _this > 1) then {_this select 1} else {30};
_deserted = if (count _this > 2) then {_this select 2} else {120};
_respawns = if (count _this > 3) then {_this select 3} else {0};
_explode = if (count _this > 4) then {_this select 4} else {false};
_dynamic = if (count _this > 5) then {_this select 5} else {false};
_unitinit = if (count _this > 6) then {_this select 6} else {};
_haveinit = if (count _this > 6) then {true} else {false};

_hasname = false;
_unitname = vehicleVarName _unit;
if (isNil _unitname) then {_hasname = false;} else {_hasname = true;};
_noend = true;
_run = true;
_rounds = 0;

if (_delay < 0) then {_delay = 0};
if (_deserted < 0) then {_deserted = 0};
if (_respawns <= 0) then {_respawns= 0; _noend = true;};
if (_respawns > 0) then {_noend = false};

_dir = getDir _unit;
_position = getPosASL _unit;
_type = typeOf _unit;
_dead = false;
_nodelay = false;


// Start monitoring the vehicle
while {_run} do
{
sleep (2 + random 10);
if ((getDammage _unit > 0.8) and ({alive _x} count crew _unit == 0)) then {_dead = true};

// Check if the vehicle is deserted.
if (_deserted > 0) then
{
if ((getPosASL _unit distance _position > 10) and ({alive _x} count crew _unit == 0) and (getDammage _unit < 0.8)) then
{
_timeout = time + _deserted;
sleep 0.1;
waitUntil {_timeout < time or !alive _unit or {alive _x} count crew _unit > 0};
if ({alive _x} count crew _unit > 0) then {_dead = false};
if ({alive _x} count crew _unit == 0) then {_dead = true; _nodelay =true};
if !(alive _unit) then {_dead = true; _nodelay = false};
};
};

// Respawn vehicle
if (_dead) then
{
if (_nodelay) then {sleep 0.1; _nodelay = false;} else {sleep _delay;};
if (_dynamic) then {_position = getPosASL _unit; _dir = getDir _unit;};
if (_explode) then {_effect = "M_AT" createVehicle getPosASL _unit; _effect setPosASL getPosASL _unit;};
sleep 0.1;

deleteVehicle _unit;
sleep 2;
_unit = _type createVehicle _position;
_unit setPosASL _position;
_unit setDir _dir;

if (_haveinit) then
{
_unit call compile format ["%1=_This; PublicVariable '%1'",_unitinit];
};

if (_hasname) then
{
_unit setVehicleVarName _unitname;
_unit call compile format ["%1=_This; PublicVariable '%1'",_unitname];
};
_dead = false;

// Check respawn amount
if !(_noend) then {_rounds = _rounds + 1};
if ((_rounds == _respawns) and !(_noend)) then {_run = false;};
};
}; 

Share this post


Link to post
Share on other sites
^ try adding
 tags around your code it makes it easier to read and copy/paste without errors.. [/quote]


You Mean try adding [php] tags...

[php]if (!isServer) exitWith {};

// Define variables
_unit = _this select 0;
_delay = if (count _this > 1) then {_this select 1} else {30};
_deserted = if (count _this > 2) then {_this select 2} else {120};
_respawns = if (count _this > 3) then {_this select 3} else {0};
_explode = if (count _this > 4) then {_this select 4} else {false};
_dynamic = if (count _this > 5) then {_this select 5} else {false};
_unitinit = if (count _this > 6) then {_this select 6} else {};
_haveinit = if (count _this > 6) then {true} else {false};

_hasname = false;
_unitname = vehicleVarName _unit;
if (isNil _unitname) then {_hasname = false;} else {_hasname = true;};
_noend = true;
_run = true;
_rounds = 0;

if (_delay < 0) then {_delay = 0};
if (_deserted < 0) then {_deserted = 0};
if (_respawns <= 0) then {_respawns= 0; _noend = true;};
if (_respawns > 0) then {_noend = false};

_dir = getDir _unit;
_position = getPosASL _unit;
_type = typeOf _unit;
_dead = false;
_nodelay = false;


// Start monitoring the vehicle
while {_run} do
{
sleep (2 + random 10);
if ((getDammage _unit > 0.8) and ({alive _x} count crew _unit == 0)) then {_dead = true};

// Check if the vehicle is deserted.
if (_deserted > 0) then
{
if ((getPosASL _unit distance _position > 10) and ({alive _x} count crew _unit == 0) and (getDammage _unit < 0.8)) then
{
_timeout = time + _deserted;
sleep 0.1;
waitUntil {_timeout < time or !alive _unit or {alive _x} count crew _unit > 0};
if ({alive _x} count crew _unit > 0) then {_dead = false};
if ({alive _x} count crew _unit == 0) then {_dead = true; _nodelay =true};
if !(alive _unit) then {_dead = true; _nodelay = false};
};
};

// Respawn vehicle
if (_dead) then
{
if (_nodelay) then {sleep 0.1; _nodelay = false;} else {sleep _delay;};
if (_dynamic) then {_position = getPosASL _unit; _dir = getDir _unit;};
if (_explode) then {_effect = "M_AT" createVehicle getPosASL _unit; _effect setPosASL getPosASL _unit;};
sleep 0.1;

deleteVehicle _unit;
sleep 2;
_unit = _type createVehicle _position;
_unit setPosASL _position;
_unit setDir _dir;

if (_haveinit) then
{
_unit call compile format ["%1=_This; PublicVariable '%1'",_unitinit];
};

if (_hasname) then
{
_unit setVehicleVarName _unitname;
_unit call compile format ["%1=_This; PublicVariable '%1'",_unitname];
};
_dead = false;

// Check respawn amount
if !(_noend) then {_rounds = _rounds + 1};
if ((_rounds == _respawns) and !(_noend)) then {_run = false;};
};
}; [/php]

See... Much better!!

Share this post


Link to post
Share on other sites

is anyone having any problems getting the download from armaholic? every time i try to download it, it says access denied and you are not allowed to do this

Share this post


Link to post
Share on other sites

The author requested us to disable his downloadpage since the script is no longer working due to changes in the Arma 3 game. He first wants to fix it so to prevent people from downloading a non-working version.

Share this post


Link to post
Share on other sites
The author requested us to disable his downloadpage since the script is no longer working due to changes in the Arma 3 game. He first wants to fix it so to prevent people from downloading a non-working version.

Not that I'm in any position to complain about delayed freestuff but it has been down for quite a while now. Any word on when its back up?

Share this post


Link to post
Share on other sites
Not that I'm in any position to complain about delayed freestuff but it has been down for quite a while now. Any word on when its back up?

The same functionality has been added in game as a module now, tried that?

Share this post


Link to post
Share on other sites
The author requested us to disable his downloadpage since the script is no longer working due to changes in the Arma 3 game. He first wants to fix it so to prevent people from downloading a non-working version.

Thumbs up! :cool:

I respect this decision!

The same functionality has been added in game as a module now, tried that?

Havent tried that. Is there a proxi calculation? I dont want respawning vehicles, when the driver is near the vehicle.

Share this post


Link to post
Share on other sites

Havent tried that. Is there a proxi calculation? I dont want respawning vehicles, when the driver is near the vehicle.

I'm curious too about 'proximity calculation'... anyone using the module can tell us?

Share this post


Link to post
Share on other sites

Nope, no "you're only deserted if I'm more than x meters away from you" option. You'd just leave off the "deserted delay" field if you wanted that kind of functionality. Either it respawns when you leave it or you stop being lazy and recover vehicles.

Share this post


Link to post
Share on other sites

Yeah, sorry guys for pulling it down and thank you for understanding! The A2 version is still up, it works with A3 as well (not all functions though). I'll look into the module thingy and see if my script is at all needed or if I can streamline it a bit. Right now I'm caught up with concerts and work. But soon :-)

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  

×