update sdk, fix weapon drop bug, update gamevent struct from hl2sdk

This commit is contained in:
Huoji's
2023-10-11 03:58:34 +08:00
parent 2f654c5d92
commit 79bc2cf89d
11 changed files with 266 additions and 156 deletions

View File

@@ -14,6 +14,7 @@ std::unordered_map<uint32_t, _CallbackNames> callbackNameWithEnumMap{
{hash_32_fnv1a_const("round_start"), _CallbackNames::kOnRoundStart},
{hash_32_fnv1a_const("round_end"), _CallbackNames::kOnRoundEnd},
{hash_32_fnv1a_const("player_hurt"), _CallbackNames::kOnPlayerHurt},
{hash_32_fnv1a_const("player_team"), _CallbackNames::kOnPlayerTeamChange},
};
auto CallBackNameToEnum(const char* name) -> _CallbackNames {
if (name == nullptr) {
@@ -205,4 +206,30 @@ auto luaCall_onPlayerHurt(int userid, int attacker, int health, int armor,
}
});
}
auto luaCall_onPlayerTeamChange(int userid, int team, int oldteam, bool disconnect, bool slient, bool isBot) -> bool {
bool result = false;
ExcuteCallbackInAllLuaVm(_CallbackNames::kOnPlayerTeamChange,
[&](lua_State* luaVm, int refIndex) -> void {
lua_rawgeti(luaVm, LUA_REGISTRYINDEX,
refIndex);
if (lua_isfunction(luaVm, -1)) {
lua_pushinteger(luaVm, userid);
lua_pushinteger(luaVm, team);
lua_pushinteger(luaVm, oldteam);
lua_pushboolean(luaVm, disconnect);
lua_pushboolean(luaVm, slient);
lua_pushboolean(luaVm, isBot);
if (lua_pcall(luaVm, 6, 1, 0) != LUA_OK) {
LOG("Error calling Lua callback: %s\n",
lua_tostring(luaVm, -1));
lua_pop(luaVm, 1);
}
if (lua_isboolean(luaVm, -1)) {
result = lua_toboolean(luaVm, -1);
}
}
});
return result;
}
} // namespace ScriptCallBacks