Skip to content

Commit

Permalink
Merge pull request #4 from xrandox/psna-script
Browse files Browse the repository at this point in the history
PSNA Marker Script
  • Loading branch information
Metallis authored Sep 27, 2023
2 parents 634de3d + 229599d commit 897659d
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Data/libdef
Metal-Marker-Myriad.zip
10 changes: 10 additions & 0 deletions Scripts/mmmmenu.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- What a glorious filename

-- Generic Menu Function
local function togglePSNA(menu)
MMM_TogglePSNA()
end

-- Construct Menu
local root = Menu:Add("Metal Marker Myriad", nil)
local psna = root:Add("Show/Hide PSNA Marker", togglePSNA, false, false, "Shows/Hides a marker with today's PSNA waypoint codes")
90 changes: 90 additions & 0 deletions Scripts/psna.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
MMM.psna = {
activeMarkers = {},
shown = false,
origin = nil
}

Debug:Watch("MMM_PSNA", MMM.psna)

-- #region Constants

local MARKER_TEXTURE = "Data/Icons/psna_clipboard.png"
local MARKER_ATTRIBUTES = {
type = "other.psna",
["schedule-duration"] = 1440,
iconSize = 3,
heightOffset = 3,
["copy-message"] = "PSNA Waypoints copied to clipboard!",
triggerRange="5"
}
local MARKER_COPIES = {
{ "0 8 * * 1", "[&BIgHAAA=][&BEwDAAA=][&BNIEAAA=][&BKYBAAA=][&BIMCAAA=][&BB4CAAA=]" },
{ "0 8 * * 2", "[&BH8HAAA=][&BEgAAAA=][&BBEAAAA=][&BKgCAAA=][&BGQCAAA=][&BIMBAAA=]" },
{ "0 8 * * 3", "[&BHoHAAA=][&BCEDAAA=][&BLQDAAA=][&BKYAAAA=][&BLQAAAA=][&BFEDAAA=]" },
{ "0 8 * * 4", "[&BH8HAAA=][&BF0AAAA=][&BEUDAAA=][&BO4CAAA=][&BJcBAAA=][&BOQBAAA=]" },
{ "0 8 * * 5", "[&BJcHAAA=][&BNUGAAA=][&BKYCAAA=][&BMwCAAA=][&BHsBAAA=][&BNMAAAA=]" },
{ "0 8 * * 6", "[&BH8HAAA=][&BB8DAAA=][&BNMCAAA=][&BFMCAAA=][&BJIBAAA=][&BF8BAAA=]" },
{ "0 8 * * 0", "[&BIYHAAA=][&BDoBAAA=][&BO4CAAA=][&BKcBAAA=][&BIUCAAA=][&BCECAAA=]" },
}

-- #endregion

-- #region Local Functions

-- Hides (removes) any active markers if they are currently shown
local function hidePSNA()
if MMM.psna.shown then
-- Loop through all active markers and remove them
for _, marker in ipairs(MMM.psna.activeMarkers) do
marker:Remove()
end
MMM.psna.activeMarkers = {}
MMM.psna.origin = nil
MMM.psna.shown = false
end
end

-- Shows (creates) a set of PSNA markers at the players current location
local function showPSNA()
-- Get and save current player position
MMM.psna.origin = Mumble.PlayerCharacter.Position

-- Create generic marker attributes and add in coordinates
local newMarkerAttributes = MARKER_ATTRIBUTES
newMarkerAttributes.xpos = MMM.psna.origin.X
newMarkerAttributes.ypos = MMM.psna.origin.Z
newMarkerAttributes.zpos = MMM.psna.origin.Y

-- Create all 7 of the PSNA markers with their respective attributes, and add to the active markers table
for i, copyAttr in ipairs(MARKER_COPIES) do
newMarkerAttributes.schedule = copyAttr[1]
newMarkerAttributes.copy = copyAttr[2]
MMM.psna.activeMarkers[i] = Pack:CreateMarker(newMarkerAttributes)
MMM.psna.activeMarkers[i]:SetTexture(MARKER_TEXTURE)
end

MMM.psna.shown = true
end

-- Tick handler to check if the player is within a certain distance of the created markers. If not, hides them
local function psnaTickHandler(gameTime)
if MMM.psna.shown then
if (Mumble.PlayerCharacter.Position - MMM.psna.origin):Length() > 40 then
hidePSNA()
end
end
end

-- #endregion

-- Global function to toggle the PSNA markers
function MMM_TogglePSNA()
if MMM.psna.shown then
hidePSNA()
else
showPSNA()
end
end

-- Assign tick handler
Event:OnTick(psnaTickHandler)
6 changes: 6 additions & 0 deletions pack.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
MMM = {}

Debug:Print("Loading Metal Marker Myriad...")

Pack:Require("Data/Scripts/compass_pointer")
Pack:Require("Scripts/psna.lua")
Pack:Require("Scripts/mmmmenu.lua")

local function tick(gameTime)
local playerPos = Mumble.PlayerCharacter.Position
Expand Down

0 comments on commit 897659d

Please sign in to comment.