GetZoneName: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
Line 22: Line 22:
'''Example 1:''' This example shows you how to return a zone name by doing /loc x y z in the chatbox or just loc x y z in console ( replace x, y and z with the co-ords you wanna check, eg /loc 1200 523 12.3 )
'''Example 1:''' This example shows you how to return a zone name by doing /loc x y z in the chatbox or just loc x y z in console ( replace x, y and z with the co-ords you wanna check, eg /loc 1200 523 12.3 )
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
addCommandHandler("loc", "playerloc")
function playerLoc ( source, command, x, y, z )
function playerloc ( source, command, x, y, z )
   local location = getZoneName ( x, y, z )
   local location = getZoneName ( x, y, z )
   outputChatBox ( "* Location: " ..location, getRootElement(), 0, 255, 255 ) -- Output the zone name
   outputChatBox ( "* Location: " .. location, getRootElement(), 0, 255, 255 ) -- Output the zone name
end
end
addCommandHandler( "loc", playerLoc )
</syntaxhighlight>
</syntaxhighlight>


'''Example 2:''' This example will tell you what zone a specified player is in when the "getloc" console command is used.
'''Example 2:''' This example will tell you what zone a specified player is in when the "getloc" console command is used.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
addCommandHandler("getloc", "getloc") -- add a command "getloc" which initiates "getloc" function
function scriptGetLoc ( source, command, playername ) --when getloc is called
function getloc ( source, command, playername ) --when getloc is called
   local player = getPlayerFromNick(playername)--get the player from nickname
   p = getPlayerFromNick(playername)--get the player from nickname
   if ( player ~= false ) then --if there is a player from the nickname
   if ( p ~= false ) then --if there is a player from the nickname
    local x, y, z = getElementPosition ( player )
     outputChatBox ( playername .. " is at " .. getZoneName(getElementPosition(p)), source ) --announce his zone
    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
end
end
addCommandHandler( "getloc", scriptGetLoc ) -- add a command "getloc" which initiates "getloc" function
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
{{World functions}}
{{World functions}}

Revision as of 14:56, 31 July 2007

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 the city name (eg Las Venturas)

Returns

Returns the string of the zone name

Example

Example 1: This example shows you how to return a zone name by doing /loc x y z in the chatbox or just loc x y z in console ( replace x, y and z with the co-ords you wanna check, eg /loc 1200 523 12.3 )

function playerLoc ( source, command, x, y, z )
  local location = getZoneName ( x, y, z )
  outputChatBox ( "* Location: " .. location, getRootElement(), 0, 255, 255 ) -- Output the zone name
end
addCommandHandler( "loc", playerLoc )

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 player = getPlayerFromNick(playername)--get the player from nickname
  if ( player ~= false ) then --if there is a player from the nickname
    local x, y, z = getElementPosition ( player )
    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 "getloc" function

See Also