diff --git a/deps/cpp-sdk b/deps/cpp-sdk index 957a07600..2e9be033b 160000 --- a/deps/cpp-sdk +++ b/deps/cpp-sdk @@ -1 +1 @@ -Subproject commit 957a076008ec5fcf28670da0e7466c0fbfcc5846 +Subproject commit 2e9be033b8902c54779ea8b9da3d185b0771770a diff --git a/server/js/events/ped.js b/server/js/events/ped.js new file mode 100644 index 000000000..b754aa993 --- /dev/null +++ b/server/js/events/ped.js @@ -0,0 +1,3 @@ +const { Event } = requireBinding("shared/events.js"); + +Event.register(alt.Enums.EventType.PED_HEAL, "PedHeal"); diff --git a/server/src/events/PedEvent.cpp b/server/src/events/PedEvent.cpp new file mode 100644 index 000000000..ecda7e697 --- /dev/null +++ b/server/src/events/PedEvent.cpp @@ -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(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()); +}); diff --git a/shared/js/events/ped.js b/shared/js/events/ped.js new file mode 100644 index 000000000..bc53b05db --- /dev/null +++ b/shared/js/events/ped.js @@ -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"); diff --git a/shared/src/events/PedEvent.cpp b/shared/src/events/PedEvent.cpp new file mode 100644 index 000000000..826a6da6d --- /dev/null +++ b/shared/src/events/PedEvent.cpp @@ -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(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(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()); +}); + + diff --git a/types/client/index.d.ts b/types/client/index.d.ts index a377a205a..b0adb7453 100644 --- a/types/client/index.d.ts +++ b/types/client/index.d.ts @@ -1193,6 +1193,14 @@ declare module "@altv/client" { export function onVoiceConnectionUpdate(callback: GenericEventCallback): altShared.Events.EventHandler; export function onceVoiceConnectionUpdate(callback: GenericEventCallback): altShared.Events.EventHandler; + // Ped related events + export function onPedDeath(callback: GenericEventCallback): altShared.Events.EventHandler; + export function oncePedDeath(callback: GenericEventCallback): altShared.Events.EventHandler; + + export function onPedDamage(callback: GenericEventCallback): altShared.Events.EventHandler; + export function oncePedDamage(callback: GenericEventCallback): altShared.Events.EventHandler; + + // World object related export function onWorldObjectPositionChange(callback: GenericEventCallback): altShared.Events.EventHandler; export function onceWorldObjectPositionChange(callback: GenericEventCallback): altShared.Events.EventHandler; export function onWorldObjectStreamIn(callback: GenericEventCallback): altShared.Events.EventHandler; @@ -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; diff --git a/types/server/index.d.ts b/types/server/index.d.ts index 437af01c6..96f06c03f 100644 --- a/types/server/index.d.ts +++ b/types/server/index.d.ts @@ -865,6 +865,16 @@ declare module "@altv/server" { export function onPlayerVehicleSeatChange(callback: GenericPlayerEventCallback): altShared.Events.EventHandler; export function oncePlayerVehicleSeatChange(callback: GenericPlayerEventCallback): altShared.Events.EventHandler; + // Ped related events + export function onPedHeal(callback: GenericEventCallback): altShared.Events.EventHandler; + export function oncePedHeal(callback: GenericEventCallback): altShared.Events.EventHandler; + + export function onPedDeath(callback: GenericEventCallback): altShared.Events.EventHandler; + export function oncePedDeath(callback: GenericEventCallback): altShared.Events.EventHandler; + + export function onPedDamage(callback: GenericEventCallback): altShared.Events.EventHandler; + export function oncePedDamage(callback: GenericEventCallback): altShared.Events.EventHandler; + // Vehicle related events export function onVehicleDestroy(callback: GenericEventCallback): altShared.Events.EventHandler; export function onceVehicleDestroy(callback: GenericEventCallback): altShared.Events.EventHandler; @@ -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; } diff --git a/types/shared/index.d.ts b/types/shared/index.d.ts index 218ddc2ef..3355490a7 100644 --- a/types/shared/index.d.ts +++ b/types/shared/index.d.ts @@ -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, @@ -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, @@ -1938,6 +1935,10 @@ declare module "@altv/shared" { VOICE_CONNECTION_EVENT, + PED_DAMAGE, + PED_DEATH, + PED_HEAL, + ALL, SIZE }