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

Description:

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.


Return Values:

This function does not return any specific values.


GetWeatherEx

Description:

This function returns the actual global weather.


Return Values:

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


SetPlayerWeatherEx

Description:

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.


Return Values:

This function does not return any specific values.


GetPlayerWeatherEx

Description:

This function returns the player's actual weather.


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


Return Values:

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


SetRealWeatherEx

Description:

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.


Return Values:

This function does not return any specific values.


GetRealWeatherEx

Description:

This function returns the actual real weather observer.


Return Values:

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


SetPlayerRealWeatherEx

Description:

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.


Return Values:

This function does not return any specific values.


GetPlayerRealWeatherEx

Description:

This function returns the player's actual weather.


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


Return Values:

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


Real weather

AddWeatherObserver

Description:

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).


Return Values:

The 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

Description:

Removes a weather observer. It will stop all update processes


Parameters:
(observerid)
observeridThe ID to remove.


Return Values:

1 if removed successfully, 0 if not.


Weather zones

AddWeatherZone

Description:

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


Return Values:

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


MoveWeatherZone

Description:

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.


Return Values:

1 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

Description:

Stops the movement of a weather zone


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


Return Values:

1 if it is a valid zone, 0 if not


Callbacks

OnPlayerWeatherZoneChange

Description:

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).


Return Values:

This callback does not handle returns.


OnWeatherZoneMoved

Description:

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.


Return Values:

This callback does not handle returns.


OnRealWeatherUpdate

Description:

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.


Return Values:

This callback does not handle returns.