deleting all entites (non player) in radius makes game quit/error out
-
This code:
void DeleteAllNearby() { Entity[] NearbyEntities = World.GetNearbyEntities(player.Position, 25f); foreach(var e in NearbyEntities) { if (e != player.AttachedEntity && e != player) { e.Delete(); } } }
Removes all nearby things and then makes the game crash after a few seconds. If I add a conditional to make sure it's of type Ped or Vehicle, it seems to work. Any ideas on why this is, or what the undeletable entities are?
-
Not sure what else is in your script but is there a reason you're not calling it in a "private void OnTick(object sender, EventArgs e) {}"?
Something like:
namespace deleteNearbyEntities { public class Main : Script { public Main() { Tick += OnTick; } private void OnTick(object sender, EventArgs e) { Entity[] NearbyEntities = World.GetNearbyEntities(player.Position, 25f); foreach(var e in NearbyEntities) { if (e != player.AttachedEntity && e != player) { e.Delete(); } } } }
Could also try something like NearbyEntities = null; just after the delete syntax (from what I assume would clear out the array with each tick). I'm no scripting buff but from what I've been tinkering with thats what seems to be going on? Someone else might be able to chime in if they know better.