SA-MP Forums Archive
CMD:sms - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: CMD:sms (/showthread.php?tid=652886)



CMD:sms - Zeus666 - 21.04.2018

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)


Re: CMD:sms - std - 21.04.2018

don't bump within less than 24 hours please?


Re: CMD:sms - JesterlJoker - 21.04.2018

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); 



Re: CMD:sms - Zeus666 - 21.04.2018

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.


Re: CMD:sms - JesterlJoker - 21.04.2018

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.


Re: CMD:sms - Zeus666 - 21.04.2018

I managed to do it, thanks for explications


Re: CMD:sms - JesterlJoker - 21.04.2018

Glad to be of help then.


Re: CMD:sms - Zeus666 - 21.04.2018

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;




Re: CMD:sms - ItsRobinson - 21.04.2018

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");



Re: CMD:sms - Zeus666 - 21.04.2018

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.