Difference between revisions of "IsPlayerMapVisible"

From Multi Theft Auto: Wiki
Jump to: navigation, search
(Example)
(Removed {{Needs Example}})
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
 
{{Client function}}
 
{{Client function}}
{{Needs_Example}}
 
 
This function checks if the local player has their map showing
 
This function checks if the local player has their map showing
  
Line 13: Line 12:
 
<section name="Example 1" class="client" show="true"><syntaxhighlight lang="lua">
 
<section name="Example 1" class="client" show="true"><syntaxhighlight lang="lua">
 
function checkMap()
 
function checkMap()
if isPlayerMapVisible() then -- check if the player has his map visible
+
  local text = (isPlayerMapVisible() and "You are currently viewing your map!") or "Your map is not visible!"
outputChatBox("You are currently viewing your map!", 255, 255, 0) -- output text if it's visible
+
  outputChatBox(text, 255, 255, 0) -- output text  
else
 
outputChatBox("Your map is not visible!", 255, 255, 0) -- output text if it's not visible
 
end
 
 
end
 
end
 
addCommandHandler("map", checkMap) -- add '/map' command to the check
 
addCommandHandler("map", checkMap) -- add '/map' command to the check
Line 24: Line 20:
 
<section name="Example 2" class="client" show="true"><syntaxhighlight lang="lua">
 
<section name="Example 2" class="client" show="true"><syntaxhighlight lang="lua">
 
function showMap()
 
function showMap()
if isPlayerMapVisible() then
+
  if isPlayerMapVisible() then
outputChatBox("Radar closed", 0, 255, 0)
+
      outputChatBox("Radar closed", 0, 255, 0)
forcePlayerMap(false)
+
      forcePlayerMap(false)
else
+
  else
outputChatBox("Viewing radar", 0, 255, 0)
+
      outputChatBox("Viewing radar", 0, 255, 0)
forcePlayerMap(true)
+
      forcePlayerMap(true)
end
+
  end
 
end
 
end
 
addCommandHandler("showmap", showMap)
 
addCommandHandler("showmap", showMap)

Revision as of 20:22, 9 October 2016

This function checks if the local player has their map showing

Syntax

bool isPlayerMapVisible ()

Returns

Returns true if the player has the map visible, false otherwise.

Example

Click to collapse [-]
Example 1
function checkMap()
   local text = (isPlayerMapVisible() and "You are currently viewing your map!") or "Your map is not visible!"
   outputChatBox(text, 255, 255, 0) -- output text 
end
addCommandHandler("map", checkMap) -- add '/map' command to the check
Click to collapse [-]
Example 2
function showMap()
   if isPlayerMapVisible() then
      outputChatBox("Radar closed", 0, 255, 0)
      forcePlayerMap(false)
   else
      outputChatBox("Viewing radar", 0, 255, 0)
      forcePlayerMap(true)
   end
end
addCommandHandler("showmap", showMap)

See Also