Jump to content
ZU23

Deleting abandoned vehicle

Recommended Posts

Hi can someone explain why this script refuses to work, Im trying to make vehicles delete after player moves 25 meter+ away from it.

[]spawn {
while {true} do {
{
_vehicle = vehicle _x;
waitUntil {(isNull driver _vehicle isEqualTo false)};
_driver = driver _vehicle;
waitUntil {(count crew _vehicle == 0) AND (_driver distance _vehicle > 25)};
deleteVehicle _vehicle;
} forEach allUnits;
sleep 5;
};
};

 

Share this post


Link to post
Share on other sites

waitUntil {(isNull driver _vehicle isEqualTo false)};  ?? should return true anytime: (a unit is its own driver even on foot).

 

It's useless to check allUnits, and CPU consuming, if you play with a distance from the player.

You need to think about empty vehicles at start (which player hasn't been yet on board). The reason why, you should not script for the vehicle before the player "get in" the vehicle.
 

player addEventHandler ["getInMan",{
  params ["_plyr","","_veh"];
  [_plyr,_veh] spawn {
    params ["_plyr","_veh"];
    waitUntil {sleep 2; _veh != objectParent _plyr && _veh distance2D _plyr > 25};
    deleteVehicle _veh
  }
}];

 

You didn't mentioned several players. I understand you're in SP session. You can add an empty crew condition inside the waitUntil, of course.

 

    

 

  • Like 1

Share this post


Link to post
Share on other sites
2 hours ago, pierremgi said:

waitUntil {(isNull driver _vehicle isEqualTo false)};  ?? should return true anytime: (a unit is its own driver even on foot).

 

It's useless to check allUnits, and CPU consuming, if you play with a distance from the player.

You need to think about empty vehicles at start (which player hasn't been yet on board). The reason why, you should not script for the vehicle before the player "get in" the vehicle.
 


player addEventHandler ["getInMan",{
  params ["_plyr","","_veh"];
  [_plyr,_veh] spawn {
    params ["_plyr","_veh"];
    waitUntil {sleep 2; _veh != objectParent _plyr && _veh distance2D _plyr > 25};
    deleteVehicle _veh
  }
}];

 

You didn't mentioned several players. I understand you're in SP session. You can add an empty crew condition inside the waitUntil, of course.

 

    

 

Is there a way to make it work after player is dead inside the vehicle, doesnt seem to delete if player dies inside of it

 

EDIT: nvm got it working with this condition waitUntil {(alive _plyr isEqualTo false) OR (_plyr distance _veh > 25) AND ({alive _x} count (crew vehicle _veh) == 0)};

Share this post


Link to post
Share on other sites

@pierremgi How does this work in a MP dedicated environment? Will it stack a bunch of waitUntils/code if alot of players getin a vehicle? Or should we use a different approach for this in a dedicated?

initPlayerlocal.sqf

player addEventHandler ["getInMan",{
  params ["_plyr","","_veh"];
  [_plyr,_veh] spawn {
    params ["_plyr","_veh"];
    waitUntil {uiSleep 300; _veh != objectParent _plyr && _veh distance2D _plyr > 1000 &&  ((crew _veh) isequalto [])};
    deleteVehicle _veh
  }
}];

 

Share this post


Link to post
Share on other sites

initPlayerLocal.sqf is local,
"getInMan" EH is AG (argument global), so all the units, players on other PCs included can fire the EH (on the local PCs, so on all players' one in game).

The code will run everywhere locally, so you will deleteVehicle several times (that doesn't throw error)

 

You're checking every 5 minutes... That seems good for performance, but your condition is :

  _veh != objectParent _plyr && _veh distance2D _plyr > 1000 && ((crew _veh) isequalto [])

As you can see, there are some redundancies.

crew _veh isEqualTo [] sounds good.

_veh distance2D _plyr > 1000  can be fine for all players who jumped once into this vehicle. But you can have players who spectate the deletion (who never embarked into it).

 

Note: You could avoid multiple deletion by some extra condition like:

if (local _veh) then {deleteVehicle _veh}

local means that only the PC which own the vehicle (last player as driver) will delete it.

On the other hand, I can't say when an owned vehicle (by driving player) will be back in server. Probably if this last driver quit the game... I'm not sure it's the only case.

So, right now, your EH will not fire on dedicated server, for abandoned vehicle on server, if you have this local condition...

Perhaps, it's better to run the deletion on all played PCs, without consideration about who own the vehicle, never mind the multiple deletion.

 

Anyone has a better answer?

Share this post


Link to post
Share on other sites
On 1/13/2020 at 8:35 PM, pierremgi said:

I can't say when an owned vehicle (by driving player) will be back in server.

when owner disconnects, or some script moves it manually, or server owned AI drives vehicle.

 

Multiple deletion doesn't really cause an issue. what is an issue though is the condition.

 

On 1/13/2020 at 1:43 PM, Robustcolor said:

_veh != objectParent _plyr && _veh distance2D _plyr > 1000 && ((crew _veh) isequalto [])

that runs for every player. so.
This would fire, when out of 5 people vehicle crew, all get out and stand right around the vehicle, and a single player runs away. Even though they are standing right next to their vehicle, the one player that ran away will delete the vehicle.

Even with a local check, if the driver runs away, he might delete the vehicle while all others are guarding it.

 

Or a more realistic scenario, everyone gets out, and the driver gets shot and dies.
_plyr is now nullobj. nullobj != _veh, distance is 1e10, crew is empty. Boom, gone.

 

I would rather just collect a list of vehicles that were occupied by a player at one point (getIn EH and pushBackUnique, preferably on server only)

and every 300 seconds or so, iterate through them, check if they are empty, check if players in circle around it (inAreaArray), delete if neither.
Problem is, what if players walk away a kilometer, then come back to their vehicle and its gone now, even though they expected it not to be?

 

Other variant.

 

On getOut EH, check if vehicle is empty, if yes, add it and current time to a list.

When a player gets back in, remove from that list again.

 

Every 300 seconds check that list, sort by time and filter out the ones that have been abandoned for X seconds.

then maybe do the player nearby check, and delete.

Share this post


Link to post
Share on other sites

Yes, first of all, try to define what is an abandoned vehicle.

// empty ? yes, but not enough

// in sight of any player ?

// distance from any player ?

// for a certain duration ? ("during" is not the same as "since")

 

 

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

×