Details | Compare with Previous | View Log
Line No. | Rev | Author | Line |
---|---|---|---|
1 | 2 | HyperToxic-7971 | |
2 | HyperToxic-7971 | htRegroup = {} |
|
3 | HyperToxic-7971 | htRegroup.name = "HyperToxicsRegroup" |
|
4 | 5 | HyperToxic-7971 | htRegroup.version = 0.6 |
5 | 2 | HyperToxic-7971 | htRegroup.currentGroupSize = 1 |
6 | HyperToxic-7971 | htRegroup.savedGroupSize = 0 |
|
7 | HyperToxic-7971 | htRegroup.unitName = {} |
|
8 | HyperToxic-7971 | htRegroup.isHidden = false |
|
9 | HyperToxic-7971 | htRegroup.savedTime = -300 |
|
10 | HyperToxic-7971 | ||
11 | 5 | HyperToxic-7971 | |
12 | HyperToxic-7971 | ||
13 | HyperToxic-7971 | -- Initialize our addon |
|
14 | HyperToxic-7971 | function htRegroup.OnAddOnLoaded(eventCode, addOnName) |
|
15 | HyperToxic-7971 | if (addOnName == htRegroup.name) then |
|
16 | HyperToxic-7971 | htRegroup:Initialize() |
|
17 | HyperToxic-7971 | end |
|
18 | HyperToxic-7971 | end |
|
19 | HyperToxic-7971 | ||
20 | HyperToxic-7971 | function htRegroup:Initialize() |
|
21 | HyperToxic-7971 | --self.savedVariables = ZO_SavedVars:New("HyperToxicsRegroupSavedVariables", 1, nil, {}) |
|
22 | HyperToxic-7971 | self.savedVariables = ZO_SavedVars:NewAccountWide("HyperToxicsRegroupSavedVariables", 1, nil, {}) |
|
23 | HyperToxic-7971 | ||
24 | HyperToxic-7971 | EVENT_MANAGER:RegisterForEvent(self.name, EVENT_PLAYER_ACTIVATED, htRegroup.LateInitialize); |
|
25 | HyperToxic-7971 | EVENT_MANAGER:UnregisterForEvent(self.name, EVENT_ADD_ON_LOADED); |
|
26 | HyperToxic-7971 | ||
27 | HyperToxic-7971 | end |
|
28 | HyperToxic-7971 | ||
29 | HyperToxic-7971 | -- Fancy loaded message |
|
30 | HyperToxic-7971 | function htRegroup.LateInitialize(eventCode, addOnName) |
|
31 | HyperToxic-7971 | d("HyperToxic's Regroup loaded...") |
|
32 | HyperToxic-7971 | d("Type \"/rgp\" or \"/regroup\" to save, disband and regroup.") |
|
33 | HyperToxic-7971 | ||
34 | HyperToxic-7971 | EVENT_MANAGER:UnregisterForEvent(htRegroup.name, EVENT_PLAYER_ACTIVATED); |
|
35 | HyperToxic-7971 | end |
|
36 | HyperToxic-7971 | ||
37 | HyperToxic-7971 | ||
38 | HyperToxic-7971 | function htRegroup:saveGroup(currentTime) |
|
39 | 2 | HyperToxic-7971 | for i=1, htRegroup.currentGroupSize, 1 do |
40 | HyperToxic-7971 | htRegroup.unitName[i] = GetUnitName(GetGroupUnitTagByIndex(i)); |
|
41 | HyperToxic-7971 | d("Saved: " .. htRegroup.unitName[i]); |
|
42 | HyperToxic-7971 | end |
|
43 | HyperToxic-7971 | htRegroup.savedGroupSize = htRegroup.currentGroupSize; |
|
44 | HyperToxic-7971 | htRegroup.savedTime = currentTime; |
|
45 | HyperToxic-7971 | end |
|
46 | HyperToxic-7971 | ||
47 | HyperToxic-7971 | function htRegroup:smartSave() |
|
48 | HyperToxic-7971 | local i |
|
49 | HyperToxic-7971 | local currentTime = GetFrameTimeSeconds(); |
|
50 | HyperToxic-7971 | ||
51 | HyperToxic-7971 | if htRegroup.currentGroupSize > 1 then |
|
52 | HyperToxic-7971 | if (htRegroup.currentGroupSize >= htRegroup.savedGroupSize) then |
|
53 | 5 | HyperToxic-7971 | htRegroup:saveGroup(currentTime) |
54 | 2 | HyperToxic-7971 | else |
55 | HyperToxic-7971 | if (currentTime >= htRegroup.savedTime + 300) then |
|
56 | 5 | HyperToxic-7971 | htRegroup:saveGroup(currentTime) |
57 | 2 | HyperToxic-7971 | end |
58 | HyperToxic-7971 | end |
|
59 | HyperToxic-7971 | end |
|
60 | HyperToxic-7971 | end |
|
61 | HyperToxic-7971 | ||
62 | HyperToxic-7971 | function htRegroup:disband() |
|
63 | HyperToxic-7971 | local i |
|
64 | HyperToxic-7971 | if htRegroup.currentGroupSize > 1 then |
|
65 | 3 | HyperToxic-7971 | if htRegroup.currentGroupSize >= htRegroup.savedGroupSize then |
66 | HyperToxic-7971 | GroupDisband(); |
|
67 | HyperToxic-7971 | d("Disband."); |
|
68 | HyperToxic-7971 | end |
|
69 | 2 | HyperToxic-7971 | end |
70 | HyperToxic-7971 | end |
|
71 | HyperToxic-7971 | ||
72 | HyperToxic-7971 | function htRegroup:regroup() |
|
73 | HyperToxic-7971 | local i |
|
74 | HyperToxic-7971 | ||
75 | HyperToxic-7971 | if htRegroup.savedGroupSize > 1 then |
|
76 | HyperToxic-7971 | local playerName = GetUnitName("player") |
|
77 | HyperToxic-7971 | ||
78 | HyperToxic-7971 | for i=1, htRegroup.savedGroupSize, 1 do |
|
79 | HyperToxic-7971 | if htRegroup.unitName[i] ~= playerName then |
|
80 | HyperToxic-7971 | GroupInviteByName(htRegroup.unitName[i]); |
|
81 | HyperToxic-7971 | d("Sent invite: " .. htRegroup.unitName[i]); |
|
82 | HyperToxic-7971 | end |
|
83 | HyperToxic-7971 | end |
|
84 | HyperToxic-7971 | end |
|
85 | HyperToxic-7971 | end |
|
86 | HyperToxic-7971 | ||
87 | HyperToxic-7971 | function htRegroup:delayedRegroup() |
|
88 | HyperToxic-7971 | zo_callLater(function () htRegroup:regroup() end, 1000) |
|
89 | HyperToxic-7971 | end |
|
90 | HyperToxic-7971 | ||
91 | HyperToxic-7971 | function smartRegroup() |
|
92 | HyperToxic-7971 | htRegroup.currentGroupSize = GetGroupSize() |
|
93 | HyperToxic-7971 | ||
94 | HyperToxic-7971 | htRegroup:smartSave() |
|
95 | HyperToxic-7971 | htRegroup:disband() |
|
96 | HyperToxic-7971 | htRegroup:delayedRegroup() |
|
97 | HyperToxic-7971 | end |
|
98 | HyperToxic-7971 | ||
99 | HyperToxic-7971 | function regroupCommand(command) |
|
100 | HyperToxic-7971 | smartRegroup(); |
|
101 | HyperToxic-7971 | end |
|
102 | HyperToxic-7971 | ||
103 | HyperToxic-7971 | SLASH_COMMANDS["/rgp"] = regroupCommand |
|
104 | HyperToxic-7971 | SLASH_COMMANDS["/regroup"] = regroupCommand |
|
105 | HyperToxic-7971 | ||
106 | HyperToxic-7971 | ||
107 | 5 | HyperToxic-7971 | EVENT_MANAGER:RegisterForEvent(htRegroup.name, EVENT_ADD_ON_LOADED, htRegroup.OnAddOnLoaded); |