From a0baa770e8e9cbe30c1bd1dfe35551be28a1f0c5 Mon Sep 17 00:00:00 2001 From: hanakocz Date: Fri, 6 Jan 2023 21:58:46 +0100 Subject: [PATCH] Fixes for some buggerinos --- maps/cave_miner.lua | 4 ++-- modules/fluids_are_explosive.lua | 1 + modules/hunger.lua | 14 ++++++++------ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/maps/cave_miner.lua b/maps/cave_miner.lua index 744575e3..d2504bc7 100644 --- a/maps/cave_miner.lua +++ b/maps/cave_miner.lua @@ -9,7 +9,7 @@ require 'modules.satellite_score' require 'modules.spawners_contain_biters' require 'modules.biter_noms_you' require 'modules.rpg' -require 'modules.hunger' +local Hunger = require 'modules.hunger' local enable_fishbank_terminal = false local simplex_noise = require 'utils.simplex_noise' @@ -1168,7 +1168,7 @@ local function on_pre_player_mined_item(event) tile_distance_to_center = 1450 end if math_random(1, 3) == 1 then - hunger_update(player, -1) + Hunger.hunger_update(player, -1) end surface.spill_item_stack(player.position, {name = 'raw-fish', count = math_random(1, 3)}, true) diff --git a/modules/fluids_are_explosive.lua b/modules/fluids_are_explosive.lua index 34855276..9c33646b 100644 --- a/modules/fluids_are_explosive.lua +++ b/modules/fluids_are_explosive.lua @@ -925,6 +925,7 @@ end local function on_entity_damaged(event) local entity = event.entity + if not entity.valid then return end if not entity.health then return end diff --git a/modules/hunger.lua b/modules/hunger.lua index 69078914..7b2592bb 100644 --- a/modules/hunger.lua +++ b/modules/hunger.lua @@ -1,5 +1,5 @@ -- hunger module by mewmew -- - +local Public = {} local P = require 'utils.player_modifiers' local starve_messages = {' ran out of foodstamps.', ' starved.', ' should not have skipped breakfast today.'} @@ -103,7 +103,7 @@ local function update_hunger_gui(player) player.gui.top['hunger_frame'].style.font_color = player_hunger_color_list[global.player_hunger[player.name]] end -local function hunger_update(player, food_value) +function Public.hunger_update(player, food_value) if not player.character then return end @@ -166,7 +166,7 @@ local function on_player_joined_game(event) end if player.online_time == 0 then global.player_hunger[player.name] = player_hunger_spawn_value - hunger_update(player, 0) + Public.hunger_update(player, 0) end update_hunger_gui(player) end @@ -177,7 +177,7 @@ local function on_player_used_capsule(event) if player.character.health < player.character.prototype.max_health + player.character_health_bonus + player.force.character_health_bonus then return end - hunger_update(player, player_hunger_fish_food_value) + Public.hunger_update(player, player_hunger_fish_food_value) player.play_sound {path = 'utility/armor_insert', volume_modifier = 0.9} end end @@ -185,13 +185,13 @@ end local function on_player_respawned(event) local player = game.players[event.player_index] global.player_hunger[player.name] = player_hunger_spawn_value - hunger_update(player, 0) + Public.hunger_update(player, 0) end local function on_tick() for _, player in pairs(game.connected_players) do if player.afk_time < 18000 then - hunger_update(player, -1) + Public.hunger_update(player, -1) end end end @@ -201,3 +201,5 @@ event.on_nth_tick(3600, on_tick) event.add(defines.events.on_player_respawned, on_player_respawned) event.add(defines.events.on_player_used_capsule, on_player_used_capsule) event.add(defines.events.on_player_joined_game, on_player_joined_game) + +return Public