Weather cmd
#1

When i type /weather i get Unkown command

pawn Код:
}
COMMAND:weather(playerid, params[])
{
    if(AccountInfo[playerid][aAdmin] >= ADMIN_LVL_TRAIN)
    {
        new weather;
        new idx = 0;
        new tmp[32];
        tmp = strtok(params,idx);
        if(!strlen(tmp)) { SendClientMessage(playerid,COLOR_LIGHTRED,"USAGE: /weather [weatherID]"); return 1; }
        if(weather < 0||weather > 45) { SendClientMessage(playerid, COLOR_GREY, "   Weather ID can't be below 0 or above 45!"); return 1; }
        SetWeather(weather);
        gWeather = weather;
        SendClientMessage(playerid, COLOR_GREY, "Weather set to everyone!");
    }
    else
    {

        SendErrorMsg(playerid,"You are not an admin.");
        return 1;

    }
}
Reply
#2

You must return 1.
pawn Код:
COMMAND:weather(playerid, params[])
{
    if(AccountInfo[playerid][aAdmin] >= ADMIN_LVL_TRAIN)
    {
        new weather;
        new idx = 0;
        new tmp[32];
        tmp = strtok(params,idx);
        if(!strlen(tmp)) { SendClientMessage(playerid,COLOR_LIGHTRED,"USAGE: /weather [weatherID]"); return 1; }
        if(weather < 0||weather > 45) { SendClientMessage(playerid, COLOR_GREY, "   Weather ID can't be below 0 or above 45!"); return 1; }
        SetWeather(weather);
        gWeather = weather;
        SendClientMessage(playerid, COLOR_GREY, "Weather set to everyone!");
    }
    else
    {

        SendErrorMsg(playerid,"You are not an admin.");
        return 1;

    }
    return 1;
}
Reply
#3

Quote:
Originally Posted by Necip
Посмотреть сообщение
You must return 1.
pawn Код:
COMMAND:weather(playerid, params[])
{
    if(AccountInfo[playerid][aAdmin] >= ADMIN_LVL_TRAIN)
    {
        new weather;
        new idx = 0;
        new tmp[32];
        tmp = strtok(params,idx);
        if(!strlen(tmp)) { SendClientMessage(playerid,COLOR_LIGHTRED,"USAGE: /weather [weatherID]"); return 1; }
        if(weather < 0||weather > 45) { SendClientMessage(playerid, COLOR_GREY, "   Weather ID can't be below 0 or above 45!"); return 1; }
        SetWeather(weather);
        gWeather = weather;
        SendClientMessage(playerid, COLOR_GREY, "Weather set to everyone!");
    }
    else
    {

        SendErrorMsg(playerid,"You are not an admin.");
        return 1;

    }
    return 1;
}
I am still wondering why you are using the "return 1" 2 times... instead of 1.
Reply
#4

Quote:
Originally Posted by Kikito
Посмотреть сообщение
I am still wondering why you are using the "return 1" 2 times... instead of 1.
Isn't it the same thing?
Reply
#5

ЁTry this


Код:
cmd:weather(playerid, params[])
{
    if(AccountInfo[playerid][aAdmin] >= ADMIN_LVL_TRAIN)
    {
        new weather;
        new idx = 0;
        new tmp[32];
        tmp = strtok(params,idx);
        if(!strlen(tmp)) { SendClientMessage(playerid,COLOR_LIGHTRED,"USAGE: /weather [weatherID]"); return 1; }
        if(weather < 0||weather > 45) { SendClientMessage(playerid, COLOR_GREY, "   Weather ID can't be below 0 or above 45!"); return 1; }
        SetWeather(weather);
        gWeather = weather;
        SendClientMessage(playerid, COLOR_GREEN, "Weather set!");
    }
    else
    {

        SendErrorMsg(playerid,"You are not an admin.");
        return 1;

    }
    return 1;
}

Or if ur using strcmp


Код:
if(strcmp(cmd, "/weather", true) == 0)
	{
	    if(IsPlayerConnected(playerid))
	    {
	        if(PlayerInfo[playerid][pAdmin] < 4) //The Admin level rank to use the command <<< //
			{
			    SendClientMessage(playerid, COLOR_RED, "  You do not have access to this command!");
			    return 1;
			}
			tmp = strtok(cmdtext, idx);
			if(!strlen(tmp))
			{
			    SendClientMessage(playerid, COLOR_WHITE, "{33CCFF}USAGE:{FFFFFF} /weather [weatherid]");
			    return 1;
			}
			new weather;
			weather = strval(tmp);
			if(weather < 0||weather > 150) { SendClientMessage(playerid, COLOR_GREY, "   Weather ID can't be below 0 or above 45!"); return 1; }
			SetWeather(weather);
			SendClientMessage(playerid, COLOR_GREY, "   Weather Set to everyone!");
			GetPlayerName(playerid, sendername, sizeof(sendername));
			if(PlayerInfo[playerid][pAdmin] == 11) { sendername = "Hidden Admin"; }
       		format(string, 256, "AdmWarning: %s has changed the weather to %d.", sendername,weather);
			ABroadCast(COLOR_YELLOW,string,1);
		}
		return 1;
	}
Reply
#6

Quote:
Originally Posted by Necip
Посмотреть сообщение
Isn't it the same thing?
It is going to do the same thing, but it isn't needed to have "return" inside of the if-else statements in this command.
The return outside of the if-else statements is enough to make it work perfectly.
PHP код:
COMMAND:weather(playeridparams[]) {
    if(
AccountInfo[playerid][aAdmin] >= ADMIN_LVL_TRAIN) {
        new 
weatheridx 0tmp[32];
        
tmp strtok(params,idx);
        if(!
strlen(tmp)) { 
            
SendClientMessage(playerid,COLOR_LIGHTRED,"USAGE: /weather [weatherID]"); 
        } else if(
weather 0||weather 45) { 
            
SendClientMessage(playeridCOLOR_GREY"   Weather ID can't be below 0 or above 45!"); 
        } else {
            
SetWeather(weather);
            
gWeather weather;
            
SendClientMessage(playeridCOLOR_GREY"Weather set to everyone!");
        }
    } else {
        
SendClientMessage(playerid,COLOR_LIGHTRED,"You are not an admin.");
    }
    return 
1;

Doesn't that looks better?
There are a few mistakes in the code which i haven't even looked at them, this function even like this isn't going to work.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)