Compare with Previous | Blame | View Log
htRegroup = {} htRegroup.name = "HyperToxicsRegroup" htRegroup.version = 0.6 htRegroup.currentGroupSize = 1 htRegroup.savedGroupSize = 0 htRegroup.unitName = {} htRegroup.isHidden = false htRegroup.savedTime = -300 -- Initialize our addon function htRegroup.OnAddOnLoaded(eventCode, addOnName) if (addOnName == htRegroup.name) then htRegroup:Initialize() end end function htRegroup:Initialize() --self.savedVariables = ZO_SavedVars:New("HyperToxicsRegroupSavedVariables", 1, nil, {}) self.savedVariables = ZO_SavedVars:NewAccountWide("HyperToxicsRegroupSavedVariables", 1, nil, {}) EVENT_MANAGER:RegisterForEvent(self.name, EVENT_PLAYER_ACTIVATED, htRegroup.LateInitialize); EVENT_MANAGER:UnregisterForEvent(self.name, EVENT_ADD_ON_LOADED); end -- Fancy loaded message function htRegroup.LateInitialize(eventCode, addOnName) d("HyperToxic's Regroup loaded...") d("Type \"/rgp\" or \"/regroup\" to save, disband and regroup.") EVENT_MANAGER:UnregisterForEvent(htRegroup.name, EVENT_PLAYER_ACTIVATED); end function htRegroup:saveGroup(currentTime) for i=1, htRegroup.currentGroupSize, 1 do htRegroup.unitName[i] = GetUnitName(GetGroupUnitTagByIndex(i)); d("Saved: " .. htRegroup.unitName[i]); end htRegroup.savedGroupSize = htRegroup.currentGroupSize; htRegroup.savedTime = currentTime; end function htRegroup:smartSave() local i local currentTime = GetFrameTimeSeconds(); if htRegroup.currentGroupSize > 1 then if (htRegroup.currentGroupSize >= htRegroup.savedGroupSize) then htRegroup:saveGroup(currentTime) else if (currentTime >= htRegroup.savedTime + 300) then htRegroup:saveGroup(currentTime) end end end end function htRegroup:disband() local i if htRegroup.currentGroupSize > 1 then if htRegroup.currentGroupSize >= htRegroup.savedGroupSize then GroupDisband(); d("Disband."); end end end function htRegroup:regroup() local i if htRegroup.savedGroupSize > 1 then local playerName = GetUnitName("player") for i=1, htRegroup.savedGroupSize, 1 do if htRegroup.unitName[i] ~= playerName then GroupInviteByName(htRegroup.unitName[i]); d("Sent invite: " .. htRegroup.unitName[i]); end end end end function htRegroup:delayedRegroup() zo_callLater(function () htRegroup:regroup() end, 1000) end function smartRegroup() htRegroup.currentGroupSize = GetGroupSize() htRegroup:smartSave() htRegroup:disband() htRegroup:delayedRegroup() end function regroupCommand(command) smartRegroup(); end SLASH_COMMANDS["/rgp"] = regroupCommand SLASH_COMMANDS["/regroup"] = regroupCommand EVENT_MANAGER:RegisterForEvent(htRegroup.name, EVENT_ADD_ON_LOADED, htRegroup.OnAddOnLoaded);