From 92c5373f31eca8115ea8f7986006d6c6d7231628 Mon Sep 17 00:00:00 2001 From: Gerkiz Date: Sun, 19 Jul 2020 12:06:53 +0200 Subject: [PATCH] minor adjustment --- maps/mountain_fortress_v3/main.lua | 1 + modules/rpg_v2.lua | 26 ++++++++++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/maps/mountain_fortress_v3/main.lua b/maps/mountain_fortress_v3/main.lua index 2e24da23..6ae336ae 100644 --- a/maps/mountain_fortress_v3/main.lua +++ b/maps/mountain_fortress_v3/main.lua @@ -230,6 +230,7 @@ function Public.reset_map() Map_score.reset_score() AntiGrief.reset_tables() RPG.rpg_reset_all_players() + RPG.set_surface_name('mountain_fortress_v3') disable_tech() diff --git a/modules/rpg_v2.lua b/modules/rpg_v2.lua index 93bca8bc..d30d3a67 100644 --- a/modules/rpg_v2.lua +++ b/modules/rpg_v2.lua @@ -34,7 +34,8 @@ local rpg_extra = { global_pool = 0, leftover_pool = 0, turret_kills_to_global_pool = true, - difficulty = false + difficulty = false, + surface_name = 'nauvis' } local rpg_frame_icons = { 'entity/small-worm-turret', @@ -1203,9 +1204,8 @@ end local function on_player_changed_position(event) local player = game.players[event.player_index] - local map_name = 'mountain_fortress_v3' - if string.sub(player.surface.name, 0, #map_name) ~= map_name then + if string.sub(player.surface.name, 0, #rpg_extra.surface_name) ~= rpg_extra.surface_name then return end @@ -1323,7 +1323,7 @@ end --- Gives connected player some bonus xp if the map was preemptively shut down. -- amount (integer) -- 10 levels --- local Public = require 'maps.mountain_fortress_v3.rpg' Public.give_xp(512) +-- local Public = require 'modules.rpg_v2' Public.give_xp(512) function Public.give_xp(amount) for _, player in pairs(game.connected_players) do if not validate_player(player) then @@ -1480,6 +1480,8 @@ function Public.gain_xp(player, amount, added_to_pool, text) rpg_t[player.index].last_floaty_text = game.tick + visuals_delay end +--- Returns the rpg_t table. +---@param key function Public.get_table(key) if key then return rpg_t[key] @@ -1488,6 +1490,8 @@ function Public.get_table(key) end end +--- Returns the rpg_extra table. +---@param key function Public.get_extra_table(key) if key then return rpg_extra[key] @@ -1496,6 +1500,7 @@ function Public.get_extra_table(key) end end +--- Toggle debug - when you need to troubleshoot. function Public.toggle_debug() if rpg_extra.debug then rpg_extra.debug = false @@ -1504,6 +1509,7 @@ function Public.toggle_debug() end end +--- Distributes the global xp pool to every connected player. function Public.distribute_pool() local count = #game.connected_players local players = game.connected_players @@ -1511,6 +1517,8 @@ function Public.distribute_pool() print('Distributed the global XP pool') end +--- Debug only - when you need to troubleshoot. +---@param str function Public.debug_log(str) if not rpg_extra.debug then return @@ -1518,6 +1526,16 @@ function Public.debug_log(str) print(str) end +--- Sets surface name for rpg_v2 to use +---@param name +function Public.set_surface_name(name) + if name then + rpg_extra.surface_name = name + else + return error('No surface name given.', 2) + end +end + Event.add(defines.events.on_entity_damaged, on_entity_damaged) Event.add(defines.events.on_entity_died, on_entity_died) Event.add(defines.events.on_gui_click, on_gui_click)