mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2024-12-26 22:56:43 +02:00
Don't alert if a player has zero items in their inventory
This commit is contained in:
parent
8ae1318c50
commit
b90f6f2811
@ -2,6 +2,7 @@ local Token = require 'utils.token'
|
||||
local Task = require 'utils.task'
|
||||
local Color = require 'utils.color_presets'
|
||||
local ICW = require 'maps.mountain_fortress_v3.icw.main'
|
||||
local ICT_Functions = require 'maps.mountain_fortress_v3.ic.functions'
|
||||
local Event = require 'utils.event'
|
||||
local Global = require 'utils.global'
|
||||
local Alert = require 'utils.alert'
|
||||
@ -716,66 +717,72 @@ function Public.remove_offline_players()
|
||||
local items = {}
|
||||
if #offline_players > 0 then
|
||||
for i = 1, #offline_players, 1 do
|
||||
if offline_players[i] and game.players[offline_players[i].index] and game.players[offline_players[i].index].connected then
|
||||
offline_players[i] = nil
|
||||
else
|
||||
if offline_players[i] and game.players[offline_players[i].index] and offline_players[i].tick < game.tick - 108000 then
|
||||
local name = offline_players[i].name
|
||||
player_inv[1] = game.players[offline_players[i].index].get_inventory(defines.inventory.character_main)
|
||||
player_inv[2] = game.players[offline_players[i].index].get_inventory(defines.inventory.character_armor)
|
||||
player_inv[3] = game.players[offline_players[i].index].get_inventory(defines.inventory.character_guns)
|
||||
player_inv[4] = game.players[offline_players[i].index].get_inventory(defines.inventory.character_ammo)
|
||||
player_inv[5] = game.players[offline_players[i].index].get_inventory(defines.inventory.character_trash)
|
||||
if not next(player_inv) then
|
||||
offline_players[i] = nil
|
||||
break
|
||||
end
|
||||
if offline_players[i] and offline_players[i].index then
|
||||
local target = game.players[offline_players[i].index]
|
||||
if target and target.connected then
|
||||
offline_players[i] = nil
|
||||
else
|
||||
if target and offline_players[i].tick < game.tick - 108000 then
|
||||
local name = offline_players[i].name
|
||||
player_inv[1] = target.get_inventory(defines.inventory.character_main)
|
||||
player_inv[2] = target.get_inventory(defines.inventory.character_armor)
|
||||
player_inv[3] = target.get_inventory(defines.inventory.character_guns)
|
||||
player_inv[4] = target.get_inventory(defines.inventory.character_ammo)
|
||||
player_inv[5] = target.get_inventory(defines.inventory.character_trash)
|
||||
ICT_Functions.remove_surface(target) -- remove empty surface
|
||||
|
||||
local pos = game.forces.player.get_spawn_position(surface)
|
||||
local e =
|
||||
surface.create_entity(
|
||||
{
|
||||
name = 'character',
|
||||
position = pos,
|
||||
force = 'neutral'
|
||||
}
|
||||
)
|
||||
local inv = e.get_inventory(defines.inventory.character_main)
|
||||
e.character_inventory_slots_bonus = #player_inv[1]
|
||||
for ii = 1, 5, 1 do
|
||||
if player_inv[ii].valid then
|
||||
for iii = 1, #player_inv[ii], 1 do
|
||||
if player_inv[ii][iii].valid then
|
||||
items[#items + 1] = player_inv[ii][iii]
|
||||
if target.get_item_count() == 0 then -- if the player has zero items, don't do anything
|
||||
offline_players[i] = nil
|
||||
goto final
|
||||
end
|
||||
|
||||
local pos = game.forces.player.get_spawn_position(surface)
|
||||
local e =
|
||||
surface.create_entity(
|
||||
{
|
||||
name = 'character',
|
||||
position = pos,
|
||||
force = 'neutral'
|
||||
}
|
||||
)
|
||||
local inv = e.get_inventory(defines.inventory.character_main)
|
||||
e.character_inventory_slots_bonus = #player_inv[1]
|
||||
for ii = 1, 5, 1 do
|
||||
if player_inv[ii].valid then
|
||||
for iii = 1, #player_inv[ii], 1 do
|
||||
if player_inv[ii][iii].valid then
|
||||
items[#items + 1] = player_inv[ii][iii]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if #items > 0 then
|
||||
for item = 1, #items, 1 do
|
||||
if items[item].valid then
|
||||
inv.insert(items[item])
|
||||
if #items > 0 then
|
||||
for item = 1, #items, 1 do
|
||||
if items[item].valid then
|
||||
inv.insert(items[item])
|
||||
end
|
||||
end
|
||||
|
||||
local message = ({'main.cleaner', name})
|
||||
local data = {
|
||||
position = pos
|
||||
}
|
||||
Alert.alert_all_players_location(data, message)
|
||||
|
||||
e.die('neutral')
|
||||
else
|
||||
e.destroy()
|
||||
end
|
||||
|
||||
for ii = 1, 5, 1 do
|
||||
if player_inv[ii].valid then
|
||||
player_inv[ii].clear()
|
||||
end
|
||||
end
|
||||
|
||||
local message = ({'main.cleaner', name})
|
||||
local data = {
|
||||
position = pos
|
||||
}
|
||||
Alert.alert_all_players_location(data, message)
|
||||
|
||||
e.die('neutral')
|
||||
else
|
||||
e.destroy()
|
||||
offline_players[i] = nil
|
||||
break
|
||||
end
|
||||
|
||||
for ii = 1, 5, 1 do
|
||||
if player_inv[ii].valid then
|
||||
player_inv[ii].clear()
|
||||
end
|
||||
end
|
||||
offline_players[i] = nil
|
||||
break
|
||||
::final::
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -116,7 +116,7 @@ end
|
||||
local function get_owner_car_object(cars, player)
|
||||
for k, car in pairs(cars) do
|
||||
if car.owner == player.index then
|
||||
return k
|
||||
return k, car
|
||||
end
|
||||
end
|
||||
return false
|
||||
@ -726,6 +726,71 @@ function Public.save_car(event)
|
||||
end
|
||||
end
|
||||
|
||||
function Public.remove_surface(player)
|
||||
local surfaces = IC.get('surfaces')
|
||||
local cars = IC.get('cars')
|
||||
local _, car = get_owner_car_object(cars, player)
|
||||
if not car then
|
||||
return
|
||||
end
|
||||
|
||||
if not car.saved_entity then
|
||||
return
|
||||
end
|
||||
|
||||
kick_players_out_of_vehicles(car)
|
||||
kick_players_from_surface(car)
|
||||
|
||||
local trust_system = IC.get('trust_system')
|
||||
local owner = car.owner
|
||||
|
||||
if owner then
|
||||
owner = game.get_player(owner)
|
||||
if owner and owner.valid then
|
||||
if trust_system[owner.index] then
|
||||
trust_system[owner.index] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local renders = IC.get('renders')
|
||||
|
||||
if renders[owner.index] then
|
||||
rendering.destroy(renders[owner.index])
|
||||
renders[owner.index] = nil
|
||||
end
|
||||
|
||||
local player_gui_data = IC.get('player_gui_data')
|
||||
if player_gui_data[owner.name] then
|
||||
player_gui_data[owner.name] = nil
|
||||
end
|
||||
|
||||
local players = IC.get('players')
|
||||
if players[owner.index] then
|
||||
players[owner.index] = nil
|
||||
end
|
||||
|
||||
local misc_settings = IC.get('misc_settings')
|
||||
if misc_settings[owner.index] then
|
||||
misc_settings[owner.index] = nil
|
||||
end
|
||||
|
||||
local surface_index = car.surface
|
||||
local surface = game.surfaces[surface_index]
|
||||
kill_doors(car)
|
||||
for _, tile in pairs(surface.find_tiles_filtered({area = car.area})) do
|
||||
surface.set_tiles({{name = 'out-of-map', position = tile.position}}, true)
|
||||
end
|
||||
for _, x in pairs({car.area.left_top.x - 1.5, car.area.right_bottom.x + 1.5}) do
|
||||
local p = {x = x, y = car.area.left_top.y + ((car.area.right_bottom.y - car.area.left_top.y) * 0.5)}
|
||||
surface.set_tiles({{name = 'out-of-map', position = {x = p.x + 0.5, y = p.y}}}, true)
|
||||
surface.set_tiles({{name = 'out-of-map', position = {x = p.x - 1, y = p.y}}}, true)
|
||||
end
|
||||
game.delete_surface(surface)
|
||||
surfaces[car.saved_entity] = nil
|
||||
cars[car.saved_entity] = nil
|
||||
end
|
||||
|
||||
function Public.kill_car(entity)
|
||||
if not validate_entity(entity) then
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user