mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2024-12-26 22:56:43 +02:00
commit
78bae6a7ad
@ -43,14 +43,17 @@ local function refund_item(event, item_name)
|
||||
if item_name == 'blueprint' then
|
||||
return
|
||||
end
|
||||
local player = game.get_player(event.player_index)
|
||||
local robot = event.robot
|
||||
if player and player.valid then
|
||||
player.insert({name = item_name, count = 1})
|
||||
return
|
||||
|
||||
if event.player_index then
|
||||
local player = game.get_player(event.player_index)
|
||||
if player and player.valid then
|
||||
player.insert({name = item_name, count = 1})
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
-- return item to robot, but don't replace ghost (otherwise might loop)
|
||||
local robot = event.robot
|
||||
if robot and robot.valid then
|
||||
local inventory = robot.get_inventory(defines.inventory.robot_cargo)
|
||||
inventory.insert({name = item_name, count = 1})
|
||||
@ -105,6 +108,31 @@ function Public.in_area(position, area_center, area_radius)
|
||||
return false
|
||||
end
|
||||
|
||||
function Public.is_another_character_near(surface, position, force)
|
||||
if not surface then
|
||||
return
|
||||
end
|
||||
if not position then
|
||||
return
|
||||
end
|
||||
if not force then
|
||||
return
|
||||
end
|
||||
|
||||
local ents = surface.find_entities_filtered {position = position, radius = 15, type = 'character'}
|
||||
if ents and #ents >= 1 then
|
||||
for _, ent in pairs(ents) do
|
||||
if ent and ent.valid then
|
||||
if ent.force.name ~= force.name and not ent.force.get_friend(force.name) and not force.get_friend(ent.force.name) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
-- is the position near another town?
|
||||
function Public.near_another_town(force_name, position, surface, radius)
|
||||
-- check for nearby town centers
|
||||
@ -237,7 +265,7 @@ local function prevent_landfill_in_restricted_zone(event)
|
||||
end
|
||||
|
||||
local function process_built_entities(event)
|
||||
local player_index = event.player_index or nil
|
||||
local player_index = event.player_index
|
||||
local entity = event.created_entity
|
||||
if entity == nil or not entity.valid then
|
||||
return
|
||||
@ -249,12 +277,42 @@ local function process_built_entities(event)
|
||||
local force_name
|
||||
if player_index ~= nil then
|
||||
local player = game.get_player(player_index)
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
|
||||
force = player.force
|
||||
force_name = force.name
|
||||
|
||||
local is_another_character_near = Public.is_another_character_near(player.surface, player.position, force)
|
||||
if is_another_character_near then
|
||||
entity.destroy()
|
||||
|
||||
player.play_sound({path = 'utility/cannot_build', position = player.position, volume_modifier = 0.75})
|
||||
error_floaty(surface, position, "Can't build near other characters!")
|
||||
if name ~= 'entity-ghost' then
|
||||
if event.stack and event.stack.valid_for_read then
|
||||
refund_item(event, event.stack.name)
|
||||
end
|
||||
end
|
||||
return
|
||||
end
|
||||
else
|
||||
local robot = event.robot
|
||||
force = robot.force
|
||||
force_name = force.name
|
||||
|
||||
local is_another_character_near = Public.is_another_character_near(robot.surface, robot.position, robot.force)
|
||||
if is_another_character_near then
|
||||
entity.destroy()
|
||||
error_floaty(surface, position, "Can't build near other characters!")
|
||||
if name ~= 'entity-ghost' then
|
||||
if event.stack and event.stack.valid_for_read then
|
||||
refund_item(event, event.stack.name)
|
||||
end
|
||||
end
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
if Public.near_another_town(force_name, position, surface, 32) == true then
|
||||
@ -262,13 +320,19 @@ local function process_built_entities(event)
|
||||
entity.force = game.forces['neutral']
|
||||
else
|
||||
entity.destroy()
|
||||
if player_index ~= nil then
|
||||
if player_index then
|
||||
local player = game.get_player(player_index)
|
||||
if not player or not player.valid then
|
||||
return
|
||||
end
|
||||
|
||||
player.play_sound({path = 'utility/cannot_build', position = player.position, volume_modifier = 0.75})
|
||||
end
|
||||
error_floaty(surface, position, "Can't build near town!")
|
||||
if name ~= 'entity-ghost' then
|
||||
refund_item(event, event.stack.name)
|
||||
if event.stack and event.stack.valid_for_read then
|
||||
refund_item(event, event.stack.name)
|
||||
end
|
||||
end
|
||||
return
|
||||
end
|
||||
|
@ -39,6 +39,7 @@ local Color = require 'utils.color_presets'
|
||||
local Server = require 'utils.server'
|
||||
local Where = require 'utils.commands.where'
|
||||
local Inventory = require 'modules.show_inventory'
|
||||
local JailData = require 'utils.datastore.jail_data'
|
||||
|
||||
local function spairs(t)
|
||||
local keys = {}
|
||||
@ -168,6 +169,7 @@ local function update_score()
|
||||
end
|
||||
|
||||
local function on_init()
|
||||
JailData.normies_can_jail(false)
|
||||
Autostash.insert_into_furnace(true)
|
||||
Autostash.insert_to_neutral_chests(true)
|
||||
Autostash.insert_into_wagon(true)
|
||||
|
@ -250,13 +250,22 @@ commands.add_command(
|
||||
game.print('[CREATIVE] ' .. player.name .. ' has activated creative-mode!', Color.warning)
|
||||
Server.to_discord_bold(table.concat {'[Creative] ' .. player.name .. ' has activated creative-mode!'})
|
||||
|
||||
for k, _player in pairs(game.connected_players) do
|
||||
if _player.character ~= nil then
|
||||
if _player.get_inventory(defines.inventory.character_armor) then
|
||||
_player.get_inventory(defines.inventory.character_armor).clear()
|
||||
for _, iter_player in pairs(game.connected_players) do
|
||||
if iter_player.character ~= nil then
|
||||
if iter_player.get_inventory(defines.inventory.character_armor) then
|
||||
iter_player.get_inventory(defines.inventory.character_armor).clear()
|
||||
end
|
||||
_player.insert {name = 'power-armor-mk2', count = 1}
|
||||
local p_armor = _player.get_inventory(5)[1].grid
|
||||
Modifiers.update_single_modifier(player, 'character_mining_speed_modifier', 'creative', 50)
|
||||
Modifiers.update_single_modifier(player, 'character_health_bonus', 'creative', 2000)
|
||||
Modifiers.update_single_modifier(player, 'character_crafting_speed_modifier', 'creative', 50)
|
||||
Modifiers.update_single_modifier(player, 'character_inventory_slots_bonus', 'creative', #game.item_prototypes)
|
||||
---@diagnostic disable-next-line: assign-type-mismatch
|
||||
iter_player.character_inventory_slots_bonus = Modifiers.get_single_modifier(player, 'character_inventory_slots_bonus', 'creative')
|
||||
Modifiers.update_player_modifiers(player)
|
||||
|
||||
iter_player.insert {name = 'power-armor-mk2', count = 1}
|
||||
---@diagnostic disable-next-line: param-type-mismatch
|
||||
local p_armor = iter_player.get_inventory(5)[1].grid
|
||||
if p_armor and p_armor.valid then
|
||||
p_armor.put({name = 'fusion-reactor-equipment'})
|
||||
p_armor.put({name = 'fusion-reactor-equipment'})
|
||||
@ -274,20 +283,12 @@ commands.add_command(
|
||||
p_armor.put({name = 'battery-mk2-equipment'})
|
||||
end
|
||||
local item = game.item_prototypes
|
||||
local i = 0
|
||||
for _k, _v in pairs(item) do
|
||||
i = i + 1
|
||||
if _k and _v.type ~= 'mining-tool' then
|
||||
Modifiers.update_single_modifier(player, 'character_inventory_slots_bonus', 'creative', tonumber(i))
|
||||
Modifiers.update_single_modifier(player, 'character_mining_speed_modifier', 'creative', 50)
|
||||
Modifiers.update_single_modifier(player, 'character_health_bonus', 'creative', 2000)
|
||||
Modifiers.update_single_modifier(player, 'character_crafting_speed_modifier', 'creative', 50)
|
||||
_player.character_inventory_slots_bonus = Modifiers.get_single_modifier(player, 'character_inventory_slots_bonus', 'creative')
|
||||
_player.insert {name = _k, count = _v.stack_size}
|
||||
_player.print('[CREATIVE] Inserted all base items.', Color.success)
|
||||
Modifiers.update_player_modifiers(player)
|
||||
iter_player.insert {name = _k, count = _v.stack_size}
|
||||
end
|
||||
end
|
||||
iter_player.print('[CREATIVE] Inserted all base items.', Color.success)
|
||||
this.creative_enabled = true
|
||||
end
|
||||
end
|
||||
|
@ -26,7 +26,8 @@ local settings = {
|
||||
clear_voted_player = 36000, -- remove player from vote-tbl after 10 minutes
|
||||
clear_terms_tbl = 300,
|
||||
votejail_count = 5,
|
||||
valid_surface = 'nauvis'
|
||||
valid_surface = 'nauvis',
|
||||
normies_can_jail = true -- states that normal players with enough playtime can jail
|
||||
}
|
||||
|
||||
local set_data = Server.set_data
|
||||
@ -1036,6 +1037,13 @@ function Public.sync_revoked_permissions()
|
||||
Server.try_get_all_data(revoked_permissions_set, sync_revoked_permissions_callback)
|
||||
end
|
||||
|
||||
---
|
||||
--- This toggles normal players ability to jail other players (non admins)
|
||||
---@param value boolean
|
||||
function Public.normies_can_jail(value)
|
||||
settings.normies_can_jail = value or false
|
||||
end
|
||||
|
||||
Server.on_data_set_changed(
|
||||
jailed_data_set,
|
||||
function(data)
|
||||
@ -1219,7 +1227,7 @@ Event.add(
|
||||
return
|
||||
end
|
||||
|
||||
if trusted and playtime >= settings.playtime_for_vote and playtime < settings.playtime_for_instant_jail and not player.admin then
|
||||
if settings.normies_can_jail and trusted and playtime >= settings.playtime_for_vote and playtime < settings.playtime_for_instant_jail and not player.admin then
|
||||
if cmd == 'jail' then
|
||||
if not terms_tbl[player.name] then
|
||||
Utils.warning(player, module_name .. 'Abusing the jail command will lead to revoked permissions. Jailing someone in cases of disagreement is _NEVER_ OK!')
|
||||
@ -1251,7 +1259,7 @@ Event.add(
|
||||
Public.try_ul_data(offender, false, player.name)
|
||||
return
|
||||
end
|
||||
elseif playtime >= settings.playtime_for_instant_jail then
|
||||
elseif settings.normies_can_jail and playtime >= settings.playtime_for_instant_jail then
|
||||
if cmd == 'jail' then
|
||||
if not terms_tbl[player.name] then
|
||||
Utils.warning(player, module_name .. 'Abusing the jail command will lead to revoked permissions. Jailing someone in cases of disagreement is _NEVER_ OK!')
|
||||
|
@ -117,11 +117,19 @@ Module.format_time = function(ticks)
|
||||
return table.concat(result, ' ')
|
||||
end
|
||||
|
||||
function Module.inside(pos, area)
|
||||
--- Compares positions
|
||||
---@param position table
|
||||
---@param area table
|
||||
---@return boolean
|
||||
function Module.inside(position, area)
|
||||
if not position then
|
||||
return false
|
||||
end
|
||||
|
||||
local lt = area.left_top
|
||||
local rb = area.right_bottom
|
||||
|
||||
return pos.x >= lt.x and pos.y >= lt.y and pos.x <= rb.x and pos.y <= rb.y
|
||||
return position.x >= lt.x and position.y >= lt.y and position.x <= rb.x and position.y <= rb.y
|
||||
end
|
||||
|
||||
return Module
|
||||
|
Loading…
Reference in New Issue
Block a user