GetPedTask: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (→‎Example: Old example was not working, uploaded a better one)
(add oop syntax)
 
(2 intermediate revisions by one other user not shown)
Line 7: Line 7:
==Syntax==
==Syntax==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
string getPedTask ( ped thePed, string priority, int taskType, [int index = 0] )
string, string, string, string getPedTask ( ped thePed, string priority, int taskType )
</syntaxhighlight>
</syntaxhighlight>
 
{{OOP||[[ped]]:getTask}}
===Required Arguments===
===Required Arguments===
*'''thePed''': The [[ped]] whose task you want to retrieve.
*'''thePed''': The [[ped]] whose task you want to retrieve.
Line 27: Line 27:
***'''4:''' TASK_SECONDARY_PARTIAL_ANIM
***'''4:''' TASK_SECONDARY_PARTIAL_ANIM
***'''5:''' TASK_SECONDARY_IK
***'''5:''' TASK_SECONDARY_IK
===Optional Arguments===
*'''index''': An integer value representing how many sub tasks to go through. -1 to get the simplest task, 0 to get the most complex task.


===Returns===
===Returns===
Returns a string containing the name of a task. See [[list of player tasks]] for valid strings. Returns ''false'' if invalid arguments are specified or if there is no task of the type or index specified.
Returns the name of the most complex task. See [[list of player tasks]] for valid strings. Returns ''false'' if invalid arguments are specified or if there is no task of the type specified.
<br>
{{New feature|3.0110|1.1|
Returns between 1 and 4 strings. The first string contains the name of the most complex task, with simpler sub-tasks being named in the following strings. See [[list of player tasks]] for valid strings. Returns ''false'' if invalid arguments are specified or if there is no task of the type specified.
}}


==Example==
==Example==
This example outputs all the primary and secondary tasks to the chatbox when a player types "/task" in chat or "task" in the console. If there is no task getPedTask will return false and that will be the output.
This example draws the active primary and secondary tasks (including task hierarchy in 1.1) as your local player moves around the world.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function myTask ( commandName, taskType )
function displayMyTask ()
for k=1,4 do
    local x,y = 100,200
local task = getPedTask ( getLocalPlayer(), "primary", k )
    for k=0,4 do
outputChatBox ( "Primary task #"..k.." is "..tostring(task) )
        local a,b,c,d = getPedTask ( getLocalPlayer(), "primary", k )
end
        dxDrawText ( "Primary task #"..k.." is "..tostring(a).." -> "..tostring(b).." -> "..tostring(c).." -> "..tostring(d).." -> ", x, y )
for k=1,5 do
        y = y + 15
local task = getPedTask ( getLocalPlayer(), "secondary", k )
    end
outputChatBox ( "Secondary task #"..k.." is "..tostring(task) )
    y = y + 15
end
    for k=0,5 do
        local a,b,c,d = getPedTask ( getLocalPlayer(), "secondary", k )
        dxDrawText ( "Secondary task #"..k.." is "..tostring(a).." -> "..tostring(b).." -> "..tostring(c).." -> "..tostring(d).." -> ", x, y )  
        y = y + 15
    end
end     
end     
addCommandHandler ( "task", myTask )
addEventHandler ( "onClientRender", root, displayMyTask )
</syntaxhighlight>
</syntaxhighlight>


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

Latest revision as of 21:11, 2 January 2015

This function is used to get any simple or complex task of a certain type for a ped.

It can provide feedback on all tasks relating to a ped. For example, while jumping, getPedSimplestTask will return TASK_SIMPLE_IN_AIR. If you wanted to know specifically if the player has jumped, you would use this function. If you did you will discover that while jumping Primary task 3 is TASK_COMPLEX_JUMP.

Syntax

string, string, string, string getPedTask ( ped thePed, string priority, int taskType )

OOP Syntax Help! I don't understand this!

Method: ped:getTask(...)


Required Arguments

  • thePed: The ped whose task you want to retrieve.
  • priority: A string determining which set of tasks you want to retrieve it from. This must be either "primary" or "secondary".
  • taskType: An integer value representing the task type (or slot) you want to get the task from. Types can be:
    • PRIMARY TASKS
      • 0: TASK_PHYSICAL_RESPONSE
      • 1: TASK_EVENT_RESPONSE_TEMP
      • 2: TASK_EVENT_RESPONSE_NONTEMP
      • 3: TASK_PRIMARY
      • 4: TASK_DEFAULT
    • SECONDARY TASKS
      • 0: TASK_SECONDARY_ATTACK
      • 1: TASK_SECONDARY_DUCK
      • 2: TASK_SECONDARY_SAY
      • 3: TASK_SECONDARY_FACIAL_COMPLEX
      • 4: TASK_SECONDARY_PARTIAL_ANIM
      • 5: TASK_SECONDARY_IK

Returns

Returns the name of the most complex task. See list of player tasks for valid strings. Returns false if invalid arguments are specified or if there is no task of the type specified.
Returns between 1 and 4 strings. The first string contains the name of the most complex task, with simpler sub-tasks being named in the following strings. See list of player tasks for valid strings. Returns false if invalid arguments are specified or if there is no task of the type specified.

Example

This example draws the active primary and secondary tasks (including task hierarchy in 1.1) as your local player moves around the world.

function displayMyTask ()
    local x,y = 100,200
    for k=0,4 do
        local a,b,c,d = getPedTask ( getLocalPlayer(), "primary", k )
        dxDrawText ( "Primary task #"..k.." is "..tostring(a).." -> "..tostring(b).." -> "..tostring(c).." -> "..tostring(d).." -> ", x, y )
        y = y + 15
    end
    y = y + 15
    for k=0,5 do
        local a,b,c,d = getPedTask ( getLocalPlayer(), "secondary", k )
        dxDrawText ( "Secondary task #"..k.." is "..tostring(a).." -> "..tostring(b).." -> "..tostring(c).." -> "..tostring(d).." -> ", x, y )    
        y = y + 15
    end
end    
addEventHandler ( "onClientRender", root, displayMyTask )

See Also