Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Loading MySQL Class
- require "resources/essentialmode/lib/MySQL"
- -- MySQL:open("IP", "databasname", "user", "password")
- MySQL:open("127.0.0.1", "gta5_gamemode_essential2", "r23fwefwfef", "fwfwefwefwf")
- function getPlayerIdentifierEasyMode(source)
- local rawIdentifiers = GetPlayerIdentifiers(source)
- if rawIdentifiers then
- for key, value in pairs(rawIdentifiers) do
- playerIdentifier = value
- end
- else
- print("IDENTIFIERS DO NOT EXIST OR WERE NOT RETIREVED PROPERLY")
- return false
- end
- return playerIdentifier -- should usually be only 1 identifier according to the wiki
- end
- function getPlayersDrug(identifier)
- -- retrieve player's drug inventory from database
- local executed_query = MySQL:executeQuery("SELECT drug FROM users WHERE identifier = '@identifier'",{['@identifier'] = identifier})
- local result = MySQL:getResults(executed_query, {'drug'})
- local playerDrug = result[1].drug
- return playerDrug
- end
- AddEventHandler("search:searchForDrugs", function(source, playerId)
- local identifier = getPlayerIdentifierEasyMode(tonumber(playerId))
- local exists = false
- local playerDrug
- if identifier ~= false then -- player exists
- -- Gives all the loaded players in the first function argument.
- TriggerEvent('es:getPlayers', function(players)
- print("#players = " .. #players)
- print("players[1].identifier = " .. players[1].identifier)
- for x=1, #players do
- if players[x].identifier == identifier then -- player exists
- exists = true
- print("players[x].identifier = " .. players[x].identifier .. "WAS MATCHED FOR SEARCH")
- else
- print("players[x].identifier = " .. players[x].identifier .. "WAS NOT MATCHED FOR SEARCH")
- end
- end
- if exists then -- player is online
- playerDrug = getPlayersDrug(identifier)
- TriggerClientEvent("search:notify", source, "^3Player ID: ^0" .. playerId)
- if playerDrug == '' then
- TriggerClientEvent("search:notify", source, "No drugs found.")
- else
- TriggerClientEvent("search:notify", source, "Found ^320 grams of concentrated cannabis^0.")
- end
- else
- TriggerClientEvent("search:notifyNoExist", source, playerId)
- end
- end)
- else
- TriggerClientEvent("search:notifyNoExist", source, playerId)
- end
- end)
- -- 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.
- TriggerEvent('es:addCommand', 'search', function(source, args, user)
- local argument = args[2] -- player id to search
- if argument == nil or type(tonumber(argument)) == nil then
- TriggerClientEvent("search:help", source)
- elseif user.job ~= "cop" and user.job ~= "sheriff" and user.job ~= "highwaypatrol" then
- TriggerClientEvent("search:failureNotJurisdiction", source)
- else -- player is a cop, so allow search and perform search with argument = player id to search
- TriggerEvent("search:searchForDrugs", source, argument)
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement