/rob closest player help
#1

Het Guys
i want to do /rob without (ID/name) ,i mean type /rob to rob the closest player
i have this
Код:
CMD:rob(playerid, params[])
{
	
    if  (sscanf( params, "r", ID )) SendClientMessage(playerid, 0xFF000AA, "Use: /rob [ID]");
    else if (ID == INVALID_PLAYER_ID) SendClientMessage(playerid, 0xFF000AA,"invalid Player ....");
    else if(ID == playerid) SendClientMessage(ID, 0xFF0000AA, "ERROR : You cant rob yourself!");
    return 1;
}
please if some on can make it with if(IsPlayerInRangeOfPoint or li
ke that

thanks
Reply
#2

You can use stock GetClosestPlayer(playerid);

Код:
stock GetClosestPlayer(playerid)
{
    new Float:dis,Float:dis2,player;
    player = -1;
    dis = 99999.99;
    foreach(Player,x)
    {
        if(x != playerid)
        {
            dis2 = GetDistanceBetweenPlayers(x,playerid);
            if(dis2 < dis && dis2 != -1.00)
            {
                dis = dis2;
                player = x;
            }
        }
    }
    return player;
}

CMD:rob(playerid, params[])
{
if(GetClosestPlayer(playerid) == -1) return SendClientMessage(ID, 0xFF0000AA, "ERROR : No player close to you!");
printf("Player with ID %i is closest to you!", GetClosestPlayer(playerid));
return 1;
}
Reply
#3

use this stock
pawn Код:
stock GetNearestPlayer(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;
    GetPlayerPos(playerid,x1,y1,z1);
    for(new i=0;i<MAX_PLAYERS;i++)
    {
        if(i == playerid) continue;
        GetPlayerPos(i,x2,y2,z2);
        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;
}
EDIT: didnt refreshed the page so didnt saw the above reply. Sry for double post
Reply
#4

EDIT: nvm..
Reply
#5

please can you give me the PAWN Code
i have that
Код:
CMD: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

+Rep for help
Reply
#6

pawn Код:
new Float:dist = 1000.0;
WHAT THE FUCK?

pawn Код:
stock GetNearestPlayer(playerid)
{
    new Float:arr1[3], Float:arr2[3];
    GetPlayerPos(playerid, arr1[0], arr1[1], arr1[2]);
    for(new i; i <MAX_PLAYERS; i++)
    {
        if(i == playerid) continue;
        GetPlayerPos(i, arr2[0], arr2[1], arr2[2]);
        if(2.0 /* DISTANCE */ < floatsqroot(floatpower(floatabs(floatsub(arr1[0], arr2[0])),2)+floatpower(floatabs(floatsub(arr1[1], arr2[1])),2)+floatpower(floatabs(floatsub(arr1[2], arr2[2])),2))){
            return i;
        }
    }
    return -1;
}
But, if you want /rob ID, you don't use this code (it detect the first player around you with a 2.0 radius)
Reply
#7

I gived u this please can someone complete it to me
Help= +Rep

Код:
CMD:rob(playerid, params[])
{
    new string[250], string2[250], string3[250], robbedcash, robbedname[MAX_PLAYER_NAME], robbername[MAX_PLAYER_NAME];                                                                                                                                                     
     robbedcash = random(5000);
     if(sscanf( params, "u", ID )) SendClientMessage(playerid, 0xFF0000AA, "Usage /rob ID");
     if(!GetNearestPlayer(playerid)) return SendClientMessage(ID, 0xFF0000AA, "ERROR : No player close to you!");
     else(GetNearestPlayer(playerid))
    
     return 1;
}
Reply
#8

duno if this might help mate im no pro but this is a command that you can put in /rob and it will say....

USAGE: /rob (playerid) but its abit messy an not finished so you will have to complete it mate as dont have the time today sorry man
http://pastebin.com/44B0B2QH

oops sorry this one might be better
http://pastebin.com/qKrgjFEV

if it does help mate please +rep i really could do with it lol
Reply
#9

Quote:
Originally Posted by Lukka_Vercetti
Посмотреть сообщение
duno if this might help mate im no pro but this is a command that you can put in /rob and it will say....

USAGE: /rob (playerid) but its abit messy an not finished so you will have to complete it mate as dont have the time today sorry man
http://pastebin.com/44B0B2QH

oops sorry this one might be better
http://pastebin.com/qKrgjFEV

if it does help mate please +rep i really could do with it lol
this is for /rob nearest player ?
Reply
#10

yea mate the new bottom pastebin i added will help man...

if you look at where i put //put shit here

thats for you to put your code of what happens when you doit mate

i know i didnt do the whole thing but dont have robbedcash and stuff mate so couldnt doit for you properly but the cmd will help mate.. it uses a prox detector so wont need the getnearestplayer bit... just need to finish it off yourself man.. and if you would like help testing it when your done gimme a shout bud
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)