Jump to content
Blitzen88

Need Help with Deleting Empty Vehicles but Not Static Weapons

Recommended Posts

I know that this is a topic that has come up before but I can't find the solution that I'm looking for and, after trying for about an hour now, I cant figure it out on my own.

 

Im trying to create a script that will delete vehicles if:

 

  1. The crew is dead
  2. The vehicle is empty
  3. The vehicle is cannot move

 

I also need for the script to ignore static weapons since those will commonly be empty for long periods of time.

 

This is what I got:

/*==========================================================================================

* Delete Empty Vehicles WIP

* Call with: [] execVM "Scripts\AI_Test.sqf"

===========================================================================================*/

While {True} do {

_AllVehicles = Vehicles;

if { (not canMove _x) || (alive _x OR count crew _x isEqualTo 0) || (not _x isKindOf "staticWeapon")} then {

	deletevehicle _x;
	
	} foreach _AllVehicles;
	
Player SideChat "AI Vehicle Script Loaded";

sleep 600;

_AllVehicles = [];

};

I've never been good with decoding IF statements with multiple conditions.  Im also not sure I have the "alive crew" part right.

 

Can anyone please help me with this?  Any help would be much appreciated.

 

Thank you!

Share this post


Link to post
Share on other sites

 

I would write it like so:

While {True} do {

_AllVehicles = Vehicles;

// ForEach loop
{

if (not (_x isKindOf "staticWeapon") && (_x isKindOf "AllVehicles")) then
{
if ( (not canMove _x) || (not alive _x) || (({ alive _x } count (crew _x)) isEqualTo 0) ) then {

deletevehicle _x;

};
};


} foreach _AllVehicles;
	
Player SideChat "AI Vehicle Script Loaded";

sleep 600;

_AllVehicles = []; // Looks pointless

};

Code not tested

Share this post


Link to post
Share on other sites
41 minutes ago, gc8 said:

 

Code not tested

Thank you for your help

 

That produces an error message:

 

if { (not canMove _x) || (not alive _x) || (count crew _x isEqualTo 0) } then {

#if { (not canMove _x) || (not alive _x) || (count crew _x isEqualTo 0) } then {

Error If: Type code, Expected Bool

 

I have no clue what the issue is.

Share this post


Link to post
Share on other sites
3 minutes ago, Blitzen88 said:

Thank you for your help

 

That produces an error message:

 

if { (not canMove _x) || (not alive _x) || (count crew _x isEqualTo 0) } then {


#if { (not canMove _x) || (not alive _x) || (count crew _x isEqualTo 0) } then {

Error If: Type code, Expected Bool

 

I have no clue what the issue is.

 

I updated the code, try again

Share this post


Link to post
Share on other sites
8 minutes ago, gc8 said:

 

I updated the code, try again

 

I tested the updated code and it does not produce any errors.  However, it might not be deleting vehicles when the crew is dead.  I added "this setdamage 1" to all of the crew members of a vehicle and then ran the script.  That particular vehicle was not deleted.  Is this type of scenario different from AI being killed in battle?

Share this post


Link to post
Share on other sites
6 minutes ago, Blitzen88 said:

 

I tested the updated code and it does not produce any errors.  However, it might not be deleting vehicles when the crew is dead.  I added "this setdamage 1" to all of the crew members of a vehicle and then ran the script.  That particular vehicle was not deleted.  Is this type of scenario different from AI being killed in battle?

 

I Updated the code again. It now checks for alive crew count, not the dead

Share this post


Link to post
Share on other sites
8 minutes ago, gc8 said:

 

I Updated the code again.

 

This runs perfectly! Thank you so much for your help!!!

  • Like 1

Share this post


Link to post
Share on other sites
3 hours ago, gc8 said:

 

I Updated the code again. It now checks for alive crew count, not the dead

 

After playing with the script for awhile, I think its a little too broad: it currently deletes ammo boxes and I'm assuming it will also delete mines.  Is there a way to add those into the initial "check" along with staticweapons? IE:

 

if (not (_x isKindOf "staticWeapon"))  &&  (not (_x isKindOf "Reammobox_F")) &&  (not (_x isKindOf "MineGeneric")) then {

Thank you again for your help

Share this post


Link to post
Share on other sites
12 hours ago, Blitzen88 said:

 

After playing with the script for awhile, I think its a little too broad: it currently deletes ammo boxes and I'm assuming it will also delete mines.  Is there a way to add those into the initial "check" along with staticweapons? IE:

 


if (not (_x isKindOf "staticWeapon"))  &&  (not (_x isKindOf "Reammobox_F")) &&  (not (_x isKindOf "MineGeneric")) then {

Thank you again for your help

 

My bad, I didn't take that into account. Code updated , hope it works now

Share this post


Link to post
Share on other sites
4 hours ago, gc8 said:

 

My bad, I didn't take that into account. Code updated , hope it works now

 

Thanks for updating it!  I tried that out and it gives an error.  Here is what I have:

_AllVehicles = Vehicles;

{

if (not (_x isKindOf "staticWeapon"))  &&  (not (_x isKindOf "Reammobox_F")) &&  (not (_x isKindOf "MineGeneric")) then 

{

	
if ( (not canMove _x) || (not alive _x) || (({ alive _x } count (crew _x)) isEqualTo 0) ) then {

{deletevehicle _X} foreach crew _x; deletevehicle _x;

	};
};


} foreach _AllVehicles;

The error it gives is this:

 

if (not (_x isKindOf "staticWeapon"))  &&  #(not (_x isKindOf "Reammobox_F")) &&  (not (_x isKindOf "MineGeneric")) then 

Type If, Expected Bool

 

Share this post


Link to post
Share on other sites
1 minute ago, Blitzen88 said:

Thanks for updating it!  I tried that out and it gives an error.  Here is what I have:

 

But that's your code, not mine. Did you try my code?

Share this post


Link to post
Share on other sites
9 minutes ago, gc8 said:

 

But that's your code, not mine. Did you try my code?

Sorry, Im an idiot and got confused about what to use.  This is what I just tried and it worked:

 

While {True} do {

_AllVehicles = Vehicles;

// ForEach loop
{

if (not (_x isKindOf "staticWeapon") && (_x isKindOf "AllVehicles")) then
{
if ( (not canMove _x) || (not alive _x) || (({ alive _x } count (crew _x)) isEqualTo 0) ) then {

deletevehicle _x;

};
};


} foreach _AllVehicles;
	
Player SideChat "AI Vehicle Script Loaded";

sleep 600;

_AllVehicles = []; // Looks pointless

};

This now accounts for ammoboxes but I dont think it accounts for mines? Also, why does it work like:  (_x iskindof "AllVehicles")) and not _AllVehicles?  I assumed "AllVehicles" is not a type of cfg "parent" class like "staticweapons" etc are...?

Share this post


Link to post
Share on other sites
Just now, Blitzen88 said:

This now accounts for ammoboxes but I dont think it accounts for mines?

 

Should work with both, if not let me know

 

1 minute ago, Blitzen88 said:

Also, why does it work like:  (_x iskindof "AllVehicles")) and not _AllVehicles?

 

They are actually entirely different things. Just similar wording. "AllVehicles" is parent config class for all "real" vehicles 

Share this post


Link to post
Share on other sites
12 minutes ago, gc8 said:

 

Should work with both, if not let me know

 

 I tried it out and it works...Im still trying to wrap my head around why/how it works 😆

 

Thank you for your help!

Share this post


Link to post
Share on other sites
On 4/22/2020 at 5:29 PM, gc8 said:

 

I would write it like so:


While {True} do {

_AllVehicles = Vehicles;

// ForEach loop
{

if (not (_x isKindOf "staticWeapon") && (_x isKindOf "AllVehicles")) then
{
if ( (not canMove _x) || (not alive _x) || (({ alive _x } count (crew _x)) isEqualTo 0) ) then {

deletevehicle _x;

};
};


} foreach _AllVehicles;
	
Player SideChat "AI Vehicle Script Loaded";

sleep 600;

_AllVehicles = []; // Looks pointless

};

Code not tested

 

 

Good day ! Can you please modify your script so it works in 2 cycles - in first cycle in should destroy empty vehicle and in second it should delete wrecks after some time.

I need this for vehicle spawner modules, if vehicle is just deleted it will not spawn again, but if vehicle is destroyed first then it works normal.

It will be great if the script can warn the players that after 30-60 seconds the empty vehicles will explode so that the players can hide or occupy it.

It will be even better if it can work with blacklisted areas so that players can have empty vehicles in the bases.

 

I am sure this script will be useful to many other players. Thanks in advance and Happy New Year !

Share this post


Link to post
Share on other sites
9 hours ago, Alith Evo said:

in first cycle in should destroy empty vehicle and in second it should delete wrecks after some time.

 

isn't there already a wreck removal feature in 3den performance menu?

Share this post


Link to post
Share on other sites
17 minutes ago, gc8 said:

 

isn't there already a wreck removal feature in 3den performance menu?

 

I am sorry, it is my mistake that I did not notice this earlier.

I use HAL commander mod in combination with vehicle spawner module. The problem with spawner modules, that it will not spawn a new group until the vehicle is destroyed, even if all the crew is dead. A script that destroys all empty vehicles every 10-15 minutes can fix this problem.

 

 

 

Share this post


Link to post
Share on other sites
40 minutes ago, Alith Evo said:

A script that destroys all empty vehicles every 10-15 minutes can fix this problem.

 

isn't that what my script does?

Share this post


Link to post
Share on other sites
6 minutes ago, gc8 said:

 

isn't that what my script does?

 

I think your script just deletes the empties, what he wants is for them to be destroyed first, then deleted. Apparently the mod he's using requires vehicles to be actually destroyed to be respawned.

Share this post


Link to post
Share on other sites
11 minutes ago, Harzach said:

 

 

I think your script just deletes the empties, what he wants is for them to be destroyed first, then deleted. Apparently the mod he's using requires vehicles to be actually destroyed to be respawned.

 

Humm, wouldn't switching from deletevehicle _x; to _x setDamage 1; work then? I have difficulty to understand the respawn logic 😄

 

Share this post


Link to post
Share on other sites
12 hours ago, gc8 said:

 

Humm, wouldn't switching from deletevehicle _x; to _x setDamage 1; work then? I have difficulty to understand the respawn logic 😄

 

 

I'm sorry again. I just know very little about scripts. I switched to "_x setDamage 1;", now works well and this is almost exactly what I need.

How can I prevent this script from destroying empty vehicles on player bases, maybe by adding a marker or trigger that the script will ignore ?

Share this post


Link to post
Share on other sites
4 hours ago, Alith Evo said:

 

I'm sorry again. I just know very little about scripts. I switched to "_x setDamage 1;", now works well and this is almost exactly what I need.

How can I prevent this script from destroying empty vehicles on player bases, maybe by adding a marker or trigger that the script will ignore ?

 

I haven't played much with triggers but I think inArea allows you to check if the vehicle is inside a trigger.

 

So the code would be like:

 

 

While {True} do {

_AllVehicles = Vehicles;

// ForEach loop
{

if (not (_x isKindOf "staticWeapon") && (_x isKindOf "AllVehicles")) then
{
if ( ((not canMove _x) || (({ alive _x } count (crew _x)) isEqualTo 0)) && !(_x inArea baseTrigger) ) then {

_x setDamage 1;

};
};


} foreach _AllVehicles;
	
Player SideChat "AI Vehicle Script Loaded";

sleep 600;

};

 

Where baseTrigger is the name of the trigger

  • Like 1

Share this post


Link to post
Share on other sites
19 minutes ago, gc8 said:

 

I haven't played much with triggers but I think inArea allows you to check if the vehicle is inside a trigger.

 

So the code would be like:

 

 


While {True} do {

_AllVehicles = Vehicles;

// ForEach loop
{

if (not (_x isKindOf "staticWeapon") && (_x isKindOf "AllVehicles")) then
{
if ( (not canMove _x) || (not alive _x) || (({ alive _x } count (crew _x)) isEqualTo 0) && !(_x inArea baseTrigger) ) then {

_x setDamage 1;

};
};


} foreach _AllVehicles;
	
Player SideChat "AI Vehicle Script Loaded";

sleep 600;

};

 

Where baseTrigger is the name of the trigger

 

Amazing ! You are my savior, thank you very much, this is exactly what I was looking for !

  • Like 1

Share this post


Link to post
Share on other sites

actually there was a small glitch with the brackets so I updated the code so that the condition works better with none moving vehicles (They get destroyed too)

  • Like 1

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

×