1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-03-11 14:49:24 +02:00
disable players from jailing eachother and building placement restriction
This commit is contained in:
Gerkiz 2023-01-23 21:40:01 +01:00
parent 0c613e5a00
commit efabdde589
2 changed files with 74 additions and 8 deletions

View File

@ -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

View File

@ -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)