09.12.2013, 12:10
This should work for you:
pawn Код:
#include <a_samp>
#include <zcmd>
new WeatherTimer; //This is the timer that will be used for the weather.
new bool:WeatherDisabled; //Will determine whether the wheather (xD) is running or not.
public OnGameModeInit()
{
WeatherDisabled = false;
WeatherTimer = SetTimerEx("ChangeWeather", 60000, false, "i", random(20)); //First timer when the gamemode is started will be 1 minute long.
SetWeather(1);
return 1;
}
CMD:startweather(playerid, params[])
{
//This will only be restricted to RCON Admins, change !IsPlayerAdmin with your own admin variables.
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFF0000FF, "Only RCON Administrators can use this command.");
if(WeatherDisabled == false) return SendClientMessage(playerid, 0xFF0000FF, "The weather is currently running. Use /stopweather to disable it.");
WeatherDisabled = false;
WeatherTimer = SetTimerEx("ChangeWeather", 1000, false, "i", random(20));
return 1;
}
CMD:stopweather(playerid, params[])
{
//This will only be restricted to RCON Admins, change !IsPlayerAdmin with your own admin variables.
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFF0000FF, "Only RCON Administrators can use this command.");
if(WeatherDisabled == true) return SendClientMessage(playerid, 0xFF0000FF, "The weather is not currently running. Use /startweather to enable it.");
WeatherDisabled = true;
SendClientMessageToAll(0xFFFF00FF, "The weather predictions have stopped, as weather is not expected to change any time soon.");
KillTimer(WeatherTimer);
return 1;
}
forward ChangeWeather(Weather);
public ChangeWeather(Weather)
{
if(WeatherDisabled == true) return 1;
new NextWeather = random(20);
new Time = random(60);
new str[125];
format(str, sizeof(str), "Good Day listeners, the current weather is {00F0F0}%s{FFFF00}. The next weather prediction will be {00F0F0}%s.", GetWeatherName(Weather), GetWeatherName(NextWeather));
SendClientMessageToAll(0xFFFF00FF, str);
WeatherTimer = SetTimerEx("ChangeWeather", (60000 + (Time * 1000)), false, "i", NextWeather);
return 1;
}
stock GetWeatherName(weatherid)
{
new Weathername[12];
switch(weatherid)
{
case 0, 6, 13, 17: Weathername = "Very Sunny";
case 1, 5, 10, 14, 18: Weathername = "Sunny";
case 4, 7, 12, 15: Weathername = "Cloudy";
case 8, 16: Weathername = "Rainy";
case 2, 3: Weathername = "Smoggy";
case 9, 20: Weathername = "Foggy";
case 11: Weathername = "Heatwave";
case 19: Weathername = "Sandstorm";
}
return Weathername;
}