SA-MP Forums Archive
Checking if Object is at the given position - 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: Checking if Object is at the given position (/showthread.php?tid=73217)



Checking if Object is at the given position - Robbin237 - 13.04.2009

I have those 2 commands

pawn Код:
dcmd_actest(playerid, params[])
{
    #pragma unused playerid
    #pragma unused params
    test = CreateObject(16442, -1194.8014, -1061.5055, 129.2188, 0, 0, 90);
}

dcmd_actest1(playerid, params[])
{
    #pragma unused playerid
    #pragma unused params
    MoveObject(test, -1191.5671, -954.3043, 129.2119, 2.0);
}
Now how can i check if the object test is at ? I know to use a timer and GetObjectPos, but how to format it.. (if its at the coordinates -1194.8014, -1061.5055, 129.2188 then do something")

Can somebody help me?

Thnx


Re: Checking if Object is at the given position - ICECOLDKILLAK8 - 13.04.2009

Modify a version of PlayerToPoint, Maybe like this?
pawn Код:
public ObjectToPoint(Float:radi, objectid, Float:x, Float:y, Float:z)
{
  if(IsValidObject(objectid))
  {
    new Float:oldposx, Float:oldposy, Float:oldposz;
    new Float:tempposx, Float:tempposy, Float:tempposz;
    GetObjectPos(objectid, oldposx, oldposy, oldposz);
    tempposx = (oldposx -x);
    tempposy = (oldposy -y);
    tempposz = (oldposz -z);
    if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
    {
      return 1;
    }
  }
  return 0;
}



Re: Checking if Object is at the given position - Robbin237 - 13.04.2009

Could you give an example of how to use this?


Re: Checking if Object is at the given position - ICECOLDKILLAK8 - 13.04.2009

Check my last post


Re: Checking if Object is at the given position - Robbin237 - 13.04.2009

But the thing is, im moving the object to the coordinates -1191.5671, -954.3043, 129.2119 and then i want it to do something, thats done with ObjectToPoint?


Re: Checking if Object is at the given position - ICECOLDKILLAK8 - 13.04.2009

Say if you wanted to check of the object is near 5.98, 6.78, 0.91, If it is then move the object else do nothing, You would do
pawn Код:
if(ObjectToPoint(2, objectid, 5.98, 6.78, 0.91))
{
  // MoveObject
}
else
{
  // It isnt near that point
}