Thread Tools Display Modes
03/11/14, 01:24 PM   #1
Aldazar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 13
As a beginner without PTS access I need help with preparing my Addon

Hi,

first time LUA and Addon developer here. Since I don't have PTS account and won't be able to use the weekend beta for more than 1 or 2 hours I am currently trying to set up as much of my Addon as possible without being able to fiddle around. So I have as much as possible ready for testing on the weekend.

So please excuse any noob questions I might ask.
The idea of the addon is to enable the import of a guild list from an CSV into ESO. In its basic form the Addon should just invite all accounts specified into a manually created guild. (Might be later enhanced to automate the whole guild setup or to supply a guild from lets say a forum member list)

Now to start of with my questions. The first on how do I get the guildId? That I can use in the invite function. Or respectivly what is the luaindex that I need to retrieve the guildID with the following function:
Lua Code:
  1. GetGuildId(luaindex index)
  2.  
  3.     Returns: integer guildId

The other question is how can I handle or how would I have to format the CSV file. So far I got the following from the wiki:
Lua Code:
  1. local function OnAddOnLoaded(eventCode, addOnName)
  2.     if(addOnName == "AddonName") then
  3.         local savedVars = ZO_SavedVars:New(TGIGuildList, 1)
  4.     end
  5. end
  6.  
  7. function ImportGuild()
  8.     AddonNameCounter:SetText(string.format("# Invited: %d", counter))
  9.     counter = counter + 1
  10. end
  11.  
  12. EVENT_MANAGER:RegisterForEvent("AddonName", EVENT_ADD_ON_LOADED, OnAddOnLoaded)

How would the savedVars be accesible/structured if I fill the file as follows:
Code:
name1, name2, name3,
Thanks for everyone reading this far. And thanks in advance for helping me out.
  Reply With Quote
03/11/14, 04:56 PM   #2
Xrystal
caritas omnia vincit
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 369
This will return the number of guilds you the player have access to
Lua Code:
  1. local numGuilds = GetNumGuilds()

you would then loop through to get details:
Lua Code:
  1. for i=1,numGuilds do
  2.      local guildID = GetGuildID(i)
  3. end

Then to invite you would use:
Lua Code:
  1. GuildInvite(guildID, displayNameOfPerson)

SavedVariables file format is as follows, based on its creation as
Lua Code:
  1. local SVData = {}
  2. local SVDefault = {}
  3. SVData = ZO_SavedVars:NewAccountWide("XrysGatherer_SavedVariables", 1, "Data", SVDefault)

Lua Code:
  1. XrysGatherer_SavedVariables =
  2. {
  3.     ["Default"] =
  4.     {
  5.         ["@xXxAccountNamexXx"] =
  6.         {
  7.             ["$AccountWide"] =
  8.             {
  9.                 ["Data"] =
  10.                 {
  11.                     ["version"] = 1,
  12.                     ["Khenarthi's Roost"] =
  13.                     {
  14.                         ["Dragonthorn"] =
  15.                         {
  16.                             [1] =
  17.                             {
  18.                                 ["Date"] = 20140302,
  19.                                 ["Y"] = 0.736750,
  20.                                 ["Time"] = [[17:38:06]],
  21.                                 ["Action"] = [[Collect]],
  22.                                 ["X"] = 0.598225,
  23.                             },
  24.                         },
  25. ..... etc

To read through the saved variables file of this type of format you would need to do something along these lines:
Lua Code:
  1. tempTable = {}
  2.         for default,sv in pairs(XrysGatherer_SavedVariables) do
  3.             for account,accountv in pairs(sv) do
  4.                 for accountWide,acWideV in pairs(accountv) do
  5.                     for index,data in pairs(acWideV) do
  6.                         if index == "Data" then
  7.                             table.insert(tempTable ,data )
  8.                         end
  9.                     end
  10.                 end
  11.             end
  12.         end

You then use tempTable to directly access the data you want.

This layout I suspect is the result of a non account wide creation like the code you have specified in your code:

Lua Code:
  1. ZO_Ingame_SavedVariables =
  2. {
  3.     ["Default"] =
  4.     {
  5.         ["xXxAccountNamexXx"] =
  6.         {
  7.             ["xXxCharacterNamexXx"] =
  8.             {
  9.                 ["Provisioner"] =
  10.                 {
  11.                     ["version"] = 1,
  12.                     ["haveSkillsChecked"] = true,
  13.                     ["haveIngredientsChecked"] = true,
  14.                 },
  15.                 ["Chat"] =
  16.                 {
  17.                     ["version"] = 4,
  18.                     ["containers"] =
  19.                     {
  20.                         [1] =
  21.                         {
  22.                             ["relPoint"] = 2,
  23.                             ["x"] = 0,
  24.                             ["point"] = 2,
  25.                             ["y"] = 253,
  26.                             ["height"] = 380,
  27.                             ["width"] = 550,
  28.                         },
  29.                     },
  30.                 },
  31. .... etc

Based on that information I would think the following code would be a good dry code start for testing with:

Lua Code:
  1. -- Do we want the Saved Variables to be Account Wide
  2. local SVAccountWide = false
  3.  
  4. -- Set to false for first run through, to create guild, saved variables table etc
  5. -- Log out ( to log in screen ) and manually adjust the saved variables table
  6. -- Set to true once the file has been adjusted with the data you want to import
  7. local SVHasData = false
  8.  
  9. -- Variable to hold the guildID/guildName of the guild you want to invite into
  10. local myGuildID
  11. local myGuildName = {NameOfGuildToInviteInto}
  12.  
  13. -- Variable to hold the sessions Saved Variables file
  14. local GuildSV = {}
  15.  
  16. -- Initialise the Saved Variables table and assign a table to hold this sessions data
  17. local function InitialiseSV()
  18.     if SVAccountWide then
  19.         GuildSV = ZO_SavedVars:NewAccountWide("{AddonName}_SavedVariables",1,"Data")
  20.     else
  21.         GuildSV = ZO_SavedVars:New("{AddonName}_SavedVariables", 1,"Data")
  22.     end
  23. end
  24.  
  25. -- Read through the Actual Saved Variables table and generate a temporary table to access the main block of data
  26. local function ReadSV()
  27.     tempTable = {}
  28.         if SVAccountWide then
  29.             for default,sv in pairs({AddonName}_SavedVariables) do
  30.                 for account,accountv in pairs(sv) do
  31.                     for accountWide,acWideV in pairs(accountv) do
  32.                         for index,data in pairs(acWideV) do
  33.                             if index == "Data" then
  34.                                 table.insert(tempTable ,data )
  35.                             end
  36.                         end
  37.                     end
  38.                 end
  39.             end
  40.         else
  41.             for default,sv in pairs({AddonName}_SavedVariables) do
  42.                 for account,accountv in pairs(sv) do
  43.                     for charKey,charData in pairs(accountv) do
  44.                         for index,data in pairs(charData) do
  45.                             if index == "Data" then
  46.                                 table.insert(tempTable ,data )
  47.                             end
  48.                         end
  49.                     end
  50.                 end
  51.             end
  52.         end
  53.    
  54.     -- Read through the tempTable and auto invite the names in the file
  55.     -- Data in the saved variables file (after the default/account/char blocks) is assumed to be as follows:
  56.     -- ["Data"] = {
  57.     --     [1] = {CharNameOfPersonToInvite},
  58.     --     [2] = {CharNameOfPersonToInvite},
  59.     -- }
  60.     for key,data in pairs(tempTable) do
  61.         -- GuildInvite(myGuildID,data)   -- Take the first 2 -- off the start of the line once you know data is valid
  62.         CHAT_SYSTEM:AddMessage(string.format("%d [%s] added to guild",key,data))
  63.     end
  64. end
  65.  
  66. -- Read through the guilds you are a member of and check against the name of the
  67. local function GetMyGuildID()
  68.     local numGuilds = GetNumGuilds()
  69.     for i=1,numGuilds do
  70.         local guildID = GetGuildID(i)
  71.         local guildName = GetGuildName(guildID)
  72.         if guildName == MyGuildName then
  73.            myGuildID = guildID
  74.            break
  75.         end
  76.     end
  77. end
  78.  
  79. -- Player is Active, SavedVariable data is available now and hopefully guild data
  80. local function PlayerActivated(eventID)
  81.     -- Update the MyGuildID variable
  82.     GetMyGuild()
  83.     if not myGuildID then
  84.         CHAT_SYSTEM:AddMessage("You are not a member of a guild called %s.",{MyGuildName})
  85.     end
  86.    
  87.     -- based on the flags set/values available read the appropriate saved variables data and autoinvite
  88.     if SVHasData and myGuildID then
  89.         ReadSV()
  90.     end
  91. end
  92.  
  93. -- Addons being loaded
  94. local function AddOnLoaded(eventID,addon)
  95.     if addon ~= {AddonName} then return end
  96.     EVENT_MANAGER:UnregisterForEvent({AddonName},eventID)
  97.     InitialiseSV()
  98.     EVENT_MANAGER:RegisterForEvent( {AddonName} ,EVENT_PLAYER_ACTIVATED , PlayerActivated )
  99. end
  100.  
  101. -- Track addons loading
  102. EVENT_MANAGER:RegisterForEvent( {AddonName},EVENT_ADD_ON_LOADED , AddOnLoaded )

Hopefully that will get you somewhat started and the first run through with data ( make sure you keep a copy of it) will not do anything major until you uncomment the line that auto invites and set the respective flags at the top of the file.

Anyone that has played with the guild stuff more than myself will hopefully spot any problem areas, my initial tests weren't conclusive enough to know if PlayerActivated is the right event to use to look at guild details.

The values in braces {AddonName.....} and {MyGuildName} etc are for you to customize with your details.

Last edited by Xrystal : 03/11/14 at 05:05 PM.
  Reply With Quote
03/11/14, 05:05 PM   #3
Aldazar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 13
Wow, quite the extensive answer. Thanks a lot. Hopefully I will be able to wrap my head around it in a quiet minute of the coming days.

And hopefully I will be able to give back to the community by releasing the tool before launch.

Currently I think my biggest issue is that I am having difficulties understanding the savedVariables without seeing them in action...
  Reply With Quote
03/11/14, 05:12 PM   #4
Xrystal
caritas omnia vincit
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 369
Tell me about it, took me over 3 hours to get that reading through the table code working. That's when I realised there is a session version of the data ( the variable ) and the full version of the data. Boy did I milk my access, went to bed almost 5am that morning and got 3 hrs sleep rofl.

Some parts of the code I posted I obviously haven't tested to know they work for sure but have coded based on the stuff I have worked out so far and theorised. But it should be enough to not error out but I couldn't identify the actual combination of functions to use to validate if you are allowed to invite as there doesn't seem to be a CanGuildInvite() function to use, so I have assumed that you were creating your own guild and were writing the addon to autoinvite your friends etc based on character names they are hoping/will eventually use in the game.

I am assuming DisplayName is the character name you see in game rather than the accountName you get to see when you chat to your friends or guild members. So you may find you need some tweaking to get the info in/out you want.
  Reply With Quote
03/11/14, 05:26 PM   #5
Aldazar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 13
Ye thats probably how I am going to spend my Sunday night (Im from the EU so I can go till 5 am >.<).

I am writing this for our guildleader and he will be the one executing, so permissions won't be an issues. (but might be nice to have for a version that I want to release publicly)

The thing with the screen name is quite an issue (think I realized it but didn't want to pay attention to it ^^" acc name would be so much easier and logical...) though and might force me to change the tbh quite simple design I had in mind designing this. Well perhaps after the weekend or information from a useful soul from the pts we are wiser.
  Reply With Quote
03/11/14, 05:31 PM   #6
Xrystal
caritas omnia vincit
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 369
Ooh, just looked at what was gonna be the start of my GuildMemberNames addon and realised I did find a GuildData event.

EVENT_MANAGER:RegisterForEvent( "{AddonName}", EVENT_GUILD_DATA_LOADED, GuildDataLoaded)

So you may want to switch out the guild data stuff into that function. I never got to the point of testing that it worked though.

And you could use EVENT_GUILD_MEMBER_ADDED even to display peoples details as they are added instead of in the function that is adding the members.

Oh, and actually, based on my little test run of these functions to see what the difference is, display Name may also be account name. As in it may be the displayname you see for that person, your friend as @Name then that is the name you are seeing etc.

local charName = GetUnitName("player")
local serverCharName = GetUniqueNameForCharacter(charName)
local accountName = GetDisplayName()

Last edited by Xrystal : 03/11/14 at 05:34 PM.
  Reply With Quote
03/11/14, 05:46 PM   #7
Aldazar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 13
Wow, you did a lot of research there.

Perhaps after all I may be able to build a half decent prototype until sunday.

You've been most helpful. What is your GuildMemberNames addon doing if i might ask, it got me curious?
  Reply With Quote
03/11/14, 06:00 PM   #8
Xrystal
caritas omnia vincit
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 369
Someone requested the ability to see the character names rather than account names which are the standard for guilds in ESO. http://www.esoui.com/forums/showthread.php?t=96

Hopefully an easy implementation but until I know all those ZO_ fancy functions that I need to override/amend to get the guild member name to display the way I want all I can do is get the code running that reads through the guild member list so that I can at least get as close as I can to what I need to do before then.

Last edited by Xrystal : 03/11/14 at 06:05 PM.
  Reply With Quote
03/12/14, 08:05 AM   #9
Aldazar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 13
Just a quick question. Where did you find the EVENT_GUILD_MEMBER_ADDED event?
I can't find it in the wiki and would need the parameters to use it.

Also in the savedVariables file is the ["Data"] required to be named exactly that way, or is it possible to give it lets say the guilds name?

Last edited by Aldazar : 03/12/14 at 08:12 AM.
  Reply With Quote
03/12/14, 02:43 PM   #10
Xrystal
caritas omnia vincit
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 369
Hmm thought it was one I saw in the wiki. Maybe it was one I spotted in another addon or a thread posting somewhere here.

edit: Hmm, looks like some of the events that were there before aren't there now. Not sure if it was intentional or not but look at this link which is the original page that was there. http://wiki.esoui.com/w/index.php?title=Events&oldid=6

The "data" field is what I use to know I have definitely reached the data I want. You probably could change that to your guild name instead or remove it.

Last edited by Xrystal : 03/12/14 at 03:23 PM.
  Reply With Quote
03/13/14, 08:45 AM   #11
Aldazar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 13
Ok, thanks to your help I think I've undersood the variables enough to make it work on Sunday.

I also have set up a first version of my addon that I can test and for which I am pretty optimistic that it'll work. If everything goes well I should be able to share a first version next week so people can use ist when setting up guilds at release.

I'll make sure to update you on how my tests on sunday went.
  Reply With Quote
03/13/14, 09:57 PM   #12
Vuelhering
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 169
Originally Posted by Xrystal View Post
edit: Hmm, looks like some of the events that were there before aren't there now. Not sure if it was intentional or not but look at this link which is the original page that was there. http://wiki.esoui.com/w/index.php?title=Events&oldid=6

The "data" field is what I use to know I have definitely reached the data I want. You probably could change that to your guild name instead or remove it.
Was that just an oversight when someone was doing editing?

Or did someone (Aiiane, to be exact) remove it on purpose during the reformatting?

Point is, if it was removed on purpose it might not be supported.
  Reply With Quote
03/14/14, 01:19 PM   #13
Xrystal
caritas omnia vincit
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 369
Thats what I was wondering Vuelhuering. It is either an oversight or they have removed the function. Until we test it and see the result or get confirmation from the addon testers we won't know
  Reply With Quote
03/17/14, 02:07 AM   #14
Aldazar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 13
Ok, so I came around to test what I had for 2-3 hrs yesterday.

GetNumGuilds() works just fine.
GetGuildId(Index luaindex) didn't work, but I don't know what the luaindex is.
GetGuildName(GuildId) Works fine. The GuildId is just a number between 1-5. And is corresponding to the guildnumber used in chat and shown in the guild menu.
GuildInvite(myGuildID,displayName) Worked fine too. GuildId is determined as above. Displayname is the Accountname (e.g. "@AccountName").

The depressing part is that I didn't get anything else working..... I failed to load the saved variables, creating a button and even writing to the chat (e.g. d("hello world"), using CHAT_SYSTEM, etc.).
Do I need to register any events for chatmessages?
Are there any good lua/addon tutorials that might help my understanding of it? (like playing around with another game or such)

I am probably switching to using locals instead of saved variables and opting for automativ start instead of a button. >.<"

Last edited by Aldazar : 03/17/14 at 02:27 AM.
  Reply With Quote
03/17/14, 02:19 AM   #15
Xrystal
caritas omnia vincit
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 369
Most addons will use maybe 2 events. Addonloaded and playeractive or words to those effects.

Addonloaded function I use for initialising windows and saved variables and what other events need to be watched.


Playeractive I use for accessing functionality that isn't available until the player is in works.


After that it depends on what events exist. If I remember rightly there is a guilddataavailable event or something similar but I can't remember if my login test did my guild info tests then or just in playeractive.


The luaindex is just a counter value, so a for loop counting from 1 to numguilds would have then given you guildid.

My own tests didn't seem to work at all so I suspect I did not use the guilddataavailable event.
  Reply With Quote
03/17/14, 02:29 AM   #16
Aldazar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 13
Well I probably have screwed the Playeractive event up then since this gave me an error and I removed it....

Ok, if the luaindex is just the loopcounter, I am pretty sure the getGuildId() function is a) not working and b) unnecessary since the guildId is pretty much just a numeric index (#1-5) too.
  Reply With Quote
03/17/14, 12:59 PM   #17
Xrystal
caritas omnia vincit
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 369
Hopefully those with PTS access can test this stuff out seeing us lesser mortals have to wait until it is released now rofl.
  Reply With Quote
03/21/14, 11:03 AM   #18
ninerapture
Join Date: Mar 2014
Posts: 1
I have PTS access. At least until they shut it down on 3/27
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » As a beginner without PTS access I need help with preparing my Addon


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