PlayerWeaponShot: Difference between revisions

From RAGE Multiplayer Wiki
m (category)
m (Readability, parameter definitions and syntax/grammar fixes/updates.)
 
Line 30: Line 30:


{{Parameters}}
{{Parameters}}
* '''targetPosition''': Targetted position, output expects a '''[[Vector3::Vector3|Vector3]]''' type.
* '''targetPosition''': Target's position, output expects a '''[[Vector3::Vector3|Vector3]]''' type.
* '''targetEntity''': Targetted entity, output expects '''any''' type.
* '''targetEntity''': Target's entity, output expects '''any''' type. Returns undefined if no target entity.


{{Example}}
{{Example}}
The example below prints a message in player's screen everytime he shots a weapon.
The example below prints a message to the player's chat every time the player fires a weapon.


<syntaxhighlight lang="javascript">
<syntaxhighlight lang="javascript">

Latest revision as of 19:14, 16 May 2019

This event is called every time a player shoots a weapon.

Client-Side Event

 C#  JavaScript


C# Syntax

public delegate void OnPlayerWeaponShotDelegate(Vector3 targetPos, Player target, CancelEventArgs cancel);

Parameters

  • targetPos - the position of the target, expects RAGE.Vector3
  • target - the target player, expects RAGE.Elements.Player
  • cancel - cancel, expects RAGE.Events.CancelEventArgs

Example

The example below shows a chat message to the client when they shoot a weapon

Events.OnPlayerWeaponShot += OnPlayerWeaponShot;
public void OnPlayerWeaponShot(RAGE.Vector3 targetPos, RAGE.Elements.Player target, RAGE.Events.CancelEventArgs cancel)
{
    RAGE.Chat.Output($"You shot a weapon");
}


JavaScript Syntax

mp.events.add('playerWeaponShot', (targetPosition, targetEntity) => {});

Parameters

  • targetPosition: Target's position, output expects a Vector3 type.
  • targetEntity: Target's entity, output expects any type. Returns undefined if no target entity.

Example

The example below prints a message to the player's chat every time the player fires a weapon.

mp.events.add('playerWeaponShot', (targetPosition, targetEntity) => {
    mp.gui.chat.push('You fired a weapon!');
});