[Include] Get Nearest
#10

Change
pawn Code:
for(new i = 0; i < CountDynamicObjects(); i++)
to
pawn Code:
for(new i = 0,j = CountDynamicObjects(); ; i < j; i++)
This way you gain efficiency.

Variable names are very common
pawn Code:
new
        Float:px,
        Float:py,
        Float:pz,
        Float:ox,
        Float:oy,
        Float:oz,
        Float:distance = MAX_DISTANCE
;
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.



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)
        );
Why all this?
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);
It's not GetDynamicObjectPos.

In conclusion: You should look in to the functions, before releasing them. Try to study, look for better methods.
Cheers.
Reply


Messages In This Thread
Get Nearest - by T0pAz - 27.02.2012, 16:44
Re: Get Nearest - by tyler12 - 27.02.2012, 16:45
Re: Get Nearest - by Konstantinos - 27.02.2012, 16:46
Re: Get Nearest - by T0pAz - 27.02.2012, 16:48
Re: Get Nearest - by rati555 - 27.02.2012, 17:03
Re: Get Nearest - by TheArcher - 27.02.2012, 17:08
Re: Get Nearest - by T0pAz - 27.02.2012, 17:11
Re: Get Nearest - by asteroid - 27.02.2012, 17:13
AW: Get Nearest - by kvn - 27.02.2012, 17:16
Re: Get Nearest - by wups - 27.02.2012, 17:55
Re: Get Nearest - by ang12123 - 27.02.2012, 17:56
Re: Get Nearest - by Lorenc_ - 27.02.2012, 19:18
Re: Get Nearest - by T0pAz - 28.02.2012, 07:35
Re: Get Nearest - by Niko_boy - 28.02.2012, 07:38
Respuesta: Get Nearest - by [Nikk] - 28.02.2012, 07:42
Re: Get Nearest - by Not Applicable - 28.02.2012, 07:56
Re: Get Nearest - by [HK]Ryder[AN] - 28.02.2012, 13:09
Re: Get Nearest - by wups - 28.02.2012, 14:40
Re: Get Nearest - by T0pAz - 28.02.2012, 14:53
Re: Get Nearest - by RyDeR` - 28.02.2012, 15:03
Re: Get Nearest - by T0pAz - 28.02.2012, 15:25
Re: Get Nearest - by wups - 28.02.2012, 16:40
Re: Get Nearest - by T0pAz - 28.02.2012, 16:54

Forum Jump:


Users browsing this thread: 1 Guest(s)