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.
<syntaxhighlight lang="lua"> [lua]
<syntaxhighlight lang="lua"> [lua]
addCommandHandler ( "jetpack", "jetPackCommand" )
function consoleJetPack ( player, commandName )
function jetPackCommand ( source, key )
if ( not doesPlayerHaveJetPack ( player ) ) then --if the player doesnt have a jetpack
  if ( doesPlayerHaveJetPack ( source ) ) then -- if he has a jetpack
local status = givePlayerJetPack ( player ) --give him one
    removePlayerJetPack ( source ) -- remove it
if ( not status ) then
  else
outputConsole ( "Failed to give jetpack.", player )--tell him if it failed
    givePlayerJetPack ( source ) -- give him one
end
  end
else --otherwise
local status = removePlayerJetPack ( player ) --remove his jetpack
if ( not status ) then
outputConsole ( "Failed to remove jetpack.", player ) --tell him if it faield
end
end
end
end
addCommandHandler ( "jetpack", consoleJetPack )
</syntaxhighlight>
</syntaxhighlight>


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

Revision as of 23:17, 15 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

This examples adds a "jetpack" command in console, which gives and removes jetpacks.

 [lua]
function consoleJetPack ( player, commandName )
	if ( not doesPlayerHaveJetPack ( player ) ) then --if the player doesnt have a jetpack
		local status = givePlayerJetPack ( player ) --give him one
		if ( not status ) then
			outputConsole ( "Failed to give jetpack.", player )--tell him if it failed
		end
	else --otherwise
		local status = removePlayerJetPack ( player ) --remove his jetpack
		if ( not status ) then
			outputConsole ( "Failed to remove jetpack.", player ) --tell him if it faield
		end
	end
end
addCommandHandler ( "jetpack", consoleJetPack )

See Also

Shared