WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   General Authoring Discussion (https://www.wowinterface.com/forums/forumdisplay.php?f=20)
-   -   Sending raw slash command. (https://www.wowinterface.com/forums/showthread.php?t=42274)

Jonisaurus 01-03-12 02:47 AM

Sending raw slash command.
 
Code:

local frame = CreateFrame("Frame")

frame:RegisterEvent("UNIT_SPELLCAST_CHANNEL_START")
frame:RegisterEvent("UNIT_SPELLCAST_CHANNEL_STOP")
frame:RegisterEvent("UNIT_SPELLCAST_CHANNEL_UPDATE")
frame:RegisterEvent("UNIT_SPELLCAST_DELAYED")
frame:RegisterEvent("UNIT_SPELLCAST_FAILED")
frame:RegisterEvent("UNIT_SPELLCAST_FAILED_QUIET")
frame:RegisterEvent("UNIT_SPELLCAST_INTERRUPTED")
frame:RegisterEvent("UNIT_SPELLCAST_SENT")
frame:RegisterEvent("UNIT_SPELLCAST_START")
frame:RegisterEvent("UNIT_SPELLCAST_STOP")
frame:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")

local function RunSlashCmd(cmd)
                local slash, rest = cmd:match("^(%S+)%s*(.-)$")
                ChatFrame_ImportAllListsToHash()
                local handler = hash_SlashCmdList[slash:upper()]
                if handler then
                        handler(rest)
                end
end

local function PageMe(self, event, ...)
        local class, classFileName = UnitClass("player")
        if unitId == "player" and classFileName == "PRIEST" then
                RunSlashCmd("/changeactionbar 1")
        end
end

frame:SetScript("OnEvent", RunSlashCmd)



I'm trying to run a slash command (/changeactionbar 1) when casting a spell.
It not be working.
I took the code from here http://us.battle.net/wow/en/forum/topic/3657445305.


Please halp.:<

Barjack 01-03-12 03:14 AM

I can't tell you if this is the most direct reason why it's not working (it may be due to a bug in RunSlashCmd or something--I didn't run that code nor do I really understand how it's supposed to work), but according to WoWPedia, ChangeActionBarPage() is protected when in combat. It stands to reason therefore that /changeactionbar is also protected in combat. Therefore attempting to run that command in a non-secure context won't work if you're in combat, which the events you're using suggest you are.

Jonisaurus 01-03-12 04:22 AM

Quote:

Originally Posted by Barjack (Post 250483)
I can't tell you if this is the most direct reason why it's not working (it may be due to a bug in RunSlashCmd or something--I didn't run that code nor do I really understand how it's supposed to work), but according to WoWPedia, ChangeActionBarPage() is protected when in combat. It stands to reason therefore that /changeactionbar is also protected in combat. Therefore attempting to run that command in a non-secure context won't work if you're in combat, which the events you're using suggest you are.

If the macro itself can change the action bar, can an addon running a macro through a slash command then also change the action bar or can't it?
I'm not that smart in these things.

Dridzt 01-03-12 05:04 AM

It can but you need to utilize Secure Templates, either a SecureActionButtonTemplate if the actionbar swap is meant to happen on a click,
or a SecureStateHeaderTemplate if the swap is meant to happen on some condition (only conditions supported by the macro system are valid).

It's going to be a bit uphill for a new programmer as these while simple in concepts are not very beginner friendly constructs.

Edit: I should tell you upfront that some of the things you want to do are not possible (just looking at events).
You cannot take action through code when you're silenced or a cast succeeded or a cast failed etc.
That falls under automation and Blizzard has specifically disabled the ability for addons to make such decisions.
Only conditions supported by secure frames are these: Conditionals

Vlad 01-03-12 05:06 AM

Keep in mind that some slash commands are only usable with hardware events, i.e. a macro can only run if you use a key to activate it, otherwise people would make addons to run macro code for them, it does not work.

I am not sure about changing action bar, but it may require hardware event to work... or?

But what is the idea? To avoid the bar from changing when pushing SHIFT+2 and such?

Jonisaurus 01-03-12 11:17 AM

Yes, it's obvious now that what I tried to do isn't possible.
I wanted to basically replace my stupid castsequence macro for Holy Fire / Smite with an addon that changes actionbars according to Holy Fire cooldown.

Unfortunately /castsequence doesn't allow spell queuing which is... ****.

As I'm short for keybindings and button space on my disc priest... is the /castsequence macro the ONLY way to combine the two abilities?

SDPhantom 01-03-12 12:18 PM

I have a lot of macros on my chars that combine 2 or more spells in a macro, something modified to your use would be something like this:
Code:

#showtooltip Holy Fire
/cast [mod] Holy Fire; Smite

This casts Smite on an unmodified run and casts Holy Fire if a modifier is held. It also makes sure it keeps displaying the cooldown and tooltip info for Holy Fire.

Jonisaurus 01-03-12 12:30 PM

Quote:

Originally Posted by SDPhantom (Post 250508)
I have a lot of macros on my chars that combine 2 or more spells in a macro, something modified to your use would be something like this:
Code:

#showtooltip Holy Fire
/cast [mod] Holy Fire; Smite

This casts Smite on an unmodified run and casts Holy Fire if a modifier is held. It also makes sure it keeps displaying the cooldown and tooltip info for Holy Fire.

Using it in Bartender so I dont need a macro just two keybindings, but thanks for trying to help :)

It's not so much that I can't watch out for the Holy Fire cooldown, it's more than I have to waste another keybind and a place for watching the CD on my UI for such a trivial task.

Grimsin 01-12-12 08:08 AM

Just a side note, use of slash commands from LUA has been completely broken as of the latest patch and no version of RunSlashCmd will work properly.

Nimhfree 01-12-12 05:44 PM

If you make a button that inherits from SecureActionButtonTemplate you can set attributes on it such as:

Code:

button:SetAttribute("alt-type1", "macro")
button:SetAttribute("macrotext", desiredMacroValue)

What this basically does is allows you to set a macro that will be executed when you alt-click the button. I use this in the addon Wholly to allow the addon to target a named NPC. The buttons get assigned their macro values dynamically.

This may allow you to get around using RunSlashCmd, but I have no idea whether the macros you want to use will be permitted.

SDPhantom 01-13-12 12:43 PM

That'll be fine as long as you don't try to change anything while in combat, secure templates lock down and their attributes cannot be changed then. Only by a secure handler and that's another mess to go through that doesn't yield any differing result.


All times are GMT -6. The time now is 11:27 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI