CanPedBeKnockedOffBike: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Example added from setPedCanBeKnockedOffBike.)
Line 18: Line 18:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function changeCanBeKnockedOff ( command )
function changeCanBeKnockedOff ( command )
    -- The player should enter /knock
-- lets players be knocked off bikes if it was set to false, true otherwise
    if canPedBeKnockedOffBike ( getLocalPlayer() ) then
local bCanBeKnockedOff = canPedBeKnockedOffBike(localPlayer)
        setPedCanBeKnockedOffBike ( getLocalPlayer(), false )
setPedCanBeKnockedOffBike(localPlayer, not bCanBeKnockedOff)
        outputChatBox ( "Now you can't be knocked off your bike." )
    else
-- outputs the respective message
        setPedCanBeKnockedOffBike ( getLocalPlayer(), true )
outputChatBox( ('Now you %s be knocked off your bike.'):format(bCanBeKnockedOff and 'can\'t' or 'can') )
        outputChatBox ( "Now you can be knocked off your bike." )
    end
end
end
addCommandHandler ( "knock", changeCanBeKnockedOff )
addCommandHandler('knock', changeCanBeKnockedOff)
</syntaxhighlight>
</syntaxhighlight>
==See Also==
==See Also==
{{Client_ped_functions}}
{{Client_ped_functions}}

Revision as of 18:58, 4 May 2013

This function checks if the given ped can fall off bikes.

Syntax

bool canPedBeKnockedOffBike ( ped thePed )         

Required Arguments

  • thePed: the ped you want to check.

Returns

Returns true if the ped can be knocked off bikes, false if he cannot or an invalid element was passed.

Example

This example adds a console command with which the local player can toggle if he can fall off bikes.

function changeCanBeKnockedOff ( command )
	-- lets players be knocked off bikes if it was set to false, true otherwise
	local bCanBeKnockedOff = canPedBeKnockedOffBike(localPlayer)
	setPedCanBeKnockedOffBike(localPlayer, not bCanBeKnockedOff)
	
	-- outputs the respective message
	outputChatBox( ('Now you %s be knocked off your bike.'):format(bCanBeKnockedOff and 'can\'t' or 'can') )
end
addCommandHandler('knock', changeCanBeKnockedOff)

See Also