GetWaterLevel: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Removed old issue)
 
(26 intermediate revisions by 14 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
{{Client function}}  
{{Client function}}  
This function allows you to retrieve the water level from a certain position.
This function allows you to retrieve the water level from a certain location. The water level is 0 in most places though it can vary (e.g. it's higher near the dam).
{{Note|Some small water areas within parts of the city do not count as water to be used with this function. For example, the shallow water area in Northwest San Fierro.}}


==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool float getWaterLevel ( float posX, float posY, float posZ, [ bool checkWaves ] )
float getWaterLevel ( float posX, float posY, float posZ [ , bool ignoreDistanceToWaterThreshold = false ] )
</syntaxhighlight>
<syntaxhighlight lang="lua">
float getWaterLevel ( water theWater )
</syntaxhighlight>
</syntaxhighlight>


Line 13: Line 17:
*'''z:''' The Z axis position
*'''z:''' The Z axis position


===Optional Arguments===
''or:''
{{OptionalArg}}
*'''theWater:''' the water element
* '''checkWaves''': An optional argument to choose if you want to return the height of the waves. ??
 
===Optional Arguments===  
*'''ignoreDistanceToWaterThreshold:''' If set to false, this function returns false, if the difference between water level (without waves) and posZ is greater than 3.0


===Returns===
===Returns===
''I'm not sure what it must return, all I got was ''false'' and ''0''. ??''
Returns an ''integer'' of the water level if the [[localPlayer]]/position is near the water (-3 to 20 on the Z coordinate) else ''false'' if there's no water near the [[localPlayer]]/position.


==Example==
==Example==
This example will tell you what's the water level where the specified player is located. '''NEEDS UPDATING!!!'''
This example will tell you what's the water level where the specified player is located.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function scriptGetLevel ( command, playername ) --when getlevel is called
function scriptGetLevel ( command, playername ) --when getlevel is called
   local thePlayer = getPlayerFromNick ( playername ) --get the player from nickname
   local thePlayer = getPlayerFromName ( playername ) --get the player from nickname
   if ( thePlayer ~= false ) then --if there is a player from the nickname
   if ( thePlayer ~= false ) then --if there is a player from the nickname
  if ( isPlayerInVehicle(thePlayer) ) then
    local x, y, z = getElementPosition ( thePlayer ) -- get his position
  local x, y, z = getElementPosition ( getPlayerOccupiedVehicle ( thePlayer ) )
  else
    local x, y, z = getElementPosition ( player ) -- get his position
    end
     local level = getWaterLevel ( x, y, z )
     local level = getWaterLevel ( x, y, z )
    if ( level ) then
  if level then -- if it's not false
        --outputChatBox ( tostring ( bool ) )
         level = z - level -- calculate how far away is he from the water
         --outputChatBox ( level )
        outputChatBox( "You are " .. level .. " units away from the water!", source )
outputChatBox( "You are " .. level .. " meters away from the water!", source )
  else outputChatBox ( "There's no sign of water" )
    end
  end
   else outputChatBox ( "Player does not exist" )
   else outputChatBox ( "Player does not exist" )
   end
   end
end
end
 
addCommandHandler( "getlevel", scriptGetLevel ) -- add a command "getloc" which
addCommandHandler( "getlevel", scriptGetLevel ) -- add a command "getloc" which  
</syntaxhighlight>
</syntaxhighlight>


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

Latest revision as of 10:19, 30 January 2022

This function allows you to retrieve the water level from a certain location. The water level is 0 in most places though it can vary (e.g. it's higher near the dam).

[[{{{image}}}|link=|]] Note: Some small water areas within parts of the city do not count as water to be used with this function. For example, the shallow water area in Northwest San Fierro.

Syntax

float getWaterLevel ( float posX, float posY, float posZ [ , bool ignoreDistanceToWaterThreshold = false ] )
float getWaterLevel ( water theWater )

Required Arguments

  • x: The X axis position
  • y: The Y axis position
  • z: The Z axis position

or:

  • theWater: the water element

Optional Arguments

  • ignoreDistanceToWaterThreshold: If set to false, this function returns false, if the difference between water level (without waves) and posZ is greater than 3.0

Returns

Returns an integer of the water level if the localPlayer/position is near the water (-3 to 20 on the Z coordinate) else false if there's no water near the localPlayer/position.

Example

This example will tell you what's the water level where the specified player is located.

function scriptGetLevel ( command, playername ) --when getlevel is called
  local thePlayer = getPlayerFromName ( playername ) --get the player from nickname
  if ( thePlayer ~= false ) then --if there is a player from the nickname
    local x, y, z = getElementPosition ( thePlayer ) -- get his position
    local level = getWaterLevel ( x, y, z )
	  if level then -- if it's not false
        level = z - level -- calculate how far away is he from the water
        outputChatBox( "You are " .. level .. " units away from the water!", source )
	  else outputChatBox ( "There's no sign of water" )
	  end
  else outputChatBox ( "Player does not exist" )
  end
end
addCommandHandler( "getlevel", scriptGetLevel ) -- add a command "getloc" which

See Also