27.02.2012, 17:55
Change
to
This way you gain efficiency.
Variable names are very common
You should consider something less common, and use them locally. You don't need them global.
+ distance is global. Let's say I call GetClosest(playerid,OBJECT) and it is 2.0 units away. Okay, the next time I call the function, it won't check for anything further than 2.0 units! Test your code next time.
Why all this?
It's not GetDynamicObjectPos.
In conclusion: You should look in to the functions, before releasing them. Try to study, look for better methods.
Cheers.
pawn Code:
for(new i = 0; i < CountDynamicObjects(); i++)
pawn Code:
for(new i = 0,j = CountDynamicObjects(); ; i < j; i++)
Variable names are very common
pawn Code:
new
Float:px,
Float:py,
Float:pz,
Float:ox,
Float:oy,
Float:oz,
Float:distance = MAX_DISTANCE
;
+ distance is global. Let's say I call GetClosest(playerid,OBJECT) and it is 2.0 units away. Okay, the next time I call the function, it won't check for anything further than 2.0 units! Test your code next time.
pawn Code:
new Float:odist = floatsqroot(
floatpower(floatabs(floatsub(ox, px)), 2.0) +
floatpower(floatabs(floatsub(oy, py)), 2.0) +
floatpower(floatabs(floatsub(oz, pz)), 2.0)
);
pawn Code:
dist = GetPlayerDistanceFromPoint(playerid,x,y,z);
pawn Code:
stock GetNearest_Object(playerid)
{
new currentobject = -1;
GetPlayerPos(playerid, px, py, pz);
for(new i = 0; i < MAX_OBJECTS; i++)
{
if(!IsValidObject(i)) continue;
GetDynamicObjectPos(i, ox, oy, oz);
In conclusion: You should look in to the functions, before releasing them. Try to study, look for better methods.
Cheers.

