Advertisement
Guest User

DutyAllow

a guest
Dec 26th, 2017
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.82 KB | None | 0 0
  1. function createAdminDuty(factionT, dutyT)
  2.     if isElement(DutyAllow.window[1]) then
  3.         destroyElement(DutyAllow.window[1])
  4.     end
  5.  
  6.     factionTable = factionT
  7.     dutyChanges = dutyT
  8.  
  9.     DutyAllow.window[1] = guiCreateWindow(562, 250, 564, 351, "Paramètre du duty", false)
  10.     centerWindow(DutyAllow.window[1])
  11.     guiWindowSetSizable(DutyAllow.window[1], false)
  12.     guiWindowSetMovable(DutyAllow.window[1], true)
  13.     guiSetInputEnabled(true)
  14.  
  15.     DutyAllow.gridlist[1] = guiCreateGridList(9, 75, 545, 224, false, DutyAllow.window[1])
  16.     guiGridListAddColumn(DutyAllow.gridlist[1], "ID", 0.1)
  17.     guiGridListAddColumn(DutyAllow.gridlist[1], "Nom", 0.3)
  18.     guiGridListAddColumn(DutyAllow.gridlist[1], "Description", 0.6)
  19.     DutyAllow.label[1] = guiCreateLabel(10, 308, 73, 21, "Item ID:", false, DutyAllow.window[1])
  20.     guiLabelSetVerticalAlign(DutyAllow.label[1], "center")
  21.     DutyAllow.edit[1] = guiCreateEdit(83, 308, 78, 21, "", false, DutyAllow.window[1])
  22.     DutyAllow.button[1] = guiCreateButton(318, 303, 108, 30, "Autoriser", false, DutyAllow.window[1])
  23.     guiSetProperty(DutyAllow.button[1], "NormalTextColour", "FFAAAAAA")
  24.     DutyAllow.button[2] = guiCreateButton(436, 303, 108, 30, "Retirer", false, DutyAllow.window[1])
  25.     guiSetProperty(DutyAllow.button[2], "NormalTextColour", "FFAAAAAA")
  26.     DutyAllow.label[2] = guiCreateLabel(11, 59, 543, 16, "Items autorisés", false, DutyAllow.window[1])
  27.     guiLabelSetHorizontalAlign(DutyAllow.label[2], "center", false)
  28.     DutyAllow.label[3] = guiCreateLabel(9, 348, 74, 24, "Vue:", false, DutyAllow.window[1])
  29.     guiLabelSetVerticalAlign(DutyAllow.label[3], "center")
  30.     DutyAllow.label[4] = guiCreateLabel(163, 308, 68, 20, "Valeur:", false, DutyAllow.window[1])
  31.     guiLabelSetVerticalAlign(DutyAllow.label[4], "center")
  32.     DutyAllow.edit[2] = guiCreateEdit(230, 308, 78, 21, "1", false, DutyAllow.window[1])  
  33.     DutyAllow.combobox[1] = guiCreateComboBox(1, 25, 242, 998, "Choisis une faction.", false, DutyAllow.window[1])
  34.     exports.global:guiComboBoxAdjustHeight(DutyAllow.combobox[1], #factionT)
  35.     DutyAllow.button[3] = guiCreateButton(442, 25, 102, 35, "Terminer", false, DutyAllow.window[1])
  36.     guiSetProperty(DutyAllow.button[3], "NormalTextColour", "FFAAAAAA")
  37.     DutyAllow.combobox[2] = guiCreateComboBox(255, 25, 124, 19, "", false, DutyAllow.window[1])
  38.     exports.global:guiComboBoxAdjustHeight(DutyAllow.combobox[2], 2)
  39.     guiComboBoxAddItem(DutyAllow.combobox[2], "Items")
  40.     guiComboBoxAddItem(DutyAllow.combobox[2], "Armes")  
  41.     guiComboBoxSetSelected( DutyAllow.combobox[2], 0 )
  42.  
  43.     local row = guiGridListAddRow( DutyAllow.gridlist[1] )
  44.     guiGridListSetItemText ( DutyAllow.gridlist[1], row, 2, "Choisis une faction...", false, false )
  45.  
  46.     for k,v in pairs(factionT) do
  47.         guiComboBoxAddItem( DutyAllow.combobox[1], "(".. v[1] ..") " .. v[2] )
  48.     end
  49.     addEventHandler("onClientGUIComboBoxAccepted", DutyAllow.combobox[1], toggleFaction)
  50.     addEventHandler("onClientGUIComboBoxAccepted", DutyAllow.combobox[2], toggleView)
  51.  
  52.     addEventHandler("onClientGUIClick", DutyAllow.button[1], allowItem, false)
  53.     addEventHandler("onClientGUIClick", DutyAllow.button[2], removeItem, false)
  54.     addEventHandler("onClientGUIClick", DutyAllow.button[3], closeGUI, false)
  55. end
  56. addEvent("adminDutyAllow", true)
  57. addEventHandler("adminDutyAllow", resourceRoot, createAdminDuty)
  58.  
  59. function populateList(key)
  60.     local selection = guiComboBoxGetSelected (DutyAllow.combobox[2])
  61.     guiGridListClear( DutyAllow.gridlist[1] )
  62.     if selection == 0 then
  63.         for k,v in pairs(factionTable[key][3]) do
  64.             if tonumber(v[2]) > 0 then
  65.                 local row = guiGridListAddRow(DutyAllow.gridlist[1])
  66.  
  67.                 guiGridListSetItemText(DutyAllow.gridlist[1], row, 1, v[2], false, true)
  68.                 guiGridListSetItemText(DutyAllow.gridlist[1], row, 2, exports["item-system"]:getItemName(v[2]), false, false)
  69.                 guiGridListSetItemText(DutyAllow.gridlist[1], row, 3, exports["item-system"]:getItemDescription(v[2], v[3]), false, false)
  70.                 guiGridListSetItemData(DutyAllow.gridlist[1], row, 1, tonumber(v[1]))
  71.             end
  72.         end
  73.     elseif selection == 1 then -- Weapons
  74.         for k,v in pairs(factionTable[key][3]) do
  75.             if tonumber(v[2]) < 0 then
  76.                 local row = guiGridListAddRow(DutyAllow.gridlist[1])
  77.                 if tonumber(v[2]) == -100 then
  78.                     guiGridListSetItemText(DutyAllow.gridlist[1], row, 1, v[2], false, true)
  79.                     guiGridListSetItemText(DutyAllow.gridlist[1], row, 2, "Armure", false, false)
  80.                     guiGridListSetItemText(DutyAllow.gridlist[1], row, 3, v[3], false, false)
  81.                 else
  82.                     guiGridListSetItemText(DutyAllow.gridlist[1], row, 1, v[2], false, true)
  83.                     guiGridListSetItemText(DutyAllow.gridlist[1], row, 2, exports["item-system"]:getItemName(v[2]), false, false)
  84.                     guiGridListSetItemText(DutyAllow.gridlist[1], row, 3, v[3], false, false)
  85.                 end
  86.                 guiGridListSetItemData(DutyAllow.gridlist[1], row, 1, tonumber(v[1]))
  87.             end
  88.         end
  89.     end
  90.     guiSetText(DutyAllow.edit[1], "")
  91.     guiSetText(DutyAllow.edit[2], "")
  92. end
  93.  
  94. function toggleView()
  95.     local item = guiComboBoxGetSelected (DutyAllow.combobox[2])
  96.     guiGridListClear( DutyAllow.gridlist[1] )
  97.  
  98.     if item == 1 then -- Armes
  99.         guiSetText(DutyAllow.label[2], "Armes autorisés")
  100.  
  101.         guiGridListSetColumnTitle(DutyAllow.gridlist[1], 2, "Nom")
  102.         guiGridListSetColumnTitle(DutyAllow.gridlist[1], 3, "Munition Max")
  103.  
  104.         guiSetText(DutyAllow.label[1], "ID de l'arme:")
  105.         guiSetText(DutyAllow.label[4], "Munitions max:")
  106.     elseif item == 0 then -- Items
  107.         guiSetText(DutyAllow.label[2], "Items Autorisés")
  108.  
  109.         guiGridListSetColumnTitle(DutyAllow.gridlist[1], 2, "Nom")
  110.         guiGridListSetColumnTitle(DutyAllow.gridlist[1], 3, "Description")
  111.  
  112.         guiSetText(DutyAllow.label[1], "ID de l'item:")
  113.         guiSetText(DutyAllow.label[4], "Valeure de l'item:")
  114.     end
  115.     if guiComboBoxGetSelected(DutyAllow.combobox[1]) and guiComboBoxGetSelected(DutyAllow.combobox[1]) > -1 then
  116.         populateList(guiComboBoxGetSelected(DutyAllow.combobox[1])+1)
  117.     end
  118. end
  119.  
  120. function toggleFaction()
  121.     local selected = guiComboBoxGetSelected(DutyAllow.combobox[1])
  122.     if selected and selected > -1 then
  123.         populateList(selected+1)
  124.     end
  125. end
  126.  
  127. function closeGUI()
  128.     destroyElement(DutyAllow.window[1])
  129.     guiSetInputEnabled(false)
  130.     triggerServerEvent("dutyAdmin:Save", resourceRoot, factionTable, dutyChanges)
  131. end
  132.  
  133. function allowItem()
  134.     local itemID = guiGetText(DutyAllow.edit[1])
  135.     local itemValue = guiGetText(DutyAllow.edit[2])
  136.     local selection = guiComboBoxGetSelected (DutyAllow.combobox[2])
  137.     local faction = guiComboBoxGetSelected (DutyAllow.combobox[1])+1
  138.     local maxIndex = getElementData(resourceRoot, "maxIndex")+1
  139.     if not tonumber(itemID) then return end
  140.  
  141.     if not exports['item-system']:isItem(itemID) and selection == 0 then
  142.         outputChatBox("Ce n'est pas un item...", 255, 0, 0)
  143.         return
  144.     elseif not getWeaponNameFromID(itemID) and selection == 1 and tonumber(itemID) ~= 100 then
  145.         outputChatBox("Ce n'est pas une arme...", 255, 0, 0)
  146.         return
  147.     end
  148.  
  149.     if faction and faction > 0 then
  150.         --[[for k,v in pairs(factionTable[faction][3]) do
  151.             if tonumber(v[2]) == tonumber(selection == 1 and -itemID or itemID) then
  152.                 outputChatBox("Tu as déjà autorisé cet item.", 255, 0, 0)
  153.                 return
  154.             end
  155.         end]]
  156.  
  157.         if tonumber(itemID) then
  158.             if selection == 0 then -- Item
  159.                 table.insert(factionTable[faction][3], { maxIndex, tonumber(itemID), itemValue })
  160.                 table.insert(dutyChanges, { faction, 1, maxIndex, tonumber(itemID), itemValue })
  161.                 setElementData(resourceRoot, "maxIndex", maxIndex)
  162.             elseif selection == 1 then -- Weapon
  163.                 if tonumber(itemValue) then
  164.                     if not weapBanList[-tonumber(itemID)] then -- Check if its banned.
  165.                         table.insert(factionTable[faction][3], { maxIndex, -tonumber(itemID), itemValue })
  166.                         table.insert(dutyChanges, { faction, 1, maxIndex, -tonumber(itemID), itemValue })
  167.                         setElementData(resourceRoot, "maxIndex", maxIndex)
  168.                     else
  169.                         outputChatBox("Cette arme a été interdite.", 255, 0, 0)
  170.                     end
  171.                 else
  172.                     outputChatBox("Les munitions max doivent être en nombre!", 255, 0, 0)
  173.                 end
  174.             end
  175.             populateList(faction)
  176.         else
  177.             outputChatBox("L'id de l'item doit être un nombre!", 255, 0, 0)
  178.         end
  179.     else
  180.         outputChatBox("Choisis d'abord un item.", 255, 0, 0)
  181.     end
  182. end
  183.  
  184. function removeItem()
  185.     local r, c = guiGridListGetSelectedItem ( DutyAllow.gridlist[1] )
  186.     local faction = guiComboBoxGetSelected(DutyAllow.combobox[1])+1
  187.     if r and r>=0 and c and c>=0 and faction and faction > 0 then
  188.         local id = guiGridListGetItemData(DutyAllow.gridlist[1], r, 1)
  189.         for k,v in pairs(factionTable[faction][3]) do
  190.             if tonumber(id) == tonumber(v[1]) then
  191.                 table.insert(dutyChanges, { faction, 0, k })
  192.                 table.remove(factionTable[faction][3], k)
  193.                 populateList(faction)
  194.             end
  195.         end
  196.     else
  197.         outputChatBox("Choisis d'abord un item.", 255, 0, 0)
  198.     end
  199. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement