sms problem
#1

Hello,

i try to make a /sms command, but i run out of ideas.
The number doesn't work, same for the text, i dont know what to do.

pawn Код:
if(!strcmp("/sms", cmdtext, true))
        {
            new temp[124], temp2[124], idx, message[124], sendernum, num;
            print("var created");
            new bool:trouve = false;
            print("var created");
            temp = strtok(cmdtext[5], idx);
            print("number stock in temp");
            temp2 = strtok(cmdtext[5], idx);
            print("message stock in temp2");
            if(strlen(temp) == 0)
            {
                SendClientMessage(playerid, -1, "USE: /sms <number> <message>");
                return 1;
            }
            print("message for non-gived number show");
            if(strlen(temp2) == 0)
            {
                SendClientMessage(playerid, -1, "USE: /sms <numero> <message>");
                return 1;
            }
            print("message for non-give text show");
            num = strval(temp);
            print("temp stock in num");
            printf("%i\n", num);
            print("nub displayed");
            printf("%s\n", temp2);
            print("message displayed");
            if (PlayerInfo[playerid][pNum] != 0)
            {
                for (new i = 0; i < MAX_PLAYERS; ++i)
                {
                    if(PlayerInfo[i][pNum] == num && i != playerid)
                    {
                        print("player with same number find.");
                        sendernum = PlayerInfo[playerid][pNum];
                        format(message, sizeof(message), "[SMS] %i: %s", sendernum, temp2);
                        print("message formated");
                        SendClientMessage(i, COLOR_YELLOW, message);
                        print("message send");
                        SendClientMessage(playerid, COLOR_YELLOW, message);
                        print("message sendІ");
                        trouve = true; // trouve = find
                        print("var trouvй modified");
                        return 1;
                    }
                }
                if (trouve == false)
                {
                    SendClientMessage(playerid, -1, "ERREUR: message non send (numйro invalide).");
                    return 1;
                }
            }
            else SendClientMessage(playerid, -1, "dont have cellular.");
        }
log:
[21:08:11] var created
[21:08:11] num stock in temp
[21:08:11] message stock in temp temp2
[21:08:11] message for non-give text show
Reply
#2

Try this

pawn Код:
strtok(const string[], &index)
{
    new length = strlen(string);
    while ((index < length) && (string[index] <= ' '))
    {
        index++;
    }
 
    new offset = index;
    new result[20];
    while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
    {
        result[index - offset] = string[index];
        index++;
    }
    result[index - offset] = EOS;
    return result;
}

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



public OnPlayerCommandText(playerid, cmdtext[])
{
    new cmd[128], idx;
    cmd = strtok(cmdtext, idx);
    if(!strcmp(cmd, "/sms", true))
    {
        new temp[128], temp2[128], message[128], sendernum, num;
        print("var created");
        new bool:trouve = false;
        print("var created");
        temp = strtok(cmdtext, idx);
        print("number stock in temp");
        temp2 = strrest(cmdtext, idx);
        print("message stock in temp2");
        if(!strlen(temp) || !strlen(temp2))
        {
            SendClientMessage(playerid, -1, "USE: /sms <number> <message>");
            return 1;
        }
     
        num = strval(temp);
        print("temp stock in num");
        printf("%i\n", num);
        print("nub displayed");
        printf("%s\n", temp2);
        print("message displayed");
        if (PlayerInfo[playerid][pNum] != 0)
        {
            for (new i = 0; i < MAX_PLAYERS; ++i)
            {
                if(PlayerInfo[i][pNum] == num && i != playerid)
                {
                    print("player with same number find.");
                    sendernum = PlayerInfo[playerid][pNum];
                    format(message, sizeof(message), "[SMS] %i: %s", sendernum, temp2);
                    print("message formated");
                    SendClientMessage(i, COLOR_YELLOW, message);
                    print("message send");
                    SendClientMessage(playerid, COLOR_YELLOW, message);
                    print("message sendІ");
                    trouve = true; // trouve = find
                    print("var trouvй modified");
                    return 1;
                }
            }
            if (trouve == false)
            {
                SendClientMessage(playerid, -1, "ERREUR: message non send (numйro invalide).");
                return 1;
            }
        }
        else SendClientMessage(playerid, -1, "dont have cellular.");
        return 1;
    }
    return 0;
}
Reply
#3

Quote:
Originally Posted by rickisme
Посмотреть сообщение
Try this

pawn Код:
strtok(const string[], &index)
{
    new length = strlen(string);
    while ((index < length) && (string[index] <= ' '))
    {
        index++;
    }
 
    new offset = index;
    new result[20];
    while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
    {
        result[index - offset] = string[index];
        index++;
    }
    result[index - offset] = EOS;
    return result;
}

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



public OnPlayerCommandText(playerid, cmdtext[])
{
    new cmd[128], idx;
    cmd = strtok(cmdtext, idx);
    if(!strcmp(cmd, "/sms", true))
    {
        new temp[128], temp2[128], message[128], sendernum, num;
        print("var created");
        new bool:trouve = false;
        print("var created");
        temp = strtok(cmdtext, idx);
        print("number stock in temp");
        temp2 = strrest(cmdtext, idx);
        print("message stock in temp2");
        if(!strlen(temp) || !strlen(temp2))
        {
            SendClientMessage(playerid, -1, "USE: /sms <number> <message>");
            return 1;
        }
     
        num = strval(temp);
        print("temp stock in num");
        printf("%i\n", num);
        print("nub displayed");
        printf("%s\n", temp2);
        print("message displayed");
        if (PlayerInfo[playerid][pNum] != 0)
        {
            for (new i = 0; i < MAX_PLAYERS; ++i)
            {
                if(PlayerInfo[i][pNum] == num && i != playerid)
                {
                    print("player with same number find.");
                    sendernum = PlayerInfo[playerid][pNum];
                    format(message, sizeof(message), "[SMS] %i: %s", sendernum, temp2);
                    print("message formated");
                    SendClientMessage(i, COLOR_YELLOW, message);
                    print("message send");
                    SendClientMessage(playerid, COLOR_YELLOW, message);
                    print("message sendІ");
                    trouve = true; // trouve = find
                    print("var trouvй modified");
                    return 1;
                }
            }
            if (trouve == false)
            {
                SendClientMessage(playerid, -1, "ERREUR: message non send (numйro invalide).");
                return 1;
            }
        }
        else SendClientMessage(playerid, -1, "dont have cellular.");
        return 1;
    }
    return 0;
}
strtok is one of the slowest and outdated command processors.

Use sscanf instead.
Reply
#4

Quote:
Originally Posted by stormchaser206
Посмотреть сообщение
strtok is one of the slowest and outdated command processors.

Use sscanf instead.
Where he got that piece of code from? Its not even fully english
Reply
#5

Sorry i'm french.
The thing is that i wanted to do that command with strtok.
rickisme, i already have strtok.

Thanks anyway.
Reply
#6

^ if you already have it, just remove
Look and learn, don't copy and paste

Here's my test log
Quote:

Console input: loadfs demo
[08:38:49] Filterscript 'demo.amx' loaded.
[08:38:58] var created
[08:38:58] var created
[08:38:58] number stock in temp
[08:38:58] message stock in temp2
[08:38:58] temp stock in num
[08:38:58] 1
[08:38:58] nub displayed
[08:38:58] asdsad asdasd
[08:38:58] message displayed

Reply
#7

Thanks rickisme. (+rep).
The two command you gave me(strtok & strrest), are same as mine.
But it work in game.

I cant see what mistake i made.

(sorry for my english)
Reply
#8

strtok for number and strrest for message
When you use strtok for message, it's only show first word in message
Example: message = "I'm Rick", it's only show "I'm"

Код:
strtok(const string[], &index)
{
    new length = strlen(string);
    while ((index < length) && (string[index] <= ' '))
    {
        index++;
    }
 
    new offset = index;
    new result[20];
    while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
    {
        result[index - offset] = string[index];
        index++;
    }
    result[index - offset] = EOS;
    return result;
}

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;
}
Here's your problem

Wrong :
pawn Код:
if(!strcmp("/sms", cmdtext, true))
Right:
pawn Код:
cmd = strtok(cmdtext, idx);
if(!strcmp(cmd, "/sms", true))
Wrong :
pawn Код:
temp = strtok(cmdtext[5], idx);
temp2 = strtok(cmdtext[5], idx);
Right :
pawn Код:
temp = strtok(cmdtext, idx);
temp2 = strrest(cmdtext, idx);
Reply
#9

Thanks a lot !
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)