View Single Post
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