badcompany309 Posted December 13, 2024 Share Posted December 13, 2024 So I tried to create my very first addon for ESO. Since I'm not into writing codes, I used ai to help me write a code. After many many hours of trying to fix the code, it still didn't run in ESO. Everytime when I want to play some BG, I accidentally end up queueing for the 4 vs 4 competetive mode instead of queueing for the 8 vs 8 standard mode. And thats what my addon should do: When I for example click on the 8 vs 8 standard - solo mod, it should save and auto select the mode for the next time when I open the BG menu, even after restarting the game. Maybe you guys can help me make it work. Spoiler -- Addon initialization BattlegroundModeSelector = { name = "BattlegroundModeSelector", version = "1.0", author = "BadCompany309", defaults = { lastSelectedMode = nil -- Will store the last selected mode } } -- Initialize saved variables and register events function BattlegroundModeSelector.Initialize() -- Create saved variables that persist between sessions BattlegroundModeSelector.savedVariables = ZO_SavedVars:NewAccountWide( "BattlegroundModeSelector", 1, nil, BattlegroundModeSelector.defaults ) -- Hook into the Activity Finder creation ZO_PreHook(ZO_ActivityFinderTemplate_Keyboard, "OnDifficultyChanged", function(self) BattlegroundModeSelector.RestoreLastSelection() return false -- Don't block original function end) -- Save selection when queuing ZO_PreHook(BATTLEGROUND_FINDER_KEYBOARD, "OnEnterQueueClicked", function() BattlegroundModeSelector.SaveCurrentSelection() return false -- Don't block original function end) end -- Save the current battleground mode selection function BattlegroundModeSelector.SaveCurrentSelection() local currentMode = BATTLEGROUND_FINDER_KEYBOARD.selectedBattlegroundId if currentMode then BattlegroundModeSelector.savedVariables.lastSelectedMode = currentMode -- Debug message d("[BGS] Saved mode: " .. tostring(currentMode)) end end -- Restore the last selected battleground mode function BattlegroundModeSelector.RestoreLastSelection() local savedMode = BattlegroundModeSelector.savedVariables.lastSelectedMode if savedMode then -- Get the activity finder object local activityFinder = BATTLEGROUND_FINDER_KEYBOARD -- Only proceed if we have a valid saved mode and the UI is ready if activityFinder and activityFinder.nodeList then -- Find and select the saved mode for _, node in pairs(activityFinder.nodeList) do if node.battlegroundId == savedMode then activityFinder:SelectNode(node) -- Debug message d("[BGS] Restored mode: " .. tostring(savedMode)) break end end end end end -- Register initialization on addon loaded local function OnAddOnLoaded(event, addonName) if addonName ~= BattlegroundModeSelector.name then return end EVENT_MANAGER:UnregisterForEvent(BattlegroundModeSelector.name, EVENT_ADD_ON_LOADED) BattlegroundModeSelector.Initialize() end EVENT_MANAGER:RegisterForEvent(BattlegroundModeSelector.name, EVENT_ADD_ON_LOADED, OnAddOnLoaded) BattlegroundModeSelector.zip Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now