SA-MP Forums Archive
Command. Distance showing. - 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)
+--- Thread: Command. Distance showing. (/showthread.php?tid=612511)



Command. Distance showing. - ,TomY' - 18.07.2016

Hi all. I would like to know if is possible to do command which shows for player distance from object?

For example I have ocject:

Code:
  
new crateloc[30], string[128], rand = random(sizeof(g_CrateSpawns));

CrateObject = CreateDynamicObject(CRATE_MODEL_ID, g_CrateSpawns[rand][0], g_CrateSpawns[rand][1], g_CrateSpawns[rand][2]-0.4, -1, -1, -1); // Spawning the crate.
If it possible, how to do command for exaplme /whereobject and it will show for me distance from that object.


Re: Command. Distance showing. - Mister0 - 18.07.2016

HTML Code:
if(strcmp(cmdtext, "/distance", true) == 0)
    {
       new Float:X,Float:Y,Float:Z;
    GetObjectPos(CrateObject , X,Y,Z);
        new
        Float: fDistance = GetPlayerDistanceFromPoint(playerid, X,Y,Z),
        szMessage[44];
 
        format(szMessage, sizeof(szMessage), "You're %0.2f meters away from the vending machine.", fDistance);
        SendClientMessage(playerid, 0xA9C4E4FF, szMessage);
 
        return 1;
    }