1. #1

    Anybody want to test an addon for me?

    Hello all,

    I am a senior computer science student and for one of my classes I have to come up with a project that gathers information and does some sort of statistical analysis on it. I chose to use WoW character names/realms but need some help gathering data to process. I created an addon that will track the names and realms of players you meet via dungeon, battleground, etc. and saves this data in a SavedVariables file.

    If anybody is willing you can download the addon from WoWInterface

    http://www.wowinterface.com/download...alProject.html

    It doesn't do anything visual, so you won't see it working. Just play WoW like normal and every once in a while send me your saved variables.

    Saved Variables can be found at:

    World of Warcraft\WTF\Account\<ACCOUNT_NAME>\SavedVariables\CS490Final.lua

    Just right click on the file and choose either Open With or Edit and copy the contents of the file. Alternatively you can email the file to me as an attachment. PM me for my email address if you wish to send it that way.

    Any help in this would be appreciated.

    Arcilux

    Just in case anybody is concerned if this is considered data mining, I asked for a response from Blizzard before making the addon. Their response was:

    I don't believe the addon you mentioned would be a data mining issue. Just please be sure you do not do anything that gives you an unfair advantage in the game. You can always review our policies here (http://us.blizzard.com/support/artic...chQuery=policy) for more information or you can contact our legal department (legal@blizzard.com)
    Game Master Beshahl

  2. #2
    Deleted
    Quite a few useless globals there. If you don't specify "local" on a variable (your AllCharNames), it's global by default. Also, all tables are a reference, so all that assigning you're doing between _G and an already global variable is pretty much useless.
    Also, you definining AllCharNames in line1 of your code is also useless, as it's overriden by the time your SavedVars are loaded.

    Also, craptons of global namespace violations. And I mean craptons.

    ---------- Post added 2011-04-13 at 08:32 AM ----------

    There. Scrap your xml file. Replace your lua file. I ripped out the global leaks and renamed your SavedVar table. Adjust your toc accordingly.
    Code:
    local addon = CreateFrame("Frame","CS490Frame")
    local country = GetCVar("realmList"):sub(1,2)
    local realm
    local UnitName, GetNumRaidMembers, GetNumPartyMembers, UnitIsPlayer =
    	  UnitName, GetNumRaidMembers, GetNumPartyMembers, UnitIsPlayer
    
    local function savePlayerInfo(uID)
    	local unitname, unitrealm = UnitName(uID)
    	realm=realm or GetRealmName()
    	CS490_CharNames[unitname.."-"..(unitrealm or realm).."-"..country]=""
    end
    
    local function GetPartyInfo()
    	if GetNumRaidMembers() > 0 then
    		for i=1, GetNumRaidMembers() do
    			savePlayerInfo("raid"..i)
    		end
    	elseif GetNumPartyMembers() > 0 then
    		for i=1, GetNumPartyMembers() do
    			savePlayerInfo("party"..i)
    		end
    	end
    end
    
    local function GetTargetInfo()
    	if UnitIsPlayer("target") then
    		savePlayerInfo("target")
    	end
    end
    
    local function GetChatInfo(author)
    	if author then
    		realm = realm or GetRealmName()
    		if not author:find("-") then
    			author = author.."-"..realm
    		end
    		CS490_CharNames[author.."-"..country]=""
    	end
    end
    
    addon:SetScript("OnEvent", function(self, event, arg1, arg2)
    	if event == "PLAYER_TARGET_CHANGED" then
    		GetTargetInfo()
    	elseif event == "PARTY_MEMBERS_CHANGED" then
    		GetPartyInfo()
    	elseif event == "ADDON_LOADED" and arg1 == "CS490Final" then
    		CS490_CharNames = CS490_CharNames or {}
    	elseif arg2 then
    		GetChatInfo(arg2)
    	end
    end)
    for _, event in ipairs({"PLAYER_TARGET_CHANGED", "PARTY_MEMBERS_CHANGED", "ADDON_LOADED", "CHAT_MSG_CHANNEL", "CHAT_MSG_ACHIEVEMENT", "CHAT_MSG_BATTLEGROUND", "CHAT_MSG_EMOTE", "CHAT_MSG_GUILD", "CHAT_MSG_SAY", "CHAT_MSG_YELL", "CHAT_MSG_WHISPER", "CHAT_MSG_TEXT_EMOTE", "CHAT_MSG_WHISPER_INFORM", "CHAT_MSG_RAID", "CHAT_MSG_PARTY"}) do
    	addon:RegisterEvent(event)
    end

  3. #3
    My bad, I am more used to languages where local is the default scope. Just a few questions for understanding purposes:

    Why create local instances of the API functions? The local UnitName, GetNumRaidMembers, etc.

    Why handle the event listening in the lua rather than the xml?

  4. #4
    Deleted
    Like Meorawr said, locals have a far faster lookup speed - fetching a global requires looking up the global table, then looking up the variable, while locals are already included in the callstack.
    If you come from languages that have a fixed name for functions and keep them seperate from variables (PHP comes to mind), this may all seem weird for you, however consider this: Every function in lua is unnamed at a memory address, the variable just contains a reference to that memory. (Same goes for tables - you can see this when you tostring() then).

    Example:
    Code:
    local a = {answer = "unknown"}
    local b=a
    b.answer = 42
    print(a.answer)
    > 42
    If you want an independent instance of the table, you have to manually go through and copy each single entry using pairs - I've written a function I usually c+p to all of my addons as needed:
    Code:
    local function tcopy(intable,outtable,overwrite,written)
    	--written is an internal table to track references to already copied tables and keep those intact
    	--create outtable if it doesn't exist
    	outtable = outtable or {}
    	--create written if this is the first call (user call)
    	written = written or {}
    	--add copied table to written
    	written[tostring(intable)] = outtable
    	--loop through data
    	for key, data in pairs(intable) do
    		--if overwrite or not exists, write value
    		if (not outtable[key]) or overwrite then
    			if type(data) == "table" then
    				outtable[key] = written[tostring(data)] or tcopy(data,nil,nil,written)
    			else
    				outtable[key] = data
    			end
    		end
    	end
    	return outtable
    end
    Last edited by mmocba105e19de; 2011-04-13 at 05:05 PM.

  5. #5
    Quote Originally Posted by Arcilux View Post
    Why handle the event listening in the lua rather than the xml?
    There are pros and cons to using XML over Lua and vice versa. I'd recommend reading this thread for a debate on "Lua vs XML".
    Myself I prefer to do everything in Lua, since I lack basic (WoW) XML knowledge

    It's good you're already checking the Chat Events; I would recommend also using COMBAT_LOG_EVENT_UNFILTERED to get player names
    This is how I gathered player names according to their UnitGUID/"Player ID" in one of my (Ace3) addons
    Code:
    local realm = MyAddOn.db.realm -- just some AceDB table lookup shortcut
    
    function MyAddOn:COMBAT_LOG_EVENT_UNFILTERED(event, ...)
    	local sourceGUID, sourceName, _, destGUID, destName = select(3, ...)
    	local sourceID = tonumber(strsub(sourceGUID, 12, 18), 16)
    	local destID = tonumber(strsub(destGUID, 12, 18), 16)
    
    	if sourceName and strsub(sourceGUID, 5, 5) == "0" and not realm[sourceID] then
    		realm[sourceID] = sourceName
    	end
    	if destName and strsub(destGUID, 5, 5) == "0" and not realm[destID] then
    		realm[destID] = destName
    	end
    end
    My coding is a bit wierd and unexplanatory, but you could remove the unneeded playerID stuff from this example, and modify it a bit (maybe with "pattern matching") to adapt to cross-realm battlegrounds and instances, since realm names are also included in the sourceName/destName when in cross-realm servers

    Anyway, aside from all the Lua stuff; you're a computer science student, and obviously know a lot more than me, in general, about programming
    I'm playing on the PTR now, and will use your addon there
    Last edited by Ketho; 2011-04-13 at 06:14 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •