mirror of
https://github.com/Refactorio/RedMew.git
synced 2024-12-12 10:04:40 +02:00
Removed Wells, on_tick.lua. Enabled walk distance again.
This commit is contained in:
parent
52ae440938
commit
a4ea9a6315
@ -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"
|
||||
|
||||
|
@ -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"
|
||||
|
@ -472,7 +472,6 @@ commands.add_command("afk", 'Shows how long players have been afk.', afk)
|
||||
commands.add_command("tag", '<player> <tag> Sets a players tag. (Admins only)', tag)
|
||||
commands.add_command("follow", '<player> 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", '<item> <items per second> 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", "<player> <minutes> Temporarily bans a player (Admins and moderators)", tempban)
|
||||
|
@ -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)
|
||||
|
3
info.lua
3
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
|
||||
|
||||
|
18
on_tick.lua
18
on_tick.lua
@ -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)
|
@ -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)
|
||||
|
3
poll.lua
3
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)
|
||||
|
@ -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)
|
||||
|
93
wells.lua
93
wells.lua
@ -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 <item> <items per second>.")
|
||||
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
|
Loading…
Reference in New Issue
Block a user