-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGuildOnTarget.lua
134 lines (105 loc) · 5.06 KB
/
GuildOnTarget.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
--------------------------------------------------------------------------------------------------------------------
--
-- ESO GuildOnTarget
--
-- This Add-on is not created by, affiliated with or sponsored by ZeniMax Media Inc. or its affiliates.
-- The Elder Scrolls® and related logos are registered trademarks or trademarks of ZeniMax Media Inc. in the United States and/or other countries.
-- All rights reserved
--
--------------------------------------------------------------------------------------------------------------------
local AddonInfo = {
addon = "GuildOnTarget",
version = "1.0",
author = "Sophie Kuehn",
savename = "GuildOnTarget"
}
local GOT = {}
GOT.guild = {}
-- localize calls to ESO API
local GetUnitType = GetUnitType
local GetUnitName = GetUnitName
local GetGuildMemberInfo = GetGuildMemberInfo
local GetGuildMemberCharacterInfo = GetGuildMemberCharacterInfo
local GetGuildId = GetGuildId
local GetGuildName = GetGuildName
local GetNumGuildMembers = GetNumGuildMembers
local IsUnitIgnored = IsUnitIgnored
-- GUILD METHODS ---------------------------------------------------------------------------------------------------
local function getGuildMembership()
local guildNum = 0
GOT.guild = {}
GOT.guild.member = {}
for guildNum = 1,5,1 do
local id = GetGuildId(guildNum)
if id then
local members = GetNumGuildMembers(id)
local guildname = GetGuildName(id)
local member = 0
for member = 1,members,1 do
local player, note, rank, status, activelast = GetGuildMemberInfo(id,member)
local hasCharacter, characterName, zoneName, classid, alliance, level, championRank = GetGuildMemberCharacterInfo(id,member)
if hasCharacter and members > 1 then
local caret = string.len(characterName) - 3
local character = ""
if caret > 0 then
character = string.sub(characterName,1,caret)
end
GOT.guild.member[player]={}
GOT.guild.member[player].character = character
GOT.guild.member[player].firstguild = GOT.guild.member[player].firstguild or { size = 0, name = "" }
if GOT.guild.member[player].firstguild.size < members then
GOT.guild.member[player].firstguild.name = guildname
GOT.guild.member[player].firstguild.size = members
end
end
end
end
end
end
local function IsUnitGuild(player)
local guild = nil
local inguild = player and GOT and GOT.guild and GOT.guild.member and GOT.guild.member[player]
if inguild then
guild = GOT.guild.member[player].firstguild.name
end
return inguild, guild
end
local function guildMemberAdded(eventCode, guildId, displayName)
getGuildMembership()
end
local function guildMemberRemoved(eventCode, guildId, displayName, characterName)
getGuildMembership()
end
local function guildSelfLeft(eventCode, guildId, guildName)
getGuildMembership()
end
local function guildSelfJoined(eventCode, guildId, guildName)
getGuildMembership()
end
-- TARGET CHANGE EVENT ---------------------------------------------------------------------------------------------
-- this fires when the target changes, then sets everything up for the next UI update
function OnTargetChange(eventCode)
local unitTag = "reticleover"
local type = GetUnitType(unitTag)
local name = GetUnitName(unitTag)
local player = GetUnitDisplayName(unitTag)
if name == nil or name == "" or type ~= UNIT_TYPE_PLAYER or IsUnitIgnored(unitTag) then return end
local inguild, guild = IsUnitGuild(player)
if not inguild then return end
local guildName = "<"..guild..">"
ZO_TargetUnitFramereticleoverCaption:SetText(ZO_TargetUnitFramereticleoverCaption:GetText() .. " " .. guildName)
end
-- REGISTER AND INIT -----------------------------------------------------------------------------------------------
local function LoadAddon(eventCode, addOnName)
if(addOnName ~= AddonInfo.addon) then return end
getGuildMembership()
if (LibNorthCastle) then LibNorthCastle:Register(AddonInfo.addon,AddonInfo.version) end
EVENT_MANAGER:RegisterForEvent(AddonInfo.addon, EVENT_GUILD_MEMBER_CHARACTER_UPDATED, guildMemberAdded)
EVENT_MANAGER:RegisterForEvent(AddonInfo.addon, EVENT_GUILD_MEMBER_ADDED, guildMemberAdded)
EVENT_MANAGER:RegisterForEvent(AddonInfo.addon, EVENT_GUILD_MEMBER_REMOVED, guildMemberRemoved)
EVENT_MANAGER:RegisterForEvent(AddonInfo.addon, EVENT_GUILD_SELF_JOINED_GUILD, guildSelfJoined)
EVENT_MANAGER:RegisterForEvent(AddonInfo.addon, EVENT_GUILD_SELF_LEFT_GUILD, guildSelfLeft)
EVENT_MANAGER:RegisterForEvent(AddonInfo.addon, EVENT_RETICLE_TARGET_CHANGED, OnTargetChange)
EVENT_MANAGER:UnregisterForEvent(AddonInfo.addon, EVENT_ADD_ON_LOADED)
end
EVENT_MANAGER:RegisterForEvent(AddonInfo.addon, EVENT_ADD_ON_LOADED, LoadAddon)