CMD:sms(playerid,params[])
{
if(PlayerHasItem(playerid,"iPhone"))
{
new targetid,smsstring[257],string[128],str2[256];
if(sscanf(params,"us[257]", targetid, smsstring)) return SendClientMessage(playerid,-1,"*"COL_GREEN" /sms [number] [message]");
if(pInfo[playerid][pLogged] == 1)
{
if(pInfo[targetid][pPhone] == 0)
{
format(string,sizeof(string),"*"COL_PMRECEIVER" [SMS] %i: %s",pInfo[playerid][number],smsstring);
SendClientMessage(targetid,-1,string);
format(str2,sizeof(str2),"*"COL_PMSEND" [SMS] %i: %s",pInfo[targetid][number], smsstring);
SendClientMessage(playerid,-1,str2);
}
else {
SendClientMessage(playerid,-1,"*"COL_RED" This number has phone shut");
}
}
}
return 1;
}
CMD:sms(number,params[])
{
if(PlayerHasItem(playerid,"iPhone"))
{
new playerid, targetid,smsstring[257],string[128],str2[256];
if(sscanf(params,"us[257]", targetid, smsstring)) return SendClientMessage(playerid,-1,"*"COL_GREEN" /sms [number] [message]");
if(pInfo[playerid][pLogged] == 1)
{
if(pInfo[targetid][pPhone] == 0)
{
format(string,sizeof(string),"*"COL_PMRECEIVER" [SMS] %i: %s",pInfo[targetid][number],smsstring);
SendClientMessage(targetid,-1,string);
format(str2,sizeof(str2),"*"COL_PMSEND" [SMS] %i: %s",pInfo[playerid][number], smsstring);
SendClientMessage(playerid,-1,str2);
}
else {
SendClientMessage(playerid,-1,"*"COL_RED" This number has phone shut");
}
}
}
return 1;
}
u parameter can hold a player id and a playername converting the playername into ID and place it into the variable |
d or i parameter can hold a integer and place it into the variable. |
if(sscanf(params, "us[32]", targetid, string)) return SCM blah blah
SendClientMessage(playerid, -1, string);
if(sscanf(params, "ds[32]", targetid, string)) return SCM blah blah
new phonetarget;
foreach(new i : Player)
{
if(targetid == PlayerData[i][phonenumber]) phonetraget = i; break;
}
SCM(phonetarget, -1, string);
This might sound sarcastic and blunt but the function you copied already shows it all
just a little bit explaining though sscanf's u parameter is explained this way. sscanf's i or d parameter is explained this way. now your "targetid" is the best explanation I could use as the targetid, it explains itself Target ID which is the targetted player id on the pm CMD now you want to target the players phone number you can either use the Players ID as a Target ID then use it to get the phone number, which is not how phone works, or you can use that Target ID as an integer variable to hold the phone number and use it to send the message to the player u usage would be PHP код:
PHP код:
|
CMD:sms(playerid, params[])
{
new string[110], string2[110], name[MAX_PLAYER_NAME], number, text[80];
GetPlayerName(playerid, name, sizeof(name));
if(sscanf(params, "is[80]", number, text)) return SendClientMessage(playerid, 0xFFFFFFFF, "/sms [number] [text]");
if(strlen(text) > 80) return SendClientMessage(playerid, 0xFFFFFFFF, "No more than 80 characters!");
format(string, sizeof(string), ""COL_SMS" SMS: %s, | Sender: %d", text, number);
format(string2, sizeof(string2), ""COL_SMS" SMS: %s, | Sent to: %d", text, number);
foreach(new i: Player)
{
if(pInfo[i][Telefon] == number)
{
SendClientMessage(i,-1, string2);
SendClientMessage(i,-1, string);
break;
}
}
return true;
}
foreach(new i: Player) { if(pInfo[i][Telefon] == number) { SendClientMessage(i,-1, string2); SendClientMessage(i,-1, string); break; } } else SendClientMessage(playerid, -1, "Couldn't send your message");
Your foreach loop is what is checking each players phone number against the one that you have entered.
If it checks all the players numbers and can't find the number entered, it will exit the foreach loop and you're just telling it to return true. If you want to make it output a message, simply edit it to this Код:
foreach(new i: Player) { if(pInfo[i][Telefon] == number) { SendClientMessage(i,-1, string2); SendClientMessage(i,-1, string); break; } } else SendClientMessage(playerid, -1, "Couldn't send your message"); |