I dont understand
#1

pawn Code:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if(strcmp(cmd, "/weather", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            if(PlayerInfo[playerid][pAdminLevel] < 3)
            {
                SendClientMessage(playerid, COLOR_RED, "** you are not authorized to use that command!");
                return 1;
            }
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp))
            {
                SendClientMessage(playerid, COLOR_WHITE, "USAGE: /weather [weatherid]");
                return 1;
            }
            new weather;
            weather = strval(tmp);
            if(weather < 0||weather > 45) { SendClientMessage(playerid, COLOR_RED, "   Weather ID can't be below 0 or above 45!"); return 1; }
            SetWeather(weather);
            format(string, sizeof(string), "[ADMIN] %s has changed everyone's weather to %d.", sendername,weather);
            ABroadCast(COLOR_LIGHTRED,string, 5);
            format(string, sizeof(string), "World's Weather Has Been Changed to %d",weather);
            SendClientMessageToAll(COLOR_GOLD,string);
            DefaultWeather = weather;
        }
        return 1;
    }
    if(strcmp(cmd, "/changeweather", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            if(PlayerInfo[playerid][pAdmin] < changeme)
            {
                SendClientMessage(playerid, COLOR_RED, "You are not authorized to use that command.");
                return 1;
            }
            ChangeWeather();
            format(string, sizeof(string), "[ADMIN]: %s has Forced the Weather Change!.", sendername);
            ABroadCast(COLOR_GOLD,string, 5);
        }
        return 1;
    }
    return 0;
}

I dont undersatnd ive started to script a brand new script ive had no errors so far i add weather and i get this

pawn Code:
(435) : error 017: undefined symbol "cmd"
(444) : error 017: undefined symbol "tmp"
(444) : error 017: undefined symbol "strtok"
(445) : error 017: undefined symbol "tmp"
(451) : error 017: undefined symbol "tmp"
(454) : error 017: undefined symbol "string"
(454) : error 017: undefined symbol "string"
(454) : error 029: invalid expression, assumed zero
454) : fatal error 107: too many error messages on one line
all the errors are based around what ive posted can yousee anything wrong
Reply
#2

This is why you use more up to date methods!

https://sampwiki.blast.hk/wiki/Fast_Commands
Reply
#3

I have no experience using strtok, but try this!

pawn Code:
// Before OnPlayerCommandText

stock strtok(szParser[], &iPos) { // By Brian or something

    new
        szResult[20];

    while(szParser[iPos] == ' ') ++iPos;
    strmid(szResult, szParser, iPos, (strfind(szParser, " ", false, iPos + 1) != -1) ? (strfind(szParser, " ", false, iPos + 1)) : (strlen(szParser)), sizeof(szResult));
    iPos = (strfind(szParser, " ", false, iPos + 1) != -1) ? (strfind(szParser, " ", false, iPos + 1)) : (strlen(szParser));
    return szResult;
}

/* or this if it won't work

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


public OnPlayerCommandText( playerid, cmdtext[ ] )
{
    new cmd[128], idx;
    cmd = strtok(cmdtext, idx);

    if(strcmp(cmd, "/weather", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            if(PlayerInfo[playerid][pAdminLevel] < 3)
            {
                SendClientMessage(playerid, COLOR_RED, "** you are not authorized to use that command!");
                return 1;
            }
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp))
            {
                SendClientMessage(playerid, COLOR_WHITE, "USAGE: /weather [weatherid]");
                return 1;
            }
            new weather;
            weather = strval(tmp);
            if(weather < 0||weather > 45) { SendClientMessage(playerid, COLOR_RED, "   Weather ID can't be below 0 or above 45!"); return 1; }
            SetWeather(weather);
            format(string, sizeof(string), "[ADMIN] %s has changed everyone's weather to %d.", sendername,weather);
            ABroadCast(COLOR_LIGHTRED,string, 5);
            format(string, sizeof(string), "World's Weather Has Been Changed to %d",weather);
            SendClientMessageToAll(COLOR_GOLD,string);
            DefaultWeather = weather;
        }
        return 1;
    }
    if(strcmp(cmd, "/changeweather", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            if(PlayerInfo[playerid][pAdmin] < changeme)
            {
                SendClientMessage(playerid, COLOR_RED, "You are not authorized to use that command.");
                return 1;
            }
            ChangeWeather();
            format(string, sizeof(string), "[ADMIN]: %s has Forced the Weather Change!.", sendername);
            ABroadCast(COLOR_GOLD,string, 5);
        }
        return 1;
    }
    return 0;
}
Reply
#4

can you recomen any up to date ways havnt scripted in ages i cant even remember the password to my account
Reply
#5

Also, I prefer other command processors than strtok.

More simpler, easier, and also faster. Try y_commands by Y_Less or ZCMD by ZeeX.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)