Quantcast WoWInterface - View Single Post - Have /cast and /use Accept spellIDs
View Single Post
09-30-18, 10:19 AM   #1
Vrul
A Frostmaul Preserver
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 296
Have /cast and /use Accept spellIDs

If the following code from ChatFrame.lua
Code:
-- We want to prefer spells for /cast and items for /use but we can use either
SecureCmdList["CAST"] = function(msg)
    local action, target = SecureCmdOptionParse(msg);
    if ( action ) then
    	local spellExists = DoesSpellExist(action)
		local name, bag, slot = SecureCmdItemParse(action);
		if ( spellExists ) then
			CastSpellByName(action, target);
		elseif ( slot or GetItemInfo(name) ) then
			SecureCmdUseItem(name, bag, slot, target);
		end
    end
end

SecureCmdList["USE"] = function(msg)
    local action, target = SecureCmdOptionParse(msg);
    if ( action ) then
		local name, bag, slot = SecureCmdItemParse(action);
		if ( slot or GetItemInfo(name) ) then
			SecureCmdUseItem(name, bag, slot, target);
		else
			CastSpellByName(action, target);
		end
    end
end
was replaced with
Code:
-- We want to prefer spells for /cast and items for /use but we can use either
SecureCmdList["CAST"] = function(msg)
    local action, target = SecureCmdOptionParse(msg);
    if ( action ) then
		local spellID = tonumber(action);
		if ( DoesSpellExist(spellID or action) ) then
			if spellID then
				CastSpellByID(spellID, target);
			else
				CastSpellByName(action, target);
			end
		else
			local name, bag, slot = SecureCmdItemParse(action);
			if ( slot or GetItemInfo(name) ) then
				SecureCmdUseItem(name, bag, slot, target);
			end
		end
    end
end

SecureCmdList["USE"] = function(msg)
    local action, target = SecureCmdOptionParse(msg);
    if ( action ) then
		local name, bag, slot = SecureCmdItemParse(action);
		if ( slot or GetItemInfo(name) ) then
			SecureCmdUseItem(name, bag, slot, target);
		else
			local spellID = tonumber(action);
			if spellID then
				CastSpellByID(spellID, target);
			else
				CastSpellByName(action, target);
			end
		end
    end
end
we could use a spellID with /cast or /use which would simplify making locale independent macros/code.
  Reply With Quote