Skip to content

Commit 515685a

Browse files
committed
feat(scripting/gameevents): OnPlayerDeath
1 parent 1801687 commit 515685a

File tree

6 files changed

+71
-0
lines changed

6 files changed

+71
-0
lines changed

plugin_files/scripting/includes/swiftly/swiftly.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ void OnBombPickup(Player *player) __attribute__((weak));
7373
void OnMapLoad(const char *mapName) __attribute__((weak));
7474
void OnMapUnload(const char *mapName) __attribute__((weak));
7575
bool OnClientGameMessage(Player *player, int destination, const char *message) __attribute__((weak));
76+
void OnPlayerDeath(Player *player, Player *attacker, Player *assister, bool assistedflash, const char *weapon, bool headshot, short dominated, short revenge, short wipe, short penetrated, bool noreplay, bool noscope, bool thrusmoke, bool attackerblind, float distance, short dmg_health, short dmg_armor, short hitgroup) __attribute__((weak));
7677

7778
extern "C"
7879
{
@@ -299,6 +300,32 @@ extern "C"
299300
OnMapUnload(mapName);
300301
}
301302

303+
void Internal_OnPlayerDeath(int slot, int attacker, int assister, bool assistedflash, const char *weapon, bool headshot, short dominated, short revenge, short wipe, short penetrated, bool noreplay, bool noscope, bool thrusmoke, bool attackerblind, float distance, short dmg_health, short dmg_armor, short hitgroup)
304+
{
305+
if (!OnPlayerDeath)
306+
return;
307+
308+
Player *player = g_playerManager->GetPlayer(slot);
309+
if (player == nullptr)
310+
return;
311+
312+
Player *attackerPlayer = nullptr, *assisterPlayer = nullptr;
313+
if (attacker != -1)
314+
{
315+
attackerPlayer = g_playerManager->GetPlayer(attacker);
316+
if (attackerPlayer == nullptr)
317+
return;
318+
}
319+
if (assister != -1)
320+
{
321+
assisterPlayer = g_playerManager->GetPlayer(assister);
322+
if (assisterPlayer == nullptr)
323+
return;
324+
}
325+
326+
OnPlayerDeath(player, attackerPlayer, assisterPlayer, assistedflash, weapon, headshot, dominated, revenge, wipe, penetrated, noreplay, noscope, thrusmoke, attackerblind, distance, dmg_health, dmg_armor, hitgroup);
327+
}
328+
302329
const char *GetPluginAuthor();
303330
const char *GetPluginVersion();
304331
const char *GetPluginName();

src/components/Plugins/inc/Plugin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const std::string funcsToLoad[] = {
3737
"OnMapLoad",
3838
"OnMapUnload",
3939
"OnClientGameMessage",
40+
"OnPlayerDeath",
4041
};
4142

4243
class Plugin

src/components/Plugins/inc/Scripting.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ typedef bool (*Plugin_OnPlayerChat)(uint32, const char *, bool);
2929
typedef void (*Plugin_OnMapLoad)(const char *);
3030
typedef void (*Plugin_OnMapUnload)(const char *);
3131
typedef bool (*Plugin_OnClientGameMessage)(uint32, int, const char *);
32+
typedef void (*Plugin_OnPlayerDeath)(int, int, int, bool, const char *, bool, short, short, short, short, bool, bool, bool, bool, float, short, short, short);
3233

3334
bool scripting_OnClientChat(CBasePlayerController *controller, const char *text, bool teamonly);
3435
bool scripting_OnClientGameMessage(CBasePlayerController *controller, int destination, const char *text);

src/components/Plugins/src/scripting/GameEvents.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,41 @@ void scripting_OnClientDisconnect(const OnClientDisconnect *e)
4242
}
4343
}
4444

45+
void scripting_PlayerDeath(const PlayerDeath *e)
46+
{
47+
CPlayerSlot slot = e->pEvent->GetPlayerSlot("userid");
48+
CPlayerSlot attacker = e->pEvent->GetPlayerSlot("attacker");
49+
CPlayerSlot assister = e->pEvent->GetPlayerSlot("assister");
50+
bool assistedflash = e->pEvent->GetBool("assistedflash");
51+
std::string weapon = e->pEvent->GetString("weapon");
52+
bool headshot = e->pEvent->GetBool("headshot");
53+
short dominated = e->pEvent->GetInt("dominated");
54+
short revenge = e->pEvent->GetInt("revenge");
55+
short wipe = e->pEvent->GetInt("wipe");
56+
short penetrated = e->pEvent->GetInt("penetrated");
57+
bool noreplay = e->pEvent->GetBool("noreplay");
58+
bool noscope = e->pEvent->GetBool("noscope");
59+
bool thrusmoke = e->pEvent->GetBool("thrusmoke");
60+
bool attackerblind = e->pEvent->GetBool("attackerblind");
61+
float distance = e->pEvent->GetFloat("distance");
62+
short dmg_health = e->pEvent->GetInt("dmg_health");
63+
short dmg_armor = e->pEvent->GetInt("dmg_armor");
64+
short hitgroup = e->pEvent->GetInt("hitgroup");
65+
66+
for (uint32 i = 0; i < plugins.size(); i++)
67+
{
68+
Plugin *plugin = plugins[i];
69+
if (plugin->IsPluginLoaded())
70+
{
71+
void *plugin_OnPlayerDeath = plugin->FetchFunction("Internal_OnPlayerDeath");
72+
if (plugin_OnPlayerDeath)
73+
{
74+
reinterpret_cast<Plugin_OnPlayerDeath>(plugin_OnPlayerDeath)(slot.Get(), attacker.Get(), assister.Get(), assistedflash, weapon.c_str(), headshot, dominated, revenge, wipe, penetrated, noreplay, noscope, thrusmoke, attackerblind, distance, dmg_health, dmg_armor, hitgroup);
75+
}
76+
}
77+
}
78+
}
79+
4580
void scripting_OnClientSpawn(const OnPlayerSpawn *e)
4681
{
4782
CBasePlayerController *controller = (CBasePlayerController *)e->pEvent->GetPlayerController("userid");
@@ -522,6 +557,7 @@ void PluginsComponent::RegisterGameEvents()
522557
gameevents::on<BombExploded>(scripting_BombExploded);
523558
gameevents::on<BombDropped>(scripting_BombDropped);
524559
gameevents::on<BombPickup>(scripting_BombPickup);
560+
gameevents::on<PlayerDeath>(scripting_PlayerDeath);
525561

526562
hooks::on<OnMapLoad>(scripting_OnMapLoad);
527563
hooks::on<OnMapUnload>(scripting_OnMapUnload);

src/events/gameevents.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,9 @@ GAME_EVENT(bomb_dropped)
9292
GAME_EVENT(bomb_pickup)
9393
{
9494
gameevents::emit<BombPickup>(pEvent);
95+
}
96+
97+
GAME_EVENT(player_death)
98+
{
99+
gameevents::emit<PlayerDeath>(pEvent);
95100
}

src/hooks/GameEvents.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ GAMEEVENT_DEFINITION(BombDropped);
3333
GAMEEVENT_DEFINITION(BombPickup);
3434
GAMEEVENT_DEFINITION(BombBeginDefuse);
3535
GAMEEVENT_DEFINITION(BombAbortDefuse);
36+
GAMEEVENT_DEFINITION(PlayerDeath);
3637

3738
typedef std::multimap<const std::type_info *, const std::function<void(const GameEvent *)>> GameEventMap;
3839

0 commit comments

Comments
 (0)