Advertisement
Xzempt

Untitled

Jan 4th, 2012
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.63 KB | None | 0 0
  1. --[[
  2. This file is part of TicketChaos. All TicketChaos code is Copyright (C) 2009 Chocochaos
  3.  
  4. TicketChaos is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8.  
  9. TicketChaos is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13.  
  14. You should have received a copy of the GNU General Public License
  15. along with TicketChaos. If not, see <http://www.gnu.org/licenses/>.
  16. --]]
  17.  
  18.  
  19. function ShowGMMessage(msg)
  20. DEFAULT_CHAT_FRAME:AddMessage("|cFFFF0000[TicketChaos]|cffffffff: "..msg);
  21. end
  22.  
  23. function pairsByKeys (t, f)
  24.  
  25. local a = {}
  26. local b = {}
  27. for n in pairs (t) do
  28. table.insert (a, n);
  29. end
  30. table.sort (a, f);
  31. for name,value in pairs(a) do
  32. table.insert (b, t[value]);
  33. end
  34. return b;
  35. end
  36.  
  37. function pairsByKeys2 (t, f)
  38. local a = {}
  39. local b = {}
  40. for n in pairs (t) do
  41. table.insert (a, n);
  42. end
  43. table.sort (a, f);
  44. for name,value in pairs(a) do
  45. table.insert (b, value);
  46. end
  47. return b;
  48. end
  49.  
  50. TicketChannel = "gm_sync_channel";
  51. TicketTab = "General";
  52.  
  53. local TicketCount = 0;
  54. local TicketPP = 15;
  55. local PageCount = 1;
  56. local CurrentPage = 1;
  57. local TicketList = {};
  58. local TicketsInList = {};
  59. local ReadTickets = {};
  60. CurName = nil;
  61. CurTicketNum = 0;
  62. local SortedBy = "num";
  63. local PrevSortedBy = "num";
  64. local SortedDir = "asc";
  65. local IsReading = {};
  66. local TicketsDone= 0;
  67. CurWhisperMessage = '';
  68.  
  69.  
  70. local MapIds = {};
  71. MapIds[1000]="Eastern Kingdoms";
  72. MapIds[1]="Kalimdor";
  73. MapIds[13]="Testing";
  74. MapIds[25]="Scott Test";
  75. MapIds[29]="CashTest";
  76. MapIds[30]="Alterac Valley";
  77. MapIds[33]="Shadowfang Keep";
  78. MapIds[34]="The Stockades";
  79. MapIds[35]="StormwindPrison";
  80. MapIds[36]="Deadmines";
  81. MapIds[37]="Azshara Crater";
  82. MapIds[42]="Collin's Test";
  83. MapIds[43]="Wailing Caverns";
  84. MapIds[44]=" Monastery";
  85. MapIds[47]="Razorfen Kraul";
  86. MapIds[48]="Blackfathom Deeps";
  87. MapIds[70]="Uldaman";
  88. MapIds[90]="Gnomeregan";
  89. MapIds[109]="Sunken Temple";
  90. MapIds[129]="Razorfen Downs";
  91. MapIds[169]="Emerald Dream";
  92. MapIds[189]="Scarlet Monastery";
  93. MapIds[209]="Zul'Farrak";
  94. MapIds[229]="Blackrock Spire";
  95. MapIds[230]="Blackrock Depths";
  96. MapIds[249]="Onyxia's Lair";
  97. MapIds[269]="The Black Morass";
  98. MapIds[289]="Scholomance";
  99. MapIds[309]="Zul'Gurub";
  100. MapIds[329]="Stratholme";
  101. MapIds[349]="Maraudon";
  102. MapIds[369]="Deeprun Tram";
  103. MapIds[389]="Ragefire Chasm";
  104. MapIds[409]="Molten Core";
  105. MapIds[429]="Dire Maul";
  106. MapIds[449]="Alliance Military Barracks";
  107. MapIds[450]="Horde Military Barracks";
  108. MapIds[451]="Development Land";
  109. MapIds[469]="Blackwing Lair";
  110. MapIds[489]="Warsong Gulch";
  111. MapIds[509]="Ruins of Ahn'Qiraj";
  112. MapIds[529]="Arathi Basin ";
  113. MapIds[530]="Outlands";
  114. MapIds[531]="Ahn'Qiraj Temple";
  115. MapIds[532]="Karazhan";
  116. MapIds[533]="Naxxramas";
  117. MapIds[534]="The Battle for Mount Hyjal";
  118. MapIds[540]="Hellfire Citadel: The Shattered Halls";
  119. MapIds[542]="Hellfire Citadel: The Blood Furnace";
  120. MapIds[543]="Hellfire Citadel: Ramparts";
  121. MapIds[544]="Magtheridon's Lair";
  122. MapIds[545]="Coilfang: The Steamvault";
  123. MapIds[546]="Coilfang: The Underbog";
  124. MapIds[547]="Coilfang: The Slave Pens";
  125. MapIds[548]="Coilfang: Serpentshrine Cavern";
  126. MapIds[550]="Tempest Keep";
  127. MapIds[552]="Tempest Keep: The Arcatraz";
  128. MapIds[553]="Tempest Keep: The Botanica";
  129. MapIds[554]="Tempest Keep: The Mechanar";
  130. MapIds[555]="Auchindoun: Shadow Labyrinth";
  131. MapIds[556]="Auchindoun: Sethekk Halls";
  132. MapIds[557]="Auchindoun: Mana-Tombs";
  133. MapIds[558]="Auchindoun: Auchenai Crypts";
  134. MapIds[559]="Nagrand Arena";
  135. MapIds[560]="Old Hillsbrad Foothills";
  136. MapIds[562]="Blade's Edge Arena";
  137. MapIds[564]="Black Temple";
  138. MapIds[565]="Gruul's Lair";
  139. MapIds[566]="Eye of the Storm";
  140. MapIds[568]="Zul'Aman";
  141. MapIds[571]="Northrend";
  142. MapIds[572]="Ruins of Lordaeron";
  143. MapIds[573]="ExteriorTest";
  144. MapIds[574]="Utgarde Keep";
  145. MapIds[575]="Utgarde Pinnacle";
  146. MapIds[576]="The Nexus";
  147. MapIds[578]="The Oculus";
  148. MapIds[582]="Transport: Ruttheran to Auberdine";
  149. MapIds[584]="Transport: Menethil to Theramore";
  150. MapIds[586]="Transport: Exodar to Auberdine";
  151. MapIds[587]="Transport: Feathermoon Ferry";
  152. MapIds[588]="Transport: Menethil to Auberdine";
  153. MapIds[589]="Transport: Orgrimmar to GromGol";
  154. MapIds[590]="Transport: GromGol to Undercity";
  155. MapIds[591]="Transport: Undercity to Orgrimmar";
  156. MapIds[593]="Transport: Booty Bay to Ratchet";
  157. MapIds[580]="The Sunwell";
  158. MapIds[585]="Magisters' Terrace";
  159. MapIds[598]="Sunwell Fix (Unused)";
  160. MapIds[592]="Transport: Borean Tundra Test";
  161. MapIds[594]="Transport: Howling Fjord Sister Mercy (Quest)";
  162. MapIds[595]="The Culling of Stratholme";
  163. MapIds[596]="Transport: Naglfar";
  164. MapIds[597]="Craig Test";
  165. MapIds[599]="Halls of Stone";
  166. MapIds[600]="Drak'Tharon Keep";
  167. MapIds[601]="Azjol-Nerub";
  168. MapIds[602]="Halls of Lightning";
  169. MapIds[603]="Ulduar";
  170. MapIds[604]="Gundrak";
  171. MapIds[605]="Development Land (non-weighted textures)";
  172. MapIds[606]="QA and DVD";
  173. MapIds[607]="Strand of the Ancients";
  174. MapIds[608]="Violet Hold";
  175. MapIds[609]="Ebon Hold";
  176. MapIds[610]="Transport: Tirisfal to Vengeance Landing";
  177. MapIds[612]="Transport: Menethil to Valgarde";
  178. MapIds[613]="Transport: Orgrimmar to Warsong Hold";
  179. MapIds[614]="Transport: Stormwind to Valiance Keep";
  180. MapIds[615]="The Obsidian Sanctum";
  181. MapIds[616]="The Eye of Eternity";
  182. MapIds[617]="Dalaran Sewers";
  183. MapIds[618]="The Ring of Valor";
  184. MapIds[619]="Ahn'kahet: The Old Kingdom";
  185. MapIds[620]="Transport: Moa'ki to Unu'pe";
  186. MapIds[621]="Transport: Moa'ki to Kamagua";
  187. MapIds[622]="Transport: Orgrim's Hammer";
  188. MapIds[623]="Transport: The Skybreaker";
  189. MapIds[624]="Wintergrasp Raid";
  190.  
  191.  
  192. function TicketWhisper()
  193. ChatFrame_SendTell(CurName);
  194. end
  195.  
  196. function AddTicket(name, map)
  197. map = tonumber(map);
  198.  
  199. --[[ if (map < 1) then
  200. map = 1000;
  201. end]]--
  202.  
  203. if(MapIds[map]) then
  204. location = MapIds[map];
  205. else
  206. location = '';
  207. end
  208.  
  209. if (TicketsInList[name] == nil) then
  210. TicketCount = TicketCount + 1;
  211. TicketsInList[name] = 1;
  212. local insertData = {["num"] = TicketCount, ["number"] = TicketCount, ["name"] = name, ["location"] = location};
  213.  
  214. if(insertData["num"] < 10) then
  215. insertData["num"] = "000" .. insertData["num"];
  216. elseif(insertData["num"] < 100) then
  217. insertData["num"] = "00" .. insertData["num"];
  218. elseif(insertData["num"] < 1000) then
  219. insertData["num"] = "0" .. insertData["num"];
  220. end
  221.  
  222. local ticketKey = insertData[SortedBy] .. insertData[PrevSortedBy];
  223. TicketList[ticketKey] = insertData;
  224. end
  225. end
  226.  
  227. function SortTicketList(key)
  228. if(key ~= SortedBy) then
  229. PrevSortedBy = SortedBy;
  230. SortedDir = "asc";
  231. SortedBy = key;
  232. else
  233. if(SortedDir == "asc") then
  234. SortedDir = "desc";
  235. else
  236. SortedDir = "asc";
  237. end
  238. end
  239. Refresh_Tickets();
  240. end
  241.  
  242. function Update_Tickets()
  243. PageCount = math.ceil(TicketCount/TicketPP);
  244. if (PageCount == 0) then
  245. PageCount = 1;
  246. end
  247. local TempPage = CurrentPage;
  248. if (CurrentPage > PageCount) then
  249. CurrentPage = PageCount;
  250. elseif (CurrentPage < 1) then
  251. CurrentPage = 1;
  252. end
  253.  
  254. Ticket_Tracker_Info_Text:SetText("Page ".. CurrentPage .." of ".. PageCount.." (".. TicketCount .." tickets)");
  255.  
  256. if (CurrentPage == 1) then
  257. Ticket_Tracker_Previous:Disable();
  258. else
  259. Ticket_Tracker_Previous:Enable();
  260. end
  261.  
  262. if (CurrentPage == PageCount) then
  263. Ticket_Tracker_Next:Disable();
  264. else
  265. Ticket_Tracker_Next:Enable();
  266. end
  267.  
  268. local MinTicket = 1 + ((CurrentPage - 1) * TicketPP);
  269. local MaxTicket = CurrentPage * TicketPP;
  270.  
  271. local NumTicket = 0;
  272.  
  273. if(SortedDir == "desc") then
  274. TicketList = pairsByKeys(TicketList, function(a,b) return a>b end);
  275.  
  276. else
  277. TicketList = pairsByKeys(TicketList);
  278.  
  279. end
  280.  
  281. for name,value in pairs(TicketList) do
  282. NumTicket = NumTicket + 1;
  283. if (NumTicket >= MinTicket and NumTicket <= MaxTicket) then
  284. local CurrentTicket = NumTicket - ((CurrentPage - 1) * TicketPP);
  285. if(value["name"] == CurName) then
  286. getglobal("TicketStatusButton".. CurrentTicket .."_Texture"):SetTexture("Interface\\FriendsFrame\\UI-FriendsFrame-HighlightBar");
  287. CurTicketNum = CurrentTicket;
  288. else
  289. getglobal("TicketStatusButton".. CurrentTicket .."_Texture"):SetTexture(0, 0, 0);
  290. print("else in update_ticket function", value["name"], CurrentTicket)
  291. end
  292. getglobal("TicketStatusButton".. CurrentTicket .."Number"):SetText(value["number"]);
  293. getglobal("TicketStatusButton".. CurrentTicket .."Name"):SetText(value["name"]);
  294. getglobal("TicketStatusButton".. CurrentTicket .."Location"):SetText(value["location"]);
  295. getglobal("TicketStatusButton".. CurrentTicket):Show();
  296. getglobal("TicketStatusButton".. CurrentTicket).charname = value["name"];
  297.  
  298. if (ReadTickets[value["name"]] == 1) then
  299. getglobal("TicketStatusButton".. CurrentTicket .."Name"):SetTextColor(1,1,1);
  300. print("ReadingTickets")
  301. else
  302. getglobal("TicketStatusButton".. CurrentTicket .."Name"):SetTextColor(1,0.82,0);
  303. end
  304. end
  305. end
  306.  
  307. if (NumTicket <= MaxTicket) then
  308. for NumTicket = NumTicket+1, MaxTicket, 1 do
  309. getglobal("TicketStatusButton".. NumTicket - ((CurrentPage - 1) * TicketPP)):Hide();
  310. end
  311. end
  312. if (TempPage > PageCount and TicketCount == 0) then
  313. CurrentPage = TempPage;
  314. end
  315. end
  316.  
  317. function Next_Page()
  318. CurrentPage = CurrentPage + 1;
  319. Update_Tickets();
  320. end
  321.  
  322. function Previous_Page()
  323. CurrentPage = CurrentPage - 1;
  324. Update_Tickets();
  325. end
  326.  
  327. function MarkTicketAsRead(name)
  328. ReadTickets[name] = 1;
  329. Chronos.scheduleByName('ticketupdate', 0, Update_Tickets);
  330. end
  331.  
  332. function RemoveTicketFromReadList(name)
  333. ReadTickets[name] = nil;
  334. end
  335.  
  336. function IsBeingRead()
  337. local NumReading = 0;
  338. local ReadingText = '';
  339. for GMname,charname in pairs(IsReading) do
  340. if (charname == CurName and GMname ~= PlayerName:GetText()) then
  341. NumReading = NumReading + 1;
  342. if NumReading > 1 then
  343. ReadingText = ReadingText .." and ";
  344. end
  345. ReadingText = ReadingText .. GMname;
  346. end
  347. end
  348. if NumReading > 0 then
  349. getglobal("View_Tickets_Ticket_Reading"):SetText("NOTE: this ticket is also being read by ".. ReadingText);
  350. getglobal("View_Tickets_Ticket_Reading"):Show();
  351. else
  352. getglobal("View_Tickets_Ticket_Reading"):Hide();
  353. end
  354. end
  355.  
  356. function StartReading(GMname, charname)
  357. IsReading[GMname] = charname;
  358. if charname == CurName then
  359. IsBeingRead();
  360. end
  361. Chronos.scheduleByName('StopReading', 300, StopReading, GMname);
  362. end
  363.  
  364. function StopReading(GMname, charname)
  365. if charname then
  366. if charname == IsReading[GMname] then
  367. IsReading[GMname] = nil;
  368. end
  369. else
  370. IsReading[GMname] = nil;
  371. end
  372. if charname == CurName then
  373. IsBeingRead();
  374. end
  375. end
  376.  
  377. --[[local ORIG_ChatFrame_MessageEventHandler = ChatFrame_MessageEventHandler;
  378. function ChatFrame_MessageEventHandler(...)]]--
  379. if not ticketFrame then
  380. ticketFrame = CreateFrame("Frame")
  381. end
  382. local frame = ticketFrame
  383. frame:RegisterEvent("CHAT_MSG_SYSTEM")
  384. frame:SetScript("OnEvent", function(self, event, ...)
  385. ticketobjectthingy, event = ...; -- sorry, I was too lazy to think of a better name =P
  386. local ticksystem_msg = select(1, ...)
  387.  
  388. if arg6 == "GM" then
  389. if (ticksystem_msg:find( "(.*)Ticket(.*):(.*)Created by(.*):(.*)") ~= nil) then
  390.  
  391. --if ticketobjectthingy.name == TicketTab then
  392.  
  393. junk,msg = strsplit(" ",arg1);
  394. args = {strsplit(" ",arg1)};
  395. if args[5] then --== "0" and arg2 == PlayerName:GetText() then
  396. AddTicket(args[5])
  397. Chronos.scheduleByName('ticketupdate', 1, Update_Tickets);
  398. elseif args[1] == "1" then
  399. RemoveTicketFromReadList(args[2]);
  400. Refresh_Tickets();
  401. print("args[1] == 1, removing ticket from read list")
  402. elseif args[1] == "2" then
  403. Chronos.scheduleByName('ticketupdate', 1, Update_Tickets);
  404. print("args[1] == 2, starting timer to update.")
  405. elseif args[1] == "3" and arg2 == PlayerName:GetText() then
  406. print("args[1] == 3 and arg2 == PlayerName:GetText()")
  407. len = string.len(args[2])+13;
  408. getglobal("View_Tickets_TitleString"):SetText(args[5] .."'s Ticket");
  409. getglobal("View_Tickets_Root"):SetAttribute("macrotext1", "/target ".. args[2] .." \n/g .para");
  410. getglobal("View_Tickets_Root"):SetAttribute("macrotext2", "/target ".. args[2] .." \n/g .unpara");
  411. print("Is this the problem????")
  412. getglobal("View_Tickets_Ticket_Text"):SetText(string.sub(arg1,len));
  413. MarkTicketAsRead(args[2]);
  414. elseif args[1] == "5" then
  415. Refresh_Tickets();
  416. print("refreshing tickets, args[1] == 5")
  417. elseif args[1] == "8" then
  418. StartReading(arg2, args[2]);
  419. print("Starting to read, args[1] == 8")
  420. elseif args[1] == "9" then
  421. StopReading(arg2, args[2]);
  422. print("args[1] == 9, stopping reading.")
  423. end
  424. end
  425. end
  426. --else
  427. --ORIG_ChatFrame_MessageEventHandler(...);
  428. --end
  429. --end
  430. end)
  431.  
  432. function Refresh_Tickets()
  433. TicketCount = 0;
  434. TicketList = {};
  435. TicketsInList = {};
  436. SendChatMessage(".ticket online","GUILD");
  437. Schedule_Refresh();
  438. end
  439.  
  440. function Schedule_Refresh()
  441. Chronos.scheduleByName('ticketrefresh', 60, Refresh_Tickets);
  442. end
  443.  
  444. function Toggle_Tickets()
  445. local frame = getglobal("Ticket_Tracker");
  446. if (frame) then
  447. if( frame:IsVisible() ) then
  448. LeaveChannelByName(TicketChannel);
  449. Chronos.unscheduleByName('ticketrefresh');
  450. frame:Hide();
  451. else
  452. JoinChannelByName(TicketChannel,"",ChatFrame1:GetID());
  453. Refresh_Tickets();
  454. Ticket_Tracker_Previous:SetText('<');
  455. Ticket_Tracker_Next:SetText('>');
  456. frame:Show();
  457. end
  458. end
  459. end
  460.  
  461. function CloseTicket(ShowTicket)
  462. --SendChatMessage("GmTicket 9,".. CurName, "CHANNEL", nil, GetChannelName(TicketChannel));
  463. SendChatMessage(".whispers off","GUILD");
  464. if(CurTicketNum ~= 0 and ShowTicket ~= true) then
  465. getglobal("TicketStatusButton".. CurTicketNum .."_Texture"):SetTexture(0, 0, 0);
  466. end
  467. CurName = nil;
  468. CurTicketNum = 0;
  469. end
  470.  
  471. function Show_Ticket(name)
  472. tname = string.gsub(name, "|r", "", 1)
  473. SendChatMessage('.ticket viewname '..tname, "SAY")
  474. getglobal("View_Tickets_TitleString"):SetText(tname.."'s Ticket");
  475. getglobal("View_Tickets_Ticket_Text"):SetText("");
  476. getglobal("View_Tickets_Ticket_Reading"):Hide();
  477.  
  478. if CurName then
  479. CloseTicket(true);
  480. end
  481. --CurName = name;
  482. --SendChatMessage("GmTicket 8,".. ticketname, "CHANNEL", nil, GetChannelName(TicketChannel));
  483. SendChatMessage(".whispers on", "GUILD");
  484. --SendWho(name);
  485. local frame = getglobal("View_Tickets");
  486. if (not frame:IsVisible()) then
  487. frame:Show();
  488.  
  489. elseif (CurName == name) then
  490. frame:Hide();
  491. end
  492. CurName = name;
  493. IsBeingRead();
  494. end
  495.  
  496. function Ticket_Revive()
  497. SendChatMessage(".reviveplr ".. CurName,"GUILD");
  498. end
  499.  
  500. function MoltenWow()
  501. ShowGMMessage('Molten WoW - One Team, One Goal, One Love - http://www.molten-wow.com');
  502. end
  503.  
  504. function Ticket_Summon()
  505. SendChatMessage(".summon ".. CurName,"GUILD");
  506. end
  507.  
  508. function Ticket_Appear()
  509. SendChatMessage(".appear ".. CurName,"GUILD");
  510. end
  511.  
  512. function Ticket_Delete()
  513. SendChatMessage(".gmticket delid ".. CurName,"GUILD");
  514. TicketsDone = TicketsDone + 1;
  515. getglobal("Ticket_Tracker_Counter"):SetText(TicketsDone .." tickets done");
  516. CloseTicket();
  517. local frame = getglobal("View_Tickets");
  518. frame:Hide();
  519. end
  520.  
  521. MoltenWow();
  522.  
  523. function SendWhisperMacro()
  524. local msg = string.gsub(WhisperMacros[this.value], "NAME", CurName);
  525. if string.find(msg, "SUBJECT") then
  526. CurWhisperMessage = msg;
  527. WhisperSubjectPopup:Show();
  528. WhisperSubjectPopup_Subject:SetFocus();
  529. else
  530. args = {strsplit("\n",msg)};
  531. for index,text in pairs(args) do
  532. SendChatMessage(text, "WHISPER", nil, CurName);
  533. end
  534. end
  535. end
  536.  
  537. function SendWhisperWithSubject()
  538. WhisperSubjectPopup:Hide();
  539. local subject = WhisperSubjectPopup_Subject:GetText();
  540. WhisperSubjectPopup_Subject:SetText('');
  541.  
  542. local msg = string.gsub(CurWhisperMessage, "SUBJECT", subject);
  543. args = {strsplit("\n",msg)};
  544. for index,text in pairs(args) do
  545. SendChatMessage(text, "WHISPER", nil, CurName);
  546. end
  547.  
  548. CurWhisperMessage = '';
  549. end
  550.  
  551. function WhispersDropdown_OnLoad()
  552. if WhisperMacros then
  553. local WhisperMacrosTemp = pairsByKeys2(WhisperMacros);
  554. for index,name in pairs(WhisperMacrosTemp) do
  555. info = {};
  556. info.text = name;
  557. info.value = name;
  558. info.func = SendWhisperMacro;
  559. info.owner = this:GetParent();
  560. UIDropDownMenu_AddButton(info);
  561. end
  562. end
  563. end
  564.  
  565. SLASH_TICKETS1 = "/tickets";
  566. SlashCmdList["TICKETS"] = Toggle_Tickets;
  567.  
  568. Chronos.scheduleRepeating('tenaciousgaming', 1800, tenaciousGaming);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement