Skip to content

Commit

Permalink
shared: update sdk and add ped events
Browse files Browse the repository at this point in the history
  • Loading branch information
xLuxy committed Sep 22, 2023
1 parent 4a265a1 commit e226e33
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 4 deletions.
2 changes: 1 addition & 1 deletion deps/cpp-sdk
3 changes: 3 additions & 0 deletions server/js/events/ped.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const { Event } = requireBinding("shared/events.js");

Event.register(alt.Enums.EventType.PED_HEAL, "PedHeal");
14 changes: 14 additions & 0 deletions server/src/events/PedEvent.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "Event.h"

// clang-format off
static js::Event pedHealEvent(alt::CEvent::Type::PED_HEAL, [](const alt::CEvent* ev, js::Event::EventArgs& args)
{
auto e = static_cast<const alt::CPedHealEvent*>(ev);

args.Set("ped", e->GetTarget());
args.Set("newHealth", e->GetNewHealth());
args.Set("oldHealth", e->GetOldHealth());

args.Set("newArmour", e->GetNewArmour());
args.Set("oldArmour", e->GetOldArmour());
});
4 changes: 4 additions & 0 deletions shared/js/events/ped.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const { Event } = requireBinding("shared/events.js");

Event.register(alt.Enums.EventType.PED_DEATH, "PedDeath");
Event.register(alt.Enums.EventType.PED_DAMAGE, "PedDamage");
24 changes: 24 additions & 0 deletions shared/src/events/PedEvent.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "Event.h"

// clang-format off
static js::Event pedDeathEvent(alt::CEvent::Type::PED_DEATH, [](const alt::CEvent* ev, js::Event::EventArgs& args)
{
auto e = static_cast<const alt::CPedDeathEvent*>(ev);

args.Set("ped", e->GetTarget());
args.Set("killer", e->GetKiller());
args.Set("weapon", e->GetWeapon());
});

static js::Event pedDamageEvent(alt::CEvent::Type::PED_DAMAGE, [](const alt::CEvent* ev, js::Event::EventArgs& args)
{
auto e = static_cast<const alt::CPedDamageEvent*>(ev);

args.Set("ped", e->GetTarget());
args.Set("attacker", e->GetAttacker());
args.Set("healthDamage", e->GetHealthDamage());
args.Set("armourDamage", e->GetArmourDamage());
args.Set("weapon", e->GetWeapon());
});


22 changes: 22 additions & 0 deletions types/client/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1193,6 +1193,14 @@ declare module "@altv/client" {
export function onVoiceConnectionUpdate(callback: GenericEventCallback<VoiceConnectionEventParameters>): altShared.Events.EventHandler;
export function onceVoiceConnectionUpdate(callback: GenericEventCallback<VoiceConnectionEventParameters>): altShared.Events.EventHandler;

// Ped related events
export function onPedDeath(callback: GenericEventCallback<PedDeathEventParameters>): altShared.Events.EventHandler;
export function oncePedDeath(callback: GenericEventCallback<PedDeathEventParameters>): altShared.Events.EventHandler;

export function onPedDamage(callback: GenericEventCallback<PedDamageEventParameters>): altShared.Events.EventHandler;
export function oncePedDamage(callback: GenericEventCallback<PedDamageEventParameters>): altShared.Events.EventHandler;

// World object related
export function onWorldObjectPositionChange(callback: GenericEventCallback<WorldObjectPositionChangeEventParameters>): altShared.Events.EventHandler;
export function onceWorldObjectPositionChange(callback: GenericEventCallback<WorldObjectPositionChangeEventParameters>): altShared.Events.EventHandler;
export function onWorldObjectStreamIn(callback: GenericEventCallback<WorldObjectStreamInEventParameters>): altShared.Events.EventHandler;
Expand Down Expand Up @@ -1220,6 +1228,20 @@ declare module "@altv/client" {
state: altShared.Enums.VoiceConnectionState;
}

interface PedDeathEventParameters {
ped: Ped;
killer: Entity;
weapon: number;
}

interface PedDamageEventParameters {
ped: Ped;
attacker: Entity;
healthDamage: number;
armourDamage: number;
weapon: number;
}

interface PlayerWeaponShootEventParameters {
weapon: number;
totalAmmo: number;
Expand Down
34 changes: 34 additions & 0 deletions types/server/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,16 @@ declare module "@altv/server" {
export function onPlayerVehicleSeatChange(callback: GenericPlayerEventCallback<PlayerVehicleSeatChangeEventParameters>): altShared.Events.EventHandler;
export function oncePlayerVehicleSeatChange(callback: GenericPlayerEventCallback<PlayerVehicleSeatChangeEventParameters>): altShared.Events.EventHandler;

// Ped related events
export function onPedHeal(callback: GenericEventCallback<PedHealEventParameters>): altShared.Events.EventHandler;
export function oncePedHeal(callback: GenericEventCallback<PedHealEventParameters>): altShared.Events.EventHandler;

export function onPedDeath(callback: GenericEventCallback<PedDeathEventParameters>): altShared.Events.EventHandler;
export function oncePedDeath(callback: GenericEventCallback<PedDeathEventParameters>): altShared.Events.EventHandler;

export function onPedDamage(callback: GenericEventCallback<PedDamageEventParameters>): altShared.Events.EventHandler;
export function oncePedDamage(callback: GenericEventCallback<PedDamageEventParameters>): altShared.Events.EventHandler;

// Vehicle related events
export function onVehicleDestroy(callback: GenericEventCallback<VehicleDestroyEventParameters>): altShared.Events.EventHandler;
export function onceVehicleDestroy(callback: GenericEventCallback<VehicleDestroyEventParameters>): altShared.Events.EventHandler;
Expand Down Expand Up @@ -1199,6 +1209,30 @@ declare module "@altv/server" {
newSeat: number;
}

interface PedHealEventParameters {
readonly ped: Ped;

newHealth: number;
oldHealth: number;

newArmour: number;
oldArmour: number;
}

interface PedDeathEventParameters {
ped: Ped;
killer: Entity;
weapon: number;
}

interface PedDamageEventParameters {
ped: Ped;
attacker: Entity;
healthDamage: number;
armourDamage: number;
weapon: number;
}

interface VehicleDestroyEventParameters {
vehicle: Vehicle;
}
Expand Down
7 changes: 4 additions & 3 deletions types/shared/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1881,7 +1881,6 @@ declare module "@altv/shared" {
STOP_SYNCED_SCENE,
UPDATE_SYNCED_SCENE,

CHECKPOINT_EVENT,
COLSHAPE_EVENT,
PLAYER_ENTER_VEHICLE,
PLAYER_START_ENTER_VEHICLE,
Expand All @@ -1901,8 +1900,6 @@ declare module "@altv/shared" {
CREATE_BASE_OBJECT_EVENT,
REMOVE_BASE_OBJECT_EVENT,

DATA_NODE_RECEIVED_EVENT,

CONSOLE_COMMAND_EVENT,

PLAYER_CHANGE_ANIMATION_EVENT,
Expand Down Expand Up @@ -1938,6 +1935,10 @@ declare module "@altv/shared" {

VOICE_CONNECTION_EVENT,

PED_DAMAGE,
PED_DEATH,
PED_HEAL,

ALL,
SIZE
}
Expand Down

0 comments on commit e226e33

Please sign in to comment.