DoesPlayerHaveJetPack: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
Line 12: Line 12:


==Example==
==Example==
This examples adds a "jetpack" command in console, which gives and removes jetpacks.
'''Example 1:''' This examples adds a "jetpack" console command, which gives and removes jetpacks.
<syntaxhighlight lang="lua"> [lua]
<syntaxhighlight lang="lua"> [lua]
function consoleJetPack ( player, commandName )
-- Checks whether or not the player has a jetpack, and gives or removes it from the player
if ( not doesPlayerHaveJetPack ( player ) ) then --if the player doesnt have a jetpack
function consoleJetPack ( thePlayer, commandName )
local status = givePlayerJetPack ( player ) --give him one
  if ( not doesPlayerHaveJetPack ( thePlayer ) ) then --if the player doesn't have a jetpack
if ( not status ) then
      local status = givePlayerJetPack ( thePlayer ) --give him one
outputConsole ( "Failed to give jetpack.", player )--tell him if it failed
      if ( not status ) then
end
        outputConsole ( "Failed to give jetpack.", thePlayer )--tell him if it failed
else --otherwise
      end
local status = removePlayerJetPack ( player ) --remove his jetpack
  else
if ( not status ) then
      local status = removePlayerJetPack ( thePlayer ) --remove his jetpack
outputConsole ( "Failed to remove jetpack.", player ) --tell him if it faield
      if ( not status ) then
end
        outputConsole ( "Failed to remove jetpack.", thePlayer ) --tell him if it failed
end
      end
  end
end
end
-- add the function above to handle the "jetpack" command
addCommandHandler ( "jetpack", consoleJetPack )
addCommandHandler ( "jetpack", consoleJetPack )
</syntaxhighlight>
'''Example 2:''' This example provides a check to see if players have a jetpack when they enter a particular marker.
<syntaxhighlight lang="lua"> [lua]
function onWarpMarkerHit(thePlayer, matchingDimension)
  -- check whether the player has a marker and store it in the hasJetPack flag
  local hasJetPack = doesPlayerHaveJetPack(thePlayer)
  if (not hasJetPack) then
      -- warp the player to their destination
      setElementPosition(thePlayer, 428, 124, 10)
  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 it's onMarkerHit event
addEventHandler("onMarkerHit", createMarker(1337, 12, 27, "ring", 1, 255, 255, 0, 255), onWarpMarkerHit)
</syntaxhighlight>
</syntaxhighlight>


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

Revision as of 04:18, 29 July 2007

This function is used to determine whether or not a player has a jetpack.

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

Example 1: This examples adds a "jetpack" console command, which gives and removes jetpacks.

 [lua]
-- 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 )

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

 [lua]
function onWarpMarkerHit(thePlayer, matchingDimension)
   -- check whether the player has a marker and store it in the hasJetPack flag
   local hasJetPack = doesPlayerHaveJetPack(thePlayer)
   if (not hasJetPack) then
      -- warp the player to their destination
      setElementPosition(thePlayer, 428, 124, 10)
   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 it's onMarkerHit event
addEventHandler("onMarkerHit", createMarker(1337, 12, 27, "ring", 1, 255, 255, 0, 255), onWarpMarkerHit)

See Also