help cmd id -
tooMuch - 08.02.2015
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?
Re: help cmd id -
Knappen - 08.02.2015
This would be fairly easy with sscanf and y_commands or ZCMD.
PHP Code:
CMD:id(playerid, params[])
{
// Creating the variables we will need
new String[128], Target, TargetName[MAX_PLAYER_NAME];
// Checking that all the params are there, and that everything is in order
if(sscanf(params, "u", Target)) SendClientMessage(playerid, COLOR_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(Target, TargetName, sizeof(TargetName));
// Formatting it to how you wanted it. Player_Name [ID:10]
format(String, sizeof(String), "%s [ID:%d]", TargetName, Target);
// Sending the message
SendClientMessage(playerid, COLOR_INFO, String);
}
}
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(String, sizeof(String), "%d - %s [ID:%d]", PhoneNumberVariable, TargetName, Target);
// Will output 1337 - Player_Name [ID:10]
Re: help cmd id -
Sime30 - 08.02.2015
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;
}
Re: help cmd id -
tooMuch - 09.02.2015
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?
Re: help cmd id -
De4dpOol - 09.02.2015
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.
AW: help cmd id -
Nero_3D - 09.02.2015
For that we first need to know how do you save the phone number (interger, string) ? which variable name do you use ?
Re: help cmd id -
tooMuch - 09.02.2015
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.
Re: help cmd id -
De4dpOol - 09.02.2015
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.
Re: help cmd id -
tooMuch - 09.02.2015
Not working
pInfo[playerid][pPhone] variable.
Re: help cmd id -
De4dpOol - 09.02.2015
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.