[HELP] Chat command.
#1

Hello,
I've made a command, a chat one.
PHP код:
    if(strcmp(cmd"/s"true) == || strcmp(cmd"/shout"true) == 0)
    {
        if(!
strlen(result))
            return 
SendClientMessage(playeridCOLOR_WHITE"USAGE: /s(hout) [text]");
        
format(stringsizeof(string), "%s shouts: %s!"Name(playerid), result);
        
ProxDetector(15.0,playerid,string,COLOR_FADE1,COLOR_FADE2,COLOR_FADE3,COLOR_FADE4,COLOR_FADE5);
        return 
1;
    } 
cmd assigned to strtok(cmdtext, idx);
result assigned to sttrest(cmdtext, idx);

When I'm writing, it will send me that I'm not writing(!strlen(result)).
It doesn't recognize the result..

Strrest:
PHP код:
stock strrest(const string[],index)
{
    new 
length strlen(string),offset index,result[256];
    while((
index length) && ((index offset) < (sizeof(result) - 1)) && (string[index] > '\r')) result[index offset] = string[index],index++;
    
result[index offset] = EOS;
    if(
result[0] == ' ' && string[0] != ' 'strdel(result,0,1);
    return 
result;

Strtok:
PHP код:
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;

Thanks advance.
Reply
#2

pawn Код:
if(strcmp(cmd, "/shout", true) == 0 || strcmp(cmd, "/s", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            if(gPlayerLogged[playerid] == 0)
            {
                SendClientMessage(playerid, COLOR_GREY, "   You need to login first.");
                return 1;
            }
                        new sendername[64];
            sendername = name(playerid)
            new length = strlen(cmdtext);
            while ((idx < length) && (cmdtext[idx] <= ' '))
            {
                idx++;
            }
            new offset = idx;
            new result[64];
            while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
            {
                result[idx - offset] = cmdtext[idx];
                idx++;
            }
            result[idx - offset] = EOS;
            if(!strlen(result))
            {
                SendClientMessage(playerid, COLOR_GRAD2, "USAGE: (/s)hout [Local IC]");
                return 1;
            }
            format(string, sizeof(string), "%s Shouts: %s!", sendername, result);
            ProxDetector(50.0, playerid, string,COLOR_WHITE,COLOR_WHITE,COLOR_WHITE,COLOR_FADE1,COLOR_FADE2);
            printf("%s", string);
        }
        return 1;
    }
Try that
Reply
#3

Quote:
Originally Posted by Rob_Maate
Посмотреть сообщение
pawn Код:
if(strcmp(cmd, "/shout", true) == 0 || strcmp(cmd, "/s", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            if(gPlayerLogged[playerid] == 0)
            {
                SendClientMessage(playerid, COLOR_GREY, "   You need to login first.");
                return 1;
            }
                        new sendername[64];
            sendername = name(playerid)
            new length = strlen(cmdtext);
            while ((idx < length) && (cmdtext[idx] <= ' '))
            {
                idx++;
            }
            new offset = idx;
            new result[64];
            while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
            {
                result[idx - offset] = cmdtext[idx];
                idx++;
            }
            result[idx - offset] = EOS;
            if(!strlen(result))
            {
                SendClientMessage(playerid, COLOR_GRAD2, "USAGE: (/s)hout [Local IC]");
                return 1;
            }
            format(string, sizeof(string), "%s Shouts: %s!", sendername, result);
            ProxDetector(50.0, playerid, string,COLOR_WHITE,COLOR_WHITE,COLOR_WHITE,COLOR_FADE1,COLOR_FADE2);
            printf("%s", string);
        }
        return 1;
    }
Try that
You just copied and pasted that from another script, i can tell this by the "gPlayerLogged" variable, as his script my not have this variable.
Reply
#4

I really dont understand why not using zcmd, believe me Its way shorter... look at your shout cmd and look at mine

pawn Код:
CMD:s(playerid,params[])
{
    if(isnull(params)) return SendClientMessage(playerid, COLOR_SYNTAX,"[SYNTAX]: /s [shout]");
    new sendername[MAX_PLAYER_NAME], string[128];
    GetPlayerName(playerid, sendername, sizeof(sendername));
    format(string, sizeof(string), "%s Shouts: %s!!", sendername, params);
    ProxDetector(40.0, playerid, string,COLOR_WHITE,COLOR_WHITE,COLOR_WHITE,COLOR_FADE1,COLOR_FADE2);
    return 1;
}
And thats all!
Reply
#5

Quote:
Originally Posted by Joshb93
Посмотреть сообщение
You just copied and pasted that from another script, i can tell this by the "gPlayerLogged" variable, as his script my not have this variable.
It's edited from my script, problem?
Reply
#6

Thanks iNorton,
How am I create a command with more params then 1?
I've tried to do params[1] and stuff but it didn't work out..
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)