vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | |
2 | local mod = klhtm |
||
3 | local me = { } |
||
4 | mod.unit = me |
||
5 | |||
6 | --[[ |
||
7 | Unit.lua |
||
8 | |||
9 | Contains helper functions for finding players and units and their properties. Most involve iterating through the raid group. |
||
10 | ]] |
||
11 | |||
12 | --[[ |
||
13 | mod.unit.findunitidfromname(name) |
||
14 | Returns the unitid of the player in your group whose name is <name>. |
||
15 | Only works on players or pets in your raid or party, or yourself. |
||
16 | Returns nil if there is no match to <name>. |
||
17 | ]] |
||
18 | me.findunitidfromname = function(name) |
||
19 | |||
20 | if name == UnitName("player") then |
||
21 | return "player" |
||
22 | end |
||
23 | |||
24 | local x |
||
25 | |||
26 | if GetNumRaidMembers() > 0 then |
||
27 | for x = 1, 40 do |
||
28 | if UnitName("raid" .. x) == name then |
||
29 | return "raid" .. x |
||
30 | end |
||
31 | end |
||
32 | |||
33 | for x = 1, 40 do |
||
34 | if UnitName("raidpet" .. x) == name then |
||
35 | return "raidpet" .. x |
||
36 | end |
||
37 | end |
||
38 | |||
39 | elseif GetNumPartyMembers() > 0 then |
||
40 | for x = 1, 4 do |
||
41 | if UnitName("party" .. x) == name then |
||
42 | return "party" .. x |
||
43 | end |
||
44 | end |
||
45 | |||
46 | for x = 1, 4 do |
||
47 | if UnitName("partypet" .. x) == name then |
||
48 | return "partypet" .. x |
||
49 | end |
||
50 | end |
||
51 | end |
||
52 | |||
53 | end |
||
54 | |||
55 | --[[ |
||
56 | mod.unit.findnearbybossname() |
||
57 | Searches the target of everyone in the raid group, looking for a worldboss. |
||
58 | Returns: the name of the worldboss, or nil. |
||
59 | ]] |
||
60 | me.findnearbybossname = function() |
||
61 | |||
62 | local x |
||
63 | |||
64 | for x = 1, 40 do |
||
65 | if UnitClassification("raid" .. x) == "worldboss" then |
||
66 | return UnitName("raid" .. x) |
||
67 | end |
||
68 | end |
||
69 | |||
70 | end |
||
71 | |||
72 | --[[ |
||
73 | mod.unit.isplayeringroup(name) |
||
74 | Returns: true if the player is in your group, nil otherwise |
||
75 | ]] |
||
76 | me.isplayeringroup = function(name) |
||
77 | |||
78 | -- raid group |
||
79 | if GetNumRaidMembers() > 0 then |
||
80 | for x = 1, 40 do |
||
81 | if UnitName("raid" .. x) == name then |
||
82 | return true |
||
83 | end |
||
84 | end |
||
85 | |||
86 | -- party (check for self separately) |
||
87 | elseif GetNumPartyMembers() > 0 then |
||
88 | for x = 1, 4 do |
||
89 | if UnitName("party" .. x) == name then |
||
90 | return true |
||
91 | end |
||
92 | end |
||
93 | |||
94 | if name == UnitName("player") then |
||
95 | return true |
||
96 | end |
||
97 | end |
||
98 | |||
99 | if name == UnitName("player") then |
||
100 | return true |
||
101 | end |
||
102 | |||
103 | end |
||
104 | |||
105 | --[[ |
||
106 | mod.unit.isplayerofficer(playername) |
||
107 | Returns: true if <playername> is an officer / leader, nil otherwise. |
||
108 | This is for the purpose of sending "special" commands, like setting the master target. |
||
109 | ]] |
||
110 | me.isplayerofficer = function(playername) |
||
111 | |||
112 | local name |
||
113 | local rank |
||
114 | |||
115 | if GetNumRaidMembers() > 0 then |
||
116 | for i = 1, 40 do |
||
117 | |||
118 | name, rank = GetRaidRosterInfo(i) |
||
119 | if name == playername then |
||
120 | if rank > 0 then |
||
121 | return true |
||
122 | else |
||
123 | return nil |
||
124 | end |
||
125 | end |
||
126 | end |
||
127 | |||
128 | elseif GetNumPartyMembers() > 0 then |
||
129 | if UnitIsPartyLeader("player") == 1 and playername == UnitName("player") then |
||
130 | return true |
||
131 | else |
||
132 | for i = 1, 4 do |
||
133 | if UnitName("party" .. i) == playername then |
||
134 | if UnitIsPartyLeader("party" .. i) == 1 then |
||
135 | return true |
||
136 | else |
||
137 | return nil |
||
138 | end |
||
139 | end |
||
140 | end |
||
141 | end |
||
142 | |||
143 | else |
||
144 | return true -- single player = officer |
||
145 | |||
146 | end |
||
147 | |||
148 | end |