/sms command not working.
#1

So what I was trying to do, was create an /sms command by taking the /pm command from 'base' filterscript that you get when you download server files. In this command, I'm using a player variable for the phone number.

Here is the command:
pawn Код:
//Check out the latest post by me.
Here is the strrest stock:
pawn Код:
stock strrest(const string[], &index)
{
    new length = strlen(string);
    while ((index < length) && (string[index] <= ' '))
    {
        index++;
    }
    new offset = index;
    new result[128];
    while ((index < length) && ((index - offset) < (sizeof(result) - 1)))
    {
        result[index - offset] = string[index];
        index++;
    }
    result[index - offset] = EOS;
    return result;
}
I was trying to make the command check if the player has the number typed in, he receives the message. Such as, if John's phone number is 3000, then he receives a message from James, whose number is 3500. Basically the command should work like "/sms 3000 Hey, what's up?". But now it doesn't work. When I type in both parameters it does nothing, just plain nothing, but if I miss both parameters, it gives two messages saying "Usage: /sms [number] [message]". So can anybody please help me? And please, don't tell me to switch to ZCMD, I already made like a million commands with the current format.
Reply
#2

This is a very nice idea man! I hope peoples will help you! I am busy at the moment
Reply
#3

Quote:
Originally Posted by Gytis0
Посмотреть сообщение
Here is the command:
pawn Код:
if(PlayerInfo[playerid][pNr] == strlen(tmp))
Here you only check if the number has the same length as the number param, you dont check if the number is correct.
Try using strval but I have no idea if it would work
Reply
#4

Quote:
Originally Posted by [NWA]Hannes
Посмотреть сообщение
Here you only check if the number has the same length as the number param, you dont check if the number is correct.
Try using strval but I have no idea if it would work
I did what you said, and made a few tweaks to the command. Here's the command:
pawn Код:
if(strcmp("/sms", cmd, true) == 0)
    {
    if(PlayerInfo[playerid][pPhone] >= 1)
    {
        tmp = strtok(cmdtext,idx);

        if(!strlen(tmp))
        {
            SendClientMessage(playerid,COLOR_WHITE,"Usage: /sms [number] [message]");
        }
        new id;
        new gMessage[256];
        new Message[256];
        new pName[MAX_PLAYER_NAME+1];
       
        new number;
        number = PlayerInfo[playerid][pNr];

        gMessage = strrest(cmdtext,idx);

        if(!strlen(gMessage))
        {
            SendClientMessage(playerid,COLOR_WHITE,"Usage: /sms [number] [message]");
        }

        if(PlayerInfo[id][pNr] == strval(tmp))
        {
            GetPlayerName(playerid,pName,sizeof(pName));
            format(Message,sizeof(Message),"%s(%d): %s",pName,number,gMessage);
            SendClientMessage(id,COLOR_YELLOW,Message);
            PlayerPlaySound(id,1085,0.0,0.0,0.0);
        }
    }
    else
    {
    SendClientMessage(playerid, COLOR_WHITE, "You don't have a cellphone. Buy one at any 24/7 store.");
    }
    }
Now, what my problem is, that I CAN message myself, my friend CAN message me and I CAN'T message him. I'm thinking, maybe this is because my id was 0, and his id was 1? I just don't get it, I just don't know what else to do.
Reply
#5

Bump. Can anybody help me?
Reply
#6

There's a few issues with your script.

pawn Код:
new gMessage[256];
        new Message[256];
These string don't need to be that big, the max displayable characters in SAMP are 128.

You also should add a return at this piece of code:
pawn Код:
if(!strlen(tmp))
        {
            SendClientMessage(playerid,COLOR_WHITE,"Usage: /sms [number] [message]");
        }
pawn Код:
if(!strlen(gMessage))
        {
            SendClientMessage(playerid,COLOR_WHITE,"Usage: /sms [number] [message]");
        }
So the script 'halts' at that line and doesn't continue.

You also don't return 1; on the bottom of the command.

I have no idea how to use strtok, so I won't comment on additional bugfixes, I myself prefer zcmd and sscanf as that's way easier to use and to-date.
Reply
#7

Quote:
Originally Posted by BuuGhost
Посмотреть сообщение
There's a few issues with your script.

pawn Код:
new gMessage[256];
        new Message[256];
These string don't need to be that big, the max displayable characters in SAMP are 128.

You also should add a return at this piece of code:
pawn Код:
if(!strlen(tmp))
        {
            SendClientMessage(playerid,COLOR_WHITE,"Usage: /sms [number] [message]");
        }
pawn Код:
if(!strlen(gMessage))
        {
            SendClientMessage(playerid,COLOR_WHITE,"Usage: /sms [number] [message]");
        }
So the script 'halts' at that line and doesn't continue.

You also don't return 1; on the bottom of the command.

I have no idea how to use strtok, so I won't comment on additional bugfixes, I myself prefer zcmd and sscanf as that's way easier to use and to-date.
Thank you, fixed a few of my problems. Do you know anyone who could try to fix my error? I found that there is a problem with the usage of the symbol "id". It's a variable that is always equal to 0. I found that out by testing the command with my friend; I was id 0, I successfully received a message from him, he was id 1 - he did not. While we relogged and re-tested it when he was id 0, the same happened, but we switched places; he received a message and he did not. So once again, can anyone help me? :/ I'm out of options here :/
Reply
#8

Bump. Can somebody just try to help me?
Reply
#9

pawn Код:
if(strcmp("/sms", cmd, true) == 0)
    {
    if(PlayerInfo[playerid][pPhone] == 1)
    {
        tmp = strtok(cmdtext,idx);

        if(!strlen(tmp))
        {
            SendClientMessage(playerid,COLOR_WHITE,"Usage: /sms [number] [message]");
        }
        new gMessage[256];
        new Message[256];
        new pName[MAX_PLAYER_NAME+1];
       
        new number;
        number = PlayerInfo[playerid][pNr];

        gMessage = strrest(cmdtext,idx);

        if(!strlen(gMessage))
        {
            SendClientMessage(playerid,COLOR_WHITE,"Usage: /sms [number] [message]");
        }

        if(PlayerInfo[playerid][pNr] == strlen(tmp))
        {
            GetPlayerName(playerid,pName,sizeof(pName));
            format(Message,sizeof(Message),"%s(%d): %s",pName,number,gMessage);
            SendClientMessage(playerid,COLOR_YELLOW,Message);
        }
    }
    return 1;// I think you need to put return 1
    }
Reply
#10

People please. I really need help. The problem is, that a variable is always 0. That variable is "id".

Check this out, the current command:
pawn Код:
if(strcmp("/sms", cmd, true) == 0)
    {
    if(PlayerInfo[playerid][pPhone] >= 1)
    {
        tmp = strtok(cmdtext,idx);

        if(!strlen(tmp))
        {
            SendClientMessage(playerid,COLOR_WHITE,"Usage: /sms [number] [message]");
        }
        new id;
        new gMessage[256];
        new Message[256];
        new pName[MAX_PLAYER_NAME+1];
       
        new number;
        number = PlayerInfo[playerid][pNr];

        gMessage = strrest(cmdtext,idx);

        if(!strlen(gMessage))
        {
            SendClientMessage(playerid,COLOR_WHITE,"Usage: /sms [number] [message]");
        }

        if(PlayerInfo[id][pNr] == strval(tmp))
        {
            GetPlayerName(playerid,pName,sizeof(pName));
            format(Message,sizeof(Message),"%s(%d): %s",pName,number,gMessage);
            SendClientMessage(id,COLOR_YELLOW,Message);
            PlayerPlaySound(id,1085,0.0,0.0,0.0);
        }
    }
    else
    {
    SendClientMessage(playerid, COLOR_WHITE, "You don't have a cellphone. Buy one at any 24/7 store.");
    }
    }
You see these lines?
pawn Код:
new id;

//and

if(PlayerInfo[id][pNr] == strval(tmp))
The variable "id" is always 0. I need the server to scroll through phone numbers and get the id of a player that has the phone number typed in and send the message to the player.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)