SA-MP Forums

SA-MP Forums (
-   Scripting Help (
-   -   Player Near Object Detection (

ApolloXD 21/02/2020 02:43 PM

Player Near Object Detection
I have created this code where first I create a Baloon with /flare cmd over the player at a height of 50 from the current position of the player. Then that object starts moving down to the player position.

I am using /near function to detect whether the player is near to the object or not. if Yes "You are near the ballon" will be displayed else "You are far away" will be displayed.

There is no compilation error but I think I am lacking with some logic here. my else statement always gets executed. "You are far away".

pawn Code:
new Float:x, Float:y, Float:z;
new baloon, movetime;

if (!strcmp("/flare", cmdtext, true))
        GetPlayerPos(playerid, x, y, z);
        baloon = CreateObject(19333, Float:x, Float:y, Float:z+50.00, 0, 0, 96.0,300.0);
        SendClientMessage(playerid, -1, "Flare created");
        new string[50];
        movetime = MoveObject(baloon, x, y, z, 2.00);
        format(string, sizeof(string), "Object will finish moving in %d milliseconds", movetime);
        SendClientMessage(playerid, 0xFF000000, string);

        //Now Lets detect if the player is near th object
        return 1;

    if (!strcmp("/near", cmdtext))
        GetObjectPos(baloon, x, y, z);
        if (IsPlayerInRangeOfPoint(playerid, 10.0, x, y, z))
            SendClientMessage(playerid,0xFFFFFFFF,"You are near the object");
            SendClientMessage(playerid,0xFFFFFFFF,"You are far away");
        return 1;

tonto125 21/02/2020 04:58 PM

Re: Player Near Object Detection
Create a float of the X,Y,Z coords. For example;

new Float:baloon[3];
Then use that in the IsPlayerInRangeOfPoint function.


If(IsPlayerInRangeOfPoint(playerid, 10.0, baloon[0], baloon[1], baloon[2]))

ApolloXD 22/02/2020 04:51 AM

Re: Player Near Object Detection
I fixed it only I have to declare my variables in global scope.
Now I want to activate this I think using this function OnPlayerWeaponShot
like this.
when player aim at sky and Hit Fire then the flare code gets executed.

Current version:

All times are GMT. The time now is 09:32 AM.

Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.