1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-08 00:39:30 +02:00
ComfyFactorio/antigrief.lua

267 lines
10 KiB
Lua
Raw Normal View History

2018-11-18 15:18:43 +02:00
--antigrief things made by mewmew
--as an admin, write trust/untrust and the players name in the chat to grant/revoke immunity from protection
2018-11-18 15:18:43 +02:00
local event = require 'utils.event'
2018-11-18 15:18:43 +02:00
local function create_admin_button(player)
if player.gui.top["admin_button"] then return end
2019-01-03 00:27:24 +02:00
local b = player.gui.top.add({type = "button", caption = "Admin", name = "admin_button", tooltip = "Use your powers wisely"})
2019-03-03 01:33:08 +02:00
b.style.font_color = {r = 0.1, g = 0.1, b = 0.1}
2018-11-18 15:18:43 +02:00
b.style.font = "default-bold"
b.style.minimal_height = 38
2019-03-02 14:06:29 +02:00
b.style.minimal_width = 54
2018-11-18 15:18:43 +02:00
b.style.top_padding = 2
b.style.left_padding = 4
b.style.right_padding = 4
b.style.bottom_padding = 2
2018-09-24 06:43:15 +02:00
end
local function on_player_joined_game(event)
2018-11-18 15:18:43 +02:00
local player = game.players[event.player_index]
if not global.trusted_players then global.trusted_players = {} end
if not global.trusted_players[player.name] then global.trusted_players[player.name] = false end
2018-11-18 15:18:43 +02:00
if player.admin == true then
create_admin_button(player)
end
2019-03-31 10:21:05 +02:00
local playtime = player.online_time
if global.player_totals then
if global.player_totals[player.name] then
playtime = player.online_time + global.player_totals[player.name][1]
end
end
if playtime > 2592000 then
global.trusted_players[player.name] = true
end
2018-11-18 15:18:43 +02:00
end
local function on_player_promoted(event)
local player = game.players[event.player_index]
create_admin_button(player)
end
local function on_player_demoted(event)
local player = game.players[event.player_index]
if player.gui.top["admin_button"] then player.gui.top["admin_button"].destroy() end
if player.gui.left["admin_panel"] then player.gui.left["admin_panel"].destroy() end
2018-09-24 06:43:15 +02:00
end
local function on_marked_for_deconstruction(event)
2018-12-03 19:27:19 +02:00
if not event.player_index then return end
local player = game.players[event.player_index]
2018-09-23 03:17:31 +02:00
if player.admin == true then return end
if global.trusted_players[player.name] == true then return end
local playtime = player.online_time
if global.player_totals then
if global.player_totals[player.name] then
playtime = player.online_time + global.player_totals[player.name][1]
end
end
2018-10-26 18:17:12 +02:00
if playtime < 2592000 then
event.entity.cancel_deconstruction(game.players[event.player_index].force.name)
2018-09-23 03:17:31 +02:00
player.print("You have not grown accustomed to this technology yet.", { r=0.22, g=0.99, b=0.99})
end
end
2018-09-23 03:17:31 +02:00
local function on_player_ammo_inventory_changed(event)
local player = game.players[event.player_index]
2018-09-23 03:17:31 +02:00
if player.admin == true then return end
if global.trusted_players[player.name] == true then return end
local playtime = player.online_time
if global.player_totals then
if global.player_totals[player.name] then
playtime = player.online_time + global.player_totals[player.name][1]
end
2018-09-23 03:17:31 +02:00
end
if playtime < 1296000 then
2018-09-23 03:17:31 +02:00
local nukes = player.remove_item({name="atomic-bomb", count=1000})
if nukes > 0 then
player.surface.spill_item_stack(player.position, {name = "atomic-bomb", count = nukes}, false)
player.print("You have not grown accustomed to this technology yet.", {r=0.22, g=0.99, b=0.99})
2019-03-23 00:42:30 +02:00
server_commands.to_discord_bold(table.concat{'[Nuke] ' .. player.name .. ' tried to equip nukes but was not trusted.'})
2018-09-23 03:17:31 +02:00
end
end
end
2018-09-23 07:40:37 +02:00
local function on_player_built_tile(event)
local placed_tiles = event.tiles
2018-12-15 15:05:07 +02:00
if placed_tiles[1].old_tile.name ~= "deepwater" and placed_tiles[1].old_tile.name ~= "water" and placed_tiles[1].old_tile.name ~= "water-green" then return end
local player = game.players[event.player_index]
--[[
if not player.admin and not global.trusted_players[player.name] then
2018-12-15 15:05:07 +02:00
local playtime = player.online_time
if global.player_totals then
if global.player_totals[player.name] then
playtime = player.online_time + global.player_totals[player.name][1]
end
end
if playtime < 648000 then
local tiles = {}
for _, t in pairs(placed_tiles) do
table.insert(tiles, {name = t.old_tile.name, position = t.position})
end
player.insert({name = "landfill", count = #placed_tiles})
player.surface.set_tiles(tiles, true)
player.print("You have not grown accustomed to this technology yet.", { r=0.22, g=0.99, b=0.99})
end
end]]
2018-09-23 07:40:37 +02:00
2018-12-15 15:05:07 +02:00
--landfill history--
if not global.landfill_history then global.landfill_history = {} end
if #global.landfill_history > 999 then global.landfill_history = {} end
local str = player.name .. " at X:"
str = str .. placed_tiles[1].position.x
str = str .. " Y:"
str = str .. placed_tiles[1].position.y
table.insert(global.landfill_history, str)
2018-09-23 07:40:37 +02:00
end
2018-11-03 19:34:29 +02:00
local function on_built_entity(event)
2018-11-18 15:18:43 +02:00
if game.tick < 1296000 then return end
2018-11-03 19:34:29 +02:00
if event.created_entity.type == "entity-ghost" then
local player = game.players[event.player_index]
if player.admin == true then return end
if global.trusted_players[player.name] == true then return end
2018-11-03 19:34:29 +02:00
local playtime = player.online_time
if global.player_totals then
if global.player_totals[player.name] then
playtime = player.online_time + global.player_totals[player.name][1]
end
end
2018-11-07 21:27:42 +02:00
if playtime < 432000 then
2018-11-03 19:34:29 +02:00
event.created_entity.destroy()
player.print("You have not grown accustomed to this technology yet.", { r=0.22, g=0.99, b=0.99})
end
end
end
2018-12-02 20:29:20 +02:00
--Artillery History and Antigrief
2018-11-25 17:04:57 +02:00
local function on_player_used_capsule(event)
local player = game.players[event.player_index]
local position = event.position
2018-12-02 20:29:20 +02:00
local used_item = event.item
if used_item.name ~= "artillery-targeting-remote" then return end
local playtime = player.online_time
if global.player_totals then
if global.player_totals[player.name] then
playtime = player.online_time + global.player_totals[player.name][1]
end
end
if playtime < 1296000 and player.admin == false and global.trusted_players[player.name] == false then
2018-12-02 20:29:20 +02:00
player.print("You have not grown accustomed to this technology yet.", { r=0.22, g=0.99, b=0.99})
local area = {{position.x - 1, position.y - 1},{position.x + 1, position.y + 1}}
local entities = player.surface.find_entities_filtered({area = area, name = "artillery-flare"})
for _, e in pairs(entities) do
e.destroy()
end
return
end
if not global.artillery_history then global.artillery_history = {} end
if #global.artillery_history > 999 then global.artillery_history = {} end
local str = player.name .. " at X:"
str = str .. math.floor(position.x)
str = str .. " Y:"
str = str .. math.floor(position.y)
table.insert(global.artillery_history, str)
2018-11-25 17:04:57 +02:00
end
2018-12-02 17:58:17 +02:00
local blacklisted_types = {
["transport-belt"] = true,
["wall"] = true,
["underground-belt"] = true,
["inserter"] = true,
["land-mine"] = true,
["gate"] = true,
["lamp"] = true,
["mining-drill"] = true,
["splitter"] = true
}
2018-12-02 06:47:58 +02:00
--Friendly Fire History
local function on_entity_died(event)
if not event.cause then return end
if event.cause.name ~= "player" then return end
if event.cause.force.name ~= event.entity.force.name then return end
2018-12-02 17:58:17 +02:00
if blacklisted_types[event.entity.type] then return end
2018-12-02 06:47:58 +02:00
local player = event.cause.player
if not global.friendly_fire_history then global.friendly_fire_history = {} end
if #global.friendly_fire_history > 999 then global.friendly_fire_history = {} end
2018-12-18 06:36:23 +02:00
if not player then return end
2018-12-02 06:47:58 +02:00
local str = player.name .. " destroyed "
str = str .. event.entity.name
str = str .. " at X:"
str = str .. math.floor(event.entity.position.x)
str = str .. " Y:"
str = str .. math.floor(event.entity.position.y)
global.friendly_fire_history[#global.friendly_fire_history + 1] = str
end
2018-12-02 07:39:54 +02:00
--Mining Thieves History
local function on_player_mined_entity(event)
if not event.entity.last_user then return end
local player = game.players[event.player_index]
if event.entity.last_user.name == player.name then return end
if event.entity.force.name ~= player.force.name then return end
if blacklisted_types[event.entity.type] then return end
if not global.mining_history then global.mining_history = {} end
if #global.mining_history > 999 then global.mining_history = {} end
local str = player.name .. " mined "
str = str .. event.entity.name
str = str .. " at X:"
str = str .. math.floor(event.entity.position.x)
str = str .. " Y:"
str = str .. math.floor(event.entity.position.y)
global.mining_history[#global.mining_history + 1] = str
end
local function on_gui_opened(event)
if not event.entity then return end
if event.entity.name ~= "character-corpse" then return end
local player = game.players[event.player_index]
local corpse_owner = game.players[event.entity.character_corpse_player_index]
2019-03-09 18:29:52 +02:00
if not corpse_owner then return end
if corpse_owner.force.name ~= player.force.name then return end
if player.name ~= corpse_owner.name then
2018-12-19 18:49:49 +02:00
game.print(player.name .. " is looting " .. corpse_owner.name .. "´s body.", { r=0.85, g=0.85, b=0.85})
2019-03-23 00:42:30 +02:00
server_commands.to_discord_bold(table.concat{'[Corpse] ' .. player.name .. " is looting " .. corpse_owner.name .. "´s body."})
end
end
local function on_pre_player_mined_item(event)
if event.entity.name ~= "character-corpse" then return end
local player = game.players[event.player_index]
local corpse_owner = game.players[event.entity.character_corpse_player_index]
2019-03-09 18:29:52 +02:00
if not corpse_owner then return end
if corpse_owner.force.name ~= player.force.name then return end
if player.name ~= corpse_owner.name then
game.print(player.name .. " has looted " .. corpse_owner.name .. "´s body.", { r=0.85, g=0.85, b=0.85})
2019-03-23 00:42:30 +02:00
server_commands.to_discord_bold(table.concat{'[Corpse] ' .. player.name .. " has looted " .. corpse_owner.name .. "´s body."})
end
end
2018-12-02 07:39:54 +02:00
event.add(defines.events.on_player_mined_entity, on_player_mined_entity)
2018-12-02 06:47:58 +02:00
event.add(defines.events.on_entity_died, on_entity_died)
2018-11-03 19:34:29 +02:00
event.add(defines.events.on_built_entity, on_built_entity)
event.add(defines.events.on_gui_opened, on_gui_opened)
event.add(defines.events.on_marked_for_deconstruction, on_marked_for_deconstruction)
2018-09-23 03:17:31 +02:00
event.add(defines.events.on_player_ammo_inventory_changed, on_player_ammo_inventory_changed)
event.add(defines.events.on_player_built_tile, on_player_built_tile)
event.add(defines.events.on_player_demoted, on_player_demoted)
event.add(defines.events.on_player_joined_game, on_player_joined_game)
event.add(defines.events.on_pre_player_mined_item, on_pre_player_mined_item)
event.add(defines.events.on_player_promoted, on_player_promoted)
event.add(defines.events.on_player_used_capsule, on_player_used_capsule)