Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Untitled

a guest Dec 26th, 2017 90 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function adminDutyStart()
  2.     local result = mysql:query("SELECT id, name FROM factions WHERE type >= 2 ORDER BY id ASC")
  3.     local max = mysql:query("SELECT id FROM duty_allowed ORDER BY id DESC LIMIT 0, 1")
  4.     if result and max then
  5.         dutyAllow = { }
  6.         dutyAllowChanges = { }
  7.         i = 0
  8.  
  9.         local maxrow = mysql:fetch_assoc(max)
  10.         maxIndex = tonumber(maxrow.id) or 0
  11.            
  12.         while true do
  13.             local row = mysql:fetch_assoc(result)
  14.             if not row then break end
  15.  
  16.             table.insert(dutyAllow, { row.id, row.name, { --[[Duty]] } })
  17.             i = i+1
  18.                
  19.             local result1 = mysql:query("SELECT * FROM duty_allowed WHERE faction="..tonumber(row.id))
  20.             if result1 then
  21.                 while true do
  22.                     local row1 = mysql:fetch_assoc(result1)
  23.                     if not row1 then break end
  24.  
  25.                     table.insert(dutyAllow[i][3], { row1.id, tonumber(row1.itemID), row1.itemValue })
  26.                 end
  27.             end
  28.         end
  29.  
  30.         setElementData(resourceRoot, "maxIndex", maxIndex)
  31.         setElementData(resourceRoot, "dutyAllowTable", dutyAllow)
  32.         mysql:free_result(result)
  33.         mysql:free_result(result1)
  34.         mysql:free_result(max)
  35.     else
  36.         outputDebugString("[Factions] ERREUR: La permission du duty a échouée.")
  37.     end
  38. end
  39. addEventHandler("onResourceStart", resourceRoot, adminDutyStart)
  40.  
  41. function getAllowList(factionID)
  42.     local factionID = tonumber(factionID)
  43.     if factionID then
  44.         for k,v in pairs(dutyAllow) do
  45.             if tonumber(v[1]) == factionID then
  46.                 key = k
  47.                 break
  48.             end
  49.         end
  50.         return dutyAllow[key][3]
  51.     end
  52. end
  53.  
  54. function adminDuty(thePlayer)
  55.     if (exports.integration:isPlayerSeniorAdmin(thePlayer) or exports.integration:isPlayerScripter(thePlayer)) then
  56.         if not getElementData(resourceRoot, "dutyadmin") and type(dutyAllow) == "table" then
  57.             triggerClientEvent(thePlayer, "adminDutyAllow", resourceRoot, dutyAllow, dutyAllowChanges)
  58.             setElementData( resourceRoot, "dutyadmin", true )
  59.         elseif type(dutyAllow) ~= "table" then
  60.             outputChatBox("Il y a un probleme de mise en cache lors du démarrage de cette resource. Contacte un Scripteur.", thePlayer, 255, 0, 0)
  61.         else
  62.             outputChatBox("Quelqu'un est déjà en train d'editer les permissions du duty de cette faction!", thePlayer, 255, 0, 0)
  63.         end
  64.     end
  65. end
  66. addCommandHandler("dutyadmin", adminDuty, false, false)
  67.  
  68. function saveChanges()
  69.     outputDebugString("[Factions] Sauvegarde des changements...")
  70.     local tick = getTickCount()
  71.  
  72.     for key,value in pairs(dutyAllowChanges) do
  73.         if value[2] == 0 then
  74.             mysql:query_free("DELETE FROM duty_allowed WHERE id="..mysql:escape_string(tonumber(value[3])))
  75.         elseif value[2] == 1 then
  76.             mysql:query_free("INSERT INTO duty_allowed SET id="..mysql:escape_string(tonumber(value[3]))..", faction="..mysql:escape_string(tonumber(value[1]))..", itemID="..mysql:escape_string(tonumber(value[4]))..", itemValue='"..mysql:escape_string(value[5]).."'")
  77.         end
  78.     end
  79.  
  80.     outputDebugString("[Factions] Terminer en ".. math.floor((getTickCount()-tick)/60) .." secondes.")
  81. end
  82. addEventHandler("onResourceStop", resourceRoot, saveChanges)
  83.  
  84. function updateTable(newTable, changesTable)
  85.     dutyAllow = newTable
  86.     dutyAllowChanges = changesTable
  87.     removeElementData(resourceRoot, "dutyadmin")
  88.     setElementData(resourceRoot, "dutyAllowTable", dutyAllow)
  89. end
  90. addEvent("dutyAdmin:Save", true)
  91. addEventHandler("dutyAdmin:Save", resourceRoot, updateTable)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top