Thread Tools Display Modes
07-08-10, 09:56 AM   #1
hairy_palms
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Feb 2010
Posts: 25
loot roll event parsing

im trying to write some lua that just prints the items name when a loot roll starts, yet all it seems to print is nil, am i getting the rollid the wrong way?

Code:
function printname(self, event, ...)
	if event == "START_LOOT_ROLL" then
		local texture, name, count, quality = GetLootRollItemInfo(self.rollID)		
		print(name)
        end
end
local eventFrame = CreateFrame("Frame", nil, UIParent)
eventFrame:RegisterEvent("START_LOOT_ROLL")
eventFrame:SetScript("OnEvent", function()  printname() end)
  Reply With Quote
07-08-10, 10:02 AM   #2
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
You're not quite using/accessing the variables from your event handler correctly.

Code:
function printname(id)
	local texture, name, count, quality = GetLootRollItemInfo(id)		
		print(name)
        end
end


eventFrame:SetScript("OnEvent", function(self, event, id)  printname(id) end)
If you're only registered for one event, then you don't need to check on which event triggered your script. The first variable passed in any frame's script (here it's "self") is a reference to the frame that called it - eventFrame. The second variable in the function (event) is what event was called - this is the first return in an OnEvent handler. The third variable (id) is the return provided by the event (if any) - in this case, it is the id of the item being rolled for.

When calling an external function from your event handler, if you need access to any of these variables, you need to pass them through - hence printname(id).


/edit: you can also just do this:
Code:
eventFrame:SetScript("OnEvent", function(self, event, id)
     local texture, name, count, quality = GetLootRollItemInfo(id)		
          print(name)
     end
end)
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
07-08-10, 10:04 AM   #3
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 822
Use the arg1 of the event. The event gives the rollid, rolltime as two args.
Code:
function printname(self, event, rollId, rollTime)
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
07-08-10, 10:12 AM   #4
hairy_palms
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Feb 2010
Posts: 25
if i did need the if event, since im using more than 1 event in the finished code, they just arent implemented yet, so if i understand rightly

Code:
function printname(self, event, id)
        if event == "START_LOOT_ROLL" then
	        local texture, name, count, quality = GetLootRollItemInfo(id)		
		print(name)
        end
end

eventFrame:SetScript("OnEvent", function(self, event, id)  printname(self, event, id) end)
would be the correct code while keeping the event check?

/edit hmm guess not that seems to crash WoW

Last edited by hairy_palms : 07-08-10 at 10:23 AM.
  Reply With Quote
07-08-10, 10:34 AM   #5
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 822
first I'd make the function local

Code:
local function printname(self, event, id)
And since all you do is passing the info to the function you can skip the additional func.

Code:
eventFrame:SetScript("OnEvent", printname)
I encounter crashes while testing code quite often. Especially if I switch
from wow-screen to desktop fast ... just retry the same code
If it crashes 3 times in a row then you should start looking for the reason
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
07-08-10, 05:46 PM   #6
hairy_palms
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Feb 2010
Posts: 25
thanks for all the help so far guys!
ive been working at this and ive come up with this debugging function

Code:
local function printname(self, id)
	local texture, name, count, quality = GetLootRollItemInfo(id)
	print(texture.." "..name.." "..count.." "..quality)
	local color = ITEM_QUALITY_COLORS[quality]
        print(color.r)
	print(self)	
end
local eventFrame2 = CreateFrame("Frame", nil, UIParent)
eventFrame2:RegisterEvent("START_LOOT_ROLL")
eventFrame2:SetScript("OnEvent", function(self, event, id)  printname(self, id) end)
so, sort of related to this, but how would i find the frame that fired the START_LOOT_ROLL event, eg GroupLootFrame1-4?
when i print(self) above it returns a table, are any of the things in there part of what im looking for?
  Reply With Quote
07-08-10, 06:31 PM   #7
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,928
The id might be what you are looking for:

http://wowprogramming.com/docs/events/START_LOOT_ROLL

The self you mentioned is your event frame identity in case you have multiple frames watching events via the same function.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
07-09-10, 03:24 AM   #8
hairy_palms
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Feb 2010
Posts: 25
hmm is there a way to get the frame that caused the event from its ID then? the ID itself is just a number that increments on its own which is no good, it doesnt reset when rolls are completed
  Reply With Quote
07-09-10, 06:00 AM   #9
v6o
An Onyxian Warder
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 399
noticed this code i blizzards default code

frame = _G["GroupLootFrame"..i];
if ( not frame:IsShown() ) then
frame.rollID = id;
frame.rollTime = rollTime;
__________________
I stopped playing back World of Warcraft in 2010 and I have no plans on returning.
This is a dead account and if you want to continue any of my addons or make a fork then feel free to do so.
This is your permission slip.

If you need to contact me, do so on Twitter @v6ooo

Best regards, v6.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » loot roll event parsing


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

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