Add sonarpinger

This commit is contained in:
2025-03-31 01:40:00 +02:00
parent 0e35890f41
commit 03c2fd436c
3 changed files with 81 additions and 2 deletions

View File

@@ -20,6 +20,7 @@ MyModGlobal = {
RELOAD = Keys.R, RELOAD = Keys.R,
STACK_TO_CURSOR = Keys.G, STACK_TO_CURSOR = Keys.G,
LOOT = Keys.L, LOOT = Keys.L,
SONAR = Keys.X,
NESTED_CONTAINERS = true, NESTED_CONTAINERS = true,
DEBUG_MODE = true, DEBUG_MODE = true,
}, },
@@ -63,6 +64,7 @@ local cursormacroer = require("Cyka.cursormacroer")
local quickunload = require("Cyka.quickunload") local quickunload = require("Cyka.quickunload")
local quickreload= require("Cyka.quickreload") local quickreload= require("Cyka.quickreload")
local quickloot = require("Cyka.quickloot") local quickloot = require("Cyka.quickloot")
local sonarpinger = require("Cyka.sonarpinger")
require("Cyka.xpticker") require("Cyka.xpticker")
require("Cyka.zoom") require("Cyka.zoom")
@@ -144,3 +146,8 @@ Hook.Patch("Barotrauma.Character", "ControlLocalPlayer", function(instance, ptab
if not PlayerInput.KeyHit(MyModGlobal.CONFIG.LOOT) then return end if not PlayerInput.KeyHit(MyModGlobal.CONFIG.LOOT) then return end
quickloot.tryLoot() quickloot.tryLoot()
end, Hook.HookMethodType.After) end, Hook.HookMethodType.After)
Hook.Patch("Barotrauma.Character", "ControlLocalPlayer", function(instance, ptable)
if not PlayerInput.KeyHit(MyModGlobal.CONFIG.SONAR) then return end
sonarpinger.tryPing()
end, Hook.HookMethodType.After)

View File

@@ -0,0 +1,72 @@
-- luacheck: globals Character MyModGlobal LuaUserData Descriptors Timer
local dump = require("Cyka.dump")
-- LuaUserData.MakeMethodAccessible(Descriptors["Barotrauma.Sonar"], "UpdateGUIElements")
-- Make sure we have access to the Sonar enum types
-- LuaUserData.RegisterType(Descriptors["Barotrauma.Items.Components.Sonar+Mode"])
local function getSonarObjectInFocus()
local character = Character.Controlled
if not character then
MyModGlobal.debugPrint("No controlled character")
return nil, nil
end
local selectedItem = character.SelectedItem
if not selectedItem then
MyModGlobal.debugPrint("No selected item")
return nil, nil
end
-- Check if the selected item is in fact the repairable object itself
for _, component in pairs(selectedItem.Components) do
if component.name == "Sonar" then
return selectedItem, component
end
end
return nil, nil
end
local function tryPing()
local character = Character.Controlled
if not character then
MyModGlobal.debugPrint("No controlled character")
return
end
local submarine = character.Submarine
if not submarine then
MyModGlobal.debugPrint("No submarine")
return
end
local sonar, sonarComponent = getSonarObjectInFocus()
if not sonar or not sonarComponent then
MyModGlobal.debugPrint("No sonar or sonar component")
return
end
local sonarButton = sonarComponent.SonarModeSwitch
if not sonarButton then
MyModGlobal.debugPrint("No sonar button")
return
end
sonarButton.Selected = not sonarButton.Selected
if sonarButton.Selected then
-- Active
sonarComponent.CurrentMode = 0
Timer.Wait(function()
sonarComponent.CurrentMode = 1
end, 100)
else
-- Passive
sonarComponent.CurrentMode = 1
end
end
return {
tryPing = tryPing,
}

View File

@@ -7,9 +7,9 @@ local smoothZoom = false -- smooth or step
local zStep = 0.5 -- step size for when smoothZoom=false local zStep = 0.5 -- step size for when smoothZoom=false
local zSpeed = 0.02 -- speed for when smoothZoom=true local zSpeed = 0.02 -- speed for when smoothZoom=true
local zMin = 0.1 -- minimum zoom modifier local zMin = 0.5 -- minimum zoom modifier
local zMax = 2.5 -- maximum zoom modifier local zMax = 2.5 -- maximum zoom modifier
local zStart = 1.5 -- default zoom level local zStart = 0.5 -- default zoom level
local zKey = Keys.P -- zoom key local zKey = Keys.P -- zoom key
local dKey = Keys.NumPad1 -- decrease zoom key local dKey = Keys.NumPad1 -- decrease zoom key