1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-16 02:47:48 +02:00

tweaks and fixes

This commit is contained in:
Gerkiz 2020-07-11 17:04:53 +02:00
parent 647d52859c
commit 0aea9c28b4
4 changed files with 257 additions and 160 deletions

View File

@ -143,12 +143,14 @@ local function get_entities(item_name, entities)
return table.concat(list)
end
local function damage_player(player, kill)
local function damage_player(player, kill, print_to_all)
local msg = ' tried to destroy our base, but it backfired!'
if player.character then
if kill then
player.character.die('enemy')
if print_to_all then
game.print(player.name .. msg, Color.yellow)
end
return
end
player.character.health = player.character.health - math.random(50, 100)
@ -167,6 +169,29 @@ local function damage_player(player, kill)
end
end
local function do_action(player, prefix, msg, ban_msg, kill)
if not prefix or not msg or not ban_msg then
return
end
kill = kill or false
damage_player(player, kill)
Utils.action_warning(prefix, msg)
if this.players_warned[player.index] == 2 then
if this.enable_autoban then
Server.ban_sync(player.name, ban_msg, '<script>')
end
elseif this.players_warned[player.index] == 1 then
this.players_warned[player.index] = 2
if this.enable_autokick then
game.kick_player(player, msg)
end
else
this.players_warned[player.index] = 1
end
end
local function on_marked_for_deconstruction(event)
local tracker = session.get_session_table()
local trusted = session.get_trusted_table()
@ -232,6 +257,13 @@ local function on_player_built_tile(event)
end
local player = game.players[event.player_index]
local surface = event.surface
if surface and surface.valid then
surface = event.surface.index
else
surface = 'nil'
end
--landfill history--
if not this.landfill_history[player.index] then
@ -248,7 +280,7 @@ local function on_player_built_tile(event)
str = str .. ' Y:'
str = str .. placed_tiles[1].position.y
str = str .. ' '
str = str .. 'surface:' .. event.surface.index
str = str .. 'surface:' .. surface
increment(this.landfill_history, player.index, str)
end
@ -327,30 +359,17 @@ local function on_player_used_capsule(event)
return
end
local prefix = '{Capsule}'
local msg = format(player.name .. ' damaged: %s with: %s', get_entities(name, entities), name)
if this.players_warned[event.player_index] == 2 then
if this.enable_autoban then
Server.ban_sync(
player.name,
local ban_msg =
format(
'Damaged: %s with: %s. This action was performed automatically. Visit getcomfy.eu/discord for forgiveness',
get_entities(name, entities),
name
),
'<script>'
)
end
elseif this.players_warned[event.player_index] == 1 then
this.players_warned[event.player_index] = true
if this.enable_autokick then
game.kick_player(player, msg)
end
else
this.players_warned[event.player_index] = 1
damage_player(player, true)
Utils.print_to(nil, msg)
end
do_action(player, prefix, msg, ban_msg, true)
if not this.capsule_history[player.index] then
this.capsule_history[player.index] = {}
end
@ -446,12 +465,16 @@ end
--Mining Thieves History
local function on_player_mined_entity(event)
local player = game.players[event.player_index]
if not player then
if not player or not player.valid then
return
end
if this.whitelist_types[event.entity.type] then
local entity = event.entity
if not entity or not entity.valid then
return
end
if this.whitelist_types[entity.type] then
if not this.mining_history[player.index] then
this.mining_history[player.index] = {}
end
@ -461,24 +484,24 @@ local function on_player_mined_entity(event)
local t = math.abs(math.floor((game.tick) / 3600))
local str = '[' .. t .. '] '
str = str .. player.name .. ' mined '
str = str .. event.entity.name
str = str .. entity.name
str = str .. ' at X:'
str = str .. math.floor(event.entity.position.x)
str = str .. math.floor(entity.position.x)
str = str .. ' Y:'
str = str .. math.floor(event.entity.position.y)
str = str .. math.floor(entity.position.y)
str = str .. ' '
str = str .. 'surface:' .. event.entity.surface.index
str = str .. 'surface:' .. entity.surface.index
increment(this.mining_history, player.index, str)
return
end
if not entity.last_user then
return
end
if not event.entity.last_user then
if entity.last_user.name == player.name then
return
end
if event.entity.last_user.name == player.name then
return
end
if event.entity.force.name ~= player.force.name then
if entity.force.name ~= player.force.name then
return
end
if blacklisted_types[event.entity.type] then
@ -551,18 +574,26 @@ local function on_gui_opened(event)
end
local function on_pre_player_mined_item(event)
if event.entity.name ~= 'character-corpse' then
local player = game.players[event.player_index]
if not player or not player.valid then
return
end
local player = game.players[event.player_index]
local corpse_owner = game.players[event.entity.character_corpse_player_index]
local entity = event.entity
if not entity or not entity.valid then
return
end
if entity.name ~= 'character-corpse' then
return
end
local corpse_owner = game.players[entity.character_corpse_player_index]
if not corpse_owner then
return
end
local entity = event.entity
if not entity then
return
end
local corpse_content = #entity.get_inventory(defines.inventory.character_corpse)
if corpse_content <= 0 then
return
@ -584,11 +615,11 @@ local function on_pre_player_mined_item(event)
str = str .. player.name .. ' mined '
str = str .. corpse_owner.name .. ' body'
str = str .. ' at X:'
str = str .. math.floor(event.entity.position.x)
str = str .. math.floor(entity.position.x)
str = str .. ' Y:'
str = str .. math.floor(event.entity.position.y)
str = str .. math.floor(entity.position.y)
str = str .. ' '
str = str .. 'surface:' .. event.entity.surface.index
str = str .. 'surface:' .. entity.surface.index
increment(this.corpse_history, player.index, str)
end
end
@ -713,6 +744,29 @@ local function on_entity_damaged(event)
protect_entities(event)
end
local function on_init()
local branch_version = '0.18.35'
local sub = string.sub
game.forces.player.research_queue_enabled = true
local is_branch_18 = sub(branch_version, 3, 4)
local get_active_version = sub(game.active_mods.base, 3, 4)
local default = game.permissions.get_group('Default')
default.set_allows_action(defines.input_action.change_multiplayer_config, false)
default.set_allows_action(defines.input_action.edit_permission_group, false)
default.set_allows_action(defines.input_action.import_permissions_string, false)
default.set_allows_action(defines.input_action.delete_permission_group, false)
default.set_allows_action(defines.input_action.add_permission_group, false)
default.set_allows_action(defines.input_action.admin_action, false)
is_branch_18 = is_branch_18 .. sub(branch_version, 6, 7)
get_active_version = get_active_version .. sub(game.active_mods.base, 6, 7)
if get_active_version >= is_branch_18 then
default.set_allows_action(defines.input_action.flush_opened_entity_fluid, false)
default.set_allows_action(defines.input_action.flush_opened_entity_specific_fluid, false)
end
end
--- Enabling this will protect all entities except for those in the not_protected table.
---@param boolean true/false
function Public.protect_entities(value)
@ -748,7 +802,7 @@ function Public.whitelist_types(key, value)
end
end
--- If the event should also check trusted players
--- If the event should also check trusted players.
---@param value string
function Public.do_not_check_trusted(value)
if value then
@ -756,7 +810,7 @@ function Public.do_not_check_trusted(value)
end
end
--- Returns the table
--- Returns the table.
---@param key string
function Public.get(key)
if key then
@ -766,6 +820,7 @@ function Public.get(key)
end
end
Event.on_init(on_init)
Event.add(defines.events.on_player_mined_entity, on_player_mined_entity)
Event.add(defines.events.on_entity_died, on_entity_died)
Event.add(defines.events.on_built_entity, on_built_entity)

View File

@ -474,13 +474,13 @@ local function player_list_show(player, frame, sort_by)
local tooltip
if game.players[player_list[i].name].admin then
trusted = '[color=#ff0000][A][/color]'
trusted = '[color=red][A][/color]'
tooltip = 'This player is an admin of this server.'
elseif play_table[player_list[i].name] then
trusted = '[color=#008000][T][/color]'
trusted = '[color=green][T][/color]'
tooltip = 'This player is trusted.'
else
trusted = '[color=#ffff00][U][/color]'
trusted = '[color=yellow][U][/color]'
tooltip = 'This player is not trusted.'
end

View File

@ -242,7 +242,7 @@ local function spawn_random_buildings(entities, p, depth)
if math.abs(p.y) < depth * 1.5 then
if math.random(1, 16) == 1 then
return buildings[randomizer](entities, p, low)
return buildings[randomizer](entities, p, medium)
else
return buildings[randomizer](entities, p, low)
end

View File

@ -10,6 +10,7 @@ local Utils = require 'utils.core'
local jailed_data_set = 'jailed'
local jailed = {}
local votejail = {}
local votefree = {}
local votejail_count = 3
local set_data = Server.set_data
local try_get_data = Server.try_get_data
@ -33,27 +34,108 @@ local valid_commands = {
Global.register(
{
jailed = jailed,
votejail = votejail
votejail = votejail,
votefree = votefree
},
function(t)
jailed = t.jailed
votejail = t.votejail
votefree = t.votefree
end
)
local Public = {}
local jail = function(target_player, player)
if jailed[target_player] then
if player then
Utils.print_to(player, target_player .. ' is already jailed!')
local validate_args = function(player, griefer)
if not game.players[griefer] then
Utils.print_to(player, 'Invalid name.')
return false
end
if votejail[player.name] and not player.admin then
Utils.print_to(player, 'You are currently being investigated since you have griefed.')
return false
end
if votefree[player.name] and not player.admin then
Utils.print_to(player, 'You are currently being investigated since you have griefed.')
return false
end
if jailed[player.name] and not player.admin then
Utils.print_to(player, 'You are jailed, you can´t run this command.')
return false
end
if player.name == griefer then
Utils.print_to(player, 'You can´t select yourself.')
return false
end
if game.players[griefer].admin and not player.admin then
Utils.print_to(player, 'You can´t select an admin.')
return false
end
return true
end
local vote_to_jail = function(player, griefer)
if not votejail[griefer] then
votejail[griefer] = {index = 0}
local message = player.name .. ' has started a vote to jail player ' .. griefer
Utils.print_to(nil, message)
end
if not votejail[griefer][player.name] then
votejail[griefer][player.name] = true
votejail[griefer].index = votejail[griefer].index + 1
Utils.print_to(player, 'You have voted to jail player ' .. griefer .. '.')
if
votejail[griefer].index >= votejail_count or
(votejail[griefer].index == #game.connected_players - 1 and
#game.connected_players > votejail[griefer].index)
then
Public.try_ul_data(griefer, true)
end
else
return false
Utils.print_to(player, 'You have already voted to kick ' .. griefer .. '.')
end
end
if not game.players[target_player] then
local vote_to_free = function(player, griefer)
if votejail[griefer] and not votefree[griefer] then
votefree[griefer] = {index = 0}
local message = player.name .. ' has started a vote to free player ' .. griefer
Utils.print_to(nil, message)
end
if not votefree[griefer][player.name] then
votefree[griefer][player.name] = true
votefree[griefer].index = votefree[griefer].index + 1
Utils.print_to(player, 'You have voted to free player ' .. griefer .. '.')
if
votefree[griefer].index >= votejail_count or
(votefree[griefer].index == #game.connected_players - 1 and
#game.connected_players > votefree[griefer].index)
then
Public.try_ul_data(griefer, false)
votejail[griefer] = nil
votefree[griefer] = nil
end
else
Utils.print_to(player, 'You have already voted to free ' .. griefer .. '.')
end
return
end
local jail = function(player, griefer)
player = player or 'script'
if jailed[griefer] then
Utils.print_to(player, griefer .. ' is already jailed!')
return false
end
if not game.players[griefer] then
return
end
@ -67,67 +149,59 @@ local jail = function(target_player, player)
permission_group.set_allows_action(defines.input_action.gui_click, true)
permission_group.set_allows_action(defines.input_action.gui_selection_state_changed, true)
end
permission_group.add_player(target_player)
local message
if player then
message =
target_player .. ' has been jailed by ' .. player .. '. ' .. jail_messages[math.random(1, #jail_messages)]
else
message =
target_player ..
' has been jailed automatically since they have griefed. ' .. jail_messages[math.random(1, #jail_messages)]
end
permission_group.add_player(griefer)
local message = griefer .. ' has been jailed by ' .. player .. '. ' .. jail_messages[math.random(1, #jail_messages)]
if
game.players[target_player].character and game.players[target_player].character.valid and
game.players[target_player].character.driving
game.players[griefer].character and game.players[griefer].character.valid and
game.players[griefer].character.driving
then
game.players[target_player].character.driving = false
game.players[griefer].character.driving = false
end
jailed[griefer] = {jailed = true, actor = player}
set_data(jailed_data_set, griefer, {jailed = true, actor = player})
Utils.print_to(nil, message)
Utils.action_warning_embed('{Jailed}', message)
Utils.print_admins('Jailed ' .. target_player, player)
Utils.print_admins('Jailed ' .. griefer, player)
game.players[target_player].clear_console()
Utils.print_to(target_player, message)
game.players[griefer].clear_console()
Utils.print_to(griefer, message)
return true
end
local free = function(target_player, player)
if not jailed[target_player] then
if player then
Utils.print_to(player, target_player .. ' is not jailed!')
local free = function(player, griefer)
player = player or 'script'
if not jailed[griefer] then
Utils.print_to(player, griefer .. ' is not jailed!')
return false
else
return false
end
end
if not game.players[target_player] then
if not game.players[griefer] then
return
end
local permission_group = game.permissions.get_group('Default')
permission_group.add_player(target_player)
local message
if player then
message =
target_player ..
permission_group.add_player(griefer)
local message =
griefer ..
' was set free from jail by ' .. player .. '. ' .. freedom_messages[math.random(1, #freedom_messages)]
else
message = target_player .. ' was set free from jail. ' .. freedom_messages[math.random(1, #freedom_messages)]
jailed[griefer] = nil
set_data(jailed_data_set, griefer, nil)
if votejail[griefer] then
votejail[griefer] = nil
end
jailed[target_player] = nil
if votejail[target_player] then
votejail[target_player] = nil
if votefree[griefer] then
votefree[griefer] = nil
end
Utils.print_to(nil, message)
Utils.action_warning_embed('{Jailed}', message)
Utils.print_admins('Free´d ' .. target_player .. ' from jail.', player)
Utils.print_admins('Free´d ' .. griefer .. ' from jail.', player)
return true
end
@ -138,8 +212,7 @@ local is_jailed =
local value = data.value
if value then
if value.jailed then
jail(key)
jailed[key] = {jailed = true, actor = value.actor}
jail(value.actor, key)
end
end
end
@ -149,14 +222,12 @@ local update_jailed =
Token.register(
function(data)
local key = data.key
local value = data.value
local value = data.value or false
local player = data.player or 'script'
if value then
jail(key)
set_data(jailed_data_set, key, {jailed = true, actor = player})
jail(player, key)
else
free(key)
set_data(jailed_data_set, key, nil)
free(player, key)
end
end
)
@ -183,7 +254,7 @@ function Public.try_ul_data(key, value, player)
local data = {
key = key,
value = value,
player = player or nil
player = player
}
Task.set_timeout_in_ticks(1, update_jailed, data)
@ -230,7 +301,6 @@ Event.add(
defines.events.on_console_command,
function(event)
local tracker = Session.get_session_table()
local script = 'script'
local cmd = event.command
local _10d = 51840000 -- 10d
local _12h = 2592000 -- 12h
@ -246,57 +316,30 @@ Event.add(
if event.player_index then
local player = game.players[event.player_index]
local playtime = player.online_time
local success = validate_args(player, griefer)
if not success then
return
end
if tracker[player.name] then
playtime = player.online_time + tracker[player.name]
end
if game.players[griefer] then
griefer = game.players[griefer].name
end
if not game.players[griefer] then
return Utils.print_to(player, 'Invalid name.')
end
local playtime = player.online_time
if tracker[player.name] then
playtime = player.online_time + tracker[player.name]
end
if votejail[player.name] and not player.admin then
return Utils.print_to(player, 'You are currently being investigated since you have griefed.')
end
if jailed[player.name] and not player.admin then
return Utils.print_to(player, 'You are jailed, you can´t run this command.')
end
if player.name == griefer then
return Utils.print_to(player, 'You can´t select yourself.')
end
if game.players[griefer].admin and not player.admin then
return Utils.print_to(player, 'You can´t select an admin.')
end
if playtime >= _12h and playtime < _10d and not player.admin then
if not votejail[griefer] then
votejail[griefer] = {}
local message = player.name .. ' has started a vote to jail player ' .. griefer
Utils.print_to(nil, message)
end
if not votejail[griefer][player.name] then
votejail[griefer][player.name] = true
Utils.print_to(player, 'You have voted to jail player ' .. griefer .. '.')
if
#votejail[griefer] >= votejail_count or
(#votejail[griefer] == 2 and 3 == #game.connected_players)
then
local message = griefer .. ' has been jailed by player vote.'
Utils.print_to(nil, message)
Public.try_ul_data(griefer, true, script)
end
else
Utils.print_to(player, 'You have already voted to kick ' .. griefer .. '.')
end
if cmd == 'jail' then
vote_to_jail(player, griefer)
return
elseif cmd == 'free' then
vote_to_free(player, griefer)
return
end
elseif playtime < _10d and not player.admin then
return Utils.print_to(player, 'You are not trusted enough to run this command.')
end
@ -310,10 +353,10 @@ Event.add(
end
else
if cmd == 'jail' then
Public.try_ul_data(griefer, true, script)
Public.try_ul_data(griefer, true)
return
elseif cmd == 'free' then
Public.try_ul_data(griefer, false, script)
Public.try_ul_data(griefer, false)
return
end
end
@ -325,11 +368,10 @@ Server.on_data_set_changed(
function(data)
if data and data.value then
if data.value.jailed and data.value.actor then
jail(data.key)
jailed[data.key] = {jailed = true, actor = data.value.actor}
jail(data.value.actor, data.key)
end
else
free(data.key)
free('script', data.key)
end
end
)