Advertisement
Guest User

search_sv.lua

a guest
May 10th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. -- Loading MySQL Class
  2. require "resources/essentialmode/lib/MySQL"
  3.  
  4. -- MySQL:open("IP", "databasname", "user", "password")
  5. MySQL:open("127.0.0.1", "gta5_gamemode_essential2", "r23fwefwfef", "fwfwefwefwf")
  6.  
  7. function getPlayerIdentifierEasyMode(source)
  8.  
  9. local rawIdentifiers = GetPlayerIdentifiers(source)
  10.  
  11. if rawIdentifiers then
  12.  
  13. for key, value in pairs(rawIdentifiers) do
  14.  
  15. playerIdentifier = value
  16.  
  17. end
  18.  
  19. else
  20.  
  21. print("IDENTIFIERS DO NOT EXIST OR WERE NOT RETIREVED PROPERLY")
  22. return false
  23.  
  24. end
  25.  
  26. return playerIdentifier -- should usually be only 1 identifier according to the wiki
  27.  
  28. end
  29.  
  30. function getPlayersDrug(identifier)
  31.  
  32. -- retrieve player's drug inventory from database
  33. local executed_query = MySQL:executeQuery("SELECT drug FROM users WHERE identifier = '@identifier'",{['@identifier'] = identifier})
  34. local result = MySQL:getResults(executed_query, {'drug'})
  35. local playerDrug = result[1].drug
  36. return playerDrug
  37.  
  38. end
  39.  
  40. AddEventHandler("search:searchForDrugs", function(source, playerId)
  41.  
  42. local identifier = getPlayerIdentifierEasyMode(tonumber(playerId))
  43. local exists = false
  44. local playerDrug
  45.  
  46. if identifier ~= false then -- player exists
  47. -- Gives all the loaded players in the first function argument.
  48. TriggerEvent('es:getPlayers', function(players)
  49.  
  50. print("#players = " .. #players)
  51. print("players[1].identifier = " .. players[1].identifier)
  52.  
  53. for x=1, #players do
  54.  
  55. if players[x].identifier == identifier then -- player exists
  56. exists = true
  57. print("players[x].identifier = " .. players[x].identifier .. "WAS MATCHED FOR SEARCH")
  58. else
  59. print("players[x].identifier = " .. players[x].identifier .. "WAS NOT MATCHED FOR SEARCH")
  60. end
  61. end
  62.  
  63. if exists then -- player is online
  64.  
  65. playerDrug = getPlayersDrug(identifier)
  66.  
  67. TriggerClientEvent("search:notify", source, "^3Player ID: ^0" .. playerId)
  68.  
  69. if playerDrug == '' then
  70.  
  71. TriggerClientEvent("search:notify", source, "No drugs found.")
  72.  
  73. else
  74.  
  75. TriggerClientEvent("search:notify", source, "Found ^320 grams of concentrated cannabis^0.")
  76.  
  77. end
  78.  
  79. else
  80.  
  81. TriggerClientEvent("search:notifyNoExist", source, playerId)
  82.  
  83. end
  84.  
  85. end)
  86.  
  87. else
  88.  
  89. TriggerClientEvent("search:notifyNoExist", source, playerId)
  90.  
  91. end
  92.  
  93. end)
  94.  
  95. -- Add a command everyone is able to run. Args is a table with all the arguments, and the user is the user object, containing all the user data.
  96. TriggerEvent('es:addCommand', 'search', function(source, args, user)
  97.  
  98. local argument = args[2] -- player id to search
  99.  
  100. if argument == nil or type(tonumber(argument)) == nil then
  101.  
  102. TriggerClientEvent("search:help", source)
  103.  
  104. elseif user.job ~= "cop" and user.job ~= "sheriff" and user.job ~= "highwaypatrol" then
  105.  
  106. TriggerClientEvent("search:failureNotJurisdiction", source)
  107.  
  108. else -- player is a cop, so allow search and perform search with argument = player id to search
  109.  
  110. TriggerEvent("search:searchForDrugs", source, argument)
  111.  
  112. end
  113.  
  114. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement