GetZoneName

From Multi Theft Auto: Wiki
Revision as of 22:36, 1 February 2021 by Zangomangu (talk | contribs) (Removed old info and added city names)
Jump to navigation Jump to search

This function allows you to retrieve the zone name of a certain location.

Syntax

string getZoneName ( float x, float y, float z, [bool citiesonly=false] )

Required Arguments

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

Optional Arguments

NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use. For more information on optional arguments, see optional arguments.

  • citiesonly: An optional argument to choose if you want to return one of the following city names:
    • Tierra Robada
    • Bone County
    • Las Venturas
    • San Fierro
    • Red County
    • Whetstone
    • Flint County
    • Los Santos

Returns

Returns the string of the zone name

Example

Click to collapse [-]
Server

Example 1: This example returns the player's City & Zone.

function outputPlayerZone(thePlayer)
    -- get the player position
    x, y, z = getElementPosition(thePlayer)
    -- get the player zone
    zone = getZoneName(x, y, z)
    -- get the player city (citiesonly as true)
    city = getZoneName(x, y, z, true)
    -- output to local player's chatbox
    outputChatBox("City: ".. city .." / Zone: ".. zone, thePlayer)
end
addCommandHandler("getloc", outputPlayerZone)

Example 2: This example will tell you what zone a specified player is in when the "getloc" console command is used.

function scriptGetLoc ( source, command, playername ) --when getloc 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 )
    local location = getZoneName ( x, y, z )
	local city = getZoneName ( x, y, z, true )
    outputChatBox ( playername .. " is at " .. location .. " (" .. city .. ")", source ) --announce his zone
  else outputChatBox ( "Player does not exist" )
  end
end
addCommandHandler( "getloc", scriptGetLoc ) -- add a command "getloc" which initiates "scriptGetloc" function

See Also