Player::taskCombat: Difference between revisions

From RAGE Multiplayer Wiki
(yay)
 
No edit summary
 
Line 1: Line 1:
Makes the specified ped attack the target player.<br>p2 should be 0<br>p3 should be 16
{{ClientsideJsFunction}}
==Syntax==
 
<syntaxhighlight lang="javascript">player.taskCombat(targetPed, p2, p3);</syntaxhighlight>
{{JSContainer|
=== Required Arguments ===
==Summary==
*'''targetPed:''' Ped handle or object
Directs the specified ped to attack a target player. Combat behavior and response can be adjusted using `combatFlags` and `threatResponseFlags`.
*'''p2:''' int
 
*'''p3:''' int
== Syntax ==
===Return value===
*'''Undefined'''
==Example==
<syntaxhighlight lang="javascript">
<syntaxhighlight lang="javascript">
// todo
player.taskCombat(targetPed, combatFlags, threatResponseFlags);
</syntaxhighlight>
</syntaxhighlight>
==See also==
 
== Combat Flags ==
* '''0''': Standard combat behavior
* '''16''': Aggressively pursue and attack the target
* '''33''': Defensive stance, attacks only if provoked
* '''128''': Avoids direct engagement in combat
 
== Threat Response Flags ==
* '''0''': Default threat response
* '''1''': Defensive response, only counters attacks
* '''16''': High aggression, prioritizes combat engagement
* '''256''': Ignores threats, remains passive
 
== Required Arguments ==
* '''targetPed:''' The handle or object of the ped the player will attack.
* '''combatFlags:''' {{RageType|int}} - Adjusts how the attacker engages the target.
* '''threatResponseFlags:''' {{RageType|int}} - Modifies how the attacker reacts to threats.
 
=== Return Value ===
* '''undefined''' - This function does not return a value.
 
== Example ==
In this example, an NPC is spawned and instructed to engage the nearest player using specific combat settings.
 
<syntaxhighlight lang="javascript">
const targetPlayer = mp.players.local; // Get the local player as the target (example)
const npc = mp.peds.new(mp.game.joaat('mp_m_freemode_01'),targetPlayer.position, 0, 0); // Create a freemode ped at a position
 
if (targetPlayer) {
    npc.taskCombat(targetPlayer.handle, 16, 16); // Task NPC to aggressively pursue and engage the player
    mp.gui.chat.push(`NPC is now engaging in combat with ${targetPlayer.name}`);
} else {
    mp.gui.chat.push("Target player not found.");
}
</syntaxhighlight>
}}
== See Also ==
{{Player_function_c}}
{{Player_function_c}}
[[Category:Clientside API]]
[[Category:Clientside API]]
[[Category:TODO: Example]]
[[Category:TODO: Example]]

Latest revision as of 13:15, 11 November 2024

Client-Side
Function

 JavaScript



JavaScript Syntax

Summary

Directs the specified ped to attack a target player. Combat behavior and response can be adjusted using `combatFlags` and `threatResponseFlags`.

Syntax

player.taskCombat(targetPed, combatFlags, threatResponseFlags);

Combat Flags

  • 0: Standard combat behavior
  • 16: Aggressively pursue and attack the target
  • 33: Defensive stance, attacks only if provoked
  • 128: Avoids direct engagement in combat

Threat Response Flags

  • 0: Default threat response
  • 1: Defensive response, only counters attacks
  • 16: High aggression, prioritizes combat engagement
  • 256: Ignores threats, remains passive

Required Arguments

  • targetPed: The handle or object of the ped the player will attack.
  • combatFlags: int - Adjusts how the attacker engages the target.
  • threatResponseFlags: int - Modifies how the attacker reacts to threats.

Return Value

  • undefined - This function does not return a value.

Example

In this example, an NPC is spawned and instructed to engage the nearest player using specific combat settings.

const targetPlayer = mp.players.local; // Get the local player as the target (example)
const npc = mp.peds.new(mp.game.joaat('mp_m_freemode_01'),targetPlayer.position, 0, 0); // Create a freemode ped at a position

if (targetPlayer) {
    npc.taskCombat(targetPlayer.handle, 16, 16); // Task NPC to aggressively pursue and engage the player
    mp.gui.chat.push(`NPC is now engaging in combat with ${targetPlayer.name}`);
} else {
    mp.gui.chat.push("Target player not found.");
}


See Also