SA-MP Forums Archive
Weather cmd - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Weather cmd (/showthread.php?tid=449397)



Weather cmd - N0FeaR - 08.07.2013

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;

    }
}



Re: Weather cmd - Necip - 08.07.2013

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



Re: Weather cmd - GWMPT - 08.07.2013

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.


Re: Weather cmd - Necip - 08.07.2013

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?


Yeyeyeye - showarn - 08.07.2013

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



Re: Weather cmd - GWMPT - 08.07.2013

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.