Mweather

From SA-MP Wiki

Jump to: navigation, search

MWeather is an include that expands the weather functionalities of SA-MP by things like (moving) weather zones, and the ability to set real world weather using yahoo weather. This page explains the functions provided by the MWeather include by User:Mauzen To use the functions, you need to use at least SA-MP server version 0.3b and of course the include that you can get here: http://forum.sa-mp.com/showthread.php?t=181897

Contents

Defines

Real weather observers use the following defines to represent the weather state of their url. Not all are used automatically in the script yet.

#define WEATHER_UNKNOWN    	    0
#define WEATHER_SUNNY	 	    1
#define WEATHER_MOSTLY_SUNNY        2
#define WEATHER_PARTLY_CLOUDY       3
#define WEATHER_MOSTLY_CLOUDY       4
#define WEATHER_CLOUDY              5
#define WEATHER_LIGHT_RAIN          6
#define WEATHER_SHOWERS             7
#define WEATHER_RAIN                8
#define WEATHER_LIGHT_THUNDERSTORM  9
#define WEATHER_THUNDERSTORM        10
#define WEATHER_MIST                11
#define WEATHER_SNOWRAIN            12
#define WEATHER_LIGHT_SNOW          13

General

SetWeatherEx

Use this function to set the server's global weather.


Image:32px-Circle-style-warning.png Important Note: Use this instead of the native SetWeather, or weather will be bugged.


Parameters:
(weatherid)
weatheridWeatherID to set.


ReturnsThis function doesn't return a specific value


GetWeatherEx

This function returns the actual global weather.


ReturnsThe current WeatherID, -1 if a global real weather is set.


SetPlayerWeatherEx

Use this function to set a player's weather.


Image:32px-Circle-style-warning.png Important Note: Use this instead of the native SetPlayerWeather, or weather will be bugged.


Parameters:
(playerid, weatherid)
playeridThe ID of the player to change the weather for.
weatheridWeatherID to set.


ReturnsThis function doesn't return a specific value


GetPlayerWeatherEx

This function returns the player's actual weather.


Parameters:
(playerid)
playeridThe ID of the player to get the weather from.


ReturnsThe current WeatherID for the player, -1 if a real weather is set for the player.


SetRealWeatherEx

Use this function to set the server's global weather from a real weather observer, created before using AddWeatherObserver. The weather is updated everytime the observer gets new data.


Parameters:
(observerid)
observeridThe observerid of a valid real weather observer.


ReturnsThis function doesn't return a specific value


GetRealWeatherEx

This function returns the actual real weather observer.


ReturnsThe current observerid, -1 if a normal global weather is set.


SetPlayerRealWeatherEx

Use this function to set a player's weather from a real weather observer, created before using AddWeatherObserver.


Parameters:
(playerid, observerid)
playeridThe ID of the player to change the weather for.
observeridThe observerid of a valid real weather observer.


ReturnsThis function doesn't return a specific value


GetPlayerRealWeatherEx

This function returns the player's actual weather.


Parameters:
(playerid)
playeridThe ID of the player to get the weather from.


ReturnsThe current observerid for the player, -1 if a normal weather is set.


Real weather

AddWeatherObserver

Creates a weather observer that updates the data for the url every specified milliseconds.


Parameters:
(url[], updatetime)
url[]The link to the wanted position from weather.yahoo.com.
updatetimeInterval in ms in which the weather is checked (10 mins are more than enough for normal use).


ReturnsThe observerid of the created observer, -1 if it could not be added.


Image:32px-Ambox_warning_orange.png Note: To get the URL, go to weather.yahoo.com and search for the town/area you want.

Use the link up to the last slash (e.g. http://weather.yahoo.com/bahrain/capital/manama-1967057/)


Example:

//This example creates a weather observer for Chicago
//and sets it as global weather
public OnGameModeInit()
{
    new chicago = AddWeatherObserver("http://weather.yahoo.com/united-states/illinois/chicago-2379574/", 900000);
    SetRealWeatherEx(chicago);
}

RemoveWeatherObserver

Removes a weather observer. It will stop all update processes


Parameters:
(observerid)
observeridThe ID to remove.


Returns1 if removed successfully, 0 if not.


Weather zones

AddWeatherZone

This creates a weatherzone with the specified size at the given position. It will set the weather (normal or real weather) for every player that enters the zone.


Parameters:
(Float:x, Float:y, Float:z, Float:length, Float:width, Float:height, weatherid, bool:observer)
Float:x/y/zThe center position of the zone.
Float:length/width/heightThe measurement of the zone
weatheridThe WeatherID or a valid observerid of the weather to set in the zone.
observerSet this to false, if weatherid is a samp WeatherID, and to true, if it is an observerid


ReturnsThe ID of the created zone, or -1 if the creation failed.


MoveWeatherZone

Moves a weather zone from its current position to the specified coords.


Parameters:
(zoneid, Float:tox, Float:toy, Float:toz, Float:speed)
zoneidThe ID of the zone to move.
Float:tox/toy/tozThe target position to move to.
Float:speedThe speed in meters/sec (not exactly in current version) the zone moves with.


Returns1 if it is a valid zone, 0 if not


Example:

//This example creates a rain weatherzone which width covers all SA in the north
//and moves it down slowly.
new northsouth;
public OnGameModeInit()
{
    northsouth = AddWeatherZone(0.0, 3000.0, 50.0, 6000.0, 500.0, 100.0, 8, false);
    MoveWeatherZone(northsouth, 0.0, 3000.0, 50.0, 20.0); 
}


StopWeatherZone

Stops the movement of a weather zone


Parameters:
(zoneid)
zoneidThe ID of the zone to stop.


Returns1 if it is a valid zone, 0 if not


Callbacks

OnPlayerWeatherZoneChange

This callback is called, when the weather zone, a player is currently in, changes.


Parameters:
(playerid, oldzone, newzone)
playeridThe ID of the player, who enters/leaves a zone.
oldzoneThe ID of the zone, the player was in previously (-1 means no zone).
newzoneThe ID of the zone, the player is now in (-1 means no zone).


ReturnsThis callback does not handle returns.


OnWeatherZoneMoved

This callback is called, when a weather zone finished its movement. It is not called, when using StopWeatherZone.


Parameters:
(zoneid)
zoneidThe ID of the zone, that stops moving.


ReturnsThis callback does not handle returns.


OnRealWeatherUpdate

This callback is called, when a real weather observer gets new data. It is also called, when the weatherstate did not change.


Parameters:
(observerid, oldstate, newstate)
observeridThe ID of the real weather observer.
oldstateThe previous weather state of the observer.
newstateThe new weather state of the observer.


ReturnsThis callback does not handle returns.
Personal tools