IsPedDoingTask: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Improve example.)
 
Line 16: Line 16:
This example checks if the player who entered the 'doingdriveby' command is doing a drive-by (clientside).
This example checks if the player who entered the 'doingdriveby' command is doing a drive-by (clientside).
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function amIDoingADriveby ()
function checkDriveBy()
     if ( isPedDoingTask ( getLocalPlayer(), "TASK_SIMPLE_GANG_DRIVEBY" ) ) then
     local playerName = getPlayerName(localPlayer)
        outputChatBox ( getPlayerName ( getLocalPlayer() ) .. " is doing a driveby!" )
    local doingDriveBy = isPedDoingTask(localPlayer, "TASK_SIMPLE_GANG_DRIVEBY")
     else
    local driveByStatus = doingDriveBy and "is doing a driveby!" or "is not doing a driveby."
        outputChatBox ( getPlayerName ( getLocalPlayer() ) .. " is not doing a driveby" )
 
    end
     outputChatBox(playerName.." "..driveByStatus)
end
end
addCommandHandler ( "doingdriveby", amIDoingADriveby )
addCommandHandler("doingdriveby", checkDriveBy)
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
{{Client_ped_functions}}
{{Client_ped_functions}}

Latest revision as of 05:24, 26 August 2021

This function checks if the specified ped is carrying out a certain task.

Syntax

bool isPedDoingTask ( ped thePed, string taskName )

Required Arguments

  • thePed: The ped you want to check.
  • taskName: A string containing the name of the task you're checking for.

Returns

Returns true if the player is currently doing the task, false otherwise.

Example

This example checks if the player who entered the 'doingdriveby' command is doing a drive-by (clientside).

function checkDriveBy()
    local playerName = getPlayerName(localPlayer)
    local doingDriveBy = isPedDoingTask(localPlayer, "TASK_SIMPLE_GANG_DRIVEBY")
    local driveByStatus = doingDriveBy and "is doing a driveby!" or "is not doing a driveby."

    outputChatBox(playerName.." "..driveByStatus)
end
addCommandHandler("doingdriveby", checkDriveBy)

See Also