mirror of
https://github.com/Refactorio/RedMew.git
synced 2025-03-03 14:53:01 +02:00
Merge branch 'master' into develop
This commit is contained in:
commit
5114955d1b
@ -1,3 +1,5 @@
|
||||
local Thread = require "locale.utils.Thread"
|
||||
|
||||
function cant_run(name)
|
||||
game.player.print("Can't run command (" .. name .. ") - insufficient permission.")
|
||||
end
|
||||
@ -75,10 +77,28 @@ function walkabout(cmd)
|
||||
for param in string.gmatch(cmd.parameter, "%w+") do table.insert(params, param) end
|
||||
local player_name = params[1]
|
||||
local distance = ""
|
||||
if params[3] == nil then
|
||||
local duraction = 60
|
||||
if #params == 2 then
|
||||
distance = params[2]
|
||||
else
|
||||
elseif #params == 3 then
|
||||
distance = params[2] .. " " .. params[3]
|
||||
if distance ~= "very far" then
|
||||
distance = params[2]
|
||||
if tonumber(params[3]) == nil then
|
||||
game.player.print(params[3] .. " is not a number.")
|
||||
return
|
||||
else
|
||||
duraction = tonumber(params[3])
|
||||
end
|
||||
end
|
||||
elseif #params == 4 then
|
||||
distance = params[2] .. " " .. params[3]
|
||||
if tonumber(params[4]) == nil then
|
||||
game.player.print(params[4] .. " is not a number.")
|
||||
return
|
||||
else
|
||||
duraction = tonumber(params[4])
|
||||
end
|
||||
end
|
||||
|
||||
if distance == nil or distance == "" then
|
||||
@ -98,44 +118,45 @@ function walkabout(cmd)
|
||||
end
|
||||
|
||||
local x = 1
|
||||
while game.players[x] ~= nil do
|
||||
local player = game.players[x]
|
||||
if player_name == player.name then
|
||||
local repeat_attempts = 5
|
||||
local r = 1
|
||||
local surface = game.surfaces[1]
|
||||
local distance_max = distance * 1.05
|
||||
local distance_min = distance * 0.95
|
||||
distance_max = round(distance_max, 0)
|
||||
distance_min = round(distance_min, 0)
|
||||
|
||||
--while r <= repeat_attempts do
|
||||
x = math.random(distance_min, distance_max)
|
||||
if 1 == math.random(1, 2) then
|
||||
x = x * -1
|
||||
end
|
||||
|
||||
y = math.random(distance_min, distance_max)
|
||||
if 1 == math.random(1, 2) then
|
||||
y = y * -1
|
||||
end
|
||||
|
||||
if 1 == math.random(1, 2) then
|
||||
z = distance_max * -1
|
||||
x = math.random(z, distance_max)
|
||||
else
|
||||
z = distance_max * -1
|
||||
y = math.random(z, distance_max)
|
||||
end
|
||||
|
||||
local pos = {x, y}
|
||||
player.teleport(pos)
|
||||
game.print(player_name .. " went on a walkabout, to find himself.")
|
||||
return
|
||||
end
|
||||
x = x + 1
|
||||
local y = 1
|
||||
local player = game.players[player_name]
|
||||
if player == nil then
|
||||
game.player.print(player_name .. " could not go on a walkabout.")
|
||||
return
|
||||
end
|
||||
game.print(player_name .. " could not go on a walkabout.")
|
||||
local surface = game.surfaces[1]
|
||||
local distance_max = distance * 1.05
|
||||
local distance_min = distance * 0.95
|
||||
distance_max = round(distance_max, 0)
|
||||
distance_min = round(distance_min, 0)
|
||||
|
||||
x = math.random(distance_min, distance_max)
|
||||
if 1 == math.random(1, 2) then
|
||||
x = x * -1
|
||||
end
|
||||
y = math.random(distance_min, distance_max)
|
||||
if 1 == math.random(1, 2) then
|
||||
y = y * -1
|
||||
end
|
||||
if 1 == math.random(1, 2) then
|
||||
z = distance_max * -1
|
||||
x = math.random(z, distance_max)
|
||||
else
|
||||
z = distance_max * -1
|
||||
y = math.random(z, distance_max)
|
||||
end
|
||||
|
||||
local pos = {x, y}
|
||||
Thread.set_timeout(duraction, return_player, {player = player, force = player.force, position = player.position})
|
||||
player.force = "enemy"
|
||||
player.teleport(player.surface.find_non_colliding_position("player", pos, 100, 1))
|
||||
game.print(player_name .. " went on a walkabout, to find himself.")
|
||||
end
|
||||
|
||||
function return_player(args)
|
||||
args.player.force = args.force
|
||||
args.player.teleport(args.player.surface.find_non_colliding_position("player", args.position, 100, 1))
|
||||
game.print(args.player.name .. " came back from his walkabout.")
|
||||
end
|
||||
|
||||
function on_set_time(cmd)
|
||||
@ -267,7 +288,7 @@ commands.add_command("detrain", "<player> - Kicks the player off a train. (Admin
|
||||
commands.add_command("tpplayer", "<player> - Teleports you to the player. (Admins and moderators)", teleport_player)
|
||||
commands.add_command("invoke", "<player> - Teleports the player to you. (Admins and moderators)", invoke)
|
||||
commands.add_command("tppos", "Teleports you to a selected entity. (Admins only)", teleport_location)
|
||||
commands.add_command("walkabout", '<player> <"close", "far", "very far", number> - Send someone on a walk. (Admins and moderators)', walkabout)
|
||||
commands.add_command("walkabout", '<player> <"close", "far", "very far", number> <duration> - Send someone on a walk. (Admins and moderators)', walkabout)
|
||||
commands.add_command("market", 'Places a fish market near you. (Admins only)', spawn_market)
|
||||
commands.add_command("settime", '<day> <month> <hour> <minute> - Sets the clock (Admins, moderators and regulars)', on_set_time)
|
||||
commands.add_command("clock", 'Look at the clock.', clock)
|
||||
|
@ -287,45 +287,42 @@ if not global.pet_command_rotation then global.pet_command_rotation = 1 end
|
||||
|
||||
function fish_market_on_180_ticks()
|
||||
|
||||
if game.tick % 180 == 0 then
|
||||
|
||||
if game.tick % 900 == 0 then
|
||||
if global.player_speed_boost_records then
|
||||
for k,v in pairs(global.player_speed_boost_records) do
|
||||
if game.tick - v.start_tick > 3000 then
|
||||
reset_player_runningspeed(game.players[k])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if global.player_pets then
|
||||
for _, pets in pairs(global.player_pets) do
|
||||
local player = game.players[pets.owner]
|
||||
if pcall(function () local x = pets.entity.name end) then
|
||||
if global.pet_command_rotation % 15 == 0 then
|
||||
local surface = game.surfaces[1]
|
||||
local pet_pos = pets.entity.position
|
||||
local pet_name = pets.entity.name
|
||||
local pet_direction = pets.entity.direction
|
||||
pets.entity.destroy()
|
||||
pets.entity = surface.create_entity {name=pet_name, position=pet_pos, direction=pet_direction, force="player"}
|
||||
end
|
||||
if global.pet_command_rotation % 2 == 1 then
|
||||
pets.entity.set_command({type=defines.command.go_to_location, destination=player.position,distraction=defines.distraction.none})
|
||||
else
|
||||
local fake_pos = pets.entity.position
|
||||
pets.entity.set_command({type=defines.command.go_to_location, destination=fake_pos,distraction=defines.distraction.none})
|
||||
end
|
||||
else
|
||||
global.player_pets[pets.id] = nil
|
||||
local str = player.name .. "´s pet died ;_;"
|
||||
game.print(str)
|
||||
end
|
||||
if game.tick % 900 == 0 then
|
||||
if global.player_speed_boost_records then
|
||||
for k,v in pairs(global.player_speed_boost_records) do
|
||||
if game.tick - v.start_tick > 3000 then
|
||||
reset_player_runningspeed(game.players[k])
|
||||
end
|
||||
end
|
||||
global.pet_command_rotation = global.pet_command_rotation + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if global.player_pets then
|
||||
for _, pets in pairs(global.player_pets) do
|
||||
local player = game.players[pets.owner]
|
||||
if pcall(function () local x = pets.entity.name end) then
|
||||
if global.pet_command_rotation % 15 == 0 then
|
||||
local surface = game.surfaces[1]
|
||||
local pet_pos = pets.entity.position
|
||||
local pet_name = pets.entity.name
|
||||
local pet_direction = pets.entity.direction
|
||||
pets.entity.destroy()
|
||||
pets.entity = surface.create_entity {name=pet_name, position=pet_pos, direction=pet_direction, force="player"}
|
||||
end
|
||||
if global.pet_command_rotation % 2 == 1 then
|
||||
pets.entity.set_command({type=defines.command.go_to_location, destination=player.position,distraction=defines.distraction.none})
|
||||
else
|
||||
local fake_pos = pets.entity.position
|
||||
pets.entity.set_command({type=defines.command.go_to_location, destination=fake_pos,distraction=defines.distraction.none})
|
||||
end
|
||||
else
|
||||
global.player_pets[pets.id] = nil
|
||||
local str = player.name .. "´s pet died ;_;"
|
||||
game.print(str)
|
||||
end
|
||||
end
|
||||
global.pet_command_rotation = global.pet_command_rotation + 1
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
51
locale/utils/Thread.lua
Normal file
51
locale/utils/Thread.lua
Normal file
@ -0,0 +1,51 @@
|
||||
-- Threading simulation module
|
||||
-- Thread.sleep()
|
||||
-- @author Valansch
|
||||
-- github: https://github.com/Valansch/RedMew
|
||||
-- ======================================================= --
|
||||
|
||||
|
||||
local Thread = {}
|
||||
|
||||
local function set_new_next_async_callback_time()
|
||||
global.next_async_callback_time = global.callbacks[1].time
|
||||
for index, callback in pairs(global.callbacks) do
|
||||
if callback.time < global.next_async_callback_time then
|
||||
global.next_async_callback_time = callback.time
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
global.callbacks = {}
|
||||
global.next_async_callback_time = -1
|
||||
|
||||
|
||||
local function on_tick()
|
||||
if game.tick == global.next_async_callback_time then
|
||||
for index, callback in pairs(global.callbacks) do
|
||||
if game.tick == callback.time then
|
||||
pcall(callback.callback, callback.params)
|
||||
table.remove(global.callbacks, index)
|
||||
if #global.callbacks == 0 then
|
||||
global.next_async_callback_time = -1
|
||||
else
|
||||
set_new_next_async_callback_time()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function Thread.set_timeout(sec, callback, params)
|
||||
local time = game.tick + 60 * sec
|
||||
if global.next_async_callback_time == -1 or global.next_async_callback_time > time then
|
||||
global.next_async_callback_time = time
|
||||
end
|
||||
if #global.callbacks == 0 then
|
||||
end
|
||||
table.insert(global.callbacks, {time = time, callback = callback, params = params})
|
||||
end
|
||||
|
||||
Event.register(defines.events.on_tick, on_tick)
|
||||
|
||||
return Thread
|
@ -1,6 +1,5 @@
|
||||
|
||||
|
||||
|
||||
local function allowed_to_nuke(player)
|
||||
return player.admin or is_mod(player.name) or is_regular(player.name) or ((player.online_time / 216000) > global.scenario.config.nuke_min_time_hours)
|
||||
end
|
||||
@ -9,10 +8,24 @@ end
|
||||
local function ammo_changed(event)
|
||||
local player = game.players[event.player_index]
|
||||
if allowed_to_nuke(player) then return end
|
||||
local nukes = player.remove_item({name="atomic-bomb", count=1000})--.remove_item("atomic-bomb")
|
||||
local nukes = player.remove_item({name="atomic-bomb", count=1000})
|
||||
if nukes > 0 then
|
||||
game.print(player.name .. " tried to use a nuke, but instead dropped it on his foot.")
|
||||
player.character.health = 0
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local function on_player_deconstructed_area(event)
|
||||
local player = game.players[event.player_index]
|
||||
if allowed_to_nuke(player) then return end
|
||||
local nukes = player.remove_item({name="deconstruction-planner", count=1000})
|
||||
game.print(player.name .. " tried to deconstruct something, but instead deconstructed himself.")
|
||||
player.character.health = 0
|
||||
for _,entity in pairs(game.players[event.player_index].surface.find_entities_filtered{area = event.area}) do
|
||||
entity.cancel_deconstruction(game.players[event.player_index].force)
|
||||
end
|
||||
end
|
||||
|
||||
Event.register(defines.events.on_player_ammo_inventory_changed, ammo_changed)
|
||||
Event.register(defines.events.on_player_deconstructed_area, on_player_deconstructed_area)
|
||||
|
12
on_tick.lua
12
on_tick.lua
@ -2,14 +2,12 @@ local function on_tick()
|
||||
if game.tick % 60 == 0 then
|
||||
poll_on_second()
|
||||
walk_distance_on_second()
|
||||
if game.tick % 120 == 0 then
|
||||
pet_on_120_ticks()
|
||||
if game.tick % 1200 == 0 then
|
||||
player_list_on_12_seconds()
|
||||
end
|
||||
elseif game.tick % 180 == 0 then
|
||||
if game.tick % 1200 == 0 then
|
||||
player_list_on_12_seconds()
|
||||
end
|
||||
if game.tick % 180 == 0 then
|
||||
fish_market_on_180_ticks()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
62
pet.lua
62
pet.lua
@ -1,62 +0,0 @@
|
||||
--[[local function on_player_joined_game(event)
|
||||
local player = game.players[event.player_index]
|
||||
|
||||
if player.gui.top.pet_button == nil then
|
||||
local button = player.gui.top.add({ type = "sprite-button", name = "pet_button", sprite = "entity/small-biter" })
|
||||
button.style.minimal_height = 38
|
||||
button.style.minimal_width = 38
|
||||
button.style.top_padding = 0
|
||||
button.style.left_padding = 0
|
||||
button.style.right_padding = 0
|
||||
button.style.bottom_padding = 0
|
||||
end
|
||||
end
|
||||
|
||||
local function show_pet_panel(player)
|
||||
local frame = player.gui.left.add { type = "frame", name = "pet-panel", direction = "vertical" }
|
||||
|
||||
pet_table = frame.add { type = "table", name = "pet_panel_table", colspan = 2 }
|
||||
pet_table.add({ type = "sprite-button", name = "pet_button", sprite = "entity/small-biter" })
|
||||
end
|
||||
]]--
|
||||
function pet(player, entity_name)
|
||||
if not player then
|
||||
player = game.connected_players[1]
|
||||
else
|
||||
player = game.players[player]
|
||||
end
|
||||
if not entity_name then
|
||||
entity_name = "small-biter"
|
||||
end
|
||||
if not global.player_pets then global.player_pets = {} end
|
||||
|
||||
local surface = game.surfaces[1]
|
||||
|
||||
local pos = player.position
|
||||
pos.y = pos.y - 2
|
||||
|
||||
local x = 1
|
||||
x = x + #global.player_pets
|
||||
|
||||
global.player_pets[x] = {}
|
||||
global.player_pets[x].entity = surface.create_entity {name=entity_name, position=pos, force="player"}
|
||||
global.player_pets[x].owner = player.index
|
||||
global.player_pets[x].id = x
|
||||
|
||||
end
|
||||
|
||||
function pet_on_120_ticks()
|
||||
for _, pets in pairs(global.player_pets) do
|
||||
local player = game.players[pets.owner]
|
||||
if pcall(function () local x = pets.entity.name end) then
|
||||
pets.entity.set_command({type=defines.command.go_to_location, destination=player.position,distraction=defines.distraction.none})
|
||||
else
|
||||
global.player_pets[pets.id] = nil
|
||||
local str = player.name .. "´s pet died ;_;"
|
||||
game.print(str)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Event.register(defines.events.on_gui_click, on_gui_click)
|
||||
Event.register(defines.events.on_player_joined_game, on_player_joined_game)
|
28
poll.lua
28
poll.lua
@ -298,19 +298,21 @@ end
|
||||
|
||||
function poll_on_second()
|
||||
for _, player in pairs(game.connected_players) do
|
||||
if global.poll_panel_creation_time[player.index] then
|
||||
local frame = player.gui.left["poll-panel"]
|
||||
if frame then
|
||||
local y = (game.tick - global.poll_panel_creation_time[player.index]) / 60
|
||||
local y = global.poll_duration_in_seconds - y
|
||||
y = round(y, 0)
|
||||
if y <= 0 then
|
||||
frame.destroy()
|
||||
global.poll_panel_creation_time[player.index] = nil
|
||||
else
|
||||
y = "Hide (" .. y
|
||||
y = y .. ")"
|
||||
frame.poll_panel_button_table.poll_hide_button.caption = y
|
||||
if global.poll_panel_creation_time then
|
||||
if global.poll_panel_creation_time[player.index] then
|
||||
local frame = player.gui.left["poll-panel"]
|
||||
if frame then
|
||||
local y = (game.tick - global.poll_panel_creation_time[player.index]) / 60
|
||||
local y = global.poll_duration_in_seconds - y
|
||||
y = round(y, 0)
|
||||
if y <= 0 then
|
||||
frame.destroy()
|
||||
global.poll_panel_creation_time[player.index] = nil
|
||||
else
|
||||
y = "Hide (" .. y
|
||||
y = y .. ")"
|
||||
frame.poll_panel_button_table.poll_hide_button.caption = y
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user