Go Back   WowAce Forums > General > Lua Code Discussion
Lua Code Discussion You scared? Terrified. Mortified. Petrified. Stupefied... by [coding].

Reply
 
Thread Tools
Old 12-18-2010   #11
Phanx
Seal Cub Clubbing Club
 
Phanx's Avatar
 
Join Date: May 2005
Location: United States
Posts: 8,056
Default Re: A rogue 'beginner' AddOn

If you're seeing errors that you don't immediately know how to fix, you should post the errors. We can't see your screen through the tubes.

Font strings are not standalone; like textures, they must be attached to a frame. You need a frame anyway to listen for events, so you'd need to create a frame even if you didn't need one for the font string.
__________________
Author/maintainer of Grid, PhanxChat, and many more. | PM me on CurseForge
Troubleshoot an addon | Turn any code into an addon | More addon resources
Need help with your code? Attach or paste your whole, real files.
Please don't PM me about addon bugs, requests, or code help. Post a comment, ticket, or thread instead!
Phanx is offline   Reply With Quote
Old 12-18-2010   #12
wwwDot
Full Member
 
Join Date: Nov 2010
Location: New York
Posts: 133
Default Re: A rogue 'beginner' AddOn

Well i didn't post the error's because i wanted to try to do something lol. I got rid of the error's and made the frame visible, I tried creating the main and off hand each have their own function to see if that would fix it, but it didn't change anything. I will post the code a little bit later, i want to try a little bit more.
__________________
Author and Maintainer of GuildLoot 2.9.1
wwwDot is offline   Reply With Quote
Old 12-18-2010   #13
wwwDot
Full Member
 
Join Date: Nov 2010
Location: New York
Posts: 133
Default Re: A rogue 'beginner' AddOn

Code:
-- Author      : wwwDot
-- Create Date : 11/14/2010 5:05:10 PM

function MainWeapNote(self)
	self:RegisterEvent("UNIT_INVENTORY_CHANGED")
end

function SecondaryWeapNote(self)
	self:RegisterEvent("UNIT_INVENTORY_CHANGED")
end

function MainWeapNote_OnEvent(self, event, arg1)
	if arg1 ~= "player" then 
		return 
	end

	if event == "UNIT_INVENTORY_CHANGED" then
				--local hasMainHandEnchant, _, _, hasSecondaryHandEnchant = GetWeaponEnchantInfo()
		local hasMainHandEnchant = GetWeaponEnchantInfo()

		local mainHandLink = GetInventoryItemLink("player", GetInventorySlotInfo("MainHandSlot"))
				--local secondaryHandLink = GetInventoryItemLink("player", GetInventorySlotInfo("MainHandSlot"))
		local hasFishingPole = mainHandLink and select(7, GetItemInfo(mainHandLink)) == "Fishing Poles"

		if mainHandLink and not hasFishingPole and not hasMainHandEnchant then
				--or ( secondaryHandLink and not hasSecondaryHandEnchant )
			self:Show()
		else
			self:Hide()
		end
	end
end

function SecondaryWeapNote_OnEvent(self, event, arg1)
	if arg1 ~= "player" then 
		return
	end
	
	if event == "UNIT_INVENTORY_CHANGED" then
	
		local hasSecondaryHandEnchant = GetWeaponEnchantInfo()

		local secondaryHandLink = GetInventoryItemLink("player", GetInventorySlotInfo("OffHandSlot"))
	
		if secondaryHandLink and not hasSecondaryHandEnchant then
			self:Show()
		else
			self:Hide()
		end
	end
end
That's my .lua right now, i didn't make a frame for the offhand weapon yet, just wanted to try to get the main hand working.

This is my .xml
Code:
<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="EasyControl.lua" />
	<Frame name="MainWeapNote" parent="UIParent" toplevel="true" movable="false" enableMouse="false">
		<Size>
			<AbsDimension x="510" y="20" />
		</Size>
		<Anchors>
			<Anchor point="CENTER">
				<Offset x="2" y="1" />
			</Anchor>
		</Anchors>
		<TitleRegion setAllPoints="true">
			<Size>
				<AbsDimension x="2" y="1" />
			</Size>
			<Anchors>
				<Anchor point="TOPLEFT" />
				<Anchor point="TOPRIGHT" />
			</Anchors>
		</TitleRegion>
		<Backdrop bgFile="Interface\DialogFrame\UI-DialogBox-Background" edgeFile="Interface\DialogFrame\UI-DialogBox-Border" 

tile="true">
			<BackgroundInsets>
				<AbsInset left="2" right="1" top="2" bottom="2" />
			</BackgroundInsets>
			<TileSize>
				<AbsValue val="2" />
			</TileSize>
			<EdgeSize>
				<AbsValue val="1" />
			</EdgeSize>
			<Color r="2" g="0.4" b="0.1" />
			<BorderColor r="1.5" g="0.2" b="0.4" />
		</Backdrop>

		<Layers>
			<Layer level="OVERLAY">
				<FontString name="NoPoisions" inherits="GameFontNormal" text="You currently have one or more weapons 

equipped without your poision enchant.">
					<Size>
						<AbsDimension x="600" y="10" />
					</Size>
					<Anchors>
						<Anchor point="CENTER">
							<Offset x="0" y="0" />
						</Anchor>
					</Anchors>
				</FontString>
			</Layer>
		</Layers>

		<Scripts>
			<OnEvent>MainWeapNote_OnEvent(self, event, arg1)</OnEvent>
		</Scripts>
	</Frame>


</Ui>
The notification still is always there no matter the state.
__________________
Author and Maintainer of GuildLoot 2.9.1

Last edited by wwwDot; 12-18-2010 at 04:10 PM.
wwwDot is offline   Reply With Quote
Old 12-18-2010   #14
Lombra
Senior Member
 
Lombra's Avatar
 
Join Date: Jan 2006
Location: Sweden
Posts: 396
Default Re: A rogue 'beginner' AddOn

You never register any events cos MainWeapNote is never called.
__________________
Grab your sword and fight the Horde!

Shattered Hand-EU
Lombra is online now   Reply With Quote
Old 12-18-2010   #15
wwwDot
Full Member
 
Join Date: Nov 2010
Location: New York
Posts: 133
Default Re: A rogue 'beginner' AddOn

Would i have to do a

<OnLoad>MainWeapNote(self)</OnLoad>

In the .xml?


edit:
^ That causes it to not show.
__________________
Author and Maintainer of GuildLoot 2.9.1

Last edited by wwwDot; 12-18-2010 at 07:35 PM.
wwwDot is offline   Reply With Quote
Old 12-18-2010   #16
wwwDot
Full Member
 
Join Date: Nov 2010
Location: New York
Posts: 133
Default Re: A rogue 'beginner' AddOn

Ok, i fixed that problem, now it's just back to always showing.

I'm stumped, i'm goona go look at some other AddOn's see if they can help me out with this.
__________________
Author and Maintainer of GuildLoot 2.9.1
wwwDot is offline   Reply With Quote
Old 12-18-2010   #17
wwwDot
Full Member
 
Join Date: Nov 2010
Location: New York
Posts: 133
Default Re: A rogue 'beginner' AddOn

Ok, i think i might have it. But when the AddOn is first activated, and your character is loaded into the world, the notification is automatically there, even if you have your poison's on, until you either, equip a fishing pole, or un-equip your dagger's and re-equip them.

Also, how do you make Anchor Point's bigger? It is hard as hell to move this notification because its so hard to find it since its such a small point.

/edit:

Just noticed, that the off hand frame fire's when the main hand does, so if the poison is added, or taken from the main, but not the off hand weapon, the off hand weapon notification still fire's.

If both hand slots are empty, there's no poison enchant on the weapon that goes in the secondary hand slot, and you equip the secondary dagger, the secondary notification fire's like it's supposed to, and the main hand doesn't... Like it's supposed to. But after that, if i still didn't enchant the secondary hand dagger, and equipped the main hand weapon that did have the poison enchant, the secondary hand notification would go away, is if the poison was applied to the secondary hand dagger.
__________________
Author and Maintainer of GuildLoot 2.9.1

Last edited by wwwDot; 12-18-2010 at 09:22 PM.
wwwDot is offline   Reply With Quote
Old 12-18-2010   #18
wwwDot
Full Member
 
Join Date: Nov 2010
Location: New York
Posts: 133
Default Re: A rogue 'beginner' AddOn

This is my .lua

Code:
-- Author      : wwwDot
-- Create Date : 12/13/2010 5:05 PM

function MainWeapNote_OnLoad(self)
	local hasMainHandEnchant = GetWeaponEnchantInfo()
	local mainHandLink = GetInventoryItemLink("player", GetInventorySlotInfo("MainHandSlot"))
	local hasFishingPole = mainHandLink and select(7, GetItemInfo(mainHandLink)) == "Fishing Poles"
	
	if mainHandLink and not hasMainHandEnchant and not hasFishingPole then
		self:Show()
	else
		self:Hide()
	end

	self:RegisterEvent("UNIT_INVENTORY_CHANGED")
end

function SecondaryWeapNote_OnLoad(self)
	local hasSecondaryHandEnchant = GetWeaponEnchantInfo()
	local secondaryHandLink = GetInventoryItemLink("player", GetInventorySlotInfo("SecondaryHandSlot"))

	if secondaryHandLink and not hasSecondaryHandEnchant then
		self:Show()
	else
		self:Hide()
	end
	
	self:RegisterEvent("UNIT_INVENTORY_CHANGED")
end

function MainWeapNote_OnEvent(self, event)
	--if arg1 ~= "player" then 
	--	return 
	--end

	if event == "UNIT_INVENTORY_CHANGED" then
		local hasMainHandEnchant = GetWeaponEnchantInfo()

		local mainHandLink = GetInventoryItemLink("player", GetInventorySlotInfo("MainHandSlot"))
		
		local hasFishingPole = mainHandLink and select(7, GetItemInfo(mainHandLink)) == "Fishing Poles"

		if mainHandLink and not hasFishingPole and not hasMainHandEnchant then
			self:Show()
		else
			self:Hide()
		end

		if hasFishingPole then
			print("Your Fishing Pole Is Equipped")
		end
	end
end

function SecondaryWeapNote_OnEvent(self, event)
	--if arg1 ~= "player" then 
	--	return
	--end
	
	if event == "UNIT_INVENTORY_CHANGED" then
	
		local hasSecondaryHandEnchant = GetWeaponEnchantInfo()

		local secondaryHandLink = GetInventoryItemLink("player", GetInventorySlotInfo("SecondaryHandSlot"))
	
		if secondaryHandLink and not hasSecondaryHandEnchant then
			self:Show()
		else
			self:Hide()
		end
	end
end
And this is my .xml

Code:
<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="EasyControl.lua" />
	<Frame name="MainWeapNote" parent="UIParent" toplevel="true" movable="true" enableMouse="true">
		<Size>
			<AbsDimension x="510" y="20" />
		</Size>
		<Anchors>
			<Anchor point="CENTER">
				<Offset x="2" y="1" />
			</Anchor>
		</Anchors>
		<TitleRegion setAllPoints="true">
			<Size>
				<AbsDimension x="2" y="1" />
			</Size>
			<Anchors>
				<Anchor point="TOPLEFT" />
				<Anchor point="TOPRIGHT" />
			</Anchors>
		</TitleRegion>
		<Backdrop bgFile="Interface\DialogFrame\UI-DialogBox-Background" edgeFile="Interface\DialogFrame\UI-DialogBox-Border" tile="true">
			<BackgroundInsets>
				<AbsInset left="2" right="1" top="2" bottom="2" />
			</BackgroundInsets>
			<TileSize>
				<AbsValue val="2" />
			</TileSize>
			<EdgeSize>
				<AbsValue val="1" />
			</EdgeSize>
			<Color r="2" g="0.4" b="0.1" />
			<BorderColor r="1.5" g="0.2" b="0.4" />
		</Backdrop>

		<Layers>
			<Layer level="OVERLAY">
				<FontString name="NoPoisionsMain" inherits="GameFontNormal" text="Your current main hand weapon is not poison enchanted.">
					<Size>
						<AbsDimension x="600" y="10" />
					</Size>
					<Anchors>
						<Anchor point="CENTER">
							<Offset x="0" y="0" />
						</Anchor>
					</Anchors>
				</FontString>
			</Layer>
		</Layers>

		<Scripts>
			<OnLoad>MainWeapNote_OnLoad(self);</OnLoad>
			<OnEvent>MainWeapNote_OnEvent(self, event, ...);</OnEvent>
			<OnDragStart>self:StartMoving();</OnDragStart>
			<OnDragStop>self:StopMovingOrSizing();</OnDragStop>
		</Scripts>
	</Frame>

	<Frame name="SecondaryWeapNote" parent="UIParent" toplevel="true" movable="true" enableMouse="true">
		<Size>
			<AbsDimension x="510" y="20" />
		</Size>
		<Anchors>
			<Anchor point="TOPLEFT">
				<Offset x="1" y="2" />
			</Anchor>
		</Anchors>
		<TitleRegion setAllPoints="true">
			<Size>
				<AbsDimension x="2" y="1" />
			</Size>
			<Anchors>
				<Anchor point="TOPLEFT" />
				<Anchor point="TOPRIGHT" />
			</Anchors>
		</TitleRegion>
		<Backdrop bgFile="Interface\DialogFrame\UI-DialogBox-Background" edgeFile="Interface\DialogFrame\UI-DialogBox-Border" tile="true">
			<BackgroundInsets>
				<AbsInset left="51" right="2" top="1" bottom="5" />
			</BackgroundInsets>
			<TileSize>
				<AbsValue val="10" />
			</TileSize>
			<EdgeSize>
				<AbsValue val="15" />
			</EdgeSize>
			<Color r="4" g="1.4" b="3.1" />
			<BorderColor r="2.5" g="0.6" b="2.4" />
		</Backdrop>

		<Layers>
			<Layer level="OVERLAY">
				<FontString name="NoPoisionsOff" inherits="GameFontNormal" text="Your current off hand weapon is not poison enchanted.">
					<Size>
						<AbsDimension x="600" y="10" />
					</Size>
					<Anchors>
						<Anchor point="CENTER">
							<Offset x="0" y="0" />
						</Anchor>
					</Anchors>
				</FontString>
			</Layer>
		</Layers>

		<Scripts>
			<OnLoad>SecondaryWeapNote_OnLoad(self);</OnLoad>
			<OnEvent>SecondaryWeapNote_OnEvent(self, event, ...);</OnEvent>
			<OnDragStart>self:StartMoving();</OnDragStart>
			<OnDragStop>self:StopMovingOrSizing();</OnDragStop>
		</Scripts>
	</Frame>


</Ui>
__________________
Author and Maintainer of GuildLoot 2.9.1
wwwDot is offline   Reply With Quote
Old 12-18-2010   #19
wwwDot
Full Member
 
Join Date: Nov 2010
Location: New York
Posts: 133
Default Re: A rogue 'beginner' AddOn

I'm now trying separate .lua and .xml files for each hand, but i am still trying to figure out how to make the anchor point's bigger.
__________________
Author and Maintainer of GuildLoot 2.9.1
wwwDot is offline   Reply With Quote
Old 12-18-2010   #20
wwwDot
Full Member
 
Join Date: Nov 2010
Location: New York
Posts: 133
Default Re: A rogue 'beginner' AddOn

Nope, that didn't help either. They both fire when the main hand changes, but they don't fire when the off hand changes. And it's weird, because the SecondHand is set to read the SecondaryHandSlot, but it seem's like it still read's the MainHandSlot.
__________________
Author and Maintainer of GuildLoot 2.9.1
wwwDot is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:42 PM.