EC: Add ability to script pressing buttons in the legacy runebooks

TimStTimSt Posts: 1,797
edited May 2023 in General Discussions
The following code changes to the EC will allow you to script pressing buttons in the legacy rune books.

To the file source\LegacyRunebook.lua

Modify the function LegacyRunebook.OnRuneClicked
function LegacyRunebook.OnRuneClicked()
local windowName = WindowUtils.GetActiveDialog()
local buttonNum = WindowGetId(SystemData.ActiveWindow.name)
local self = LegacyRunebook.knownWindows[windowName]

--start of added code
LegacyRunebook.RuneClicked(windowName, buttonNum, self)
end

function LegacyRunebook.ClickOnRune(runeNumber)
local windowName = "LEGACY_Runebook_GUMP-1"
local buttonNum = runeNumber
local self = nil
local index = 0
while(self == nil and index < 100000)
do
index = index + 1
windowName = "LEGACY_Runebook_GUMP-"..index
self = LegacyRunebook.knownWindows[windowName]
end

LegacyRunebook.RuneClicked(windowName, buttonNum, self)
end

function LegacyRunebook.RuneClicked(windowName, buttonNum, self)
--end of added code
if(self) then


Modify the function LegacyRunebook.OnDefaultClicked
function LegacyRunebook.OnDefaultClicked()
local currWindow = WindowUtils.GetActiveDialog()
local buttonNum = WindowGetId(SystemData.ActiveWindow.name)
local self = LegacyRunebook.knownWindows[currWindow]

--start of added code
LegacyRunebook.DefaultButtonClicked(currWindow, buttonNum, self)
end

function LegacyRunebook.ClickDefaultButton(buttonNum)
local currWindow = "LEGACY_Runebook_GUMP-1"
local self = nil
local index = 0
while(self == nil and index < 100000)
do
index = index + 1
currWindow = "LEGACY_Runebook_GUMP-"..index
self = LegacyRunebook.knownWindows[currWindow]
end
LegacyRunebook.DefaultButtonClicked(currWindow, buttonNum + 1, self)
end

function LegacyRunebook.DefaultButtonClicked(currWindow, buttonNum, self)
--end of added code
if(self) then


To select the first rune use the following script command
script LegacyRunebook.ClickOnRune(1)

To select the recall button use the following script command
script LegacyRunebook.ClickDefaultButton(3)

The button numbers to use with ClickDefaultButton are

LegacyRunebook.DefaultNum.RENAME_BOOK		= 1
LegacyRunebook.DefaultNum.DROP_RUNE = 2
LegacyRunebook.DefaultNum.RECALL = 3
LegacyRunebook.DefaultNum.GATE_TRAVEL = 4
LegacyRunebook.DefaultNum.SACRED = 5
LegacyRunebook.DefaultNum.SET_DEFAULT = 6





Comments

  • Arroth_ThaielArroth_Thaiel Posts: 1,030
    edited May 2023
    @TimSt

    I was just testing this and it's actually running on the C indexing. 'Cause UO.

    script LegacyRunebook.ClickDefaultButton(0)		-- Rename
    script LegacyRunebook.ClickDefaultButton(1)		-- Drop Rune
    script LegacyRunebook.ClickDefaultButton(2)		-- Charge Recall
    script LegacyRunebook.ClickDefaultButton(3)		-- Recall
    script LegacyRunebook.ClickDefaultButton(4)		-- Gate Travel
    script LegacyRunebook.ClickDefaultButton(5)		-- Sacred Journey
    script LegacyRunebook.ClickDefaultButton(6)		-- Set Default

    Rune positions 1 - 16 are working correctly though. :)

    --

    Many thanks to TimSt for developing this solution.

    If you make the above code changes and use the new scripting language you can write a macro as follows:

    Runebook
    Delay 0.25s
    Action>Command "script LegacyRunebook.ClickOnRune(14)"
    Action>Command "script LegacyRunebook.ClickDefaultButton(3)"


    The macro will automagically open the runebook, click on the 14th rune, and cast recall.

    No more need to carry around 20 runebooks, all with different default locations.

    Visually, the macro would look like this:

    -Arroth
  • Garth_GreyGarth_Grey Posts: 1,453
    Works beautifully, thank you again @TimSt and @Arroth_Thaiel . More people need to realize just how slick the EC can be.
    You and Several Others like this.


    Please make the Grizzled Mare a 5 slot mount, it's incredibly rare and deserves it. Some of us have been waiting a long time for this simple addition.
  • ForeverFunForeverFun Posts: 801
    For the numerically challenged?

        -- before RuneClicked, support case sensitive unicode / non-unicode
            local name = nil
        
        if(type (runeNumber) == "string") then
            name = towstring(runeNumber)
        elseif(type (runeNumber) == "wstring") then
            name = runeNumber
        end

        if(name ~= nil) then
            for index = 1, LegacyRunebook.NumActiveRunes[windowName] do
                local labelName = windowName.."RuneButton"..tostring(index).."Name"
                local location = LabelGetText(labelName)
               
                if(location ~= nil and location == name ) then
                    buttonNum = index
                    break
                end
            end

            if(type(buttonNum) ~= "number") then
                return                -- perhaps return true/false from this function.
            end
        end



Sign In or Register to comment.