Advertisement
Guest User

Untitled

a guest
Jun 16th, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.69 KB | None | 0 0
  1. -- NO TOUCHY, IF SOMETHING IS WRONG CONTACT KANERSPS! --
  2. -- NO TOUCHY, IF SOMETHING IS WRONG CONTACT KANERSPS! --
  3. -- NO TOUCHY, IF SOMETHING IS WRONG CONTACT KANERSPS! --
  4. -- NO TOUCHY, IF SOMETHING IS WRONG CONTACT KANERSPS! --
  5.  
  6.  
  7. -- Server
  8. Users = {}
  9. commands = {}
  10. settings = {}
  11. settings.defaultSettings = {
  12. ['pvpEnabled'] = true,
  13. ['permissionDenied'] = false,
  14. ['debugInformation'] = false,
  15. ['startingCash'] = 2000,
  16. ['enableRankDecorators'] = true,
  17. ['moneyIcon'] = "$"
  18. }
  19. settings.sessionSettings = {}
  20.  
  21. AddEventHandler('playerDropped', function()
  22. if(Users[source])then
  23. TriggerEvent("es:playerDropped", Users[source])
  24.  
  25. db.updateUser(Users[source].identifier, {money = Users[source].money, Users[source].bank}, function()
  26. Users[source] = nil
  27. end)
  28. end
  29. end)
  30.  
  31. local justJoined = {}
  32.  
  33. RegisterServerEvent('es:firstJoinProper')
  34. AddEventHandler('es:firstJoinProper', function()
  35. registerUser(GetPlayerIdentifiers(source)[1], source)
  36. justJoined[source] = true
  37.  
  38. if(settings.defaultSettings.pvpEnabled)then
  39. TriggerClientEvent("es:enablePvp", source)
  40. end
  41. end)
  42.  
  43. AddEventHandler('es:setSessionSetting', function(k, v)
  44. settings.sessionSettings[k] = v
  45. end)
  46.  
  47. AddEventHandler('es:getSessionSetting', function(k, cb)
  48. cb(settings.sessionSettings[k])
  49. end)
  50.  
  51. RegisterServerEvent('playerSpawn')
  52. AddEventHandler('playerSpawn', function()
  53. if(justJoined[source])then
  54. TriggerEvent("es:firstSpawn", source, Users[source])
  55. justJoined[source] = nil
  56. end
  57. end)
  58.  
  59. AddEventHandler("es:setDefaultSettings", function(tbl)
  60. for k,v in pairs(tbl) do
  61. if(settings.defaultSettings[k] ~= nil)then
  62. settings.defaultSettings[k] = v
  63. end
  64. end
  65.  
  66. debugMsg("Default settings edited.")
  67. end)
  68.  
  69. AddEventHandler('chatMessage', function(source, n, message)
  70. if(startswith(message, "/"))then
  71. local command_args = stringsplit(message, " ")
  72.  
  73. command_args[1] = string.gsub(command_args[1], "/", "")
  74.  
  75. local command = commands[command_args[1]]
  76.  
  77. if(command)then
  78. CancelEvent()
  79. if(command.perm > 0)then
  80. if(Users[source].permission_level >= command.perm or Users[source].group:canTarget(command.group))then
  81. command.cmd(source, command_args, Users[source])
  82. TriggerEvent("es:adminCommandRan", source, command_args, Users[source])
  83. else
  84. command.callbackfailed(source, command_args, Users[source])
  85. TriggerEvent("es:adminCommandFailed", source, command_args, Users[source])
  86.  
  87. if(type(settings.defaultSettings.permissionDenied) == "string" and not WasEventCanceled())then
  88. TriggerClientEvent('chatMessage', source, "", {0,0,0}, defaultSettings.permissionDenied)
  89. end
  90.  
  91. debugMsg("Non admin (" .. GetPlayerName(source) .. ") attempted to run admin command: " .. command_args[1])
  92. end
  93. else
  94. command.cmd(source, command_args, Users[source])
  95. TriggerEvent("es:userCommandRan", source, command_args, Users[source])
  96. end
  97.  
  98. TriggerEvent("es:commandRan", source, command_args, Users[source])
  99. else
  100. TriggerEvent('es:invalidCommandHandler', source, command_args, Users[source])
  101.  
  102. if WasEventCanceled() then
  103. CancelEvent()
  104. end
  105. end
  106. else
  107. TriggerEvent('es:chatMessage', source, message, Users[source])
  108. end
  109. end)
  110.  
  111. AddEventHandler('es:addCommand', function(command, callback)
  112. commands[command] = {}
  113. commands[command].perm = 0
  114. commands[command].group = "user"
  115. commands[command].cmd = callback
  116.  
  117. debugMsg("Command added: " .. command)
  118. end)
  119.  
  120. AddEventHandler('es:addAdminCommand', function(command, perm, callback, callbackfailed)
  121. commands[command] = {}
  122. commands[command].perm = perm
  123. commands[command].group = "superadmin"
  124. commands[command].cmd = callback
  125. commands[command].callbackfailed = callbackfailed
  126.  
  127. debugMsg("Admin command added: " .. command .. ", requires permission level: " .. perm)
  128. end)
  129.  
  130. AddEventHandler('es:addGroupCommand', function(command, group, callback, callbackfailed)
  131. commands[command] = {}
  132. commands[command].perm = math.maxinteger
  133. commands[command].group = group
  134. commands[command].cmd = callback
  135. commands[command].callbackfailed = callbackfailed
  136.  
  137. debugMsg("Group command added: " .. command .. ", requires group: " .. group)
  138. end)
  139.  
  140. RegisterServerEvent('es:updatePositions')
  141. AddEventHandler('es:updatePositions', function(x, y, z)
  142. if(Users[source])then
  143. Users[source]:setCoords(x, y, z)
  144. end
  145. end)
  146.  
  147. -- Info command
  148. commands['info'] = {}
  149. commands['info'].perm = 0
  150. commands['info'].cmd = function(source, args, user)
  151. TriggerClientEvent('chatMessage', source, 'SYSTEM', {255, 0, 0}, "^2[^3EssentialMode^2]^0 Version: ^23.2.3")
  152. TriggerClientEvent('chatMessage', source, 'SYSTEM', {255, 0, 0}, "^2[^3EssentialMode^2]^0 Commands loaded: ^2" .. (returnIndexesInTable(commands) - 1))
  153. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement