SetWaterLevel: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
(remove deprecated syntax)
 
(24 intermediate revisions by 12 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
{{Client function}}
{{Server client function}}


Sets the height of some or all the water in the game world.
Sets the height of some or all the water in the game world.
{{Note|When the water level is 0, the standard GTA rendering is performed so that water is visible when viewed through translucent surfaces, such as vehicle windows. However, some MTA custom objects placed underwater will appear in front of the water. Setting the water level to any non-zero value (i.e. setWaterLevel(0.001) ) forces alternative rendering and MTA custom objects placed underwater will be drawn correctly.}}
==Syntax==
<syntaxhighlight lang="lua">
bool setWaterLevel ( [ water theWater, ] float level )
</syntaxhighlight>
{{Added feature/item|1.5.9|1.5.8|20716|
<syntaxhighlight lang="lua">
bool setWaterLevel ( float level [, bool includeWaterFeatures = true, bool includeWaterElements = true, bool includeWorldSea = true, bool includeOutsideWorldSea = false ] )
</syntaxhighlight>
}}


==Syntax==
{{OOP||[[water]]:setLevel|level|getWaterLevel}}
<syntaxhighlight lang="lua">bool setWaterLevel ( [float x, float y, float z,] float level )
bool setWaterLevel ( [element water], float level )</syntaxhighlight>


===Required Arguments===
===Required Arguments===
*'''level:''' the new Z coordinate of the water surface. If '''x''', '''y''' and '''z''', or '''water''', are specified, the area of water containing that point or corresponding to that water element is changed. Otherwise, all water in the game world is changed.
*'''level:''' the new Z coordinate of the water surface. All water in the game world is set to this height.
 
===Optional Arguments===
*'''theWater:''' the water element to change.
 
''or:''
{{New feature/item|3.0120|1.2||
*'''includeWaterFeatures :''' a boolean indicating whether to also set the level of water features such as ponds and pools.
*'''includeWaterElements :''' a boolean indicating whether to also set the level of all water elements.
{{Added feature/item|1.5.9|1.5.8|20716|
*'''includeWorldSea :''' a boolean indicating whether to set the level of the sea water
*'''includeOutsideWorldSea:''' a boolean indicating whether to also set the level of sea water outside the world area, ie. outside -3000, 3000.
}}
}}
 
===Returns===
Returns ''true'' if successful, ''false'' in case of failure.


== Alternate client-only syntax ==
<section name="Client only" class="client" show="true">
<syntaxhighlight lang="lua">bool setWaterLevel ( [float x, float y, float z,] float level )</syntaxhighlight>
===Required Arguments===
*'''level:''' the new Z coordinate of the water surface
===Optional Arguments===
===Optional Arguments===
The area of water containing that point or corresponding to that water element is changed.
*'''x:''' the X coordinate of the point indicating the water area to change.
*'''x:''' the X coordinate of the point indicating the water area to change.
*'''y:''' the Y coordinate of the point indicating the water area to change.
*'''y:''' the Y coordinate of the point indicating the water area to change.
*'''z:''' the Z coordinate of the point indicating the water area to change. This parameter is reserved and is currently ignored, set it to 0.
*'''z:''' the Z coordinate of the point indicating the water area to change. This parameter is reserved and is currently ignored, set it to 0.
''or:''
*'''water:''' the water element to change.


===Returns===
===Returns===
Returns ''true'' if successful, ''false'' in case of failure (there is no water at the specified coordinates).
Returns ''true'' if successful, ''false'' in case of failure (there is no water at the specified coordinates).
</section>


==Example==  
==Example==  
Line 32: Line 62:
     setWaterLevel ( level )
     setWaterLevel ( level )
end
end
setTimer ( setWaterLevel, 100, 15000 )
setTimer ( drainSomeWater, 100, 15000 )
</syntaxhighlight>
</section>
<section name="Server" class="server" show="true">
This example code will slowly drain away all rivers and seas.
<syntaxhighlight lang="lua">
local level = 0
 
function drainSomeWater()
    level = level - 0.01
    setWaterLevel ( level )
end
setTimer ( drainSomeWater, 100, 15000 )
</syntaxhighlight>
 
This example code adds a command ''water'' which can be used to change the current water level.
<syntaxhighlight lang="lua">
addCommandHandler ( "water",
    function ( thePlayer, command, level )
        if level and tonumber ( level ) then -- if we have input something and if it is actually a number value
            setWaterLevel ( tonumber( level ) ) -- change the water level
            outputChatBox ( "Waterlevel is now: " .. level ) -- send a message to everyone to inform about the change
        end
    end
)
</syntaxhighlight>
</syntaxhighlight>
</section>
</section>


==See Also==
==See Also==
{{Client world functions}}
{{Client water functions}}

Latest revision as of 23:09, 22 October 2023

Sets the height of some or all the water in the game world.

[[{{{image}}}|link=|]] Note: When the water level is 0, the standard GTA rendering is performed so that water is visible when viewed through translucent surfaces, such as vehicle windows. However, some MTA custom objects placed underwater will appear in front of the water. Setting the water level to any non-zero value (i.e. setWaterLevel(0.001) ) forces alternative rendering and MTA custom objects placed underwater will be drawn correctly.

Syntax

bool setWaterLevel ( [ water theWater, ] float level )
bool setWaterLevel ( float level [, bool includeWaterFeatures = true, bool includeWaterElements = true, bool includeWorldSea = true, bool includeOutsideWorldSea = false ] )


OOP Syntax Help! I don't understand this!

Method: water:setLevel(...)
Variable: .level
Counterpart: getWaterLevel


Required Arguments

  • level: the new Z coordinate of the water surface. All water in the game world is set to this height.

Optional Arguments

  • theWater: the water element to change.

or:

  • includeWaterFeatures : a boolean indicating whether to also set the level of water features such as ponds and pools.
  • includeWaterElements : a boolean indicating whether to also set the level of all water elements.
  • includeWorldSea : a boolean indicating whether to set the level of the sea water
  • includeOutsideWorldSea: a boolean indicating whether to also set the level of sea water outside the world area, ie. outside -3000, 3000.

Returns

Returns true if successful, false in case of failure.

Alternate client-only syntax

Click to collapse [-]
Client only
bool setWaterLevel ( [float x, float y, float z,] float level )

Required Arguments

  • level: the new Z coordinate of the water surface

Optional Arguments

The area of water containing that point or corresponding to that water element is changed.

  • x: the X coordinate of the point indicating the water area to change.
  • y: the Y coordinate of the point indicating the water area to change.
  • z: the Z coordinate of the point indicating the water area to change. This parameter is reserved and is currently ignored, set it to 0.

Returns

Returns true if successful, false in case of failure (there is no water at the specified coordinates).

Example

Click to collapse [-]
Client

This example code will slowly drain away all rivers and seas.

local level = 0

function drainSomeWater()
    level = level - 0.01
    setWaterLevel ( level )
end
setTimer ( drainSomeWater, 100, 15000 )
Click to collapse [-]
Server

This example code will slowly drain away all rivers and seas.

local level = 0

function drainSomeWater()
    level = level - 0.01
    setWaterLevel ( level )
end
setTimer ( drainSomeWater, 100, 15000 )

This example code adds a command water which can be used to change the current water level.

addCommandHandler ( "water",
    function ( thePlayer, command, level )
        if level and tonumber ( level ) then -- if we have input something and if it is actually a number value
            setWaterLevel ( tonumber( level ) ) -- change the water level
            outputChatBox ( "Waterlevel is now: " .. level ) -- send a message to everyone to inform about the change
        end
    end
)

See Also