If you want to find the closest object to a player, and destroy it, you would have to loop around all created objects, which is very resource unfriendly, the more objects you have.
An example:
pawn Код:
stock IsPlayerInRangeOfObject(playerid, objectid)
{
new
Float:ox, Float:oy, Float:oz;
GetObjectPos(objectid, ox, oy, oz);
if(IsPlayerInRangeOfPoint(playerid, YOUR_RANGE, ox, oy, oz)) return 1;
return 0;
}
stock IsPlayerInRangeOfAnyObject(playerid)
{
new
Float:ox, Float:oy, Float:oz, closest = -1;
for(new a = 0; a < MAX_OBJECTS; a++)
{
GetObjectPos(a, ox, oy, oz);
if(IsPlayerInRangeOfPoint(playerid, YOUR_RANGE, ox, oy, oz))
{
closest = a;
}
}
if(closest != -1) return closest;
return -1;
}
There's two example functions.
Now, I'd use the 2nd example, with a varible instead of 'MAX_OBJECTS', The reason being, MAX_OBJECTS would probably be made quite high, and in most cases, thousands more than how many objects you have.
When you load a object, you should increase a varible, for example 'ObjectCount' by one, then loop around ObjectCount, so that you only loop around created objects.
In the long run, this is more efficient than using a constant, due to it being more dynamic (eg, the value of ObjectCount will change when a object is deleted/created, and a constant like MAX_OBJECTS will have to be changed manualy or redefined)
pawn Код:
stock CreateObjectEx(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz)
{
new
Objectid = CreateObject(modelid, x, y, z, rx, ry, rz);
ObjectCount++;
return Objectid;
}
The above example should only be used in one file (for example a gamemode, due to varibles not being able to go across scripts)
The below example, which is untested, and in logic, probably pretty slow, due to varibles being faster than functions, and it sounds like you're making an object streamer, if that's the case, speed is needed.
pawn Код:
stock CreateObjectEx(modelid, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz)
{
new
Objectid = CreateObject(modelid, x, y, z, rx, ry, rz);
SetGVarInt("ObjectCount", GetGVarInt("ObjectCount") + 1, Objectid);
return Objectid;
}
GVar is a plugin by Icognito, it works like the PVar system, but is not bound to players, It's like a varible, but with an ID, you could say it's like an Array(?).
pawn Код:
SetGVarInt("Arr", 0, 0);
SetGVarInt("Arr", 1, 1);
SetGVarInt("Arr", 2, 2);
If you look at that, it looks like it works like an array, but I don't know, anyway, hope this helped.