GetPedControlState: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
(Example)
Line 14: Line 14:
===Returns===
===Returns===
Returns ''true'' if the ped is pressing the specified control, ''false'' if not or an invalid argument was passed.
Returns ''true'' if the ped is pressing the specified control, ''false'' if not or an invalid argument was passed.
===Example===
<section name="Client" class="client" show="true">
<syntaxhighlight lang="lua">
local controlTable = {"forwards", "backwards", "left", "right", "jump", "crouch"}
function invisibleOnSpawn()
    setElementAlpha (localPlayer, 0)
    checkControlState = setTimer(controlState, 50, 0)
end
addEventHandler ("onClientPlayerSpawn", localPlayer, invisibleOnSpawn)
function controlState()
    for i,control in ipairs(controlTable) do
        local state = getPedControlState(localPlayer, control)
if (state) then
    setElementAlpha (localPlayer, 255)
    if (isTimer(checkControlState)) then
killTimer(checkControlState)
checkControlState = nil
    end
end
    end
end
</syntaxhighlight>
</section>


==See Also==
==See Also==
{{Client ped functions}}
{{Client ped functions}}

Revision as of 12:55, 4 September 2016

Checks whether a ped has a certain control pressed.

Syntax

bool getPedControlState ( ped thePed, string control )

Required Arguments

  • thePed: the ped you want to check.
  • control: the control to get the status of. See control names for a list of valid names.

Returns

Returns true if the ped is pressing the specified control, false if not or an invalid argument was passed.

Example

Click to collapse [-]
Client
local controlTable = {"forwards", "backwards", "left", "right", "jump", "crouch"}

function invisibleOnSpawn()
    setElementAlpha (localPlayer, 0)
    checkControlState = setTimer(controlState, 50, 0)
end
addEventHandler ("onClientPlayerSpawn", localPlayer, invisibleOnSpawn)

function controlState()
    for i,control in ipairs(controlTable) do
        local state = getPedControlState(localPlayer, control)
	if (state) then
	    setElementAlpha (localPlayer, 255)
	    if (isTimer(checkControlState)) then
		killTimer(checkControlState)
		checkControlState = nil
	    end 
	end
    end
end

See Also