From a4ea9a6315cd7226d9918f7bcbf4d0851790f7cc Mon Sep 17 00:00:00 2001 From: Valansch Date: Thu, 5 Apr 2018 15:39:35 +0200 Subject: [PATCH 1/3] Removed Wells, on_tick.lua. Enabled walk distance again. --- config.lua | 3 +- control.lua | 2 - custom_commands.lua | 1 - fish_market.lua | 4 +- info.lua | 3 ++ on_tick.lua | 18 --------- player_list.lua | 24 ++++++------ poll.lua | 3 +- walk_distance.lua | 12 +++--- wells.lua | 93 --------------------------------------------- 10 files changed, 28 insertions(+), 135 deletions(-) delete mode 100644 on_tick.lua delete mode 100644 wells.lua diff --git a/config.lua b/config.lua index ef87fa9e..3d8571fb 100644 --- a/config.lua +++ b/config.lua @@ -2,11 +2,10 @@ global.scenario = {} global.spys = {"valansch", "air20"} global.scenario.variables = {} global.scenario.variables.player_positions = {} --- global.scenario.variables.player_walk_distances = {} +global.player_walk_distances = {} global.scenario.variables.player_deaths = {} global.scenario.config = {} global.scenario.custom_functions = {} global.scenario.config.nuke_min_time_hours = 3 --how long a player must be on the server to be allowed to use the nuke global.newline = "\n" newline = "\n" - diff --git a/control.lua b/control.lua index 8114b289..7d761895 100644 --- a/control.lua +++ b/control.lua @@ -15,9 +15,7 @@ require "score" require "map_layout" require "nuke_control" require "walk_distance" -require "on_tick" require "follow" -require "wells" require "custom_commands" require "tasklist" require "autodeconstruct" diff --git a/custom_commands.lua b/custom_commands.lua index 2d2471ce..c6ae9cd6 100644 --- a/custom_commands.lua +++ b/custom_commands.lua @@ -472,7 +472,6 @@ commands.add_command("afk", 'Shows how long players have been afk.', afk) commands.add_command("tag", ' Sets a players tag. (Admins only)', tag) commands.add_command("follow", ' makes you follow the player. Use /unfollow to stop following a player.', follow) commands.add_command("unfollow", 'stops following a player.', unfollow) -commands.add_command("well", ' Spawns an item well. (Admins only)', well_command) commands.add_command("tpmode", "Toggles tp mode. When on place a ghost entity to teleport there (Admins and moderators)", toggle_tp_mode) commands.add_command("forcetoggle", "Toggles the players force between player and enemy (Admins and moderators)", forcetoggle) commands.add_command("tempban", " Temporarily bans a player (Admins and moderators)", tempban) diff --git a/fish_market.lua b/fish_market.lua index 09557104..c45402cf 100644 --- a/fish_market.lua +++ b/fish_market.lua @@ -348,7 +348,7 @@ end if not global.pet_command_rotation then global.pet_command_rotation = 1 end -function fish_market_on_180_ticks() +function on_180_ticks() if game.tick % 900 == 0 then if global.player_speed_boost_records then @@ -402,6 +402,8 @@ function fish_player_crafted_item(event) end end + +script.on_nth_tick(180, on_180_ticks) Event.register(defines.events.on_pre_player_mined_item, pre_player_mined_item) Event.register(defines.events.on_entity_died, fish_drop_entity_died) Event.register(defines.events.on_market_item_purchased, market_item_purchased) diff --git a/info.lua b/info.lua index 3254e5e2..0fec5635 100644 --- a/info.lua +++ b/info.lua @@ -9,6 +9,9 @@ local function create_info_button(event) button.style.left_padding = 4 button.style.right_padding = 4 button.style.bottom_padding = 2 + button.style.vertically_stretchable = true + button.style.vertically_squashable = true + button.style.vertical_spacing = 0 end end diff --git a/on_tick.lua b/on_tick.lua deleted file mode 100644 index d84c2b7c..00000000 --- a/on_tick.lua +++ /dev/null @@ -1,18 +0,0 @@ -local function on_tick() - walk_on_tick() - if game.tick % 60 == 0 then - poll_on_second() - walk_distance_on_second() - if game.tick % 1200 == 0 then - player_list_on_12_seconds() - end - if game.tick % 180 == 0 then - fish_market_on_180_ticks() - if game.tick % 900 == 0 then - refill_well() - end - end - end -end - -Event.register(defines.events.on_tick, on_tick) diff --git a/player_list.lua b/player_list.lua index 28002286..d98d1d87 100644 --- a/player_list.lua +++ b/player_list.lua @@ -144,8 +144,8 @@ local function get_sorted_list(sort_by) player_list[i2] = a end end - --[[if sort_by == "distance_asc" then - if global.scenario.variables.player_walk_distances[player_list[i].name] > global.scenario.variables.player_walk_distances[player_list[i2].name] then + if sort_by == "distance_asc" then + if global.player_walk_distances[player_list[i].name] > global.player_walk_distances[player_list[i2].name] then local a = player_list[i] local b = player_list[i2] player_list[i] = b @@ -153,14 +153,13 @@ local function get_sorted_list(sort_by) end end if sort_by == "distance_desc" then - if global.scenario.variables.player_walk_distances[player_list[i].name] < global.scenario.variables.player_walk_distances[player_list[i2].name] then + if global.player_walk_distances[player_list[i].name] < global.player_walk_distances[player_list[i2].name] then local a = player_list[i] local b = player_list[i2] player_list[i] = b player_list[i2] = a end end - ]]-- if sort_by == "name_asc" then if player_list[i].name > player_list[i2].name then local a = player_list[i] @@ -187,14 +186,14 @@ local function player_list_show(player, sort_by) if frame then frame.destroy() end local frame = player.gui.left.add { type = "frame", name = "player-list-panel", direction = "vertical" } - frame.style.minimal_width = 650 + frame.style.minimal_width = 700 frame.style.top_padding = 8 frame.style.left_padding = 8 frame.style.right_padding = 8 frame.style.bottom_padding = 8 - local player_list_panel_header_table = frame.add { type = "table", name = "player_list_panel_header_table", column_count = 6 } + local player_list_panel_header_table = frame.add { type = "table", name = "player_list_panel_header_table", column_count = 7 } local label = player_list_panel_header_table.add { type = "label", name = "player_list_panel_header_1", caption = " " .. #game.connected_players } label.style.font = "default-game" @@ -218,14 +217,14 @@ local function player_list_show(player, sort_by) label.style.maximal_width = 130 ---[[ str = "" + str = "" if sort_by == "distance_asc" then str = symbol_asc .. " " end if sort_by == "distance_desc" then str = symbol_desc .. " " end local label = player_list_panel_header_table.add { type = "label", name = "player_list_panel_header_4", caption = str .. "Walked" } label.style.font_color = { r=0.98, g=0.66, b=0.22} label.style.minimal_width = 100 label.style.maximal_width = 100 ---]] + str = "" if sort_by == "fish_asc" then str = symbol_asc .. " " end if sort_by == "fish_desc" then str = symbol_desc .. " " end @@ -253,7 +252,7 @@ local function player_list_show(player, sort_by) player_list_panel_table.style.maximal_height = 650 - player_list_panel_table = player_list_panel_table.add { type = "table", name = "player_list_panel_table", column_count = 6 } + player_list_panel_table = player_list_panel_table.add { type = "table", name = "player_list_panel_table", column_count = 7 } local player_list = get_sorted_list(sort_by) @@ -276,10 +275,10 @@ local function player_list_show(player, sort_by) label.style.minimal_width = 130 label.style.maximal_width = 130 ---[[ local label = player_list_panel_table.add { type = "label", name = "player_list_panel_player_distance_" .. i, caption = round(global.scenario.variables.player_walk_distances[player_list[i].name]/1000, 1) .. " km" } + local label = player_list_panel_table.add { type = "label", name = "player_list_panel_player_distance_" .. i, caption = round(global.player_walk_distances[player_list[i].name]/1000, 1) .. " km" } label.style.minimal_width = 100 label.style.maximal_width = 100 ---]] + local label = player_list_panel_table.add { type = "label", name = "player_list_panel_player_fish" .. i, caption = global.fish_market_fish_caught[player_list[i].player_index] .. " / " .. global.fish_market_fish_spent[player_list[i].player_index] } label.style.minimal_width = 80 label.style.maximal_width = 80 @@ -374,7 +373,7 @@ local function on_gui_click(event) end -function player_list_on_12_seconds() +function on_12_seconds() for _,player in pairs(game.connected_players) do if player.gui.left["player-list-panel"] then local sort_method @@ -412,6 +411,7 @@ local function player_list_on_player_died(event) end +script.on_nth_tick(720, on_12_seconds) Event.register(defines.events.on_player_joined_game, on_player_joined_game) Event.register(defines.events.on_gui_click, on_gui_click) Event.register(defines.events.on_player_died, player_list_on_player_died) diff --git a/poll.lua b/poll.lua index e952292a..1025ce21 100644 --- a/poll.lua +++ b/poll.lua @@ -294,7 +294,7 @@ local function on_gui_click(event) end end -function poll_on_second() +function on_second() for _, player in pairs(game.connected_players) do if global.poll_panel_creation_time then if global.poll_panel_creation_time[player.index] then @@ -317,6 +317,7 @@ function poll_on_second() end end +script.on_nth_tick(61, on_second) Event.register(defines.events.on_gui_click, on_gui_click) Event.register(defines.events.on_player_joined_game, create_poll_gui) Event.register(defines.events.on_player_joined_game, poll_sync_for_new_joining_player) diff --git a/walk_distance.lua b/walk_distance.lua index 7dac4d2f..9ba86f80 100644 --- a/walk_distance.lua +++ b/walk_distance.lua @@ -1,4 +1,4 @@ -function walk_distance_on_second() +function on_second() local last_positions = global.scenario.variables.player_positions local d_x = 0 local d_y = 0 @@ -7,7 +7,7 @@ function walk_distance_on_second() if last_positions[v.name] then d_x = last_positions[v.name].x - v.position.x d_y = last_positions[v.name].y - v.position.y - global.scenario.variables.player_walk_distances[v.name] = global.scenario.variables.player_walk_distances[v.name] + math.sqrt(d_x*d_x + d_y*d_y) + global.player_walk_distances[v.name] = global.player_walk_distances[v.name] + math.sqrt(d_x*d_x + d_y*d_y) global.scenario.variables.player_positions[v.name] = v.position end end @@ -25,9 +25,11 @@ end local function init_player_position(event) local player = game.players[event.player_index] global.scenario.variables.player_positions[player.name] = player.position - if not global.scenario.variables.player_walk_distances[player.name] then - global.scenario.variables.player_walk_distances[player.name] = 0 + if not global.player_walk_distances[player.name] then + global.player_walk_distances[player.name] = 0 end end --- Event.register(defines.events.on_player_joined_game, init_player_position) + +script.on_nth_tick(62, on_second) +Event.register(defines.events.on_player_joined_game, init_player_position) diff --git a/wells.lua b/wells.lua deleted file mode 100644 index 8485391d..00000000 --- a/wells.lua +++ /dev/null @@ -1,93 +0,0 @@ -global.wells = {} - -function refill_well() - local current_tick = game.tick - - local wells = global.wells - -- iterate backwards to allow for removals. - for i = #wells, 1, -1 do - local well = wells[i] - local entity = well.entity - if not entity.valid then - table.remove(wells, i) - else - local items_per_tick = well.items_per_tick - local diff = current_tick - well.last_tick - local count = diff * items_per_tick - - if count >= 1 then - local whole = math.floor(count) - entity.insert({ name = well.item, count = whole }) - - local frac = count - whole - well.last_tick = current_tick - frac / items_per_tick - end - end - end -end - -local function validate(item, items_per_second) - if not game.item_prototypes[item] then - return "item is not valid" - end - - if type(items_per_second) ~= "number" or items_per_second <= 0 then - return "items per second must be a number and greater than 0" - end -end - -local function non_validating_create_well(entity, item, items_per_second) - local well = - { - entity = entity, - item = item, - items_per_tick = items_per_second / 60, - last_tick = game.tick - } - - table.insert(global.wells, well) -end - -function create_well(entity, item, items_per_second) - if not entity or entity.type ~= "container" then - return "entity must be a container" - end - - local error = validate(item, items_per_second) - if error then - return error - end - - non_validating_create_well(entity, item, items_per_second) -end - -function well_command(cmd) - if not game.player or not game.player.admin then - cant_run(cmd.name) - return - end - - if cmd.parameter == nil then - return - end - - local params = {} - for param in string.gmatch(cmd.parameter, "%S+") do table.insert(params, param) end - - if #params ~= 2 then - game.player.print("Usage: /well .") - return - end - - local error = validate(params[1], tonumber(params[2])) - if error then - game.player.print(error) - return - end - - local chest = game.player.surface.create_entity({name = "steel-chest", force = game.player.force, position = game.player.position}) - chest.minable = false; - chest.destructible = false; - - non_validating_create_well(chest, params[1], tonumber(params[2])) -end \ No newline at end of file From ee2d41caa0bb71f0536e4a51d7d623475516668e Mon Sep 17 00:00:00 2001 From: Valansch Date: Thu, 5 Apr 2018 15:43:42 +0200 Subject: [PATCH 2/3] disabled pets --- fish_market.lua | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/fish_market.lua b/fish_market.lua index c45402cf..4b3b1e4d 100644 --- a/fish_market.lua +++ b/fish_market.lua @@ -35,7 +35,7 @@ function spawn_market(cmd) market.destructible = false market.add_market_item{price={{"raw-fish", 10}}, offer={type="give-item", item="discharge-defense-remote"}} - market.add_market_item{price={{"raw-fish", 30}}, offer={type="give-item", item="small-plane"}} + --market.add_market_item{price={{"raw-fish", 30}}, offer={type="give-item", item="small-plane"}} market.add_market_item{price={{"raw-fish", 10}}, offer={type="give-item", item="wood"}} market.add_market_item{price={{"raw-fish", 1}}, offer={type="give-item", item="rail", count=2}} market.add_market_item{price={{"raw-fish", 2}}, offer={type="give-item", item="rail-signal"}} @@ -195,7 +195,7 @@ local function fish_drop_entity_died(event) end -function pet(player, entity_name) +local function pet(player, entity_name) if not player then player = game.connected_players[1] else @@ -296,11 +296,12 @@ local function market_item_purchased(event) boost_player_runningspeed(player) --disabled due to on_tick being disabled end - if event.offer_index == 3 then -- exoskeleton-equipment + if event.offer_index == 2 then -- exoskeleton-equipment player.remove_item({name="wood", count=event.count}) boost_player_miningspeed(player) end + --[[ if event.offer_index == 2 then player.remove_item({name="small-plane", count=event.count}) local chance = 4 @@ -344,6 +345,7 @@ local function market_item_purchased(event) game.print(str) pet(event.player_index, rolled_pet) end + --]] end if not global.pet_command_rotation then global.pet_command_rotation = 1 end From a48036ea68c0e280b474a0bd9e9d043d727572ee Mon Sep 17 00:00:00 2001 From: Valansch Date: Thu, 5 Apr 2018 15:46:37 +0200 Subject: [PATCH 3/3] fixed show polls button --- poll.lua | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/poll.lua b/poll.lua index 1025ce21..18986319 100644 --- a/poll.lua +++ b/poll.lua @@ -127,7 +127,7 @@ local function poll(player) local x = 1 - while (game.players[x] ~= nil) do + while game.players[x] do local player = game.players[x] @@ -137,7 +137,7 @@ local function poll(player) frame.destroy() end - if (global.autoshow_polls_for_player[player.name] == true) then + if global.autoshow_polls_for_player[player.name] then poll_show(player) end @@ -268,7 +268,8 @@ local function on_gui_click(event) end if (name == "auto_show_polls_checkbox") then - global.autoshow_polls_for_player[player.name] = event.element.state + global.autoshow_polls_for_player[player.name] = not global.autoshow_polls_for_player[player.name] + game.print(global.autoshow_polls_for_player[player.name]) end if global.poll_voted[event.player_index] == nil then