CMD:sms
#1

Hi, I tried to duplicate /pm command as the /sms, but I want to eliminate playerid with "number"


PHP код:
CMD:sms(playerid,params[])
{
if(
PlayerHasItem(playerid,"iPhone"))
    {
    new 
targetid,smsstring[257],string[128],str2[256];
     if(
sscanf(params,"us[257]"targetidsmsstring)) 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;

Should my code look like this?

PHP код:
CMD:sms(number,params[])
{
if(
PlayerHasItem(playerid,"iPhone"))
    {
    new 
playeridtargetid,smsstring[257],string[128],str2[256];
     if(
sscanf(params,"us[257]"targetidsmsstring)) 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;

And how can I check if typed phone number exists (as pm's this player is offline)
Reply
#2

don't bump within less than 24 hours please?
Reply
#3

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.

Quote:

u parameter can hold a player id and a playername converting the playername into ID and place it into the variable

sscanf's i or d parameter is explained this way.

Quote:

d or i parameter can hold a integer and place it into the variable.

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 код:
if(sscanf(params"us[32]"targetidstring)) return SCM blah blah
SendClientMessage
(playerid, -1string); 
the d usage would be

PHP код:
if(sscanf(params"ds[32]"targetidstring)) return SCM blah blah
new phonetarget;
foreach(new 
Player)
{
      if(
targetid == PlayerData[i][phonenumber]) phonetraget i; break;
}
SCM(phonetarget, -1string); 
Reply
#4

Quote:
Originally Posted by JesterlJoker
Посмотреть сообщение
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 код:
if(sscanf(params"us[32]"targetidstring)) return SCM blah blah
SendClientMessage
(playerid, -1string); 
the d usage would be

PHP код:
if(sscanf(params"ds[32]"targetidstring)) return SCM blah blah
new phonetarget;
foreach(new 
Player)
{
      if(
targetid == PlayerData[i][phonenumber]) phonetraget i; break;
}
SCM(phonetarget, -1string); 
Well I want to use player Id's phone number (from pInfo[playerid][Telefon])

its like, /pm ID but instead of ID is number from pInfo.
Reply
#5

Then use the d way I showed you above.
The one with the loop. It should work the way you want it to be.

To explain it I looked for the matching phone number from all the players online. If the number is not found then the message does not get sent.
Reply
#6

I managed to do it, thanks for explications
Reply
#7

Glad to be of help then.
Reply
#8

Quote:
Originally Posted by JesterlJoker
Посмотреть сообщение
Glad to be of help then.
My question is

How to SCM if no phone number is avaible? (if i type 221 but no player with number 221 is online)

PHP код:
CMD:sms(playeridparams[])
{
    new 
string[110], string2[110], name[MAX_PLAYER_NAME], numbertext[80];
    
GetPlayerName(playeridnamesizeof(name));
    if(
sscanf(params"is[80]"numbertext)) return SendClientMessage(playerid0xFFFFFFFF"/sms [number] [text]");
    if(
strlen(text) > 80) return SendClientMessage(playerid0xFFFFFFFF"No more than 80 characters!");
    
format(stringsizeof(string), ""COL_SMS" SMS: %s, | Sender: %d"textnumber);
    
format(string2sizeof(string2), ""COL_SMS" SMS: %s, | Sent to: %d"textnumber);
    foreach(new 
iPlayer)
    {
        if(
pInfo[i][Telefon] == number)
        {
            
SendClientMessage(i,-1string2);
            
SendClientMessage(i,-1string);
            break;
        }
    }
    return 
true;

Reply
#9

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");
Reply
#10

Quote:
Originally Posted by ItsRobinson
Посмотреть сообщение
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");
Its giving me invalid assumed zero.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)