--�õ����������� function GetTeamPlayerNum(MapID,InstanceID,RoleID) local PlayerNum = 0 local PlayerTeamID = role.IsRoleHaveTeam(MapID,InstanceID,RoleID) if PlayerTeamID == nil or PlayerTeamID == -1 or PlayerTeamID == 4294967295 then PlayerNum = 1 else local Player = {} Player[1], Player[2], Player[3], Player[4], Player[5], Player[6] = role.GetRoleTeamMemID(PlayerTeamID) for i=1, 6 do if Player[i] and Player[i]~= 4294967295 then PlayerNum = PlayerNum + 1 end end end return PlayerNum end -- ����������� function deepcopy(object) local lookup_table = {} local function _copy(object) if type(object) ~= "table" then return object elseif lookup_table[object] then return lookup_table[object] end local new_table = {} lookup_table[object] = new_table for index, value in pairs(object) do new_table[_copy(index)] = _copy(value) end return setmetatable(new_table, getmetatable(object)) end return _copy(object) end -- Weighted random picker. -- Accepts array-like tables such as: { {itemId, count, weight}, ... } -- Also supports { {item_id=..., count=..., weight=...}, ... }. -- Returns the selected entry table (not a copy) or nil if nothing selectable. function GetWeightedRandomItem(items) if type(items) ~= "table" then return nil end local total = 0 local n = #items if n > 0 then for i = 1, n do local it = items[i] if type(it) == "table" then local w = tonumber(it[3] or it.weight) or 1 if w > 0 then total = total + w end end end if total <= 0 then return nil end local r = math.random(total) for i = 1, n do local it = items[i] if type(it) == "table" then local w = tonumber(it[3] or it.weight) or 1 if w > 0 then r = r - w if r <= 0 then return it end end end end return items[n] end -- Fallback for non-array tables. for _, it in pairs(items) do if type(it) == "table" then local w = tonumber(it[3] or it.weight) or 1 if w > 0 then total = total + w end end end if total <= 0 then return nil end local r = math.random(total) for _, it in pairs(items) do if type(it) == "table" then local w = tonumber(it[3] or it.weight) or 1 if w > 0 then r = r - w if r <= 0 then return it end end end end return nil end