Advertisement
Guest User

server.lua

a guest
Apr 30th, 2017
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.10 KB | None | 0 0
  1. local commands = {}
  2.  
  3. for command, _ in pairs(LOADOUTS) do
  4. table.insert(commands, command)
  5. end
  6.  
  7. RegisterServerEvent("loadout:playerSpawned")
  8. AddEventHandler("loadout:playerSpawned", function(spawn)
  9. TriggerEvent("loadout:doLoadout", source, "random")
  10. end)
  11.  
  12. RegisterServerEvent("loadout:doLoadout")
  13. AddEventHandler("loadout:doLoadout", function(player, loadoutName)
  14. print("changing " .. player)
  15. local loadout = LOADOUTS[loadoutName]
  16. local skins, weapons
  17.  
  18. if not loadout.skins then
  19. skins = {}
  20. else
  21. skins = loadout.skins
  22. end
  23.  
  24. if not loadout.weapons then
  25. weapons = {}
  26. else
  27. weapons = loadout.weapons
  28. end
  29.  
  30. local sIdx = math.random(1, (#skins or 0) +1)
  31. local skin = skins[sIdx] -- Choose a random skin
  32. --print( "------- GOT SKIN: " .. skin .. " --------")
  33. TriggerClientEvent("loadout:changeSkin", player, skin)
  34.  
  35. if weapons then
  36. local delay = nil
  37. if skin ~= nil then
  38. delay = 2000
  39. end
  40.  
  41. for wIdx = 1, #weapons do
  42. --print("giving weapon " .. weapons[wIdx] .. " with delay " .. tostring(delay))
  43. TriggerClientEvent("loadout:giveWeapon", player, weapons[wIdx], delay)
  44. end
  45. end
  46. end)
  47.  
  48. TriggerEvent("es:addCommand", "police", function(source, args, user)
  49. if #args > 1 then
  50. local arg = args[2]
  51.  
  52. if LOADOUTS[arg] then
  53. -- Do loadout
  54. local loadout = LOADOUTS[arg]
  55.  
  56. print("checking permission levels")
  57. if user.permission_level >= (loadout.permission_level or 0) then
  58. print("executing command..." .. tostring(loadout.skins) .. " " .. tostring(loadout.weapons))
  59.  
  60. TriggerEvent("loadout:doLoadout", source, arg)
  61. TriggerClientEvent("loadout:missiontext", source, "Tu as maintenant le grade de " .. loadout.name, 5000)
  62.  
  63. return
  64. end
  65.  
  66. -- They don't have permission
  67. print("no permission")
  68. TriggerClientEvent("loadout:missiontext", source, "Tu n'as pas la permission pour devenir " .. loadout.name .. " ", 5000)
  69.  
  70. else
  71. -- TODO: Other commands? e.g. /loadout help
  72. if arg == "help" then
  73. local availableCommands = {}
  74. for command in pairs(commands) do
  75. local permission = LOADOUTS[commands[command]].permission_level
  76. if user.permission_level >= (permission or 0) then
  77. table.insert(availableCommands, commands[command])
  78. end
  79. end
  80.  
  81. TriggerClientEvent('chatMessage', source, "Loadouts", {255, 255, 255}, "There are " .. #availableCommands .. " loadouts to choose from.")
  82. TriggerClientEvent("chatMessage", source, "Loadouts", {255, 255, 255}, table.concat(availableCommands, ", "))
  83. end
  84. end
  85. else
  86. TriggerClientEvent('chatMessage', source, "Loadouts", {255, 255, 255}, "Utilise /police recrue ou brigadier ou sergent pour devenir flic.")
  87. end
  88. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement