WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   /using an item in an addon (https://www.wowinterface.com/forums/showthread.php?t=17364)

SydneyBarringer 07-25-08 10:54 PM

/using an item in an addon
 
I'm trying to make an addon where, by pushing a button on the frame, you'll use a item.

For example, say the item is a super mana potion. How would I tell the addon to use the potion every time I click the button?

Thanks for the help,
Sydney Barringer

EDIT: Could I just cheat and tell it to say "/use Super Mana Potion" in chat?

dafire 07-26-08 02:15 AM

If you want to use this button/frame in combat it would have to be a secure frame.

you are very limited with what you could do with it... your addon would have to decide what happens when you press the frame before the combat starts, because addons are not allowed to make such decisions in combat.

SydneyBarringer 07-26-08 11:00 AM

Could you possibly show me the correct format for a secure frame? All I want the button to do is /use a Super Mana Potion, so it does have just one preset function.

Mera 07-26-08 11:54 AM

here is a very nice page about secure frames

http://www.wowwiki.com/Secure_Frames_Overview


I recommand you to buy the "World of Warcraft programming" book by cladhaire kaelten, there is a nice chapter of around 20 pages explaining secure frames and all needed for writing simple or strong addons, dealing with secure frames is not that simple because once you use such frames they are restricted in combat and you will have to deal with lots of workarounds.

kerrang 07-26-08 12:06 PM

BelleBoom's Addon Template has a nice, simple Secure Template example - it's documented and I found it easy to develop a mod based on it...

Download/info is here
http://belleboom.googlepages.com/bellemaison

Add that to the WoWWiki stuff (above) and you have almost all you need to know...

SydneyBarringer 07-26-08 06:03 PM

And I'm still completely lost.
I've looked through all the stuff you guys have sent me, and, while I have a very basic grasp of it, I'm still completely lost. I attempted to write some of it into my own code, but all it did was break any progress I had made.


The addon I am making is a relatively simple addon that informs you when you have a Na'jentus Spine from High Warlord Na'jentus in BT. The frame that pops up features a hide button, a textstring saying "You have the spine!" and a large button labeled "Throw It!", which should use the spine.

For purposes of testing, I am currently using soul shards as a placeholder item. I was able to make the frame pop up as soon as one obtained a soul shard.

Here is the code I have so far. (A lot of it is borrowed from ESN_Hexer. Most instances where you see ESN_Hexer in this code are going to be replaced.)

NajentusHelper.lua

local f = CreateFrame("Frame","ESN_Hexer_Frame",WorldFrame)
f:SetFrameStrata("BACKGROUND")
f:SetAllPoints(WorldFrame)
f:SetAlpha(0)
f:SetPoint("CENTER",0,0)


f:RegisterEvent("CHAT_MSG_LOOT")


f:SetScript("OnEvent", function(frame, event, name)
if (event == "CHAT_MSG_LOOT") then
if (string.find (arg1, ESN_Hexer_String_YouCreate) and string.find(arg1, ESN_Hexer_String_SoulShard)) then
Frame1:Show();
end
end
end)

function Button2_OnClick()
Frame1:Hide();
end



localization.lua


ESN_Hexer_String_YouCreate = "You create"
ESN_Hexer_String_SoulShard = "Soul Shard"

end



Frame.xml (Before I made any changes to a secure frame)


<Ui xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.blizzard.com/wow/ui/">
<Script file="Frame.lua" />
- <Frame name="Frame1" parent="UIParent" toplevel="true" movable="true" enableMouse="true">
- <Size>
<AbsDimension x="200" y="142" />
</Size>
- <Anchors>
- <Anchor point="TOPLEFT">
- <Offset>
<AbsDimension x="100" y="-137" />
</Offset>
</Anchor>
</Anchors>
- <Scripts>
<OnEvent>Frame1_OnEvent()</OnEvent>
<OnMouseDown>self:StartMoving();</OnMouseDown>
<OnMouseUp>self:StopMovingOrSizing();</OnMouseUp>
</Scripts>
- <Layers>
- <Layer>
- <FontString name="FontString1" inherits="GameFontNormalSmall" text="You Have The Spine!">
<Size x="170" y="20" />
- <Anchors>
- <Anchor point="TOPLEFT">
<Offset x="15" y="-45" />
</Anchor>
</Anchors>
</FontString>
</Layer>
</Layers>
- <Backdrop bgFile="Interface\DialogFrame\UI-DialogBox-Background" edgeFile="Interface\DialogFrame\UI-DialogBox-Border" tile="true">
- <BackgroundInsets>
<AbsInset left="11" right="12" top="12" bottom="11" />
</BackgroundInsets>
- <TileSize>
<AbsValue val="32" />
</TileSize>
- <EdgeSize>
<AbsValue val="32" />
</EdgeSize>
</Backdrop>
- <Frames>
- <Button name="Button2" inherits="UIPanelButtonTemplate" text="Hide">
<Size x="53" y="24" />
- <Anchors>
- <Anchor point="TOPLEFT">
<Offset x="132" y="-15" />
</Anchor>
</Anchors>
- <Scripts>
<OnClick>Button2_OnClick();</OnClick>
</Scripts>
</Button>
- <Button name="Button1" inherits="UIPanelButtonTemplate" text="Throw It!">
<Size x="100" y="45" />
- <Anchors>
- <Anchor point="TOPLEFT">
<Offset x="52" y="-71" />
</Anchor>
</Anchors>
</Button>
</Frames>
</Frame>
</Ui>



----------------------------------------------

The "Throw It!" button currently has no function.

I would be extremely grateful if someone could give me some pointers regarding where exactly I'm supposed to put
the scripts that make the "Throw It!"button usable. ((E.G. Where am I supposed to set the attributes?))

For now, assume that I am using a Hearthstone as a placeholder for the spine. It'd certainly be a lot easier to test than having to obtain a spine.


Thank you so much for your help so far.

LBXZero 08-01-08 08:58 PM

The first time I looked at secure frames, it threw me for a loop.

For a button that does an action, your button must inherit SecureActionButtonTemplate.

Next, you have a few attributes to set via ActionButton:SetAttribute() function.
First attribute is "type" which says what type of action click is involved. Since you are using an item, type must be item.

Button:SetAttribute("type","item");

Second is setting which item. That is done by two ways that you can find on www.wowwiki.com's Secure Frames Overview.

There is an optional part to these attributes, adding prefixes and postfixes to type and secondary attribute. These prefixes and postfixes customize on which modifier and mouse click to do said action.

Also with the SecureActionButtonTemplate, you cannot change the OnClick handler. Instead, if you need something special to happen on a click, set the PreClick to have it occur before the OnClick handler or PostClick for after.

TheOneAndLonely 08-04-08 01:39 PM

I did a mage/warlock gui whit round buttons and used secure this is a fragment from it that might be to some help.


local function CreateSheepButton()
local SheepBtn = CreateFrame("Button", "SheepBtn", MainFrame, "SecureActionButtonTemplate")
SheepBtn:SetWidth(64)
SheepBtn:SetHeight(64)
SheepBtn:SetPoint("CENTER", MainFrame, "CENTER", 0, MainFrame:GetHeight()/2)

SheepBtn:SetAttribute("type", "spell");
SheepBtn:SetAttribute("spell","Polymorph(Rank 1)");
SheepBtn:SetNormalTexture("Interface\\Addons\\Mage\\SpellIcons\\SheepNormal")
SheepBtn:SetHighlightTexture("Interface\\Addons\\Mage\\SpellIcons\\SheepHighlight")
SheepBtn:SetPushedTexture("Interface\\Addons\\Mage\\SpellIcons\\SheepPushed")
SheepBtn:SetScale(0.6)
SheepBtn:RegisterForClicks("LeftButtonUp", "RightButtonUp")

SheepBtn:SetScript("OnEnter",
function()
GameTooltip:SetOwner(this, "ANCHOR_LEFT");
GameTooltip:AddLine("Just make him a Sheep");
GameTooltip:Show();
end)

SheepBtn:SetScript("OnLeave", function() GameTooltip:Hide() end)
return SheepBtn;
end;


All times are GMT -6. The time now is 07:41 AM.

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