Player Near Object Detection
#1

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];
        //while(movetime)
        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");
        }
        else
        {
            SendClientMessage(playerid,0xFFFFFFFF,"You are far away");
        }
 
        return 1;
    }
Reply
#2

Create a float of the X,Y,Z coords. For example;
Code:
new Float:baloon[3];
Then use that in the IsPlayerInRangeOfPoint function.

Code:
If(IsPlayerInRangeOfPoint(playerid, 10.0, baloon[0], baloon[1], baloon[2]))
Reply
#3

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.
https://i.postimg.cc/PqhYHM8v/Screenshot-132.png
when player aim at sky and Hit Fire then the flare code gets executed.

Current version:
https://youtu.be/sG0IYm1j5bM
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)