SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Old 21/02/2020, 02:43 PM   #1
ApolloXD
Big Clucker
 
ApolloXD's Avatar
 
Join Date: Jun 2013
Posts: 90
Reputation: 6
Default 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];
        //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;
    }
ApolloXD is offline   Reply With Quote
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Object detection from single player???? CMH Scripting Help 8 05/09/2017 11:33 PM
Detection of is player near any source of water Beckett Scripting Help 2 04/05/2015 10:56 AM
Object Hit Detection Avi57 Scripting Help 4 12/06/2013 08:06 AM
Object aiming detection xDeadlyBoy Scripting Help 3 09/10/2012 07:09 PM
Player angle and walls detection arnutisz Help Archive 5 04/02/2010 11:56 AM


All times are GMT. The time now is 03:18 AM.


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