mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-01-08 00:39:30 +02:00
team manager added
This commit is contained in:
parent
8ed81a5ae4
commit
5706dea11c
@ -175,6 +175,7 @@ local function on_player_joined_game(event)
|
||||
if player.gui.left["map_pregen"] then player.gui.left["map_pregen"].destroy() end
|
||||
|
||||
if player.online_time == 0 then
|
||||
player.force = game.forces.spectator
|
||||
if surface.is_chunk_generated({0,0}) then
|
||||
player.teleport(surface.find_non_colliding_position("character", {0,0}, 3, 0.5), surface)
|
||||
else
|
||||
@ -182,7 +183,7 @@ local function on_player_joined_game(event)
|
||||
end
|
||||
player.character.destructible = false
|
||||
game.permissions.get_group("spectator").add_player(player)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function on_init(surface)
|
||||
@ -202,4 +203,5 @@ require "maps.biter_battles_v2.no_turret_creep"
|
||||
require "maps.biter_battles_v2.chat"
|
||||
require "maps.biter_battles_v2.bb_map_intro"
|
||||
require "maps.biter_battles_v2.difficulty_vote"
|
||||
require "maps.biter_battles_v2.team_manager"
|
||||
require "modules.custom_death_messages"
|
@ -10,7 +10,7 @@ local difficulties = {
|
||||
[7] = {name = "Insane", str = "300%", value = 3, color = {r=0.45, g=0.00, b=0.00}, print_color = {r=0.9, g=0.0, b=0.00}}
|
||||
}
|
||||
|
||||
local timeout = 54000
|
||||
local timeout = 18000
|
||||
|
||||
local function difficulty_gui()
|
||||
for _, player in pairs(game.connected_players) do
|
||||
|
@ -43,33 +43,6 @@ local function create_sprite_button(player)
|
||||
button.style.bottom_padding = 2
|
||||
end
|
||||
|
||||
local function create_team_lock_gui(player)
|
||||
if player.gui.top["bb_team_lock_button"] then player.gui.top["bb_team_lock_button"].destroy() end
|
||||
|
||||
if player.admin == false and global.teams_are_locked ~= true then return end
|
||||
|
||||
local caption = "Unlocked"
|
||||
local color = {r = 0.33, g = 0.77, b = 0.33}
|
||||
local width = 68
|
||||
local tooltip = "Lock teams to disable joining"
|
||||
if global.teams_are_locked then
|
||||
caption = "Teams Locked"
|
||||
color = {r = 0.77, g = 0.33, b = 0.33}
|
||||
width = 100
|
||||
tooltip = "An admin has locked the teams, joining is currently disabled"
|
||||
end
|
||||
|
||||
local button = player.gui.top.add({type = "sprite-button", name = "bb_team_lock_button", caption = caption, tooltip = tooltip})
|
||||
button.style.font = "heading-2"
|
||||
button.style.font_color = color
|
||||
button.style.minimal_height = 38
|
||||
button.style.minimal_width = width
|
||||
button.style.top_padding = 2
|
||||
button.style.left_padding = 0
|
||||
button.style.right_padding = 0
|
||||
button.style.bottom_padding = 2
|
||||
end
|
||||
|
||||
local function create_first_join_gui(player)
|
||||
if not global.game_lobby_timeout then global.game_lobby_timeout = 5999940 end
|
||||
if global.game_lobby_timeout - game.tick < 0 then global.game_lobby_active = false end
|
||||
@ -116,7 +89,12 @@ local function create_main_gui(player)
|
||||
if player.gui.left["bb_main_gui"] then player.gui.left["bb_main_gui"].destroy() end
|
||||
|
||||
if global.bb_game_won_by_team then return end
|
||||
if player.force.name == "player" then create_first_join_gui(player) return end
|
||||
if not global.chosen_team[player.name] then
|
||||
if not global.tournament_mode then
|
||||
create_first_join_gui(player)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local frame = player.gui.left.add { type = "frame", name = "bb_main_gui", direction = "vertical" }
|
||||
|
||||
@ -211,10 +189,11 @@ local function refresh_gui()
|
||||
end
|
||||
end
|
||||
|
||||
local function join_team(player, force_name)
|
||||
function join_team(player, force_name, forced_join)
|
||||
if not player.character then return end
|
||||
if global.teams_are_locked then player.print("The Teams are currently locked.", {r = 0.98, g = 0.66, b = 0.22}) return end
|
||||
|
||||
if not forced_join then
|
||||
if global.tournament_mode then player.print("The game is set to tournament mode. Teams can only be changed via team manager.", {r = 0.98, g = 0.66, b = 0.22}) return end
|
||||
end
|
||||
if not force_name then return end
|
||||
local surface = player.surface
|
||||
|
||||
@ -222,21 +201,25 @@ local function join_team(player, force_name)
|
||||
if force_name == "south" then enemy_team = "north" end
|
||||
|
||||
if bb_config.team_balancing then
|
||||
if #game.forces[force_name].connected_players > #game.forces[enemy_team].connected_players then
|
||||
if not global.chosen_team[player.name] then
|
||||
player.print("Team " .. force_name .. " has too many players currently.", {r = 0.98, g = 0.66, b = 0.22})
|
||||
return
|
||||
if not forced_join then
|
||||
if #game.forces[force_name].connected_players > #game.forces[enemy_team].connected_players then
|
||||
if not global.chosen_team[player.name] then
|
||||
player.print("Team " .. force_name .. " has too many players currently.", {r = 0.98, g = 0.66, b = 0.22})
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if global.chosen_team[player.name] then
|
||||
if game.tick - global.spectator_rejoin_delay[player.name] < 3600 then
|
||||
player.print(
|
||||
"Not ready to return to your team yet. Please wait " .. 60-(math.floor((game.tick - global.spectator_rejoin_delay[player.name])/60)) .. " seconds.",
|
||||
{r = 0.98, g = 0.66, b = 0.22}
|
||||
)
|
||||
return
|
||||
if global.chosen_team[player.name] then
|
||||
if not forced_join then
|
||||
if game.tick - global.spectator_rejoin_delay[player.name] < 3600 then
|
||||
player.print(
|
||||
"Not ready to return to your team yet. Please wait " .. 60-(math.floor((game.tick - global.spectator_rejoin_delay[player.name])/60)) .. " seconds.",
|
||||
{r = 0.98, g = 0.66, b = 0.22}
|
||||
)
|
||||
return
|
||||
end
|
||||
end
|
||||
local p = surface.find_non_colliding_position("character", game.forces[force_name].get_spawn_position(surface), 8, 0.5)
|
||||
player.teleport(p, surface)
|
||||
@ -253,7 +236,9 @@ local function join_team(player, force_name)
|
||||
player.force = game.forces[force_name]
|
||||
player.character.destructible = true
|
||||
game.permissions.get_group("Default").add_player(player)
|
||||
game.print(player.name .. " has joined team " .. player.force.name .. "!", {r = 0.98, g = 0.66, b = 0.22})
|
||||
if not forced_join then
|
||||
game.print(player.name .. " has joined team " .. player.force.name .. "!", {r = 0.98, g = 0.66, b = 0.22})
|
||||
end
|
||||
local i = player.get_inventory(defines.inventory.character_main)
|
||||
i.clear()
|
||||
player.insert {name = 'pistol', count = 1}
|
||||
@ -265,42 +250,22 @@ local function join_team(player, force_name)
|
||||
refresh_gui()
|
||||
end
|
||||
|
||||
local function spectate(player)
|
||||
function spectate(player, forced_join)
|
||||
if not player.character then return end
|
||||
if not forced_join then
|
||||
if global.tournament_mode then player.print("The game is set to tournament mode. Teams can only be changed via team manager.", {r = 0.98, g = 0.66, b = 0.22}) return end
|
||||
end
|
||||
player.teleport(player.surface.find_non_colliding_position("character", {0,0}, 4, 1))
|
||||
player.force = game.forces.spectator
|
||||
player.character.destructible = false
|
||||
game.print(player.name .. " is spectating.", {r = 0.98, g = 0.66, b = 0.22})
|
||||
if not forced_join then
|
||||
game.print(player.name .. " is spectating.", {r = 0.98, g = 0.66, b = 0.22})
|
||||
end
|
||||
game.permissions.get_group("spectator").add_player(player)
|
||||
global.spectator_rejoin_delay[player.name] = game.tick
|
||||
create_main_gui(player)
|
||||
end
|
||||
|
||||
local function lock_teams(locking_player)
|
||||
if locking_player.admin == false then return end
|
||||
if global.teams_are_locked then
|
||||
global.teams_are_locked = false
|
||||
game.print(locking_player.name .. " has unlocked Teams.", {r = 0.98, g = 0.66, b = 0.22})
|
||||
for _, player in pairs(game.players) do
|
||||
if not global.chosen_team[player.name] then
|
||||
player.force = game.forces.player
|
||||
create_main_gui(player)
|
||||
end
|
||||
create_team_lock_gui(player)
|
||||
end
|
||||
else
|
||||
global.teams_are_locked = true
|
||||
game.print(locking_player.name .. " has locked Teams.", {r = 0.98, g = 0.66, b = 0.22})
|
||||
for _, player in pairs(game.players) do
|
||||
if not global.chosen_team[player.name] then
|
||||
player.force = game.forces.spectator
|
||||
create_main_gui(player)
|
||||
end
|
||||
create_team_lock_gui(player)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function join_gui_click(name, player)
|
||||
local team = {
|
||||
["join_north_button"] = "north",
|
||||
@ -345,14 +310,12 @@ local function on_gui_click(event)
|
||||
return
|
||||
end
|
||||
|
||||
if player.force.name == "player" then join_gui_click(name, player) end
|
||||
if name == "join_north_button" then join_gui_click(name, player) return end
|
||||
if name == "join_south_button" then join_gui_click(name, player) return end
|
||||
|
||||
if name == "raw-fish" then spy_fish(player) return end
|
||||
|
||||
if food_names[name] then
|
||||
feed_the_biters(player, name)
|
||||
return
|
||||
end
|
||||
if food_names[name] then feed_the_biters(player, name) return end
|
||||
|
||||
if name == "bb_leave_spectate" then join_team(player, global.chosen_team[player.name]) end
|
||||
|
||||
@ -373,8 +336,6 @@ local function on_gui_click(event)
|
||||
global.bb_view_players[player.name] = true
|
||||
create_main_gui(player)
|
||||
end
|
||||
|
||||
if name == "bb_team_lock_button" then lock_teams(player) end
|
||||
end
|
||||
|
||||
local function on_player_joined_game(event)
|
||||
@ -391,29 +352,18 @@ local function on_player_joined_game(event)
|
||||
global.game_lobby_timeout = 5999940
|
||||
end
|
||||
|
||||
if not global.chosen_team[player.name] then
|
||||
if global.teams_are_locked then
|
||||
player.force = game.forces.spectator
|
||||
else
|
||||
player.force = game.forces.player
|
||||
end
|
||||
end
|
||||
--if not global.chosen_team[player.name] then
|
||||
-- if global.tournament_mode then
|
||||
-- player.force = game.forces.spectator
|
||||
-- else
|
||||
-- player.force = game.forces.player
|
||||
-- end
|
||||
--end
|
||||
|
||||
create_sprite_button(player)
|
||||
create_team_lock_gui(player)
|
||||
create_main_gui(player)
|
||||
end
|
||||
|
||||
local function on_player_promoted(event)
|
||||
create_team_lock_gui(game.players[event.player_index])
|
||||
end
|
||||
|
||||
local function on_player_demoted(event)
|
||||
create_team_lock_gui(game.players[event.player_index])
|
||||
end
|
||||
|
||||
event.add(defines.events.on_player_promoted, on_player_promoted)
|
||||
event.add(defines.events.on_player_demoted, on_player_demoted)
|
||||
event.add(defines.events.on_gui_click, on_gui_click)
|
||||
event.add(defines.events.on_player_joined_game, on_player_joined_game)
|
||||
|
||||
|
@ -5,23 +5,66 @@ local forces = {
|
||||
}
|
||||
|
||||
local function get_player_array(force_name)
|
||||
local a = {}
|
||||
for i = 1, math.random(3, 111), 1 do
|
||||
a[#a + 1] = math.random(100, 10000)
|
||||
end
|
||||
|
||||
for _, p in pairs(game.forces[force_name].players) do a[#a + 1] = p.name end
|
||||
local a = {}
|
||||
for _, p in pairs(game.forces[force_name].connected_players) do a[#a + 1] = p.name end
|
||||
return a
|
||||
end
|
||||
|
||||
local function leave_corpse(player)
|
||||
if not player.character then return end
|
||||
|
||||
local inventories = {
|
||||
player.get_inventory(defines.inventory.character_main),
|
||||
player.get_inventory(defines.inventory.character_guns),
|
||||
player.get_inventory(defines.inventory.character_ammo),
|
||||
player.get_inventory(defines.inventory.character_armor),
|
||||
player.get_inventory(defines.inventory.character_vehicle),
|
||||
player.get_inventory(defines.inventory.character_trash),
|
||||
}
|
||||
|
||||
local corpse = false
|
||||
for _, i in pairs(inventories) do
|
||||
for index = 1, #i, 1 do
|
||||
if not i[index].valid then break end
|
||||
corpse = true
|
||||
break
|
||||
end
|
||||
if corpse then
|
||||
player.character.die()
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if player.character then player.character.destroy() end
|
||||
player.character = nil
|
||||
player.set_controller({type=defines.controllers.god})
|
||||
player.create_character()
|
||||
end
|
||||
|
||||
local function switch_force(player_name, force_name)
|
||||
if not game.players[player_name] then game.print("Team Manager >> Player " .. player_name .. " does not exist.", {r=0.98, g=0.66, b=0.22}) return end
|
||||
if not game.forces[force_name] then game.print("Team Manager >> Force " .. force_name .. " does not exist.", {r=0.98, g=0.66, b=0.22}) return end
|
||||
|
||||
local player = game.players[player_name]
|
||||
player.force = game.forces[force_name]
|
||||
|
||||
game.print(player_name .. " has been switched into team " .. force_name .. ".", {r=0.98, g=0.66, b=0.22})
|
||||
|
||||
leave_corpse(player)
|
||||
|
||||
global.chosen_team[player_name] = nil
|
||||
if force_name == "spectator" then
|
||||
spectate(player, true)
|
||||
else
|
||||
join_team(player, force_name, true)
|
||||
end
|
||||
end
|
||||
|
||||
local function draw_manager_button(player)
|
||||
if player.gui.top["bb_team_lock_button"] then player.gui.top["bb_team_lock_button"].destroy() end
|
||||
|
||||
if not player.admin then return end
|
||||
|
||||
if player.gui.top["team_manager_toggle_button"] then player.gui.top["team_manager_toggle_button"].destroy() end
|
||||
local button = player.gui.top.add({type = "sprite-button", name = "team_manager_toggle_button", caption = "Team Manager", tooltip = tooltip})
|
||||
button.style.font = "heading-2"
|
||||
button.style.font_color = {r = 0.33, g = 0.77, b = 0.33}
|
||||
button.style.font_color = {r = 0.88, g = 0.55, b = 0.11}
|
||||
button.style.minimal_height = 38
|
||||
button.style.minimal_width = 120
|
||||
button.style.top_padding = 2
|
||||
@ -33,7 +76,7 @@ end
|
||||
local function draw_manager_gui(player)
|
||||
if player.gui.center["team_manager_gui"] then player.gui.center["team_manager_gui"].destroy() end
|
||||
|
||||
local frame = player.gui.center.add({type = "frame", name = "team_manager_gui", caption = "Manage Teams"})
|
||||
local frame = player.gui.center.add({type = "frame", name = "team_manager_gui", caption = "Manage Teams", direction = "vertical"})
|
||||
|
||||
local t = frame.add({type = "table", name = "team_manager_root_table", column_count = 5})
|
||||
|
||||
@ -52,30 +95,113 @@ local function draw_manager_gui(player)
|
||||
local i2 = 1
|
||||
for i = 1, #forces * 2 - 1, 1 do
|
||||
if i % 2 == 1 then
|
||||
local list_box = t.add({type = "list-box", name = "team_manager_list_box_" .. i, items = get_player_array(forces[i2].name)})
|
||||
local list_box = t.add({type = "list-box", name = "team_manager_list_box_" .. i2, items = get_player_array(forces[i2].name)})
|
||||
list_box.style.minimal_height = 360
|
||||
list_box.style.minimal_width = 160
|
||||
list_box.style.maximal_height = 480
|
||||
i2 = i2 + 1
|
||||
else
|
||||
local tt = t.add({type = "table", column_count = 1})
|
||||
local b = tt.add({type = "sprite-button", caption = "→"})
|
||||
local b = tt.add({type = "sprite-button", name = i2 - 1, caption = "→"})
|
||||
b.style.font = "heading-1"
|
||||
b.style.maximal_height = 38
|
||||
b.style.maximal_width = 38
|
||||
local b = tt.add({type = "sprite-button", caption = "←"})
|
||||
local b = tt.add({type = "sprite-button", name = i2, caption = "←"})
|
||||
b.style.font = "heading-1"
|
||||
b.style.maximal_height = 38
|
||||
b.style.maximal_width = 38
|
||||
end
|
||||
end
|
||||
|
||||
frame.add({type = "label", caption = ""})
|
||||
|
||||
local t = frame.add({type = "table", name = "team_manager_bottom_buttons", column_count = 3})
|
||||
local button = t.add({
|
||||
type = "button",
|
||||
name = "team_manager_close",
|
||||
caption = "Close",
|
||||
tooltip = "Close this window."
|
||||
})
|
||||
button.style.font = "heading-2"
|
||||
|
||||
if global.tournament_mode then
|
||||
button = t.add({
|
||||
type = "button",
|
||||
name = "team_manager_activate_tournament",
|
||||
caption = "Tournament Mode Activated",
|
||||
tooltip = "Only admins can move players. Active players can no longer go spectate. New joining players are spectators."
|
||||
})
|
||||
button.style.font_color = {r = 222, g = 22, b = 22}
|
||||
else
|
||||
button = t.add({
|
||||
type = "button",
|
||||
name = "team_manager_activate_tournament",
|
||||
caption = "Tournament Mode Disabled",
|
||||
tooltip = "Only admins can move players. Active players can no longer go spectate. New joining players are spectators."
|
||||
})
|
||||
button.style.font_color = {r = 55, g = 55, b = 55}
|
||||
end
|
||||
button.style.font = "heading-2"
|
||||
end
|
||||
|
||||
local function on_player_joined_game(event)
|
||||
local player = game.players[event.player_index]
|
||||
draw_manager_button(player)
|
||||
local function on_gui_click(event)
|
||||
if not event.element then return end
|
||||
if not event.element.valid then return end
|
||||
local player = game.players[event.player_index]
|
||||
local name = event.element.name
|
||||
|
||||
if name == "team_manager_toggle_button" then
|
||||
if player.gui.center["team_manager_gui"] then player.gui.center["team_manager_gui"].destroy() return end
|
||||
draw_manager_gui(player)
|
||||
return
|
||||
end
|
||||
|
||||
if not player.gui.center["team_manager_gui"] then return end
|
||||
|
||||
if name == "team_manager_close" then
|
||||
player.gui.center["team_manager_gui"].destroy()
|
||||
return
|
||||
end
|
||||
|
||||
if name == "team_manager_activate_tournament" then
|
||||
if not player.admin then player.print("Only admins can manage teams.", {r = 175, g = 0, b = 0}) return end
|
||||
if global.tournament_mode then
|
||||
global.tournament_mode = false
|
||||
draw_manager_gui(player)
|
||||
game.print("Tournament Mode has been disabled.", {r = 22, g = 22, b = 22})
|
||||
return
|
||||
end
|
||||
global.tournament_mode = true
|
||||
draw_manager_gui(player)
|
||||
game.print("Tournament Mode has been enabled!", {r = 225, g = 0, b = 0})
|
||||
return
|
||||
end
|
||||
|
||||
if not event.element.parent then return end
|
||||
local element = event.element.parent
|
||||
if not element.parent then return end
|
||||
local element = element.parent
|
||||
if element.name ~= "team_manager_root_table" then return end
|
||||
if not player.admin then player.print("Only admins can manage teams.", {r = 175, g = 0, b = 0}) return end
|
||||
|
||||
local listbox = player.gui.center["team_manager_gui"]["team_manager_root_table"]["team_manager_list_box_" .. tonumber(name)]
|
||||
local selected_index = listbox.selected_index
|
||||
if selected_index == 0 then player.print("No player selected.", {r = 175, g = 0, b = 0}) return end
|
||||
local player_name = listbox.items[selected_index]
|
||||
|
||||
local m = -1
|
||||
if event.element.caption == "→" then m = 1 end
|
||||
local force_name = forces[tonumber(name) + m].name
|
||||
|
||||
switch_force(player_name, force_name)
|
||||
|
||||
draw_manager_gui(player)
|
||||
end
|
||||
|
||||
local function on_player_joined_game(event)
|
||||
draw_manager_button(game.players[event.player_index])
|
||||
end
|
||||
|
||||
local event = require 'utils.event'
|
||||
event.add(defines.events.on_player_joined_game, on_player_joined_game)
|
||||
event.add(defines.events.on_player_joined_game, on_player_joined_game)
|
||||
event.add(defines.events.on_gui_click, on_gui_click)
|
Loading…
Reference in New Issue
Block a user