IsPedDucked: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(New page: __NOTOC__ {{Client function}} This function checks if the specified ped is ducked (crouched) or not. ==Syntax== <syntaxhighlight lang="lua">bool isPedDucked ( ped thePed )</syntaxhighlight> ===Required Argume...)
 
mNo edit summary
 
(5 intermediate revisions by 4 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
{{Client function}}
{{Server client function}}
This function checks if the specified [[ped]] is ducked (crouched) or not.
This function checks if the specified [[ped]] is ducked (crouched) or not.


==Syntax==
==Syntax==
<syntaxhighlight lang="lua">bool isPedDucked ( ped thePed )</syntaxhighlight>
<syntaxhighlight lang="lua">bool isPedDucked ( ped thePed )</syntaxhighlight>
{{OOP||[[ped]]:isDucked|ducked}}


===Required Arguments===
===Required Arguments===
Line 13: Line 14:


==Example==
==Example==
<section class="client" name="Client" show="true">
This example checks if a random player is ducked or not, and if so displays a message in the chat box.
This example checks if a random player is ducked or not, and if so displays a message in the chat box.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
local players = getElementsByType ( "player" )
local players = getElementsByType ( "player" )
local randomPlayer = players[math.random(#players)]
local randomPlayer = players[math.random(#players)]
if ( isPlayerDucked ( randomPlayer ) ) then
if isPedDucked ( randomPlayer ) then
outputChatBox ( getPlayerName ( randomPlayer ) .. " is currently crouching." )
outputChatBox ( getPlayerName ( randomPlayer ) .. " is currently crouching." )
end
end
</syntaxhighlight>
</syntaxhighlight>


This example creates a function that lets you toggle the crouching state of a ped.
<syntaxhighlight lang="lua">
function setPedDucked(ped, bool)
local alreadyDucked = isPedDucked(ped)
if (alreadyDucked and not bool) then
setPedControlState(ped, "crouch", true)
setTimer(setPedControlState, 50, 1, ped, "crouch", false)
return true
elseif (not alreadyDucked and bool) then
setPedControlState(ped, "crouch", true)
setTimer(setPedControlState, 50, 1, ped, "crouch", false)
return true
end
return false
end
</syntaxhighlight>
</section>
[[ru:IsPedDucked]]
==See Also==
==See Also==
{{Client_ped_functions}}
{{Ped functions}}

Latest revision as of 23:05, 8 July 2018

This function checks if the specified ped is ducked (crouched) or not.

Syntax

bool isPedDucked ( ped thePed )

OOP Syntax Help! I don't understand this!

Method: ped:isDucked(...)
Variable: .ducked


Required Arguments

  • thePed: The ped to check.

Returns

Returns true if the ped is ducked, false otherwise.

Example

Click to collapse [-]
Client

This example checks if a random player is ducked or not, and if so displays a message in the chat box.

local players = getElementsByType ( "player" )
local randomPlayer = players[math.random(#players)]
if isPedDucked ( randomPlayer ) then
	outputChatBox ( getPlayerName ( randomPlayer ) .. " is currently crouching." )
end

This example creates a function that lets you toggle the crouching state of a ped.

function setPedDucked(ped, bool)
	local alreadyDucked = isPedDucked(ped)
	if (alreadyDucked and not bool) then
		setPedControlState(ped, "crouch", true)
		setTimer(setPedControlState, 50, 1, ped, "crouch", false)
		return true
	elseif (not alreadyDucked and bool) then
		setPedControlState(ped, "crouch", true)
		setTimer(setPedControlState, 50, 1, ped, "crouch", false)
		return true
	end
	return false
end

See Also

Shared