UGCProjects/SoloKing/Script/gamemode/Action_PlayerLeave.lua
2025-01-04 23:00:19 +08:00

44 lines
1.5 KiB
Lua
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

local Action_PlayerLeave = {
PlayerKey = 0;
ExitPlayer = {};
}
-- 触发器激活时将执行Action的Execute
function Action_PlayerLeave:Execute(...)
-- 检查是否是玩家,而不是观察者
if type(self.ExitPlayer) == 'userdata' then
UGCLogSystem.Log("[Action_PlayerLeave:Execute] ExitPlayer = %s", UE.GetName(self.ExitPlayer));
if self.ExitPlayer:IsPureSpectator() then
return true;
end
else
local PC = UGCGameSystem.GetPlayerControllerByPlayerKey(self.PlayerKey)
if PC and UE.IsValid(PC) then
-- 不让他有操作
if PC:IsPureSpectator() or PC:IsFriendObserver() then return true; end
end
end
UGCLogSystem.Log("[Action_PlayerLeave:Execute] PlayerKey = %s", tostring(self.PlayerKey));
-- 保存 ArchiveData
table.func(MiniManager, "OnPlayerLeave", self.PlayerKey);
--- 玩家掉线。服务器客户端都是这样执行
GameState.PlayerDisconnect[self.PlayerKey] = true;
UGCLogSystem.Log("[Action_PlayerLeave:Execute] 发送结束协议 PlayerKey = %s", tostring(self.PlayerKey));
local Success = UGCGameSystem.SendPlayerSettlement(self.PlayerKey);
UGCLogSystem.Log("[Action_PlayerLeave:Execute] 执行是否成功:%s", Success)
UE.CloseServer();
UGCLogSystem.Log("[Action_PlayerLeave:Execute] 玩家退出");
return true;
end
--[[
-- 需要勾选Action的EnableTick才会执行Update
-- 触发器激活后将在每个tick执行Action的Update直到self.bEnableActionTick为false
function Action_PlayerLeave:Update(DeltaSeconds)
end
]]
return Action_PlayerLeave;