Skip to content

Commit

Permalink
compat: Added a custom event for whenever submarines or players subme…
Browse files Browse the repository at this point in the history
…rge between surfaces.
  • Loading branch information
notnotmelon committed Dec 19, 2024
1 parent 55b330e commit df76804
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
8 changes: 8 additions & 0 deletions data.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,11 @@ require "prototypes.tips-and-tricks.tips-and-tricks"
require "prototypes.offshore-pump"
require "prototypes.planet.space-location"
require "prototypes.conduit"

--- custom event for submarine submerged
--- also triggers on character submerged with abyssal diving gear
--- event table: {entity, old_surface_index, old_position}
data:extend {{
type = "custom-event",
name = "maraxsis-on-submerged",
}}
20 changes: 18 additions & 2 deletions scripts/submarine.lua
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ local function decend_or_ascend(submarine)
driver = driver.player
end

maraxsis.execute_later("play_submerge_sound", 1, submarine.surface, submarine.position)
local old_surface = submarine.surface
local old_position = submarine.position
maraxsis.execute_later("play_submerge_sound", 1, old_surface, old_position)
maraxsis.execute_later("play_submerge_sound", 1, target_surface, target_position)

local players_to_open_gui = {}
Expand Down Expand Up @@ -215,6 +217,12 @@ local function decend_or_ascend(submarine)
maraxsis.execute_later("enter_submarine", 1, driver, submarine)
end

script.raise_event("maraxsis-on-submerged", {
entity = submarine,
old_surface_index = old_surface.index,
old_position = old_position
})

return true
end

Expand All @@ -226,11 +234,19 @@ local function decend_or_ascend_character(character)
if not target_surface then return false end
if not target_position then return false end

maraxsis.execute_later("play_submerge_sound", 1, character.surface, character.position)
local old_surface = character.surface
local old_position = character.position
maraxsis.execute_later("play_submerge_sound", 1, old_surface, old_position)
maraxsis.execute_later("play_submerge_sound", 1, target_surface, target_position)

character.teleport(target_position, target_surface, true)

script.raise_event("maraxsis-on-submerged", {
entity = character,
old_surface_index = old_surface.index,
old_position = old_position
})

return true
end

Expand Down

0 comments on commit df76804

Please sign in to comment.