GetPlayerWantedLevel: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
m (fix oop syntax)
 
(8 intermediate revisions by 7 users not shown)
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
This function gets a player's current wanted level. The wanted level is indicated by the amount of stars a player has on the [[HUD]].
{{Server client function}}
This function gets a player's current wanted level. The wanted level is indicated by the amount of stars a player has on the GTA HUD.


==Syntax==  
==Syntax==  
<section name="Server" class="server" show="true">
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
int getPlayerWantedLevel ( player thePlayer )
int getPlayerWantedLevel ( player thePlayer )
</syntaxhighlight>  
</syntaxhighlight>  
 
{{OOP||[[player]]:getWantedLevel|wantedLevel|setPlayerWantedLevel}}
===Required Arguments===  
===Required Arguments===  
*'''thePlayer:''' The player whose wanted level you wish to get
*'''thePlayer:''' The player whose wanted level you wish to get
</section>
<section name="Client" class="client" show="true">
<syntaxhighlight lang="lua">
int getPlayerWantedLevel ( )
</syntaxhighlight>
{{OOP||[[Player]].getWantedLevel||setPlayerWantedLevel}}
</section>


===Returns===
===Returns===
Line 14: Line 23:


==Example==
==Example==
<section name="Example 1: Server" class="server" show="true">
This example finds which players in the server have a wanted level:
This example finds which players in the server have a wanted level:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
local players = getElementsByType ( "player" ) -- get a table of all the players in the server
local players = getElementsByType ( "player" ) -- get a table of all the players in the server
for theKey,thePlayer in players do -- use a generic for loop to step through each player
for theKey,thePlayer in ipairs(players) do -- use a generic for loop to step through each player
   local level = getPlayerWantedLevel ( thePlayer ) -- get the wanted level of the player
   local level = getPlayerWantedLevel ( thePlayer ) -- get the wanted level of the player
   if ( level > 0 ) then -- if the player has any stars, announce it in the chat:
   if ( level > 0 ) then -- if the player has any stars, announce it in the chat:
       outputChatBox ( getClientName ( thePlayer ) .. " has a wanted level of " .. level .. "  stars!" )
       outputChatBox ( getPlayerName ( thePlayer ) .. " has a wanted level of " .. level .. "  stars!" )
   end  
   end  
end
end
</syntaxhighlight>
</syntaxhighlight>
</section>
<section name="Example 2: Client" class="client" show="true">
This script output your wanted level when you type /wanted.
<syntaxhighlight lang="lua">
function outputWantedLevel ()
local wantedLvl = getPlayerWantedLevel ( )
  if wantedLvl == 0 then
      outputChatBox ( "You clean", 0, 255, 0)
  else
      outputChatBox ( "You have "..wantedLvl.." wanted stars!", 255, 0, 0)
  end
end
addCommandHandler ( "wanted", outputWantedLevel )
</syntaxhighlight>
</section>


==See Also==
==See Also==
{{Player functions}}
{{Player functions}}

Latest revision as of 04:15, 29 December 2014

This function gets a player's current wanted level. The wanted level is indicated by the amount of stars a player has on the GTA HUD.

Syntax

Click to collapse [-]
Server
int getPlayerWantedLevel ( player thePlayer )

OOP Syntax Help! I don't understand this!

Method: player:getWantedLevel(...)
Variable: .wantedLevel
Counterpart: setPlayerWantedLevel


Required Arguments

  • thePlayer: The player whose wanted level you wish to get
Click to collapse [-]
Client
int getPlayerWantedLevel ( )

OOP Syntax Help! I don't understand this!

Method: Player.getWantedLevel(...)
Counterpart: setPlayerWantedLevel


Returns

Returns an int from 0 to 6 representing the player's wanted level, false if the player does not exist.

Example

Click to collapse [-]
Example 1: Server

This example finds which players in the server have a wanted level:

local players = getElementsByType ( "player" ) -- get a table of all the players in the server
for theKey,thePlayer in ipairs(players) do -- use a generic for loop to step through each player
   local level = getPlayerWantedLevel ( thePlayer ) -- get the wanted level of the player
   if ( level > 0 ) then -- if the player has any stars, announce it in the chat:
      outputChatBox ( getPlayerName ( thePlayer ) .. " has a wanted level of " .. level .. "  stars!" )
   end 
end
Click to collapse [-]
Example 2: Client

This script output your wanted level when you type /wanted.

function outputWantedLevel ()
local wantedLvl = getPlayerWantedLevel ( )
   if wantedLvl == 0 then
      outputChatBox ( "You clean", 0, 255, 0)
   else
      outputChatBox ( "You have "..wantedLvl.." wanted stars!", 255, 0, 0)
   end
end
addCommandHandler ( "wanted", outputWantedLevel )

See Also