RyanUSNS

gamrev.lua

Jun 4th, 2018
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 12.59 KB | None | 0 0
  1. ------------------------------------------------------------------------------------
  2. --  COMMUNITY CONTRIBUTION FOR CIT2.NET
  3. --  PURPOSE: GAM review - Ability to review
  4. --  DEVELOPERS: Ryan (acc:hassam)
  5. ------------------------------------------------------------------------------------
  6.  
  7. local groupInfo, plrSelected = {}, {}
  8. local groupName
  9.  
  10. function createGAMGui()
  11.     local sx, sh = guiGetScreenSize()
  12.     gamWindow = guiCreateWindow((sx / 2) - (689 / 2), (sh / 2) - (306 / 2), 689, 306, "Group Review", false)
  13.     guiWindowSetSizable(gamWindow, false)
  14.     guiSetAlpha(gamWindow, 1.00)
  15.     guiSetVisible(gamWindow, false)
  16.     groupTabPanel = guiCreateTabPanel(9, 21, 670, 275, false, gamWindow)
  17.     -- Group Informations Tab
  18.     groupInfoTab = guiCreateTab("Group Information", groupTabPanel)
  19.     groupSearchEdit = guiCreateEdit(3, 5, 99, 26, "", false, groupInfoTab)
  20.     confirmButton = guiCreateButton(108, 4, 77, 27, "Confirm", false, groupInfoTab)
  21.     groupInfoMemo = guiCreateMemo(5, 41, 180, 199, "Information: \nAmount Members: \nGroup Level:\nAmount players logged in last 2 months:\nLast Review:\nReviewed by: \nLeaders Name:\n", false, groupInfoTab)
  22.     guiMemoSetReadOnly(groupInfoMemo, true)
  23.     gMemberList = guiCreateGridList(200, 41, 456, 199, false, groupInfoTab)
  24.     guiGridListAddColumn(gMemberList, "Name", 0.3)
  25.     guiGridListAddColumn(gMemberList, "Account Name", 0.3)
  26.     guiGridListAddColumn(gMemberList, "Rank", 0.3)
  27.     guiGridListAddColumn(gMemberList, "WL", 0.05)
  28.     getInfoButton = guiCreateButton(543, 4, 113, 27, "Get Informations", false, groupInfoTab)
  29.     searchPlrOrRankEdit = guiCreateEdit(200, 5, 157, 26, "", false, groupInfoTab)
  30.     selectPlrsRankButton = guiCreateButton(367, 4, 166, 27, "Select Players with same rank", false, groupInfoTab)
  31.     --Copy Informations Tab (Without BBCodes)
  32.     reviewTab = guiCreateTab("Reviewed", groupTabPanel)
  33.     groupRevLabel = guiCreateLabel(10, 10, 238, 26, "Group Informations", false, reviewTab)
  34.     guiLabelSetHorizontalAlign(groupRevLabel, "center", false)
  35.     guiLabelSetVerticalAlign(groupRevLabel, "center")
  36.     groupRevCopyMemo = guiCreateMemo(10, 42, 238, 199, "", false, reviewTab)
  37.     guiMemoSetReadOnly(groupRevCopyMemo, true)
  38.     leaderRevLabel = guiCreateLabel(276, 10, 238, 26, "Leaders Informations", false, reviewTab)
  39.     guiLabelSetHorizontalAlign(leaderRevLabel, "center", false)
  40.     guiLabelSetVerticalAlign(leaderRevLabel, "center")
  41.     leaderRevCopyMemo = guiCreateMemo(276, 42, 238, 199, "", false, reviewTab)
  42.     guiMemoSetReadOnly(leaderRevCopyMemo, true)
  43.     --Copy Informations Tab (With BBCodes)
  44.     infoTab = guiCreateTab("Reviewed + BBCodes ready", groupTabPanel)
  45.     groupInfoLabel = guiCreateLabel(10, 10, 238, 26, "Group Informations", false, infoTab)
  46.     guiLabelSetHorizontalAlign(groupInfoLabel, "center", false)
  47.     guiLabelSetVerticalAlign(groupInfoLabel, "center")
  48.     groupInfoCopyMemo = guiCreateMemo(10, 42, 238, 199, "", false, infoTab)
  49.     guiMemoSetReadOnly(groupInfoCopyMemo, true)
  50.     leaderInfoLabel = guiCreateLabel(276, 10, 238, 26, "Leaders Informations", false, infoTab)
  51.     guiLabelSetHorizontalAlign(leaderInfoLabel, "center", false)
  52.     guiLabelSetVerticalAlign(leaderInfoLabel, "center")
  53.     leaderInfoCopyMemo = guiCreateMemo(276, 42, 238, 199, "", false, infoTab)
  54.     guiMemoSetReadOnly(leaderInfoCopyMemo, true)
  55.     copyGInfoButton = guiCreateButton(543, 134, 117, 29, "Copy Group Informations", false, infoTab)
  56.     copyLInfoButton = guiCreateButton(543, 173, 117, 29, "Copy Leader Informations", false, infoTab)
  57.     reviewedButton = guiCreateButton(543, 212, 117, 29, "Reviewed", false, infoTab)
  58.     --Close Tab
  59.     closeTab = guiCreateTab("Close", groupTabPanel)
  60.     --Event handlers
  61.     addEventHandler("onClientGUIClick", confirmButton, onGetCorrectGroup, false)
  62.     addEventHandler("onClientGUIClick", getInfoButton, enabledInformations, false)
  63.     addEventHandler("onClientGUIChanged", searchPlrOrRankEdit, searchPlrOrRank, false)
  64.     addEventHandler("onClientGUIClick", selectPlrsRankButton, addLeadRankList, false)
  65.     addEventHandler("onClientGUIDoubleClick", gMemberList, addLeader, false)
  66.     --
  67.     addEventHandler("onClientGUIClick", copyGInfoButton, copyInfos, false)
  68.     addEventHandler("onClientGUIClick", copyLInfoButton, copyInfos, false)
  69.     addEventHandler("onClientGUIClick", reviewedButton, reviewedGroup, false)
  70.     --
  71.     addEventHandler("onClientGUITabSwitched", closeTab, toggleMainGUI, false)  
  72. end
  73.  
  74. function toggleMainGUI()
  75.     if (not gamWindow) then
  76.         createGAMGui()
  77.     end
  78.     local state = not guiGetVisible(gamWindow)
  79.     guiSetVisible(gamWindow, state)
  80.     showCursor(state)
  81.     if (not state) then
  82.         return false
  83.     end
  84.     cleaningInfo()
  85. end
  86. addEvent("CITgamReview.showPanel", true)
  87. addEventHandler("CITgamReview.showPanel", root, toggleMainGUI)
  88.  
  89. function onGetCorrectGroup()
  90.     if (not guiGetText(groupSearchEdit) or guiGetText(groupSearchEdit) == "") then
  91.         return false
  92.     end
  93.     groupName = guiGetText(groupSearchEdit)
  94.     triggerServerEvent("CITgamReview.checkExistedGroup", resourceRoot, groupName)
  95. end
  96.  
  97. function groupCorrectEnabled(groupT)
  98.     if (not groupT) then
  99.         return false
  100.     end
  101.     guiSetEnabled(selectPlrsRankButton, true)
  102.     guiEditSetReadOnly(groupSearchEdit, true)
  103.     guiEditSetReadOnly(searchPlrOrRankEdit, false)
  104.     guiSetEnabled(getInfoButton, true)
  105.     guiSetEnabled(confirmButton, false)
  106.     groupInfo = groupT
  107.     refreshGroupList()
  108.     guiSetText(groupInfoMemo, "Information: Group Exist\nAmount Members: "..groupInfo["info"][1].."\nGroup Level: "..groupInfo["info"][2].."\nAmount players logged in last 2 months: "..groupInfo["info"][3].."\nLast Review: "..groupInfo["info"][4].."\nReviewed by: "..groupInfo["info"][5].."\nLeaders Name:")
  109. end
  110. addEvent("CITgamReview.groupCorrectEnabled", true)
  111. addEventHandler("CITgamReview.groupCorrectEnabled", root, groupCorrectEnabled)
  112.  
  113. function enabledInformations()
  114.     if (next(plrSelected) == nil) then
  115.         outputChatBox("You didn't select any leader!", 255, 0, 0)
  116.         return false
  117.     end
  118.     guiSetText(leaderInfoCopyMemo, "[size=18pt][color=green]Activity in-game[/color][/size]\n[b]Leaders Activity -[/b] [i]Provide number of logins/hours of their leaders for the last 2 months[/i][list]")
  119.     for i, v in pairs(groupInfo["review"]) do
  120.         if (plrSelected[v[1]]) then
  121.             local totalHits = v[3][1][2] + v[3][2][2] + v[3][3][2]
  122.             local totalPlay = math.ceil(((v[3][1][1] + v[3][2][1] + v[3][3][1])/24), 2)
  123.             guiSetText(leaderInfoCopyMemo, guiGetText(leaderInfoCopyMemo).."\n[list][li]Leader Name (Acc: "..v[1].."): "..v[2].."\n[list]\n[li][i]LOGIN hits:[/i] "..totalHits.."\n[list]\n[li]First month: "..v[3][3][2].."[/li]\n[li]Second month: "..v[3][2][2].."[/li]\n[li]Third month (Currently): "..v[3][1][2].."[/li]\n[/list][/li]\n[li][i]Playtime played:[/i] "..totalPlay.."\n[list]\n[li]First month: "..math.ceil((v[3][3][1]/24), 2).."[/li]\n[li]Second month :"..math.ceil((v[3][2][1]/24), 2).."[/li]\n[li]Third month (Currently): "..math.ceil((v[3][1][1]/24), 2).."[/li]\n[/list][/li]\n[li][i]Hours and LOGIN hits comparison:[/i] "..math.ceil((totalPlay/totalHits), 3).."\n[list]\n[li]First month: "..math.ceil(((v[3][3][1]/24)/v[3][3][2]), 3) or (0).."[/li]\n[li]Second month :"..math.ceil(((v[3][2][1]/24)/v[3][2][2]), 3) or (0).."[/li]\n[li]Third month (Currently): "..math.ceil(((v[3][1][1]/24)/v[3][1][2]), 3) or (0).."[/li]\n[/list][/li]\n[/list][/list]\n")
  124.             guiSetText(leaderRevCopyMemo, "Leader Name (Acc: "..v[1].."): "..v[2].."\nLOGIN hits: "..totalHits.."\nFirst month: "..v[3][3][2].."\nSecond month: "..v[3][2][2].."\nThird month (Currently): "..v[3][1][2].."\nPlaytime played: "..totalPlay.."\nFirst month: "..math.ceil((v[3][3][1]/24), 2).."\nSecond month :"..math.ceil((v[3][2][1]/24), 2).."\nThird month (Currently): "..math.ceil((v[3][1][1]/24), 2).."\nHours and LOGIN hits comparison:[/i] "..math.ceil((totalPlay/totalHits), 3).."\nFirst month: "..math.ceil(((v[3][3][1]/24)/v[3][3][2]), 3) or (0).."\nSecond month :"..math.ceil(((v[3][2][1]/24)/v[3][2][2]), 3) or (0).."\nThird month (Currently): "..math.ceil(((v[3][1][1]/24)/v[3][1][2]), 3) or (0))
  125.         end
  126.     end
  127.     guiSetText(leaderInfoCopyMemo, guiGetText(leaderInfoCopyMemo).."\n[/list]")
  128.     guiSetText(groupInfoCopyMemo, "[size=24pt][color=purple][b]"..groupName.."'s Auto-Review[/b][/color][/size]\n\n[b]Amount Members: [/b]"..groupInfo["info"][1].."\n[b]Group Level:[/b] "..groupInfo["info"][2].."\n[b]Amount players logged in last 2 months:[/b] "..groupInfo["info"][3].."\n[b]Last Review:[/b] "..groupInfo["info"][4].."\n[b]Reviewed by:[/b] "..groupInfo["info"][5])
  129.     guiSetText(groupRevCopyMemo, "Amount Members: "..groupInfo["info"][1].."\nGroup Level: "..groupInfo["info"][2].."\nAmount players logged in last 2 months: "..groupInfo["info"][3].."\nLast Review: "..groupInfo["info"][4].."\nReviewed by: "..groupInfo["info"][5])
  130.     guiSetEnabled(infoTab, true)
  131.     guiSetEnabled(groupInfoTab, false)
  132.     guiSetEnabled(reviewTab, true)
  133.     guiSetSelectedTab(groupTabPanel, reviewTab)
  134.     guiSetEnabled(reviewedButton, false)
  135. end
  136.  
  137. function searchPlrOrRank()
  138.     local text = string.lower(guiGetText(searchPlrOrRankEdit))
  139.     if (text == "") then
  140.         refreshGroupList()
  141.         return false
  142.     end
  143.     local rankTable = {}
  144.     for i, v in pairs(groupInfo["members"]) do
  145.         local looping
  146.         if (string.find(text, "%rank:")) then
  147.             looping = string.lower("rank:"..v[3])
  148.         else
  149.             looping = string.lower(v[2])
  150.         end
  151.         if (string.find(looping, text)) then
  152.             table.insert(rankTable, {v[1], v[2], v[3], v[4], v[5]})
  153.        end
  154.     end
  155.     guiGridListClear(gMemberList)
  156.     for i, v in pairs(rankTable) do
  157.         local row = guiGridListAddRow(gMemberList)
  158.         guiGridListSetItemText(gMemberList, row, 1, v[1], false, false)
  159.         guiGridListSetItemText(gMemberList, row, 2, v[2], false, false)
  160.         guiGridListSetItemText(gMemberList, row, 3, v[3], false, false)
  161.         guiGridListSetItemText(gMemberList, row, 4, v[4], false, false)
  162.     end
  163. end
  164.  
  165. function addLeadRankList()
  166.     local text = string.lower(guiGetText(searchPlrOrRankEdit))
  167.     local count = 0
  168.     for i, v in pairs(groupInfo["members"]) do
  169.         if (string.find(text, "%rank:")) then
  170.             local looping = string.lower("rank:"..v[3])
  171.             if (string.find(looping, text)) then
  172.                 count = count + 1
  173.             end
  174.         end
  175.     end
  176.     if (count ~= 1) then
  177.         outputChatBox("You should have just 1 rank selected or forgot use 'rank:'!", 255, 0, 0)
  178.         return false
  179.     end
  180.     for i = 0, guiGridListGetRowCount(gMemberList) - 1 do
  181.         local acc = guiGridListGetItemText(gMemberList, i, 2)
  182.         if (not plrSelected[acc]) then
  183.             plrSelected[acc] = true
  184.         end
  185.     end
  186.     refreshLeaderList()
  187. end
  188.  
  189. function addLeader()
  190.     local r, c = guiGridListGetSelectedItem(gMemberList)
  191.     if (r < 0) then
  192.         return false
  193.     end
  194.     local name = guiGridListGetItemText(gMemberList, r, 1)
  195.     local acc = guiGridListGetItemText(gMemberList, r, 2)
  196.     plrSelected[acc] = not plrSelected[acc]
  197.     refreshLeaderList()
  198. end
  199.  
  200. function copyInfos()
  201.     if (source == copyGInfoButton) then
  202.         setClipboard(guiGetText(groupInfoCopyMemo))
  203.         return true
  204.     end
  205.     setClipboard(guiGetText(leaderInfoCopyMemo))
  206.     guiSetEnabled(reviewedButton, true)
  207. end
  208.  
  209. function reviewedGroup()
  210.     triggerServerEvent("CITgamReview.reviewedGroup", resourceRoot, groupName)
  211.     cleaningInfo()
  212. end
  213.  
  214. function cleaningInfo()
  215.     guiSetEnabled(groupInfoTab, true)
  216.     guiSetSelectedTab(groupTabPanel, groupInfoTab)
  217.     guiSetEnabled(selectPlrsRankButton, false)
  218.     guiSetEnabled(infoTab, false)
  219.     guiSetEnabled(reviewTab, false)
  220.     guiEditSetReadOnly(searchPlrOrRankEdit, true)
  221.     guiEditSetReadOnly(groupSearchEdit, false)
  222.     guiSetEnabled(confirmButton, true)
  223.     guiSetEnabled(getInfoButton, false)
  224.     guiGridListClear(gMemberList)
  225.     guiSetText(groupSearchEdit, "")
  226.     guiSetText(searchPlrOrRankEdit, "")
  227.     groupInfo = {}
  228.     plrSelected = {}
  229.     guiSetText(groupInfoMemo, "")
  230. end
  231.  
  232. --Refresh Time
  233. function refreshGroupList()
  234.     if (not groupInfo["members"]) then
  235.         return false
  236.     end
  237.     guiGridListClear(gMemberList)
  238.     for i, val in pairs(groupInfo["members"]) do
  239.         local row = guiGridListAddRow(gMemberList)
  240.         guiGridListSetItemText(gMemberList, row, 1, val[1], false, false)
  241.         guiGridListSetItemText(gMemberList, row, 2, val[2], false, false)
  242.         guiGridListSetItemText(gMemberList, row, 3, val[3], false, false)
  243.         guiGridListSetItemText(gMemberList, row, 4, val[4], false, false)
  244.     end
  245. end
  246.  
  247. function refreshLeaderList()
  248.     guiSetText(groupInfoMemo, "Information: Group Exist\nAmount Members: "..groupInfo["info"][1].."\nGroup Level: "..groupInfo["info"][2].."\nAmount players logged in last 2 months: "..groupInfo["info"][3].."\nLast Review: "..groupInfo["info"][4].."\nReviewed by: "..groupInfo["info"][5].."\nLeaders Name:")
  249.     if (next(plrSelected) == nil or not groupInfo["members"]) then
  250.         return false
  251.     end
  252.     for i, val in pairs(groupInfo["members"]) do
  253.         if (plrSelected[val[2]]) then
  254.             guiSetText(groupInfoMemo, (guiGetText(groupInfoMemo).."\n"..val[1]))
  255.         end
  256.     end
  257. end
Advertisement
Add Comment
Please, Sign In to add comment