UGCProjects/SoloKing/Script/gamemode/Action_ChangeTeamID.lua

48 lines
1.5 KiB
Lua
Raw Normal View History

2025-01-04 23:00:19 +08:00
local Action_ChangeTeamID = {
-- 可配置参数定义参数将显示在Action配置面板
-- 例:
-- MyIntParameter = 0
}
-- 触发器激活时将执行Action的Execute
function Action_ChangeTeamID:Execute(...)
GlobalTickTool:AddTick(self, self.CheckTeamIds, 3);
return true
end
function Action_ChangeTeamID:CheckTeamIds()
local PCs = UGCGameSystem.GetAllPlayerController(false);
local HadChange = false;
UGCLogSystem.LogTree(string.format("[Action_ChangeTeamID:CheckTeamIds] DefaultTeamIds ="), DefaultTeamIds)
for i, PC in pairs(PCs) do
if UE.IsValid(PC) then
local TeamId = DefaultTeamIds[PC.PlayerKey];
local PreTeamId = UGCPlayerControllerSystem.GetTeamID(PC);
if TeamId ~= nil and TeamId ~= PreTeamId then
UGCLogSystem.Log("[Action_ChangeTeamID:CheckTeamIds] 改变队伍 ID PreTeamId = %d, Target TeamId = %d", PreTeamId, TeamId);
UGCTeamSystem.ChangePlayerTeamID(PC.PlayerKey, TeamId);
HadChange = true;
end
end
end
--- 一直调用,直到下一次没问题才结束
if not HadChange and table.getCount(DefaultTeamIds) > 1 then
UGCLogSystem.Log("[Action_ChangeTeamID:CheckTeamIds] 关闭检查")
self:CloseCheckTeamIds();
end
end
function Action_ChangeTeamID:CloseCheckTeamIds()
GlobalTickTool:RemoveTickByOwner(self);
end
--[[
-- 需要勾选Action的EnableTick才会执行Update
-- 触发器激活后将在每个tick执行Action的Update直到self.bEnableActionTick为false
function Action_ChangeTeamID:Update(DeltaSeconds)
end
]]
return Action_ChangeTeamID