SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 09/12/2012, 10:29 AM   #1
GoldZoroGrab
Huge Clucker
 
GoldZoroGrab's Avatar
 
Join Date: Nov 2012
Posts: 277
Reputation: -12
Default nearest Player

how to make for example i made rob command

how for example if player did /rob without id it robs the nearest player


just give me the code of nearest player

i have rob command but id must be written

tell me how to make get nearest player if no id written

and if there is no near player it will say no near players\ /rob [id]

the range of point must be 8 (distance)
__________________
Hate me? Go sit with the rest of the haters waiting for me to care!

Click on the Signature, to see GrabCnR info

Code:
[TUTORIAL] Ban Tutorial
[FILTERSCRIPT] Grab Warning System
GoldZoroGrab is offline   Reply With Quote
Old 09/12/2012, 10:34 AM   #2
Konstantinos
Spam Machine
 
Konstantinos's Avatar
 
Join Date: Dec 2011
Posts: 11,841
Reputation: 1399
Default Re: nearest Player

pawn Code:
#define GetDistanceBetweenCoords(%1,%2,%3,%4,%5,%6) floatsqroot((%4 - %1)*(%4 - %1) + (%5 - %2)*(%5 - %2) + (%6 - %3)*(%6 - %3))

stock GetPlayerClosestPlayer(playerid,bool:NPC = true)
{
    new pid = INVALID_PLAYER_ID,
        Float:distance = 8.0,
        Float:tmp[7];
    GetPlayerPos(playerid,tmp[0],tmp[1],tmp[2]);
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(i == playerid) continue;
        if(!IsPlayerConnected(i)) continue;
        if(NPC == false) if(IsPlayerNPC(i)) continue;
        GetPlayerPos(i,tmp[3],tmp[4],tmp[5]);
        tmp[6] = GetDistanceBetweenCoords(tmp[0],tmp[1],tmp[2],tmp[3],tmp[4],tmp[5]);
        if(distance < tmp[6]) continue;
        distance = tmp[6];
        pid = i;
    }
    return pid;
}

// Usage: GetPlayerClosestPlayer( playerid );
__________________
Life is like riding a bicycle. To keep your balance, you must keep moving.

[Tutorial] How to use SQLite
[FilterScript] Tune System
Konstantinos is offline   Reply With Quote
Old 09/12/2012, 10:46 AM   #3
GoldZoroGrab
Huge Clucker
 
GoldZoroGrab's Avatar
 
Join Date: Nov 2012
Posts: 277
Reputation: -12
Default Re: nearest Player

command(rob, playerid, params[])
{
new ID;
return 1;
}
ok i gave u new ID
now for example do it for me in that code the nearest player
__________________
Hate me? Go sit with the rest of the haters waiting for me to care!

Click on the Signature, to see GrabCnR info

Code:
[TUTORIAL] Ban Tutorial
[FILTERSCRIPT] Grab Warning System
GoldZoroGrab is offline   Reply With Quote
Old 09/12/2012, 10:52 AM   #4
Konstantinos
Spam Machine
 
Konstantinos's Avatar
 
Join Date: Dec 2011
Posts: 11,841
Reputation: 1399
Default Re: nearest Player

Not finished, you should make it. I'll just give you some tips for the beginning.
pawn Code:
#define GetDistanceBetweenCoords(%1,%2,%3,%4,%5,%6) floatsqroot((%4 - %1)*(%4 - %1) + (%5 - %2)*(%5 - %2) + (%6 - %3)*(%6 - %3))

command(rob, playerid, params[])
{
    new
        ID
    ;
    if( !sscanf( params, "r", ID ) )
    {
        // Rob the ID
    }
    else GetPlayerClosestPlayer( playerid );
    return 1;
}

stock GetPlayerClosestPlayer(playerid,bool:NPC = true)
{
    new pid = INVALID_PLAYER_ID,
        Float:distance = 8.0,
        Float:tmp[7];
    GetPlayerPos(playerid,tmp[0],tmp[1],tmp[2]);
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(i == playerid) continue;
        if(!IsPlayerConnected(i)) continue;
        if(NPC == false) if(IsPlayerNPC(i)) continue;
        GetPlayerPos(i,tmp[3],tmp[4],tmp[5]);
        tmp[6] = GetDistanceBetweenCoords(tmp[0],tmp[1],tmp[2],tmp[3],tmp[4],tmp[5]);
        if(distance < tmp[6]) continue;
        distance = tmp[6];
        pid = i;
    }
    return pid;
}
__________________
Life is like riding a bicycle. To keep your balance, you must keep moving.

[Tutorial] How to use SQLite
[FilterScript] Tune System
Konstantinos is offline   Reply With Quote
Reply

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
how can i get the nearest player from point? Yoseflm Scripting Help 7 26/10/2012 01:48 PM
Nearest player budelis Help Archive 2 27/07/2011 07:11 AM
Get nearest player austin070 Help Archive 2 04/03/2011 12:07 AM
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:32 PM.


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