DoesPlayerHaveJetPack: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
m (Changed "DeprecatedWithAlt" template to "Deprecated")
 
(8 intermediate revisions by 6 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
This function is used to determine whether or not a player has a jetpack.
{{Server client function}}
{{Deprecated|doesPedHaveJetPack|}}
 
This function is used to determine whether or not a player has a jetpack. Jetpacks can be given to players using the [[givePlayerJetPack]] function and removed with the [[removePlayerJetPack]] function.


==Syntax==
==Syntax==
Line 12: Line 15:


==Example==
==Example==
This examples adds a "jetpack" command in console, which gives and removes jetpacks.
<section name="Server" class="server" show="true">
<syntaxhighlight lang="lua"> [lua]
'''Example 1:''' This examples adds a "jetpack" console command, which gives or removes a jetpack from the player.
function consoleJetPack ( player, commandName )
<syntaxhighlight lang="lua">
if ( not doesPlayerHaveJetPack ( player ) ) then --if the player doesnt have a jetpack
-- Checks whether or not the player has a jetpack, and gives or removes it from the player
local status = givePlayerJetPack ( player ) --give him one
function consoleJetPack ( thePlayer, commandName )
if ( not status ) then
  if ( not doesPlayerHaveJetPack ( thePlayer ) ) then           -- if the player doesn't have a jetpack
outputConsole ( "Failed to give jetpack.", player )--tell him if it failed
      local status = givePlayerJetPack ( thePlayer )             -- give him one
end
      if ( not status ) then
else --otherwise
        outputConsole ( "Failed to give jetpack.", thePlayer )   -- tell him if it failed
local status = removePlayerJetPack ( player ) --remove his jetpack
      end
if ( not status ) then
  else
outputConsole ( "Failed to remove jetpack.", player ) --tell him if it faield
      local status = removePlayerJetPack ( thePlayer )           -- remove his jetpack
end
      if ( not status ) then
end
        outputConsole ( "Failed to remove jetpack.", thePlayer ) -- tell him if it failed
      end
  end
end
end
-- add the function above to handle the "jetpack" command
addCommandHandler ( "jetpack", consoleJetPack )
addCommandHandler ( "jetpack", consoleJetPack )
</syntaxhighlight>
</syntaxhighlight>
</section>
<section name="Server and client" class="both" show="true">
'''Example 2:''' This example provides a check to see if players have a jetpack when they enter a particular marker.
<syntaxhighlight lang="lua">
function onWarpMarkerHit(thePlayer, matchingDimension)
  -- check whether the player has a jetpack and store it in the hasJetPack flag
  local hasJetPack = doesPlayerHaveJetPack(thePlayer)
  if (not hasJetPack) then
      -- warp the player to their destination
      setElementPosition(thePlayer, 1337, 1337, 50)
  else
      -- tell the player to remove their jetpack
      outputChatBox("You must remove your jetpack to use this marker!", thePlayer)
  end
end
-- create a marker and add the function above to its onMarkerHit event
addEventHandler("onMarkerHit", createMarker(3180, 200, 27), onWarpMarkerHit)
</syntaxhighlight>
</section>


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

Latest revision as of 16:21, 13 February 2015

Emblem-important.png This function is deprecated. This means that its use is discouraged and that it might not exist in future versions.

Please use doesPedHaveJetPack instead.


This function is used to determine whether or not a player has a jetpack. Jetpacks can be given to players using the givePlayerJetPack function and removed with the removePlayerJetPack function.

Syntax

bool doesPlayerHaveJetPack ( player thePlayer )

Required Arguments

  • thePlayer: The player you are checking.

Returns

Returns true if a player has a jetpack, false otherwise.

Example

Click to collapse [-]
Server

Example 1: This examples adds a "jetpack" console command, which gives or removes a jetpack from the player.

-- Checks whether or not the player has a jetpack, and gives or removes it from the player
function consoleJetPack ( thePlayer, commandName )
   if ( not doesPlayerHaveJetPack ( thePlayer ) ) then            -- if the player doesn't have a jetpack
      local status = givePlayerJetPack ( thePlayer )              -- give him one
      if ( not status ) then
         outputConsole ( "Failed to give jetpack.", thePlayer )   -- tell him if it failed
      end
   else
      local status = removePlayerJetPack ( thePlayer )            -- remove his jetpack
      if ( not status ) then
         outputConsole ( "Failed to remove jetpack.", thePlayer ) -- tell him if it failed
      end
   end
end

-- add the function above to handle the "jetpack" command
addCommandHandler ( "jetpack", consoleJetPack )
Click to collapse [-]
Server and client

Example 2: This example provides a check to see if players have a jetpack when they enter a particular marker.

function onWarpMarkerHit(thePlayer, matchingDimension)
   -- check whether the player has a jetpack and store it in the hasJetPack flag
   local hasJetPack = doesPlayerHaveJetPack(thePlayer)
   if (not hasJetPack) then
      -- warp the player to their destination
      setElementPosition(thePlayer, 1337, 1337, 50)
   else
      -- tell the player to remove their jetpack
      outputChatBox("You must remove your jetpack to use this marker!", thePlayer)
   end
end

-- create a marker and add the function above to its onMarkerHit event
addEventHandler("onMarkerHit", createMarker(3180, 200, 27), onWarpMarkerHit)

See Also