UGCProjects/ProjectTemp_T/Script/gamemode/Action_PlayerExit.lua

53 lines
1.8 KiB
Lua
Raw Normal View History

2025-01-04 23:00:19 +08:00
local Action_PlayerExit = {
PlayerKey = 0;
}
-- 触发器激活时将执行Action的Execute
function Action_PlayerExit:Execute(...)
UGCGameSystem.SendPlayerSettlement(self.PlayerKey);
local PlayerState = UGCGameSystem.GetPlayerStateByPlayerKey(self.PlayerKey)
local PlayerPawn = UGCGameSystem.GetPlayerPawnByPlayerKey(self.PlayerKey)
if PlayerPawn then
PlayerPawn:K2_DestroyActor()
else
UGCLogSystem.LogError("[Action_PlayerExit_Execute] PlayerPawn is nil")
local AllPawn = UGCGameSystem.GetAllPlayerPawn()
local HasNotControlled = false
for k, Pawn in pairs(AllPawn) do
if not Pawn:IsControlled() then
Pawn:K2_DestroyActor()
HasNotControlled = true
end
end
if HasNotControlled == false then UGCLogSystem.LogError("[Action_PlayerExit_Execute] HasNotControlled is false") end
end
if UGCGameSystem.GameState and PlayerState then
UGCLogSystem.Log("[Action_PlayerExit_Execute] PlayerName = "..PlayerState.PlayerName)
local PlayerData = UGCGameSystem.GameState.PlayerDataList[self.PlayerKey]
if PlayerData ~= nil then
PlayerData.IsOffline = true
end
local PlayerNum = #UGCGameSystem.GetAllPlayerState()
if PlayerNum == 0 then
UGCGameSystem.GameState.GameEndTimeStamp = GameplayStatics.GetRealTimeSeconds(self)
UGCGameSystem.SendModeCustomEvent("GameEnd")
end
end
UGCEventSystem.SendEvent(EventEnum.PlayerExit, self.PlayerKey)
return true
end
--[[
-- 需要勾选Action的EnableTick才会执行Update
-- 触发器激活后将在每个tick执行Action的Update直到self.bEnableActionTick为false
function Action_PlayerExit:Update(DeltaSeconds)
end
]]
return Action_PlayerExit