SA-MP Forums Archive
Object id - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Object id (/showthread.php?tid=261943)



Object id - bartje01 - 15.06.2011

How to get the nearest object and how to do like :

If(IsPlayerInRangeOfPoint(playerid,nearestobject,4 .0))

?


Thanks


Re: Object id - bartje01 - 15.06.2011

Editted. Can someone help me with this?


Re: Object id - bartje01 - 16.06.2011

Someone? PLease help


Re: Object id - Jeffry - 16.06.2011

Hi.

Try something like this:

pawn Код:
new Float:lowestdis = 1000000.0;
new nearID = -1;
for(new i=0; i<MAX_OBJECTS; i++)
{
    new Float:x, Float:y, Float:z;
    GetObjectPos(i, x, y, z);
    new Float:px, Float:py, Float:pz;
    GetPlayerPos(playerid, px, py, pz);
    new Float:dis=floatsqroot( ( (x-px)*(x-px) ) + ( (y*(y-py) ) + ( (z-pz)*(z-pz) ) );
    if(dis < lowestdis)
    {
        lowestdis = dis;
        nearID = i;
    }
}
if(IsPlayerInRangeOfPoint(playerid,nearID,4 .0))
{
    //do whatever you want here.
}
I hope it works. ^^
If you have any questions, feel free to ask.

Jeffry


Re: Object id - bartje01 - 16.06.2011

It's like giving many errors :P

pawn Код:
C:\Users\Bart\Desktop\SampScripting\filterscripts\bDrugs.pwn(136) : error 001: expected token: ",", but found ";"
C:\Users\Bart\Desktop\SampScripting\filterscripts\bDrugs.pwn(143) : error 001: expected token: ",", but found "."
C:\Users\Bart\Desktop\SampScripting\filterscripts\bDrugs.pwn(143) : error 029: invalid expression, assumed zero
C:\Users\Bart\Desktop\SampScripting\filterscripts\bDrugs.pwn(143) : warning 215: expression has no effect
C:\Users\Bart\Desktop\SampScripting\filterscripts\bDrugs.pwn(143) : error 001: expected token: ";", but found ")"
C:\Users\Bart\Desktop\SampScripting\filterscripts\bDrugs.pwn(143) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase


5 Errors.
Thanks btw


Re: Object id - Jeffry - 16.06.2011

Well, I thought the snippet you posted before was out of errors. ^^

Fixed this:

pawn Код:
new Float:lowestdis = 1000000.0;
    new nearID = -1;
    new Float:ox, Float:oy, Float:oz;
    for(new i=0; i<MAX_OBJECTS; i++)
    {
        new Float:x, Float:y, Float:z;
        GetObjectPos(i, x, y, z);
        new Float:px, Float:py, Float:pz;
        GetPlayerPos(playerid, px, py, pz);
        new Float:dis=floatsqroot( ( (x-px)*(x-px) ) + ( (y-py)*(y-py) ) + ( (z-pz)*(z-pz) ) );
        if(dis < lowestdis)
        {
            lowestdis = dis;
            nearID = i;
            ox=x;
            oy=y;
            oz=z;
        }
    }
    if(IsPlayerInRangeOfPoint(playerid, 4.0, ox, oy, oz))
    {
        printf("Object: %d  is nearest.", nearID);
        //do whatever you want here.
    }



Re: Object id - bartje01 - 16.06.2011

YEAS IT WORKS THANKYOU!!!!!!!!


One more question. How to check if the object is model 873?