mirror of
https://github.com/Refactorio/RedMew.git
synced 2024-12-12 10:04:40 +02:00
Merge branch 'disable_pets' into develop
# Conflicts: # fish_market.lua # on_tick.lua # player_list.lua # poll.lua # walk_distance.lua
This commit is contained in:
commit
999d7c141f
@ -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"
|
||||
|
||||
|
@ -14,9 +14,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)
|
||||
|
@ -37,7 +37,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"}}
|
||||
@ -197,7 +197,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
|
||||
@ -298,11 +298,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
|
||||
@ -346,11 +347,12 @@ 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
|
||||
|
||||
function fish_market_on_180_ticks()
|
||||
function on_180_ticks()
|
||||
|
||||
if game.tick % 900 == 0 then
|
||||
if global.player_speed_boost_records then
|
||||
@ -404,7 +406,9 @@ function fish_player_crafted_item(event)
|
||||
end
|
||||
end
|
||||
|
||||
Event.on_nth_tick(180, on_180_ticks)
|
||||
Event.add(defines.events.on_pre_player_mined_item, pre_player_mined_item)
|
||||
Event.add(defines.events.on_entity_died, fish_drop_entity_died)
|
||||
Event.add(defines.events.on_market_item_purchased, market_item_purchased)
|
||||
Event.add(defines.events.on_player_crafted_item, fish_player_crafted_item)
|
||||
|
||||
|
3
info.lua
3
info.lua
@ -11,6 +11,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
|
||||
|
||||
|
20
on_tick.lua
20
on_tick.lua
@ -1,20 +0,0 @@
|
||||
local Event = require "utils.event"
|
||||
|
||||
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.add(defines.events.on_tick, on_tick)
|
@ -146,8 +146,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
|
||||
@ -155,14 +155,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]
|
||||
@ -189,14 +188,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"
|
||||
@ -220,14 +219,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
|
||||
@ -255,7 +254,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)
|
||||
|
||||
@ -278,10 +277,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
|
||||
@ -376,7 +375,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
|
||||
@ -414,6 +413,7 @@ local function player_list_on_player_died(event)
|
||||
end
|
||||
|
||||
|
||||
Event.on_nth_tick(720, on_12_seconds)
|
||||
Event.add(defines.events.on_player_joined_game, on_player_joined_game)
|
||||
Event.add(defines.events.on_gui_click, on_gui_click)
|
||||
Event.add(defines.events.on_player_died, player_list_on_player_died)
|
||||
|
10
poll.lua
10
poll.lua
@ -129,7 +129,7 @@ local function poll(player)
|
||||
|
||||
local x = 1
|
||||
|
||||
while (game.players[x] ~= nil) do
|
||||
while game.players[x] do
|
||||
|
||||
local player = game.players[x]
|
||||
|
||||
@ -139,7 +139,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
|
||||
|
||||
@ -270,7 +270,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
|
||||
@ -296,7 +297,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
|
||||
@ -319,6 +320,7 @@ function poll_on_second()
|
||||
end
|
||||
end
|
||||
|
||||
Event.on_nth_tick(61, on_second)
|
||||
Event.add(defines.events.on_gui_click, on_gui_click)
|
||||
Event.add(defines.events.on_player_joined_game, create_poll_gui)
|
||||
Event.add(defines.events.on_player_joined_game, poll_sync_for_new_joining_player)
|
||||
|
@ -1,6 +1,5 @@
|
||||
local Event = require "utils.event"
|
||||
|
||||
function walk_distance_on_second()
|
||||
function on_second()
|
||||
local last_positions = global.scenario.variables.player_positions
|
||||
local d_x = 0
|
||||
local d_y = 0
|
||||
@ -9,7 +8,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
|
||||
@ -27,9 +26,10 @@ 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.add(defines.events.on_player_joined_game, init_player_position)
|
||||
Event.on_nth_tick(62, on_second)
|
||||
Event.add(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