Skip to content

Commit

Permalink
ALTV-640 - add parachuteStateChange event
Browse files Browse the repository at this point in the history
  • Loading branch information
Doxoh committed Jan 18, 2025
1 parent 5c5d679 commit 2504fa1
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 48 deletions.
107 changes: 60 additions & 47 deletions client/src/events/Entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,43 +11,44 @@
#include "cpp-sdk/events/CWeaponDamageEvent.h"
#include "cpp-sdk/events/CEntityHitEntityEvent.h"
#include "cpp-sdk/events/CPlayerBulletHitEvent.h"
#include "cpp-sdk/events/CParachuteStateChangeEvent.h"

#include "cpp-sdk/SDK.h"

using alt::CEvent;
using EventType = CEvent::Type;

V8_EVENT_HANDLER gameEntityCreate(
EventType::GAME_ENTITY_CREATE,
[](V8ResourceImpl* resource, const alt::CEvent* e)
{
CV8ScriptRuntime::Instance().OnEntityStreamIn(static_cast<const alt::CGameEntityCreateEvent*>(e)->GetTarget());
EventType::GAME_ENTITY_CREATE,
[](V8ResourceImpl* resource, const alt::CEvent* e)
{
CV8ScriptRuntime::Instance().OnEntityStreamIn(static_cast<const alt::CGameEntityCreateEvent*>(e)->GetTarget());

return resource->GetLocalHandlers("gameEntityCreate");
},
[](V8ResourceImpl* resource, const alt::CEvent* e, std::vector<v8::Local<v8::Value>>& args)
{
auto ev = static_cast<const alt::CGameEntityCreateEvent*>(e);
v8::Isolate* isolate = resource->GetIsolate();
return resource->GetLocalHandlers("gameEntityCreate");
},
[](V8ResourceImpl* resource, const alt::CEvent* e, std::vector<v8::Local<v8::Value>>& args)
{
auto ev = static_cast<const alt::CGameEntityCreateEvent*>(e);
v8::Isolate* isolate = resource->GetIsolate();

args.push_back(resource->GetOrCreateEntity(ev->GetTarget())->GetJSVal(isolate));
});
args.push_back(resource->GetOrCreateEntity(ev->GetTarget())->GetJSVal(isolate));
});

V8_EVENT_HANDLER gameEntityDestroy(
EventType::GAME_ENTITY_DESTROY,
[](V8ResourceImpl* resource, const alt::CEvent* e)
{
CV8ScriptRuntime::Instance().OnEntityStreamOut(static_cast<const alt::CGameEntityDestroyEvent*>(e)->GetTarget());
EventType::GAME_ENTITY_DESTROY,
[](V8ResourceImpl* resource, const alt::CEvent* e)
{
CV8ScriptRuntime::Instance().OnEntityStreamOut(static_cast<const alt::CGameEntityDestroyEvent*>(e)->GetTarget());

return resource->GetLocalHandlers("gameEntityDestroy");
},
[](V8ResourceImpl* resource, const alt::CEvent* e, std::vector<v8::Local<v8::Value>>& args)
{
auto ev = static_cast<const alt::CGameEntityDestroyEvent*>(e);
v8::Isolate* isolate = resource->GetIsolate();
return resource->GetLocalHandlers("gameEntityDestroy");
},
[](V8ResourceImpl* resource, const alt::CEvent* e, std::vector<v8::Local<v8::Value>>& args)
{
auto ev = static_cast<const alt::CGameEntityDestroyEvent*>(e);
v8::Isolate* isolate = resource->GetIsolate();

args.push_back(resource->GetOrCreateEntity(ev->GetTarget())->GetJSVal(isolate));
});
args.push_back(resource->GetOrCreateEntity(ev->GetTarget())->GetJSVal(isolate));
});

V8_LOCAL_EVENT_HANDLER taskChange(EventType::TASK_CHANGE,
"taskChange",
Expand All @@ -73,16 +74,16 @@ V8_LOCAL_EVENT_HANDLER playerWeaponShoot(EventType::PLAYER_WEAPON_SHOOT_EVENT,
});

V8_LOCAL_EVENT_HANDLER playerBulletHit(EventType::PLAYER_BULLET_HIT_EVENT,
"playerBulletHit",
[](V8ResourceImpl* resource, const alt::CEvent* e, std::vector<v8::Local<v8::Value>>& args)
{
auto ev = static_cast<const alt::CPlayerBulletHitEvent*>(e);
v8::Isolate* isolate = resource->GetIsolate();
"playerBulletHit",
[](V8ResourceImpl* resource, const alt::CEvent* e, std::vector<v8::Local<v8::Value>>& args)
{
auto ev = static_cast<const alt::CPlayerBulletHitEvent*>(e);
v8::Isolate* isolate = resource->GetIsolate();

args.push_back(V8Helpers::JSValue(ev->GetWeapon()));
args.push_back(resource->GetBaseObjectOrNull(ev->GetVictim()));
args.push_back(resource->CreateVector3(ev->GetPosition()));
});
args.push_back(V8Helpers::JSValue(ev->GetWeapon()));
args.push_back(resource->GetBaseObjectOrNull(ev->GetVictim()));
args.push_back(resource->CreateVector3(ev->GetPosition()));
});

V8_LOCAL_EVENT_HANDLER playerWeaponChange(EventType::PLAYER_WEAPON_CHANGE,
"playerWeaponChange",
Expand Down Expand Up @@ -123,21 +124,33 @@ V8_LOCAL_EVENT_HANDLER entityHitEntity(EventType::ENTITY_HIT_ENTITY,
});

V8_LOCAL_EVENT_HANDLER playerStartTalking(EventType::PLAYER_START_TALKING,
"playerStartTalking",
[](V8ResourceImpl* resource, const CEvent* e, std::vector<v8::Local<v8::Value>>& args)
{
auto ev = static_cast<const alt::CPlayerStartTalkingEvent*>(e);
v8::Isolate* isolate = resource->GetIsolate();
"playerStartTalking",
[](V8ResourceImpl* resource, const CEvent* e, std::vector<v8::Local<v8::Value>>& args)
{
auto ev = static_cast<const alt::CPlayerStartTalkingEvent*>(e);
v8::Isolate* isolate = resource->GetIsolate();

args.push_back(resource->GetBaseObjectOrNull(ev->GetPlayer()));
});
args.push_back(resource->GetBaseObjectOrNull(ev->GetPlayer()));
});

V8_LOCAL_EVENT_HANDLER playerStopTalking(EventType::PLAYER_STOP_TALKING,
"playerStopTalking",
[](V8ResourceImpl* resource, const CEvent* e, std::vector<v8::Local<v8::Value>>& args)
{
auto ev = static_cast<const alt::CPlayerStopTalkingEvent*>(e);
v8::Isolate* isolate = resource->GetIsolate();
"playerStopTalking",
[](V8ResourceImpl* resource, const CEvent* e, std::vector<v8::Local<v8::Value>>& args)
{
auto ev = static_cast<const alt::CPlayerStopTalkingEvent*>(e);
v8::Isolate* isolate = resource->GetIsolate();

args.push_back(resource->GetBaseObjectOrNull(ev->GetPlayer()));
});
args.push_back(resource->GetBaseObjectOrNull(ev->GetPlayer()));
});

V8_LOCAL_EVENT_HANDLER parachuteStateChange(EventType::PARACHUTE_STATE_CHANGE,
"parachuteStateChange",
[](V8ResourceImpl* resource, const CEvent* e, std::vector<v8::Local<v8::Value>>& args)
{
auto ev = static_cast<const alt::CParachuteStateChangeEvent*>(e);
v8::Isolate* isolate = resource->GetIsolate();

args.emplace_back(resource->GetBaseObjectOrNull(ev->GetPlayer()));
args.emplace_back(V8Helpers::JSValue(static_cast<int8_t>(ev->GetOldState())));
args.emplace_back(V8Helpers::JSValue(static_cast<int8_t>(ev->GetNewState())));
});
2 changes: 1 addition & 1 deletion shared/deps/cpp-sdk

0 comments on commit 2504fa1

Please sign in to comment.