2023-10-01 02:28:13 +08:00
|
|
|
#include "events.h"
|
2023-10-01 22:13:20 +08:00
|
|
|
|
2023-10-01 02:28:13 +08:00
|
|
|
namespace events {
|
2023-10-11 03:58:34 +08:00
|
|
|
auto OnPlayerTeamChangeEevent(IGameEvent* event) -> void {
|
|
|
|
|
GameEventKeySymbol_t userIdNameParams{ "userid" };
|
|
|
|
|
GameEventKeySymbol_t teamNameParams{ "team" };
|
|
|
|
|
GameEventKeySymbol_t oldteamNameParams{ "oldteam" };
|
|
|
|
|
GameEventKeySymbol_t disconnectNameParams{ "disconnect"};
|
|
|
|
|
GameEventKeySymbol_t silentNameParams{ "silent" };
|
|
|
|
|
GameEventKeySymbol_t isbotParams{ "isbot"};
|
|
|
|
|
|
|
|
|
|
const auto PlayerPawn = reinterpret_cast<CCSPlayerPawn*>(
|
|
|
|
|
event->GetPlayerPawn(userIdNameParams));
|
|
|
|
|
if (PlayerPawn == nullptr) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (PlayerPawn->IsBasePlayerController() == false) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const auto Player = PlayerPawn->GetPlayerController();
|
|
|
|
|
if (Player == nullptr) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const auto playerIndex = Player->GetRefEHandle().GetEntryIndex();
|
|
|
|
|
auto team = event->GetInt(teamNameParams);
|
|
|
|
|
auto oldTeam = event->GetInt(oldteamNameParams);
|
|
|
|
|
auto disconnect = event->GetBool(disconnectNameParams);
|
|
|
|
|
auto slient = event->GetBool(silentNameParams);
|
|
|
|
|
auto isBot = event->GetBool(isbotParams);
|
|
|
|
|
if (ScriptCallBacks::luaCall_onPlayerTeamChange(playerIndex, team, oldTeam, disconnect, slient, isBot) == true) {
|
|
|
|
|
event->SetBool(silentNameParams, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-10-08 05:28:41 +08:00
|
|
|
auto OnPlayerHurtEvent(IGameEvent* event) -> void {
|
|
|
|
|
/*
|
|
|
|
|
auto luaCall_onPlayerHurt(int userid, int attacker, int health, int armor,
|
|
|
|
|
const char* weapon, int dmg_health, int dmg_armor,
|
|
|
|
|
int hitgroup) -> void
|
|
|
|
|
*/
|
2023-10-11 03:58:34 +08:00
|
|
|
GameEventKeySymbol_t userIdNameParams{"userid"};
|
|
|
|
|
GameEventKeySymbol_t attackerNameParams{"attacker"};
|
|
|
|
|
GameEventKeySymbol_t healthNameParams{"health"};
|
|
|
|
|
GameEventKeySymbol_t armorNameParams{"armor"};
|
|
|
|
|
GameEventKeySymbol_t weaponNameParams{"weapon"};
|
|
|
|
|
GameEventKeySymbol_t dmg_healthNameParams{"dmg_health"};
|
|
|
|
|
GameEventKeySymbol_t dmg_armorNameParams{"dmg_armor"};
|
|
|
|
|
GameEventKeySymbol_t hitgroupNameParams{"hitgroup"};
|
2023-10-08 05:28:41 +08:00
|
|
|
|
|
|
|
|
const auto victimPawn = reinterpret_cast<CCSPlayerPawn*>(
|
2023-10-11 03:58:34 +08:00
|
|
|
event->GetPlayerPawn(userIdNameParams));
|
2023-10-08 05:28:41 +08:00
|
|
|
const auto attackerPawn = reinterpret_cast<CCSPlayerPawn*>(
|
2023-10-11 03:58:34 +08:00
|
|
|
event->GetPlayerPawn(attackerNameParams));
|
2023-10-08 05:28:41 +08:00
|
|
|
if (victimPawn == nullptr || attackerPawn == nullptr) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (victimPawn->IsBasePlayerController() == false ||
|
|
|
|
|
attackerPawn->IsBasePlayerController() == false) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const auto victim = victimPawn->GetPlayerController();
|
|
|
|
|
const auto attacker = attackerPawn->GetPlayerController();
|
|
|
|
|
if (victim == nullptr || attacker == nullptr) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const auto victimIndex = victim->GetRefEHandle().GetEntryIndex();
|
|
|
|
|
const auto attackerIndex = attacker->GetRefEHandle().GetEntryIndex();
|
|
|
|
|
|
2023-10-11 03:58:34 +08:00
|
|
|
auto health = event->GetInt(healthNameParams);
|
|
|
|
|
auto armor = event->GetInt(armorNameParams);
|
|
|
|
|
auto weapon = event->GetString(weaponNameParams);
|
|
|
|
|
auto dmg_health = event->GetInt(dmg_healthNameParams);
|
|
|
|
|
auto dmg_armor = event->GetInt(dmg_armorNameParams);
|
|
|
|
|
auto hitgroup = event->GetInt(hitgroupNameParams);
|
2023-10-08 11:30:48 +00:00
|
|
|
ScriptCallBacks::luaCall_onPlayerHurt(victimIndex, attackerIndex, health,
|
|
|
|
|
armor, weapon, dmg_health, dmg_armor,
|
2023-10-08 05:28:41 +08:00
|
|
|
hitgroup);
|
|
|
|
|
}
|
2023-10-08 01:56:49 +08:00
|
|
|
auto OnRoundEndEvent(IGameEvent* event) -> void {
|
|
|
|
|
/*
|
|
|
|
|
"winner" "byte" // winner team/user i
|
|
|
|
|
"reason" "byte" // reson why team won
|
|
|
|
|
"message" "string" // end round message
|
|
|
|
|
*/
|
|
|
|
|
|
2023-10-11 03:58:34 +08:00
|
|
|
GameEventKeySymbol_t winnerNameParams{"winner"};
|
|
|
|
|
GameEventKeySymbol_t reasonNameParams{"reason"};
|
|
|
|
|
GameEventKeySymbol_t messageNameParams{"message"};
|
2023-10-08 01:56:49 +08:00
|
|
|
|
2023-10-11 03:58:34 +08:00
|
|
|
const auto message = event->GetString(messageNameParams);
|
|
|
|
|
const auto winner = event->GetInt(winnerNameParams);
|
|
|
|
|
const auto reason = event->GetInt(reasonNameParams);
|
2023-10-08 01:56:49 +08:00
|
|
|
|
|
|
|
|
ScriptCallBacks::luaCall_onRoundEnd(winner, reason, message);
|
|
|
|
|
}
|
|
|
|
|
auto OnRoundStartEvent(IGameEvent* event) -> void {
|
2023-10-11 03:58:34 +08:00
|
|
|
GameEventKeySymbol_t timelimitNameParams{"timelimit"};
|
|
|
|
|
const auto timelimit = event->GetInt(timelimitNameParams);
|
2023-10-08 01:56:49 +08:00
|
|
|
ScriptCallBacks::luaCall_onRoundStart(timelimit);
|
|
|
|
|
}
|
2023-10-06 05:08:40 +08:00
|
|
|
auto OnPlayerSpawnEvent(IGameEvent* event) -> void {
|
2023-10-11 03:58:34 +08:00
|
|
|
GameEventKeySymbol_t userIdNameParams{"userid"};
|
2023-10-06 05:08:40 +08:00
|
|
|
const auto playerPawn = reinterpret_cast<CCSPlayerPawn*>(
|
2023-10-11 03:58:34 +08:00
|
|
|
event->GetPlayerPawn(userIdNameParams));
|
2023-10-06 05:08:40 +08:00
|
|
|
if (playerPawn == nullptr) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const auto player = playerPawn->GetPlayerController();
|
|
|
|
|
if (player == nullptr) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const auto playerIndex = player->GetRefEHandle().GetEntryIndex();
|
|
|
|
|
ScriptCallBacks::luaCall_onPlayerSpawn(playerIndex);
|
|
|
|
|
}
|
2023-10-02 05:03:37 +08:00
|
|
|
auto OnPlayerDeathEvent(IGameEvent* event) -> void {
|
2023-10-11 03:58:34 +08:00
|
|
|
GameEventKeySymbol_t userIdNameParams{"userid"};
|
|
|
|
|
GameEventKeySymbol_t attackerNameParams{"attacker"};
|
|
|
|
|
GameEventKeySymbol_t headshotNameParams{"headshot"};
|
|
|
|
|
|
2023-10-03 00:25:23 +08:00
|
|
|
const auto victimPawn = reinterpret_cast<CCSPlayerPawn*>(
|
2023-10-11 03:58:34 +08:00
|
|
|
event->GetPlayerPawn(userIdNameParams));
|
2023-10-03 00:25:23 +08:00
|
|
|
const auto attackerPawn = reinterpret_cast<CCSPlayerPawn*>(
|
2023-10-11 03:58:34 +08:00
|
|
|
event->GetPlayerPawn(attackerNameParams));
|
|
|
|
|
const auto isHeadShot = event->GetBool(headshotNameParams);
|
2023-10-03 00:25:23 +08:00
|
|
|
if (victimPawn == nullptr || attackerPawn == nullptr) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (victimPawn->IsBasePlayerController() == false ||
|
|
|
|
|
attackerPawn->IsBasePlayerController() == false) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const auto victim = victimPawn->GetPlayerController();
|
|
|
|
|
const auto attacker = attackerPawn->GetPlayerController();
|
|
|
|
|
if (victim == nullptr || attacker == nullptr) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-10-03 04:07:50 +08:00
|
|
|
const auto victimIndex = victim->GetRefEHandle().GetEntryIndex();
|
|
|
|
|
const auto attackerIndex = attacker->GetRefEHandle().GetEntryIndex();
|
2023-10-04 06:01:28 +08:00
|
|
|
ScriptCallBacks::luaCall_onPlayerDeath(victimIndex, attackerIndex,
|
|
|
|
|
isHeadShot);
|
2023-10-10 22:11:01 +08:00
|
|
|
//printf("player[%p] %s kill[%p] %llu\n", attacker, &attacker->m_iszPlayerName(), victim, &victim->m_steamID());
|
2023-10-02 17:31:02 +08:00
|
|
|
}
|
|
|
|
|
auto OnPlayerChat(CCSPlayerController* player, std::string message) -> bool {
|
2023-10-03 00:25:23 +08:00
|
|
|
auto [procesChatSuccess, chatType, chatCtx] =
|
|
|
|
|
SdkTools::ProcessChatString(message);
|
2023-10-02 17:31:02 +08:00
|
|
|
if (procesChatSuccess == false) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2023-10-04 06:01:28 +08:00
|
|
|
return ScriptCallBacks::luaCall_onPlayerSpeak(
|
|
|
|
|
player->GetRefEHandle().GetEntryIndex(), chatType, chatCtx);
|
2023-10-02 05:03:37 +08:00
|
|
|
}
|
2023-10-03 00:25:23 +08:00
|
|
|
auto OnPlayerConnect(int slot, const char* pszName, uint64_t xuid,
|
|
|
|
|
const char* pszNetworkID, const char* pszAddress,
|
|
|
|
|
bool bFakePlayer) -> void {
|
|
|
|
|
const auto PlayerIndex = PlayerSlot_to_EntityIndex(slot);
|
|
|
|
|
ScriptCallBacks::luaCall_onPlayerConnect(PlayerIndex, slot, pszName, xuid,
|
|
|
|
|
pszNetworkID, pszAddress,
|
|
|
|
|
bFakePlayer);
|
|
|
|
|
}
|
|
|
|
|
auto OnPlayerDisconnect(int slot, const char* pszName, uint64_t xuid,
|
|
|
|
|
const char* pszNetworkID, const char* pszAddress,
|
|
|
|
|
bool bFakePlayer) -> void {
|
|
|
|
|
const auto PlayerIndex = PlayerSlot_to_EntityIndex(slot);
|
|
|
|
|
ScriptCallBacks::luaCall_onPlayerDisconnect(PlayerIndex, slot, pszName,
|
|
|
|
|
xuid, pszNetworkID, pszAddress,
|
|
|
|
|
bFakePlayer);
|
|
|
|
|
}
|
2023-10-02 05:03:37 +08:00
|
|
|
} // namespace events
|