Sign in to follow this  
WobLight

[Supermacro] Auto-unshift

4 posts in this topic

I've been recently asked if you can check if you have enough mana for a spell before unshifting in a macro, like auto-dismount addon does.

Answer is: you can't.

Auto-dismount addon probably hooks error messages to unshift you, but the error reported when you have not enough mana and you're shapeshifted is "not enough mana", thus failing to unshift.

Here the supermacro code to reproduce auto-dismount behaviour:

Spoiler

 

function GetActiveForm()
    for i=1,GetNumShapeshiftForms() do
        if  ({GetShapeshiftFormInfo(i)})[3] then
            return i
        end
    end
    return 0
end

function CancelForm()
    local f = GetActiveForm()
    if f ~= 0 then
        CastShapeshiftForm(f)
    end
end

if not AutoUnshift then
    AutoUnshift = {sendError = UIErrorsFrame.AddMessage}
    function UIErrorsFrame:AddMessage(...)
        for _,s in {
            ERR_CANT_INTERACT_SHAPESHIFTED,
            SPELL_FAILED_NOT_SHAPESHIFT,
            SPELL_FAILED_NO_ITEMS_WHILE_SHAPESHIFTED,
            SPELL_NOT_SHAPESHIFTED,
            SPELL_NOT_SHAPESHIFTED_NOSPACE,
            ERR_EMBLEMERROR_NOTABARDGEOSET,
            ERR_MOUNT_SHAPESHIFTED,
            ERR_NOT_WHILE_SHAPESHIFTED,
            ERR_NO_ITEMS_WHILE_SHAPESHIFTED,
            ERR_TAXIPLAYERSHAPESHIFTED
        } do
            if strfind(arg[1],s,nil,true) then
                CancelForm()
                return
            end
        end
        AutoUnshift.sendError(self,unpack(arg))
    end
end

 

Share this post


Link to post
Share on other sites

wait im not sure i understand. i thought you said you can't replicate it, if you can't replicate it what does the code do?

Share this post


Link to post
Share on other sites
10 hours ago, retrorocket said:

wait im not sure i understand. i thought you said you can't replicate it, if you can't replicate it what does the code do?

You can't check, but you can capture the error trying to. it's not exactly the same.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this