From b20def29745ba8ca678440f7abbd68c20ff38452 Mon Sep 17 00:00:00 2001 From: Piratux <58703216+Piratux@users.noreply.github.com> Date: Sat, 24 Jun 2023 20:55:43 +0300 Subject: [PATCH] Fixed Lua errors Changes: - Fixed Lua errors --- maps/pirates/ai.lua | 2 +- maps/pirates/api_events.lua | 6 ++- maps/pirates/gui/runs.lua | 39 +++++++++++-------- .../quest_structures/quest_structures.lua | 13 ++++--- 4 files changed, 34 insertions(+), 26 deletions(-) diff --git a/maps/pirates/ai.lua b/maps/pirates/ai.lua index eae84aa1..57edac9c 100644 --- a/maps/pirates/ai.lua +++ b/maps/pirates/ai.lua @@ -133,7 +133,7 @@ function Public.wave_size_rng() -- random variance in attack sizes local memory = Memory.get_crew_memory() local destination = Common.current_destination() - local rng_scale = Common.crew_scale()^(1/4) -- slightly dampen wave variance for small crews as they can't handle it + local rng_scale = Balance.crew_scale()^(1/4) -- slightly dampen wave variance for small crews as they can't handle it -- prevent situation where when player reveals spawner, he immediately gets surrounded by massive amount of biters (especially late game) if destination and destination.type == SurfacesCommon.enum.ISLAND then diff --git a/maps/pirates/api_events.lua b/maps/pirates/api_events.lua index cbb2e739..fd9c8e08 100644 --- a/maps/pirates/api_events.lua +++ b/maps/pirates/api_events.lua @@ -592,8 +592,10 @@ local function maze_walls_resistance(event) if e2.valid then e2.destroy() end end else - if string.sub(event.cause.force.name, 1, 4) == 'crew' then --player damage only - event.entity.health = event.entity.health + damage * 0.9 + if event.cause and event.cause.valid then + if string.sub(event.cause.force.name, 1, 4) == 'crew' then --player damage only + event.entity.health = event.entity.health + damage * 0.9 + end end end end diff --git a/maps/pirates/gui/runs.lua b/maps/pirates/gui/runs.lua index d8a9cd97..26a83405 100644 --- a/maps/pirates/gui/runs.lua +++ b/maps/pirates/gui/runs.lua @@ -707,34 +707,39 @@ function Public.click(event) if eventname == 'join_crew' then local listbox = flow.ongoing_runs.body.ongoing_runs_listbox - local crewid = tonumber(listbox.get_item(listbox.selected_index)[2]) - local memory = global_memory.crew_memories[crewid] + -- It was observed that "listbox.get_item(listbox.selected_index)" can produce "Index out of range error" + -- This is to prevent that error. + if listbox.selected_index >= 1 and listbox.selected_index <= #listbox.items then + local crewid = tonumber(listbox.get_item(listbox.selected_index)[2]) - -- If run is private - if global_memory.crew_memories[crewid].run_is_private then - if global_memory.crew_memories[crewid].private_run_password == flow.ongoing_runs.body.password_namefield.text then + local memory = global_memory.crew_memories[crewid] + + -- If run is private + if global_memory.crew_memories[crewid].run_is_private then + if global_memory.crew_memories[crewid].private_run_password == flow.ongoing_runs.body.password_namefield.text then + Crew.join_crew(player, crewid) + flow.ongoing_runs.body.join_private_crew_info.visible = false + flow.ongoing_runs.body.password_namefield.visible = false + + if memory.run_is_protected and (not Roles.captain_exists()) then + Common.notify_player_expected(player, {'pirates.player_joins_protected_run_with_no_captain'}) + Common.notify_player_expected(player, {'pirates.create_new_crew_tip'}) + end + else + Common.notify_player_error(player, {'pirates.gui_join_private_run_error_wrong_password'}) + end + else Crew.join_crew(player, crewid) - flow.ongoing_runs.body.join_private_crew_info.visible = false - flow.ongoing_runs.body.password_namefield.visible = false if memory.run_is_protected and (not Roles.captain_exists()) then Common.notify_player_expected(player, {'pirates.player_joins_protected_run_with_no_captain'}) Common.notify_player_expected(player, {'pirates.create_new_crew_tip'}) end - else - Common.notify_player_error(player, {'pirates.gui_join_private_run_error_wrong_password'}) end - else - Crew.join_crew(player, crewid) - if memory.run_is_protected and (not Roles.captain_exists()) then - Common.notify_player_expected(player, {'pirates.player_joins_protected_run_with_no_captain'}) - Common.notify_player_expected(player, {'pirates.create_new_crew_tip'}) - end + return end - - return end if eventname == 'propose_crew' then diff --git a/maps/pirates/structures/quest_structures/quest_structures.lua b/maps/pirates/structures/quest_structures/quest_structures.lua index baf9621b..11b90688 100644 --- a/maps/pirates/structures/quest_structures/quest_structures.lua +++ b/maps/pirates/structures/quest_structures/quest_structures.lua @@ -393,8 +393,13 @@ function Public.tick_quest_structure_entry_price_check() if removed > 0 then local count = 1 for k, v in pairs(entry_price.batchRawMaterials) do - red_invs[count].insert({name = k, count = v * removed / entry_price.batchSize}); - count = count + 1 + local item_count = v * removed / entry_price.batchSize + if item_count > 0 then + red_invs[count].insert({name = k, count = item_count}); + count = count + 1 + else + log('Error (non-critical): item_count is not positive. v: ' .. v .. '; removed: ' .. removed .. '; entry_price.batchSize: ' .. entry_price.batchSize) + end end end end @@ -402,8 +407,4 @@ function Public.tick_quest_structure_entry_price_check() end - - - - return Public \ No newline at end of file