GetRainLevel: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
(6 intermediate revisions by one other user not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
{{Server client function}}
{{Server client function}}
{{Needs Example}}
This function is used to get the current rain level.
This function is used to get the current rain level.


Line 16: Line 15:
==Example==  
==Example==  
<section name="Client" class="client" show="true">
<section name="Client" class="client" show="true">
todo
'''Example:''' Sets the rain (So it can detect it) before returning it. (In this case, when resource starts.)
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
--todo
addEventHandler("onClientResourceStart", getResourceRootElement(), function()
setRainLevel(math.random(5))
end)
function returnRain()
local rain = getRainlevel()
if(rain >= 1) then
outputChatBox("Looks like it's going to be a rainy day!",255,130,130,false)
else
outputChatBox("Surprisingly dry!",255,130,130,false)
end
end
addCommandHandler("rain", returnRain)
</syntaxhighlight>
</section>
 
<section name="Server" class="server" show="true">
'''Example:''' Sets the rain (So it can detect it) before returning it. (In this case, when resource starts.)
<syntaxhighlight lang="lua">
addEventHandler("onResourceStart", getResourceRootElement(), function()
setRainLevel(math.random(5))
end)
 
function returnRain(player)
local rain = getRainlevel()
if(rain >= 1) then
outputChatBox("Looks like it's going to be a rainy day!",player,255,130,130,false)
else
outputChatBox("Surprisingly dry!",player,255,130,130,false)
end
end
addCommandHandler("rain", returnRain)
</syntaxhighlight>
</syntaxhighlight>
</section>
</section>

Revision as of 16:36, 11 February 2015

This function is used to get the current rain level.

Note: The server can only return the rain level if it has actually been set by script, otherwise it will return false.

Syntax

float getRainLevel( )

Returns

Returns the rain level as a number.

Example

Click to collapse [-]
Client

Example: Sets the rain (So it can detect it) before returning it. (In this case, when resource starts.)

addEventHandler("onClientResourceStart", getResourceRootElement(), function()
	setRainLevel(math.random(5))
end)
function returnRain()
	local rain = getRainlevel()
	if(rain >= 1) then
		outputChatBox("Looks like it's going to be a rainy day!",255,130,130,false)
	else
		outputChatBox("Surprisingly dry!",255,130,130,false)
	end
end
addCommandHandler("rain", returnRain)
Click to collapse [-]
Server

Example: Sets the rain (So it can detect it) before returning it. (In this case, when resource starts.)

addEventHandler("onResourceStart", getResourceRootElement(), function()
	setRainLevel(math.random(5))
end)

function returnRain(player)
	local rain = getRainlevel()
	if(rain >= 1) then
		outputChatBox("Looks like it's going to be a rainy day!",player,255,130,130,false)
	else
		outputChatBox("Surprisingly dry!",player,255,130,130,false)
	end
end
addCommandHandler("rain", returnRain)

See Also