完成复活
This commit is contained in:
@@ -12,8 +12,18 @@ struct _luaApi_WeaponInfo {
|
||||
int weaponType;
|
||||
};
|
||||
namespace ScriptApis {
|
||||
auto RunTickCallBack(_GameTickRunTime* timer) -> void {
|
||||
LOG("excute tick function: %d %d \n", timer->m_iLuaCallBackFn,
|
||||
timer->m_iParamIndex);
|
||||
lua_rawgeti(timer->m_luaVm, LUA_REGISTRYINDEX, timer->m_iLuaCallBackFn);
|
||||
lua_rawgeti(timer->m_luaVm, LUA_REGISTRYINDEX, timer->m_iParamIndex);
|
||||
lua_pcall(timer->m_luaVm, 1, 0, 0);
|
||||
luaL_unref(timer->m_luaVm, LUA_REGISTRYINDEX, timer->m_iLuaCallBackFn);
|
||||
luaL_unref(timer->m_luaVm, LUA_REGISTRYINDEX, timer->m_iParamIndex);
|
||||
}
|
||||
auto TimerCallBack(_GameTimer* timer) -> void {
|
||||
LOG("excute timer: %d %d m_bRepeat: %d\n", timer->m_iLuaCallBackFn, timer->m_iParamIndex, timer->m_bRepeat);
|
||||
LOG("excute timer: %d %d m_bRepeat: %d\n", timer->m_iLuaCallBackFn,
|
||||
timer->m_iParamIndex, timer->m_bRepeat);
|
||||
lua_rawgeti(timer->m_luaVm, LUA_REGISTRYINDEX, timer->m_iLuaCallBackFn);
|
||||
lua_rawgeti(timer->m_luaVm, LUA_REGISTRYINDEX, timer->m_iParamIndex);
|
||||
lua_pcall(timer->m_luaVm, 1, 0, 0);
|
||||
@@ -109,8 +119,9 @@ auto luaApi_RespawnPlayer(lua_State* luaVm) -> int {
|
||||
}
|
||||
auto playerController = reinterpret_cast<CCSPlayerController*>(player);
|
||||
auto playerPawn = playerController->m_hPawn().Get<CCSPlayerPawn>();
|
||||
|
||||
playerPawn->m_bRespawning(false);
|
||||
LOG("respawn player: %llx \n", playerPawn);
|
||||
Offset::FnRespawnPlayer(playerPawn);
|
||||
//playerPawn->ForceRespawnPlayer();
|
||||
} while (false);
|
||||
lua_pop(luaVm, 1);
|
||||
return 0;
|
||||
@@ -269,26 +280,57 @@ auto luaApi_GetPlayerCurrentWeaponInfo(lua_State* luaVm) -> _luaApi_WeaponInfo {
|
||||
} while (false);
|
||||
return info;
|
||||
}
|
||||
auto luaApi_CreateTickRunFunction(lua_State* luaVm) -> int {
|
||||
// params:lua_table, callback:function
|
||||
if (!lua_istable(luaVm, 1)) {
|
||||
luaL_error(luaVm, "Parameter 'params' must be a table");
|
||||
return 0;
|
||||
}
|
||||
lua_pushvalue(luaVm, 1); // Duplicate the table for luaL_ref
|
||||
const auto params = luaL_ref(luaVm, LUA_REGISTRYINDEX);
|
||||
|
||||
if (!lua_isfunction(luaVm, 2)) {
|
||||
luaL_error(luaVm, "Parameter 'callback' must be a function");
|
||||
return 0;
|
||||
}
|
||||
lua_pushvalue(luaVm, 2); // Duplicate the function for luaL_ref
|
||||
const auto callback = luaL_ref(luaVm, LUA_REGISTRYINDEX);
|
||||
GameTickRunTime::AddTickFunction(new _GameTickRunTime{
|
||||
.m_luaVm = luaVm,
|
||||
.m_iParamIndex = params,
|
||||
.m_iLuaCallBackFn = callback,
|
||||
});
|
||||
return 0;
|
||||
}
|
||||
auto luaApi_CreateTimer(lua_State* luaVm) -> int {
|
||||
// param: time:float, callback:function, params:lua_table
|
||||
const auto time = lua_tonumber(luaVm, 1);
|
||||
// param: time:float,repeat:bool,preservermapchange:bool,params:lua_table,
|
||||
// callback:function
|
||||
const auto time = luaL_checknumber(luaVm, 1);
|
||||
const auto repeat = lua_toboolean(luaVm, 2);
|
||||
const auto preserveMapChange = lua_toboolean(luaVm, 3);
|
||||
auto timerHandle = 0;
|
||||
do {
|
||||
const auto params = lua_gettable(luaVm, 4);
|
||||
const auto callback = luaL_ref(luaVm, LUA_REGISTRYINDEX);
|
||||
LOG("luaApi_CreateTimer: params: %d callback: %d \n", params, callback);
|
||||
timerHandle = GameTimer::AddTimer(new _GameTimer{
|
||||
.m_flTime = (float)time,
|
||||
.m_bRepeat = (bool)repeat,
|
||||
.m_bPreserveMapChange = (bool)preserveMapChange,
|
||||
.m_luaVm = luaVm,
|
||||
.m_iParamIndex = params,
|
||||
.m_iLuaCallBackFn = callback
|
||||
});
|
||||
} while (false);
|
||||
lua_pop(luaVm, 5);
|
||||
|
||||
if (!lua_istable(luaVm, 4)) {
|
||||
luaL_error(luaVm, "Parameter 'params' must be a table");
|
||||
return 0;
|
||||
}
|
||||
lua_pushvalue(luaVm, 4); // Duplicate the table for luaL_ref
|
||||
const auto params = luaL_ref(luaVm, LUA_REGISTRYINDEX);
|
||||
|
||||
if (!lua_isfunction(luaVm, 5)) {
|
||||
luaL_error(luaVm, "Parameter 'callback' must be a function");
|
||||
return 0;
|
||||
}
|
||||
lua_pushvalue(luaVm, 5); // Duplicate the function for luaL_ref
|
||||
const auto callback = luaL_ref(luaVm, LUA_REGISTRYINDEX);
|
||||
|
||||
auto timerHandle = GameTimer::AddTimer(
|
||||
new _GameTimer{.m_flTime = (float)time,
|
||||
.m_bRepeat = (bool)repeat,
|
||||
.m_bPreserveMapChange = (bool)preserveMapChange,
|
||||
.m_luaVm = luaVm,
|
||||
.m_iParamIndex = params,
|
||||
.m_iLuaCallBackFn = callback});
|
||||
|
||||
lua_pushinteger(luaVm, timerHandle);
|
||||
return 1;
|
||||
}
|
||||
@@ -359,7 +401,7 @@ auto luaApi_SetPlayerTeam(lua_State* luaVm) -> int {
|
||||
break;
|
||||
}
|
||||
auto playerController = reinterpret_cast<CCSPlayerController*>(player);
|
||||
playerController->m_iTeamNum() = team;
|
||||
playerController->m_iTeamNum(team);
|
||||
isSuccess = true;
|
||||
} while (false);
|
||||
lua_pop(luaVm, 2);
|
||||
@@ -401,6 +443,8 @@ auto initFunciton(lua_State* luaVm) -> void {
|
||||
luaApi_SetPlayerArmorValue);
|
||||
lua_register(luaVm, "luaApi_RespawnPlayer", luaApi_RespawnPlayer);
|
||||
lua_register(luaVm, "luaApi_CreateTimer", luaApi_CreateTimer);
|
||||
lua_register(luaVm, "luaApi_CreateTickRunFunction",
|
||||
luaApi_CreateTickRunFunction);
|
||||
lua_register(luaVm, "luaApi_CheckPlayerIsAlive", luaApi_CheckPlayerIsAlive);
|
||||
lua_register(luaVm, "luaApi_GetPlayerTeam", luaApi_GetPlayerTeam);
|
||||
lua_register(luaVm, "luaApi_SetPlayerTeam", luaApi_SetPlayerTeam);
|
||||
|
||||
Reference in New Issue
Block a user