help cmd id
#1

I wanna make a command which will work like command /id like this when u use /id James

It shows James_Binco [ID:48]

So I wanna make it same but with phone number if you use /checkphone it would show you this


48756 - James_Binco.

I can't get funcion like GetPlayerName, any suggestion please?
Reply
#2

This would be fairly easy with sscanf and y_commands or ZCMD.

PHP Code:
CMD:id(playeridparams[])
{
    
// Creating the variables we will need
    
new String[128], TargetTargetName[MAX_PLAYER_NAME];
    
    
// Checking that all the params are there, and that everything is in order
    
if(sscanf(params"u"Target)) SendClientMessage(playeridCOLOR_INFO"* Usage: /id [playerid/PartOfName]");
    else    
// If everything is in order, this will happen
    
{
        
// Checking that the player is online and that the ID is valid
        
if(Target != INVALID_PLAYER_ID)        
        {
            
// Getting player name into the formerly created string
            
GetPlayerName(TargetTargetNamesizeof(TargetName));    
            
            
// Formatting it to how you wanted it. Player_Name [ID:10]
            
format(Stringsizeof(String), "%s [ID:%d]"TargetNameTarget);    
            
            
// Sending the message
            
SendClientMessage(playeridCOLOR_INFOString);                    
        }
    }
    return 
1;                                                                

EDIT: The command for getting phone number is fairly similar. Just edit the name of the command and edit the format variables to how you want them.

PHP Code:
format(Stringsizeof(String), "%d - %s [ID:%d]"PhoneNumberVariableTargetNameTarget);
// Will output 1337 - Player_Name [ID:10] 
Reply
#3

Using ZCMD and SSCANF

pawn Code:
CMD:checkphone(playerid, params[])
{
    new id,string[128],name[MAX_PLAYER_NAME];
    if(sscanf(params, "u",id)) return SendClientMessage(playerid, -1,"USE /checkphone [ID/Player name]");
    if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid,-1,"Wrong ID!");
    GetPlayerName(id, name, sizeof(name));
    format(string,sizeof(string),"Number: | %d | User: | %s |",YourPhoneNumVariable, name);
    SendClientMessage(playerid,-1,string);
    return 1;
}
Reply
#4

Thanks guys, but you all didint get what I want. I wanna make with strfind function that I can put half of number and it would show similars. Can anyone help with this?
Reply
#5

pawn Code:
CMD:checkphone(playerid, params[])
{
    new id,string[128],name[MAX_PLAYER_NAME];
    if(sscanf(params, "u",id)) return SendClientMessage(playerid, -1,"USE /checkphone [ID/Player name]");
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        GetPlayerName(i, name, sizeof(name));
        if(strfind(name, id, true) != -1)
        {
            format(string,sizeof(string),"Number: | %d | User: | %s |",YourPhoneNumVariable, name);
            SendClientMessage(playerid,-1,string);
        }
    }    
    return 1;
}
Untested code, but it should work. Not sure.. please fix my code if anyone see any mistake.
Reply
#6

For that we first need to know how do you save the phone number (interger, string) ? which variable name do you use ?
Reply
#7

phone number using interger.

@De4dpOol

You didin't make how I want but still thanks for trying. How I say I wanna make similar like De4dpOol but you have to put not a name but phone number like /checkphone [Phone Number] and then would show a name and player id.
Reply
#8

That won't be so much different. Here is my try...
pawn Code:
CMD:checkphone(playerid, params[])
{
    new pn,string[128],name[MAX_PLAYER_NAME];
    if(sscanf(params, "u",pn)) return SendClientMessage(playerid, -1,"USE /checkphone [Phone Number]");
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(YourPhoneNumVariable[i] == pn)
        {
            GetPlayerName(i, name, sizeof(name));
            format(string,sizeof(string),"Number: | %d | User: | %s |",YourPhoneNumVariable[i], name);
            SendClientMessage(playerid,-1,string);
        }
    }    
    return 1;
}
Again not sure if it will work.

EDIT: It will not work if you are saving phone numbers as string.
Reply
#9

Not working pInfo[playerid][pPhone] variable.
Reply
#10

pawn Code:
CMD:checkphone(playerid, params[])
{
    new pn,string[128],name[MAX_PLAYER_NAME];
    if(sscanf(params, "u",pn)) return SendClientMessage(playerid, -1,"USE: /checkphone [Phone Number]");
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(pInfo[i][pPhone] == pn)
        {
            GetPlayerName(i, name, sizeof(name));
            format(string,sizeof(string),"Number: | %d | User: | %s |",pInfo[i][pPhone], name);
            SendClientMessage(playerid,-1,string);
        }
    }    
    return 1;
}
I see no problem. Added your variable in the code. If the above code is not working, please provide more info about the "error" you are getting.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)