Jump to content
Sign in to follow this  
pd3

Looking for a very simple, single use check/delete script for empty vehicles

Recommended Posts

I found a script that I've been using for manual garbage collection of nearly everything from bodies, dead vehicles, weaponholders, smoke shells, etc.

However I need something simple that can check for an empty vehicle and delete it either from a radius around the player or within a trigger. I'm currently using a spawning system that supposedly has a garbage collection system that doesn't seem to be 100% effective. My solution for this was to package a script wherein I could activate it from a radio command and manually ensure certain things are removed to ensure optimal performance.

The only bit I haven't figured out how to include is uncrewed vehicles as there's no actual command iirc to check for a vehicle that is empty like there is an "alldead" command to check for both dead bodies and vehicles. It doesn't need to be fancy, nor run on a timer, I'm explicitly trying to avoid that, just something I can manually execute to shore up anything missed by the spawn system's existing garbage collector.

Any help in this matter would be greatly appreciated.


 

Share this post


Link to post
Share on other sites
{alive _x} count crew _vehicle < 1

That'll check if a vehicle has no one in it.  Basically crew will return an empty array if there's no crew.  The alive check is because apparently it takes forever to detect the dead in crew.

  • Like 1

Share this post


Link to post
Share on other sites

Thank you for the reply.

I was thinking of something that looks something like this, although this isn't specifically functional itself.

_vehicles = nearestObjects [player, ["landvehicle"], 14000]

 

if (count crew vehicle _x == 0) then deleteVehicle _x forEach _vehicles;

Would a concept like this be workable?
 

Share this post


Link to post
Share on other sites

Yes you can combine your code with Kylania's to get a check which you describe, like:

 

{
    if ({alive _x} count crew _x < 1) then {
        {
            deleteVehicle _x
        } count (crew _x);
        deleteVehicle _x
    }
} forEach (nearestObjects [player,["landvehicle"],14000])
 
Paste that in debug console and it should delete any vehicles with no alive people (and any corpses in them).
 
From a perf pov, you might want to use nearEntities rather than nearestObjects.
 
{
    if ({alive _x} count crew _x < 1) then {
        {
            deleteVehicle _x
        } count (crew _x);
        deleteVehicle _x
    }
} forEach (player nearEntities ["landvehicle",14000])
  • Like 1

Share this post


Link to post
Share on other sites

I'd also throw in a check if the vehicle has been assigned to a group and if none of them are alive.

I always hate it in MP sessions when you disembark for some recon only to find your vehicle disappeared after a few minutes.

 

Cheers

  • Like 1

Share this post


Link to post
Share on other sites

I'd also throw in a check if the vehicle has been assigned to a group and if none of them are alive.

I always hate it in MP sessions when you disembark for some recon only to find your vehicle disappeared after a few minutes.

 

Cheers

 

Bah, too much work.  Just delete all vehicles every 30 seconds to 5 minutes (random) regardless if they are manned, empty, ruined or actually in flight.   :d:

Share this post


Link to post
Share on other sites

Bah, too much work.  Just delete all vehicles every 30 seconds to 5 minutes (random) regardless if they are manned, empty, ruined or actually in flight.   :D:

I wish the script-supplied garbage collection was a bit more thorough for the dynamic spawn system I'm using, but it works pretty good all the same.

I just basically want a manual in-game "reset button" that can eliminate sources of performance decline (which does seem to inexplicably increase in spite of the included garbage collector) when you have numbers of groups spawning in and out, dying, abandoning vehicles - over time.

I'll definitely set about implementing the suggestions supplied and see how it works out.

Share this post


Link to post
Share on other sites

Have whatever method you're using for spawning track what it's created and when you need to clean up run through the lists of what it made and delete it all.

Share this post


Link to post
Share on other sites

Have whatever method you're using for spawning track what it's created and when you need to clean up run through the lists of what it made and delete it all.

I think one thing that might be screwing me over, which I hope my script might get rid of is the fact that I'm running the old script-based version of Dragonfyre (I know it's old, but I like it and I'm slow to accept change)

for some of the effects it creates a #particlesource object and then plays a sound.

I'm wondering if over time it just creates and does not delete a whole ton of these, which is why I included this into the array to potentially eliminate that possibility.

 

{ deleteVehicle _x; } forEach allDead;
{ deleteVehicle _x; } forEach nearestObjects [getpos player,["WeaponHolder","GroundWeaponHolder","WeaponHolderSimulated","SmokeShell","#destructioneffects","#particlesource"],14000]

Also I'm interested in what das attorney had mentioned about preferring nearEntities vs nearestObjects

I found this on the BI wiki

 

 

nearEntities vs nearestObjects

nearEntities is much faster than nearestObjects given on range and amount of object(s) which are within the given range.

If a range was set to more thean 100 meters it is highly recommend to use nearEntities instead of nearestObjects.

Note: nearEntities only searches for objects which are alive. Killed units, destroyed vehicles, static objects and buildings will be ignored by the nearEntities command.

So it seems that for deleting "dead" things nearestObjects is still necessary. Does anyone know which one should be used to get rid of #particlesource objects?

Also, I don't really know if I have the chops to go digging into somebody else's code and change it in such a fundamental manner, the included garbage collection system is already beyond what I'm capable of coding myself.  I was told however that certain aspects of the script compilation simply aren't up to date and don't work properly, what I'm doing is basically a stop-gap solution for the time being.

Share this post


Link to post
Share on other sites

Got a link to that script you're using?  Only Dragonfyre things I'm finding is a sound mod.

Share this post


Link to post
Share on other sites

Got a link to that script you're using?  Only Dragonfyre things I'm finding is a sound mod.

Yes, Dragonfyre is a sound mod, but it uses scripts in the earliest version. That was really only of peripheral interest, I'll have to do my own experiments to see if removing #particlesource objects helps any.

https://forums.bistudio.com/topic/155690-ai-spawn-script-pack/

Presently I'm only using the Ambient Combat set of scripts.

The thing is, I have encountered abandoned vehicles which should have been removed at some point if the integrated garbage removal script actually does so, it doesn't seem as if LV_fnc_ACcleanUp.sqf or LV_fnc_removeDead.sqf do so at least.

After a fairly long period of time of playing the mission does seem to start abnormally slowing down to a considerable degree, saving and loading after restarting does not seem to help, so I'm not sure it's memory related.

I suspect a lot of unculled objects are left after some time and it might help if they're deleted via script when performance starts to degrade.

{
    if ({alive _x} count crew _x < 1) then {
        {
            deleteVehicle _x
        } count (crew _x);
        deleteVehicle _x
    }
} forEach (player nearEntities ["landvehicle",14000])

This worked really well run from the debug console, thanks.

How would I do to get this to be executable via a script? 

 

Share this post


Link to post
Share on other sites

Seems that spawn script allows you to add a custom init field, so you could try something like:

cleanUp pushback _this;

Where you'd previously setup a cleanUp  = []; array, and then just cycle through that array for your completely random and rubbish* cleanup.

{
    if ({alive _x} count crew _x < 1) then {
        {
            deleteVehicle _x
        } count (crew _x);
        deleteVehicle _x
    }
    cleanUp deleteAt _forEachIndex;
} forEach cleanUp;

Untested as I'm away from the editor.

 

* See next post...  :unsure:

  • Like 2

Share this post


Link to post
Share on other sites

 

{
    if ({alive _x} count crew _x < 1) then {
        {
            deleteVehicle _x
        } count (crew _x);
        deleteVehicle _x
    }
    cleanUp deleteAt _forEachIndex;
} forEach cleanUp;

 

 

Hi,

 

Not to be rude or anything about your method, but I've always had problems when modifying the length of the array that I'm iterating through, so I normally set any element that I want to remove to some sort of rubbish (to preserve the length of the array) and then delete the rubbish after.  

 

Otherwise it's like you're literally munching through the array as you test it and the engine returns incorrect values for _forEachIndex because you diminish the available indices as you eat it all up with deleteAt while iterating through.

 

I just tested a variant of your code and for a random assortment of crewed vehicles & static weapons (the ones in the results with GROUP designations) and also some uncrewed vehicles & static weapons  (with .p3d in the object name), it deletes the wrong indexes and leaves something like:

21:55:25 O Alpha 1-3:2
21:55:25 O Alpha 2-3:6
21:55:25 O Alpha 2-3:8
21:55:25 O Alpha 2-3:10
21:55:25 O Alpha 2-3:12
21:55:25 O Alpha 2-3:14
21:55:25 893e1600# 168059: quadbike_01_f.p3d
21:55:25 5cb39600# 168117: truck_03_transport_f.p3d
21:55:25 8cc06b00# 165282: mbt_02_arty_f.p3d
21:55:25 8cc20100# 165283: mbt_02_arty_f.p3d
 
Whereas it should leave something like this:
 
21:57:34 O Alpha 1-3:1
21:57:34 O Alpha 2-3:5
21:57:34 O Alpha 2-3:6
21:57:34 O Alpha 2-3:7
21:57:34 O Alpha 2-3:8
21:57:34 O Alpha 2-3:9
21:57:34 O Alpha 2-3:10
21:57:34 O Alpha 2-3:11
21:57:34 O Alpha 2-3:12
21:57:34 O Alpha 2-3:13
21:57:34 O Alpha 2-3:14
21:57:34 O Alpha 2-3:15
21:57:34 O Alpha 2-3:16
21:57:34 O Alpha 2-3:17
21:57:34 O Alpha 2-3:18
 

 

Here's some sample code that should delete the right vehicles:

cleanup = player nearEntities ["landvehicle",14000];
{
    if ({alive _x} count crew _x < 1) then {
        cleanUp set [_forEachIndex,objNull];
        {
            deleteVehicle _x
        } count (crew _x);
        deleteVehicle _x
    };
    
} forEach cleanUp;
cleanup = cleanup - [objNull];


diag_log "--------";
{
    diag_log _x
} forEach cleanup;
  • Like 3

Share this post


Link to post
Share on other sites

it deletes the wrong indexes

 

Untested is my only excuse!  pd3 started it!  Wasn't me! *runs and hides*

  • Like 3

Share this post


Link to post
Share on other sites
Seems that spawn script allows you to add a custom init field, so you could try something like:
cleanUp pushback _this;

Where you'd previously setup a cleanUp  = []; array, and then just cycle through that array for your completely random and rubbish* cleanup.

When it comes to dealing with existing code, I'm not so inclined to get into territory I'm not familiar with, and one unfortunate problem for me that has always been an issue with myself and coding is appropriate syntax. Unless, I had access to previous examples of how to do that effectively, I'm inclined to avoid it.

The more abstract the issues with syntax becomes, the more I seem to fail at it. I'm not sure if that's what you're advocating, but I really just want something completely external to the existing spawn scripts (if possible) that I can use to get rid of unwanted objects in field manually. I just don't have enough confidence in my abilities to script to dig that far in without screwing the whole business up, I can decipher some code and script as long as it isn't exceedingly abstract and I can simply do the legwork and figure out what it all means. Syntax on the other hand is where I get hamstrung when writing it myself, and I know my limits.

With regard to this

 

cleanup = player nearEntities ["landvehicle",14000];
{
    if ({alive _x} count crew _x < 1) then {
        cleanUp set [_forEachIndex,objNull];
        {
            deleteVehicle _x
        } count (crew _x);
        deleteVehicle _x
    };
   
} forEach cleanUp;
cleanup = cleanup - [objNull];
diag_log "--------";
{
    diag_log _x
} forEach cleanup;

Especially the last few lines

Is this supposed to display a log or write to a file any details? I tried executing in the code in the debug console and once more in the small test-area I used, it seemed to work fine as well (it however did not display any additional info). Also, I still would like to be able to activate something like this via trigger and script ideally. It doesn't seem that's possible in its present form.

If I'm able to get everything set up as I would like I will continue testing the scenario I've created, as it stands I've basically created a few temporary test missions to see if the script works (which it does).

Share this post


Link to post
Share on other sites

The diag_log command writes to your RPT file, not the screen, which is why you wouldn't have seen anything.

 

This line was kind of neat, I hadn't realized it works this way:

cleanup = cleanup - [objNull];

array = array1 - array2 gives you array including only items that were in array1 and NOT in array 2.  I'd thought it would just delete one instance of [objNull] instead of all of them.

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  

×