GetRainLevel: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "__NOTOC__ {{Server client function}} ==Syntax== <syntaxhighlight lang="lua"> float getRainLevel() </syntaxhighlight>")
 
(Replace to predefined variables.)
 
(11 intermediate revisions by 5 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
{{Server client function}}
{{Server client function}}
This function is used to get the current rain level.
{{Note|The function will return ''false'' server-side if rain level has not been set before the function is called.}}
==Syntax==
<syntaxhighlight lang="lua">
float getRainLevel( )
</syntaxhighlight>
===Returns===
Returns the rain level as a number.


==Syntax==
==Example==  
<section name="Client" class="client" show="true">
'''Example:''' Sets the rain (So it can detect it) before returning it. (In this case, when resource starts.)
<syntaxhighlight lang="lua">
addEventHandler("onClientResourceStart", resourceRoot, 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">
<syntaxhighlight lang="lua">
float getRainLevel()
addEventHandler("onResourceStart", resourceRoot, 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>
==See Also==
{{World functions}}

Latest revision as of 23:12, 11 January 2023

This function is used to get the current rain level.

[[{{{image}}}|link=|]] Note: The function will return false server-side if rain level has not been set before the function is called.

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", resourceRoot, 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", resourceRoot, 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