SA-MP Forums

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

Thread Tools Display Modes
Old 03/03/2011, 11:54 PM   #1
Huge Clucker
austin070's Avatar
Join Date: Aug 2010
Posts: 372
Reputation: 18
Default Get nearest player

Hey guys, I need a little help. I have a police radar command that is used as follows: "/radar [playerid]". It works, but instead of entering a player's id, I want it to find the velocity of the nearest player's vehicle. I know this is possible, and I have ******d it, but I've found nothing, so don't say "GO ****** IT NOOB." Can someone show me how to do it or point me in the right direction to a tutorial?
austin070 is offline  
Old 04/03/2011, 12:01 AM   #2
Antonio [G-RP]
Join Date: Jul 2009
Location: Canada
Posts: 1,114
Reputation: 4
Default Re: Get nearest player

This will start you off.

pawn Code:
forward GetClosestPlayerToPlayer(playerid);
public GetClosestPlayerToPlayer(playerid)
    new Float:dist = 1000.0;
    new targetid = INVALID_PLAYER_ID;
    new Float:x1,Float:y1,Float:z1;
    new Float:x2,Float:y2,Float:z2;
    new Float:tmpdis;
    for(new i=0;i<MAX_PLAYERS;i++)
        if(i == playerid) continue;
        tmpdis = floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
        if(tmpdis < dist)
            dist = tmpdis;
            targetid = i;
    return targetid;
If I've helped you at all, give me a REP. It's appreciated.
Antonio [G-RP] is offline  
Old 04/03/2011, 12:07 AM   #3
Huge Clucker
austin070's Avatar
Join Date: Aug 2010
Posts: 372
Reputation: 18
Default Re: Get nearest player

Thanks. It worked fine.
austin070 is offline  

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
Getting the nearest point. Haydz Help Archive 1 20/02/2011 04:52 AM
get nearest point... Owenlishious Help Archive 0 23/01/2011 05:10 PM
[HELP]Get nearest to farthest WThieves Help Archive 2 15/06/2010 08:13 PM
SetPlayerAngle to nearest player.. wiilweer Help Archive 1 09/01/2010 12:19 PM
How can I get the vehicle which is the nearest to a player =? KIDUL Help Archive 1 04/11/2009 03:29 PM

All times are GMT. The time now is 03:57 PM.

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