This will return the number of guilds you the player have access to
Lua Code:
local numGuilds = GetNumGuilds()
you would then loop through to get details:
Lua Code:
for i=1,numGuilds do
local guildID = GetGuildID(i)
end
Then to invite you would use:
Lua Code:
GuildInvite(guildID, displayNameOfPerson)
SavedVariables file format is as follows, based on its creation as
Lua Code:
local SVData = {}
local SVDefault = {}
SVData = ZO_SavedVars:NewAccountWide("XrysGatherer_SavedVariables", 1, "Data", SVDefault)
Lua Code:
XrysGatherer_SavedVariables =
{
["Default"] =
{
["@xXxAccountNamexXx"] =
{
["$AccountWide"] =
{
["Data"] =
{
["version"] = 1,
["Khenarthi's Roost"] =
{
["Dragonthorn"] =
{
[1] =
{
["Date"] = 20140302,
["Y"] = 0.736750,
["Time"] = [[17:38:06]],
["Action"] = [[Collect]],
["X"] = 0.598225,
},
},
..... etc
To read through the saved variables file of this type of format you would need to do something along these lines:
Lua Code:
tempTable = {}
for default,sv in pairs(XrysGatherer_SavedVariables) do
for account,accountv in pairs(sv) do
for accountWide,acWideV in pairs(accountv) do
for index,data in pairs(acWideV) do
if index == "Data" then
table.insert(tempTable ,data )
end
end
end
end
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:
ZO_Ingame_SavedVariables =
{
["Default"] =
{
["xXxAccountNamexXx"] =
{
["xXxCharacterNamexXx"] =
{
["Provisioner"] =
{
["version"] = 1,
["haveSkillsChecked"] = true,
["haveIngredientsChecked"] = true,
},
["Chat"] =
{
["version"] = 4,
["containers"] =
{
[1] =
{
["relPoint"] = 2,
["x"] = 0,
["point"] = 2,
["y"] = 253,
["height"] = 380,
["width"] = 550,
},
},
},
.... etc
Based on that information I would think the following code would be a good dry code start for testing with:
Lua Code:
-- Do we want the Saved Variables to be Account Wide
local SVAccountWide = false
-- Set to false for first run through, to create guild, saved variables table etc
-- Log out ( to log in screen ) and manually adjust the saved variables table
-- Set to true once the file has been adjusted with the data you want to import
local SVHasData = false
-- Variable to hold the guildID/guildName of the guild you want to invite into
local myGuildID
local myGuildName = {NameOfGuildToInviteInto}
-- Variable to hold the sessions Saved Variables file
local GuildSV = {}
-- Initialise the Saved Variables table and assign a table to hold this sessions data
local function InitialiseSV()
if SVAccountWide then
GuildSV = ZO_SavedVars:NewAccountWide("{AddonName}_SavedVariables",1,"Data")
else
GuildSV = ZO_SavedVars:New("{AddonName}_SavedVariables", 1,"Data")
end
end
-- Read through the Actual Saved Variables table and generate a temporary table to access the main block of data
local function ReadSV()
tempTable = {}
if SVAccountWide then
for default,sv in pairs({AddonName}_SavedVariables) do
for account,accountv in pairs(sv) do
for accountWide,acWideV in pairs(accountv) do
for index,data in pairs(acWideV) do
if index == "Data" then
table.insert(tempTable ,data )
end
end
end
end
end
else
for default,sv in pairs({AddonName}_SavedVariables) do
for account,accountv in pairs(sv) do
for charKey,charData in pairs(accountv) do
for index,data in pairs(charData) do
if index == "Data" then
table.insert(tempTable ,data )
end
end
end
end
end
end
-- Read through the tempTable and auto invite the names in the file
-- Data in the saved variables file (after the default/account/char blocks) is assumed to be as follows:
-- ["Data"] = {
-- [1] = {CharNameOfPersonToInvite},
-- [2] = {CharNameOfPersonToInvite},
-- }
for key,data in pairs(tempTable) do
-- GuildInvite(myGuildID,data) -- Take the first 2 -- off the start of the line once you know data is valid
CHAT_SYSTEM:AddMessage(string.format("%d [%s] added to guild",key,data))
end
end
-- Read through the guilds you are a member of and check against the name of the
local function GetMyGuildID()
local numGuilds = GetNumGuilds()
for i=1,numGuilds do
local guildID = GetGuildID(i)
local guildName = GetGuildName(guildID)
if guildName == MyGuildName then
myGuildID = guildID
break
end
end
end
-- Player is Active, SavedVariable data is available now and hopefully guild data
local function PlayerActivated(eventID)
-- Update the MyGuildID variable
GetMyGuild()
if not myGuildID then
CHAT_SYSTEM:AddMessage("You are not a member of a guild called %s.",{MyGuildName})
end
-- based on the flags set/values available read the appropriate saved variables data and autoinvite
if SVHasData and myGuildID then
ReadSV()
end
end
-- Addons being loaded
local function AddOnLoaded(eventID,addon)
if addon ~= {AddonName} then return end
EVENT_MANAGER:UnregisterForEvent({AddonName},eventID)
InitialiseSV()
EVENT_MANAGER:RegisterForEvent( {AddonName} ,EVENT_PLAYER_ACTIVATED , PlayerActivated )
end
-- Track addons loading
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.