Guest User

Untitled

a guest
Aug 14th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.90 KB | None | 0 0
  1. Global("wtMainPanel", nil)
  2. Global("wtPlayerList_Name", nil)
  3. Global("wtPlayerList_Level", nil)
  4. Global("wtPlayerList_Health", nil)
  5. Global("wtButtonSelector", nil)
  6. Global( "wtTotHealth", nil )
  7.  
  8. Global("wtPlayerList_Names", {})
  9. Global("wtPlayerList_Levels", {})
  10. Global("wtPlayerList_Healths", {})
  11. Global("wtButtonSelectors", {})
  12. Global( "wtTotHealths", {})
  13.  
  14. Global("wtMainPanelDNDId", 834)
  15.  
  16. Global("unitList", {})
  17. Global("unitCount", 0)
  18.  
  19. Global("bExecLock", false)
  20. Global("bUIToggleVisible", true)
  21.  
  22. Global('PLAYERLIST_MAX_ROWS', 15)
  23. Global('PLAYERLIST_ROW_HEIGHT', 20)
  24.  
  25. Global('PLAYERLIST_PRIORITY_FLAGGED', 100)
  26. Global('PLAYERLIST_PRIORITY_CLASSES', {
  27. ["DRUID"] = 100,
  28. ["MAGE"] = 100,
  29. ["NECROMANCER"] = 100,
  30. ["PALADIN"] = 100,
  31. ["PRIEST"] = 110,
  32. ["PSIONIC"] = 100,
  33. ["STALKER"] = 100,
  34. ["WARRIOR"] = 100,
  35. ["BARD"] = 105
  36. })
  37.  
  38. Global("ClassColors", {
  39. ["WARRIOR"] = { r = 131/255; g = 112/255; b = 72/255; a = 1 },
  40. ["PALADIN"] = { r = 255/255; g = 255/255; b = 255/255; a = 1 },
  41. ["STALKER"] = { r = 0/255; g = 255/255; b = 0/255; a = 1 },
  42. ["BARD"] = { r = 0/255; g = 0/255; b = 0/255; a = 1 },
  43. ["PRIEST"] = { r = 255/255; g = 255/255; b = 0/255; a = 1 },
  44. ["DRUID"] = { r = 255/255; g = 78/255; b = 0/255; a = 1 },
  45. ["PSIONIC"] = { r = 255/255; g = 0/255; b = 255/255; a = 1 },
  46. ["MAGE"] = { r = 0/255; g = 0/255; b = 255/255; a = 1 },
  47. ["NECROMANCER"] = { r = 255/255; g = 0/255; b = 0/255; a = 1 }
  48. })
  49.  
  50.  
  51.  
  52. function TrackEnvironment(event)
  53.  
  54. if bExecLock or not bUIToggleVisible then
  55. return
  56. end
  57.  
  58. bExecLock = true
  59.  
  60. local detectedUnits = avatar.GetUnitList()
  61. local i = 1
  62.  
  63. unitList = {}
  64.  
  65. for key, unitId in detectedUnits do
  66.  
  67. -- Check if unit is player and not dead
  68. if unit.IsPlayer(unitId) and not object.IsDead(unitId) then
  69.  
  70. local faction = unit.GetFaction(unitId)
  71.  
  72. -- Check if player belongs to opposite faction
  73. if not faction.isFriend or (not raid.IsPlayerInAvatarsRaid(object.GetName(unitId)) and unit.GetZonePvPType(avatar.GetId())==0) then
  74.  
  75. local fow = unit.GetPvPFlagInfo(unitId)
  76. local unitClass = unit.GetClass(unitId)
  77. local unitFlagged = 0
  78. local unitHPP = unit.GetHealthPercentage(unitId)
  79. local unitKiller = 0
  80. local unitRWNDS = unit.GetRelativeWoundsComplexity(unitId)
  81. local unitCURSE = unit.GetRuneWoundsComplexity(unitId)
  82. local unitDONAT = 0
  83.  
  84. if unitCURSE > 0 then
  85. unitDONAT = unitCURSE * 10
  86. end
  87.  
  88. if unitHPP < 100 then
  89. unitKiller = (100 - unitHPP) * 200
  90. end
  91.  
  92. if fow.isOn then
  93. unitFlagged = PLAYERLIST_PRIORITY_FLAGGED * 125
  94. end
  95.  
  96. unitList[i] = {}
  97. unitList[i].id = unitId
  98. unitList[i].priority = (PLAYERLIST_PRIORITY_CLASSES[unitClass.className]) + unitFlagged + unitKiller + unitRWNDS + unitDONAT
  99. unitList[i].flagged = fow.isOn
  100.  
  101. i = i + 1
  102.  
  103. end
  104.  
  105. end
  106. end
  107.  
  108. unitCount = i - 1
  109.  
  110. detectedUnits = nil
  111.  
  112. ClearPlayerList()
  113.  
  114. if unitCount > 0 then
  115. CreatePlayerList()
  116. wtMainPanel:Show(true)
  117. else
  118. wtMainPanel:Show(false)
  119. end
  120.  
  121. bExecLock = false
  122.  
  123. end
  124.  
  125. function CreatePlayerList()
  126.  
  127. table.sort(unitList, function(a, b) return a.priority > b.priority end)
  128.  
  129. for i = 1, unitCount do
  130.  
  131. local unitId = unitList[i].id
  132.  
  133. wtPlayerList_Names[i] = mainForm:CreateWidgetByDesc(wtPlayerList_Name:GetWidgetDesc())
  134. wtPlayerList_Names[i]:SetName("PlayerList_Name"..i)
  135. wtPlayerList_Names[i]:SetVal("Name", object.GetName(unitId))
  136.  
  137. if unitList[i].flagged then
  138. wtPlayerList_Names[i]:SetClassVal("class", "tip_red")
  139. else
  140. wtPlayerList_Names[i]:SetClassVal("class", "tip_white")
  141. end
  142.  
  143.  
  144. local place = wtPlayerList_Names[i]:GetPlacementPlain()
  145. place.posY = PLAYERLIST_ROW_HEIGHT * i;
  146. wtPlayerList_Names[i]:SetPlacementPlain(place)
  147.  
  148. wtPlayerList_Levels[i] = mainForm:CreateWidgetByDesc(wtPlayerList_Level:GetWidgetDesc())
  149. wtPlayerList_Levels[i]:SetName("PlayerList_Level"..i)
  150. wtPlayerList_Levels[i]:SetVal("Level", common.FormatInt(unit.GetLevel(unitId), "%d"))
  151. wtPlayerList_Levels[i]:SetClassVal("class", "tip_white")
  152.  
  153. local place = wtPlayerList_Levels[i]:GetPlacementPlain()
  154. place.posY = PLAYERLIST_ROW_HEIGHT * i;
  155. wtPlayerList_Levels[i]:SetPlacementPlain(place)
  156.  
  157. wtPlayerList_Healths[i] = mainForm:CreateWidgetByDesc(wtPlayerList_Health:GetWidgetDesc())
  158. wtPlayerList_Healths[i]:SetName("PlayerList_Health"..i)
  159.  
  160. --local unitHP = unit.GetHealthPercentage(unitId)
  161. --local unitHP = unit.GetRuneWoundsComplexity(unitId)
  162. local unitWND = unit.GetRelativeWoundsComplexity(unitId)
  163.  
  164.  
  165. --wtPlayerList_Healths[i]:SetVal("Health", common.FormatInt(unitHP, "%d"))
  166. --Would be good to add total value of enemy runes, currently I don't think it is possible.
  167. wtPlayerList_Healths[i]:SetVal("Health", common.FormatInt(unitWND, "%d" ))
  168. wtPlayerList_Healths[i]:SetClassVal("class", "tip_white")
  169.  
  170. --Maybe will add it later, now to much coloring.
  171. --if unitHP > 40 then
  172. --wtPlayerList_Healths[i]:SetClassVal("class", "tip_red")
  173. --elseif unitHP <= 40 and unitHP > 20 then
  174. --wtPlayerList_Healths[i]:SetClassVal("class", "tip_yellow")
  175. --elseif unitHP <= 20 then
  176. --wtPlayerList_Healths[i]:SetClassVal("class", "tip_green")
  177. --end
  178.  
  179. local place = wtPlayerList_Healths[i]:GetPlacementPlain()
  180. place.posY = PLAYERLIST_ROW_HEIGHT * i;
  181. wtPlayerList_Healths[i]:SetPlacementPlain(place)
  182.  
  183. wtButtonSelectors[i] = mainForm:CreateWidgetByDesc(wtButtonSelector:GetWidgetDesc())
  184. wtButtonSelectors[i]:SetName("ButtonSelector_"..i)
  185.  
  186. local place = wtButtonSelectors[i]:GetPlacementPlain()
  187. place.posY = PLAYERLIST_ROW_HEIGHT * i;
  188. wtButtonSelectors[i]:SetPlacementPlain(place)
  189.  
  190. local place
  191. local Percentage
  192. local PlayerClass
  193.  
  194.  
  195. wtTotHealths[i] = mainForm:CreateWidgetByDesc(wtTotHealth:GetWidgetDesc())
  196. Percentage = unit.GetHealthPercentage(unitId)
  197. PlayerClass = unit.GetClass(unitId)
  198.  
  199. if Percentage ~= nil then
  200. place = wtTotHealths[i]:GetPlacementPlain()
  201. place.posY = PLAYERLIST_ROW_HEIGHT * i;
  202. place.sizeX = math.ceil( 175 * Percentage / 100 ) -- Health bar width, px = 86
  203. wtTotHealths[i]:SetBackgroundColor( ClassColors[PlayerClass.className] )
  204. wtTotHealths[i]:SetPlacementPlain(place)
  205. end
  206.  
  207.  
  208. wtMainPanel:AddChild(wtPlayerList_Names[i])
  209. wtMainPanel:AddChild(wtPlayerList_Levels[i])
  210. wtMainPanel:AddChild(wtPlayerList_Healths[i])
  211. wtMainPanel:AddChild(wtButtonSelectors[i])
  212. wtMainPanel:AddChild(wtTotHealths[i])
  213.  
  214. if i >= PLAYERLIST_MAX_ROWS then
  215. break
  216. end
  217.  
  218. end
  219.  
  220.  
  221.  
  222. end
  223.  
  224. function ClearPlayerList()
  225.  
  226. if wtPlayerList_Names then
  227. for i, w in wtPlayerList_Names do
  228. wtPlayerList_Names[i]:DestroyWidget()
  229. wtPlayerList_Levels[i]:DestroyWidget()
  230. wtPlayerList_Healths[i]:DestroyWidget()
  231. wtTotHealths[i]:DestroyWidget()
  232. wtButtonSelectors[i]:DestroyWidget()
  233. end
  234. end
  235.  
  236. end
  237.  
  238. function ReactionSelectTarget(params)
  239.  
  240. local senderIndex = tonumber(string.sub(params.sender, string.len("ButtonSelector_") + 1))
  241.  
  242. if senderIndex then
  243. avatar.SelectTarget(unitList[senderIndex].id)
  244. end
  245.  
  246. end
  247.  
  248. function MemRequestHandler(params)
  249. userMods.SendEvent("U_EVENT_ADDON_MEM_USAGE_RESPONSE", {sender = common.GetAddonName(), memUsage = gcinfo()})
  250. end
  251.  
  252. function ToggleDNDHandler(params)
  253. if params.target == common.GetAddonName() then
  254. DnD:Enable(wtMainPanel, params.state)
  255. end
  256. end
  257.  
  258. function ToggleUIHandler(params)
  259. bUIToggleVisible = params.visible
  260. mainForm:Show( params.visible )
  261. end
  262.  
  263.  
  264. function Init()
  265. common.RegisterReactionHandler(ReactionSelectTarget, "SelectTarget")
  266. common.RegisterEventHandler(TrackEnvironment, "EVENT_SECOND_TIMER")
  267. common.RegisterEventHandler(MemRequestHandler, "U_EVENT_ADDON_MEM_USAGE_REQUEST")
  268. common.RegisterEventHandler(ToggleDNDHandler, "U_EVENT_TOGGLE_DND")
  269. common.RegisterEventHandler(ToggleUIHandler, "SCRIPT_TOGGLE_UI")
  270.  
  271. wtMainPanel = mainForm:GetChildChecked("MainPanel", false)
  272. wtPlayerList_Name = wtMainPanel:GetChildChecked("PlayerList_Name", false)
  273. wtPlayerList_Level = wtMainPanel:GetChildChecked("PlayerList_Level", false)
  274. wtPlayerList_Health = wtMainPanel:GetChildChecked("PlayerList_Health", false)
  275. wtButtonSelector = wtMainPanel:GetChildChecked("ButtonSelector", false)
  276. wtTotHealth = wtMainPanel:GetChildChecked( "TotHealth", false )
  277.  
  278. DnD:Init(wtMainPanelDNDId, wtMainPanel, wtMainPanel, true, true, {-8,-8,-8,-8})
  279.  
  280. wtPlayerList_Name:Show(false)
  281. wtPlayerList_Level:Show(false)
  282. wtPlayerList_Health:Show(false)
  283. wtButtonSelector:Show(false)
  284. wtTotHealth:Show(false)
  285.  
  286. wtMainPanel:Show(false)
  287.  
  288. local place = wtMainPanel:GetPlacementPlain()
  289. place.sizeY = PLAYERLIST_ROW_HEIGHT * PLAYERLIST_MAX_ROWS + 36;
  290. wtMainPanel:SetPlacementPlain(place)
  291.  
  292.  
  293.  
  294. end
  295.  
  296. Init()
Add Comment
Please, Sign In to add comment