Jump to content
Sign in to follow this  
ADuke

Destroy vehicle when empty

Recommended Posts

OK guys,

I searched for how to do this and found some handy bits of sqf script to use but am having trouble with this script I am writing, this is my first time writing a script from scratch so please excuse any obvious mistakes I am making.

I just want my script to monitor the vehicle that I am executing it on, and when the vehicle is empty (crew == 0). Then I want the vehicle to be destroyed.

Here is my script....

if (!isServer) exitWith {};

_vehicle = _this select 0;
_run = true;

while {_run} do
{
if (count crew _vehicle == 0) then {_vehicle setDamage 1};

and here is how I execute it on the vehicle...

nul = [this] execVM "destroy.sqf"

I appreciate any help you could give me.

-AD

Share this post


Link to post
Share on other sites
if (!isServer) exitWith {};

_vehicle = _this select 0;
_run = true;

while {_run} do
{
 if ((count (crew _vehicle)) == 0) then 
 {
   _vehicle setDamage 1;
   _run = false;
 };
};

Share this post


Link to post
Share on other sites
if (!isServer) exitWith {};

_vehicle = _this select 0;
_run = true;

while {_run} do
{
 if ((count (crew _vehicle)) == 0) then 
 {
   _vehicle setDamage 1;
   _run = false;
 };
};

Awesome, worked perfectly, thanks a lot :)

Share this post


Link to post
Share on other sites

Oh, it's recommended to add some sleeping in "while" loop, because currently it checks several times per second what is unnecesary heavy.

Better:

if (!isServer) exitWith {};

_vehicle = _this select 0;
_run = true;

while {_run} do
{
 if ((count (crew _vehicle)) == 0) then 
 {
   _vehicle setDamage 1;
   _run = false;
 };
 sleep 1;
};

Share this post


Link to post
Share on other sites

Thank you for that sleep suggestion, cuts down on the resources. How might I add an or statement in this script so that it also executes when either the driver or gunner are dead?

Thanks,

-AD

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  

×