mirror of
https://github.com/qbcore-fivem/qb-core.git
synced 2026-08-29 01:08:57 +00:00
easier file management
This commit is contained in:
@@ -0,0 +1,162 @@
|
||||
QBCore.Commands = {}
|
||||
QBCore.Commands.List = {}
|
||||
|
||||
QBCore.Commands.Add = function(name, help, arguments, argsrequired, callback, permission) -- [name] = command name (ex. /givemoney), [help] = help text, [arguments] = arguments that need to be passed (ex. {{name="id", help="ID of a player"}, {name="amount", help="amount of money"}}), [argsrequired] = set arguments required (true or false), [callback] = function(source, args) callback, [permission] = rank or job of a player
|
||||
QBCore.Commands.List[name:lower()] = {
|
||||
name = name:lower(),
|
||||
permission = permission ~= nil and permission:lower() or "user",
|
||||
help = help,
|
||||
arguments = arguments,
|
||||
argsrequired = argsrequired,
|
||||
callback = callback,
|
||||
}
|
||||
end
|
||||
|
||||
QBCore.Commands.Refresh = function(source)
|
||||
local Player = QBCore.Functions.GetPlayer(tonumber(source))
|
||||
if Player ~= nil then
|
||||
for command, info in pairs(QBCore.Commands.List) do
|
||||
if QBCore.Functions.HasPermission(source, "god") or QBCore.Functions.HasPermission(source, QBCore.Commands.List[command].permission) then
|
||||
TriggerClientEvent('chat:addSuggestion', source, "/"..command, info.help, info.arguments)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
QBCore.Commands.Add("tp", "Teleport to a player or location", {{name="id/x", help="ID of player or X position"}, {name="y", help="Y position"}, {name="z", help="Z position"}}, false, function(source, args)
|
||||
if (args[1] ~= nil and (args[2] == nil and args[3] == nil)) then
|
||||
-- tp to player
|
||||
local Player = QBCore.Functions.GetPlayer(tonumber(args[1]))
|
||||
if Player ~= nil then
|
||||
TriggerClientEvent('QBCore:Command:TeleportToPlayer', source, Player.PlayerData.source)
|
||||
else
|
||||
TriggerClientEvent('QBCore:Notify', source, "Player is not online!", "error")
|
||||
end
|
||||
else
|
||||
-- tp to location
|
||||
if args[1] ~= nil and args[2] ~= nil and args[3] ~= nil then
|
||||
local x = tonumber(args[1])
|
||||
local y = tonumber(args[2])
|
||||
local z = tonumber(args[3])
|
||||
TriggerClientEvent('QBCore:Command:TeleportToCoords', source, x, y, z)
|
||||
else
|
||||
TriggerClientEvent('QBCore:Notify', source, "Not every argument has been entered (x, y, z)", "error")
|
||||
end
|
||||
end
|
||||
end, "admin")
|
||||
|
||||
QBCore.Commands.Add("addpermission", "Grant permissions to someone (god/admin)", {{name="id", help="ID of player"}, {name="permission", help="Permission level"}}, true, function(source, args)
|
||||
local Player = QBCore.Functions.GetPlayer(tonumber(args[1]))
|
||||
local permission = tostring(args[2]):lower()
|
||||
if Player ~= nil then
|
||||
QBCore.Functions.AddPermission(Player.PlayerData.source, permission)
|
||||
else
|
||||
TriggerClientEvent('QBCore:Notify', source, "Player is not online!", "error")
|
||||
end
|
||||
end, "god")
|
||||
|
||||
QBCore.Commands.Add("removepermission", "Remove permissions from someone", {{name="id", help="ID of player"}}, true, function(source, args)
|
||||
local Player = QBCore.Functions.GetPlayer(tonumber(args[1]))
|
||||
if Player ~= nil then
|
||||
QBCore.Functions.RemovePermission(Player.PlayerData.source)
|
||||
else
|
||||
TriggerClientEvent('QBCore:Notify', source, "Player is not online!", "error")
|
||||
end
|
||||
end, "god")
|
||||
|
||||
QBCore.Commands.Add("sv", "Spawn a vehicle", {{name="model", help="Model name of the vehicle"}}, true, function(source, args)
|
||||
TriggerClientEvent('QBCore:Command:SpawnVehicle', source, args[1])
|
||||
end, "admin")
|
||||
|
||||
QBCore.Commands.Add("debug", "Turn debug mode on / off", {}, false, function(source, args)
|
||||
TriggerClientEvent('koil-debug:toggle', source)
|
||||
end, "admin")
|
||||
|
||||
QBCore.Commands.Add("dv", "Despawn a vehicle", {}, false, function(source, args)
|
||||
TriggerClientEvent('QBCore:Command:DeleteVehicle', source)
|
||||
end, "admin")
|
||||
|
||||
QBCore.Commands.Add("tpm", "Teleport to your waypoint", {}, false, function(source, args)
|
||||
TriggerClientEvent('QBCore:Command:GoToMarker', source)
|
||||
end, "admin")
|
||||
|
||||
QBCore.Commands.Add("givemoney", "Give money to a player", {{name="id", help="Player ID"},{name="moneytype", help="Type of money (cash, bank, crypto)"}, {name="amount", help="Amount of money"}}, true, function(source, args)
|
||||
local Player = QBCore.Functions.GetPlayer(tonumber(args[1]))
|
||||
if Player ~= nil then
|
||||
Player.Functions.AddMoney(tostring(args[2]), tonumber(args[3]))
|
||||
else
|
||||
TriggerClientEvent('QBCore:Notify', source, "Player is not online!", "error")
|
||||
end
|
||||
end, "admin")
|
||||
|
||||
QBCore.Commands.Add("setmoney", "set a players money amount", {{name="id", help="Player ID"},{name="moneytype", help="Type of money (cash, bank, crypto)"}, {name="amount", help="Amount of money"}}, true, function(source, args)
|
||||
local Player = QBCore.Functions.GetPlayer(tonumber(args[1]))
|
||||
if Player ~= nil then
|
||||
Player.Functions.SetMoney(tostring(args[2]), tonumber(args[3]))
|
||||
else
|
||||
TriggerClientEvent('QBCore:Notify', source, "Player is not online!", "error")
|
||||
end
|
||||
end, "admin")
|
||||
|
||||
QBCore.Commands.Add("setjob", "Assign a job to a player", {{name="id", help="Speler ID"}, {name="job", help="Job name"}}, true, function(source, args)
|
||||
local Player = QBCore.Functions.GetPlayer(tonumber(args[1]))
|
||||
if Player ~= nil then
|
||||
Player.Functions.SetJob(tostring(args[2]))
|
||||
else
|
||||
TriggerClientEvent('QBCore:Notify', source, "Player is not online!", "error")
|
||||
end
|
||||
end, "admin")
|
||||
|
||||
QBCore.Commands.Add("job", "See what job you have", {}, false, function(source, args)
|
||||
local Player = QBCore.Functions.GetPlayer(source)
|
||||
TriggerClientEvent('QBCore:Notify', source, "Job: "..Player.PlayerData.job.label)
|
||||
end)
|
||||
|
||||
QBCore.Commands.Add("setgang", "Assign a player to a gang", {{name="id", help="Player ID"}, {name="job", help="Name of a gang"}}, true, function(source, args)
|
||||
local Player = QBCore.Functions.GetPlayer(tonumber(args[1]))
|
||||
if Player ~= nil then
|
||||
Player.Functions.SetGang(tostring(args[2]))
|
||||
else
|
||||
TriggerClientEvent('QBCore:Notify', source, "Player is not online!", "error")
|
||||
end
|
||||
end, "admin")
|
||||
|
||||
QBCore.Commands.Add("gang", "See what gang you're in", {}, false, function(source, args)
|
||||
local Player = QBCore.Functions.GetPlayer(source)
|
||||
|
||||
if Player.PlayerData.gang.name ~= "geen" then
|
||||
TriggerClientEvent('QBCore:Notify', source, "Gang: "..Player.PlayerData.gang.label)
|
||||
else
|
||||
TriggerClientEvent('QBCore:Notify', source, "You're not in a gang!", "error")
|
||||
end
|
||||
end)
|
||||
|
||||
QBCore.Commands.Add("testnotify", "test notify", {{name="text", help="Tekst enzo"}}, true, function(source, args)
|
||||
TriggerClientEvent('QBCore:Notify', source, table.concat(args, " "), "success")
|
||||
end, "god")
|
||||
|
||||
QBCore.Commands.Add("clearinv", "Clear the inventory of a player", {{name="id", help="Player ID"}}, false, function(source, args)
|
||||
local playerId = args[1] ~= nil and args[1] or source
|
||||
local Player = QBCore.Functions.GetPlayer(tonumber(playerId))
|
||||
if Player ~= nil then
|
||||
Player.Functions.ClearInventory()
|
||||
else
|
||||
TriggerClientEvent('QBCore:Notify', source, "Player is not online!", "error")
|
||||
end
|
||||
end, "admin")
|
||||
|
||||
QBCore.Commands.Add("ooc", "Out of Character message", {}, false, function(source, args)
|
||||
local message = table.concat(args, " ")
|
||||
TriggerClientEvent("QBCore:Client:LocalOutOfCharacter", -1, source, GetPlayerName(source), message)
|
||||
local Players = QBCore.Functions.GetPlayers()
|
||||
local Player = QBCore.Functions.GetPlayer(source)
|
||||
|
||||
for k, v in pairs(QBCore.Functions.GetPlayers()) do
|
||||
if QBCore.Functions.HasPermission(v, "admin") then
|
||||
if QBCore.Functions.IsOptin(v) then
|
||||
TriggerClientEvent('chatMessage', v, "OOC " .. GetPlayerName(source), "normal", message)
|
||||
TriggerEvent("qb-log:server:CreateLog", "ooc", "OOC", "white", "**"..GetPlayerName(source).."** (CitizenID: "..Player.PlayerData.citizenid.." | ID: "..source..") **Message:** " ..message, false)
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
@@ -0,0 +1,36 @@
|
||||
RegisterServerEvent('QBCore:DebugSomething')
|
||||
AddEventHandler('QBCore:DebugSomething', function(resource, obj, depth)
|
||||
print("\x1b[4m\x1b[36m["..resource..":DEBUG]\x1b[0m")
|
||||
if type(obj) == "string" then
|
||||
print(string.format("%q", obj))
|
||||
elseif type(obj) == "table" then
|
||||
local str = "{"
|
||||
for k, v in pairs(obj) do
|
||||
if type(v) == "table" then
|
||||
for ik, iv in pairs(v) do
|
||||
str = str.."\n["..k.."] -> ["..ik.."] -> "..tostring(iv)
|
||||
end
|
||||
else
|
||||
str = str.."\n["..k.."] -> "..tostring(v)
|
||||
end
|
||||
end
|
||||
|
||||
print(str.."\n}")
|
||||
else
|
||||
local success, value = pcall(function() return tostring(obj) end)
|
||||
print((success and value or "<!!error in __tostring metamethod!!>"))
|
||||
end
|
||||
print("\x1b[4m\x1b[36mEND OF DEBUG\x1b[0m")
|
||||
end)
|
||||
|
||||
QBCore.Debug = function(resource, obj, depth)
|
||||
TriggerEvent('QBCore:DebugSomething', resource, obj, depth)
|
||||
end
|
||||
|
||||
QBCore.ShowError = function(resource, msg)
|
||||
print("\x1b[31m["..resource..":ERROR]\x1b[0m "..msg)
|
||||
end
|
||||
|
||||
QBCore.ShowSuccess = function(resource, msg)
|
||||
print("\x1b[32m["..resource..":LOG]\x1b[0m "..msg)
|
||||
end
|
||||
@@ -0,0 +1,290 @@
|
||||
-- Player joined
|
||||
RegisterServerEvent("QBCore:PlayerJoined")
|
||||
AddEventHandler('QBCore:PlayerJoined', function()
|
||||
local src = source
|
||||
end)
|
||||
|
||||
AddEventHandler('playerDropped', function(reason)
|
||||
local src = source
|
||||
print("Dropped: "..GetPlayerName(src))
|
||||
TriggerEvent("qb-log:server:CreateLog", "joinleave", "Dropped", "red", "**".. GetPlayerName(src) .. "** ("..GetPlayerIdentifiers(src)[1]..") left..")
|
||||
TriggerEvent("qb-log:server:sendLog", GetPlayerIdentifiers(src)[1], "joined", {})
|
||||
if reason ~= "Reconnecting" and src > 60000 then return false end
|
||||
if(src==nil or (QBCore.Players[src] == nil)) then return false end
|
||||
QBCore.Players[src].Functions.Save()
|
||||
QBCore.Players[src] = nil
|
||||
end)
|
||||
|
||||
-- Checking everything before joining
|
||||
AddEventHandler('playerConnecting', function(playerName, setKickReason, deferrals)
|
||||
deferrals.defer()
|
||||
local src = source
|
||||
deferrals.update("\nChecking name...")
|
||||
local name = GetPlayerName(src)
|
||||
if name == nil then
|
||||
QBCore.Functions.Kick(src, 'Please don\'t use a blank Steam username.', setKickReason, deferrals)
|
||||
CancelEvent()
|
||||
return false
|
||||
end
|
||||
if(string.match(name, "[*%%'=`\"]")) then
|
||||
QBCore.Functions.Kick(src, 'You have a character in your username ('..string.match(name, "[*%%'=`\"]")..') that is not allowed.\nPlease remove this out of your Steam username.', setKickReason, deferrals)
|
||||
CancelEvent()
|
||||
return false
|
||||
end
|
||||
if (string.match(name, "drop") or string.match(name, "table") or string.match(name, "database")) then
|
||||
QBCore.Functions.Kick(src, 'Your username contains a word (drop/table/database) that is not allowed.\nPlease change your Steam username.', setKickReason, deferrals)
|
||||
CancelEvent()
|
||||
return false
|
||||
end
|
||||
deferrals.update("\nChecking identifiers...")
|
||||
local identifiers = GetPlayerIdentifiers(src)
|
||||
local steamid = identifiers[1]
|
||||
local license = identifiers[2]
|
||||
if (QBConfig.IdentifierType == "steam" and (steamid:sub(1,6) == "steam:") == false) then
|
||||
QBCore.Functions.Kick(src, 'You need to open Steam to play.', setKickReason, deferrals)
|
||||
CancelEvent()
|
||||
return false
|
||||
elseif (QBConfig.IdentifierType == "license" and (steamid:sub(1,6) == "license:") == false) then
|
||||
QBCore.Functions.Kick(src, 'No Social Club license found.', setKickReason, deferrals)
|
||||
CancelEvent()
|
||||
return false
|
||||
end
|
||||
deferrals.update("\nChecking ban status...")
|
||||
local isBanned, Reason = QBCore.Functions.IsPlayerBanned(src)
|
||||
if(isBanned) then
|
||||
QBCore.Functions.Kick(src, Reason, setKickReason, deferrals)
|
||||
CancelEvent()
|
||||
return false
|
||||
end
|
||||
deferrals.update("\nChecking whitelist status...")
|
||||
if(not QBCore.Functions.IsWhitelisted(src)) then
|
||||
QBCore.Functions.Kick(src, 'You aren\'t whitelisted.', setKickReason, deferrals)
|
||||
CancelEvent()
|
||||
return false
|
||||
end
|
||||
deferrals.update("\nChecking server status...")
|
||||
if(QBCore.Config.Server.closed and not IsPlayerAceAllowed(src, "qbadmin.join")) then
|
||||
QBCore.Functions.Kick(_source, 'the server is closed:\n'..QBCore.Config.Server.closedReason, setKickReason, deferrals)
|
||||
CancelEvent()
|
||||
return false
|
||||
end
|
||||
TriggerEvent("qb-log:server:CreateLog", "joinleave", "Queue", "orange", "**"..name .. "** ("..json.encode(GetPlayerIdentifiers(src))..") in queue..")
|
||||
TriggerEvent("qb-log:server:sendLog", GetPlayerIdentifiers(src)[1], "left", {})
|
||||
TriggerEvent("connectqueue:playerConnect", src, setKickReason, deferrals)
|
||||
end)
|
||||
|
||||
RegisterServerEvent("QBCore:server:CloseServer")
|
||||
AddEventHandler('QBCore:server:CloseServer', function(reason)
|
||||
local src = source
|
||||
local Player = QBCore.Functions.GetPlayer(src)
|
||||
|
||||
if QBCore.Functions.HasPermission(source, "admin") or QBCore.Functions.HasPermission(source, "god") then
|
||||
local reason = reason ~= nil and reason or "No reason specified..."
|
||||
QBCore.Config.Server.closed = true
|
||||
QBCore.Config.Server.closedReason = reason
|
||||
TriggerClientEvent("qbadmin:client:SetServerStatus", -1, true)
|
||||
else
|
||||
QBCore.Functions.Kick(src, "You don't have permissions for this..", nil, nil)
|
||||
end
|
||||
end)
|
||||
|
||||
RegisterServerEvent("QBCore:server:OpenServer")
|
||||
AddEventHandler('QBCore:server:OpenServer', function()
|
||||
local src = source
|
||||
local Player = QBCore.Functions.GetPlayer(src)
|
||||
if QBCore.Functions.HasPermission(source, "admin") or QBCore.Functions.HasPermission(source, "god") then
|
||||
QBCore.Config.Server.closed = false
|
||||
TriggerClientEvent("qbadmin:client:SetServerStatus", -1, false)
|
||||
else
|
||||
QBCore.Functions.Kick(src, "You don't have permissions for this..", nil, nil)
|
||||
end
|
||||
end)
|
||||
|
||||
RegisterServerEvent("QBCore:UpdatePlayer")
|
||||
AddEventHandler('QBCore:UpdatePlayer', function(data)
|
||||
local src = source
|
||||
local Player = QBCore.Functions.GetPlayer(src)
|
||||
|
||||
if Player ~= nil then
|
||||
Player.PlayerData.position = data.position
|
||||
|
||||
local newHunger = Player.PlayerData.metadata["hunger"] - 4.2
|
||||
local newThirst = Player.PlayerData.metadata["thirst"] - 3.8
|
||||
if newHunger <= 0 then newHunger = 0 end
|
||||
if newThirst <= 0 then newThirst = 0 end
|
||||
Player.Functions.SetMetaData("thirst", newThirst)
|
||||
Player.Functions.SetMetaData("hunger", newHunger)
|
||||
|
||||
Player.Functions.AddMoney("bank", Player.PlayerData.job.payment)
|
||||
TriggerClientEvent('QBCore:Notify', src, "You received your paycheck of €"..Player.PlayerData.job.payment)
|
||||
TriggerClientEvent("hud:client:UpdateNeeds", src, newHunger, newThirst)
|
||||
|
||||
Player.Functions.Save()
|
||||
end
|
||||
end)
|
||||
|
||||
RegisterServerEvent("QBCore:UpdatePlayerPosition")
|
||||
AddEventHandler("QBCore:UpdatePlayerPosition", function(position)
|
||||
local src = source
|
||||
local Player = QBCore.Functions.GetPlayer(src)
|
||||
if Player ~= nil then
|
||||
Player.PlayerData.position = position
|
||||
end
|
||||
end)
|
||||
|
||||
RegisterServerEvent("QBCore:Server:TriggerCallback")
|
||||
AddEventHandler('QBCore:Server:TriggerCallback', function(name, ...)
|
||||
local src = source
|
||||
QBCore.Functions.TriggerCallback(name, src, function(...)
|
||||
TriggerClientEvent("QBCore:Client:TriggerCallback", src, name, ...)
|
||||
end, ...)
|
||||
end)
|
||||
|
||||
RegisterServerEvent("QBCore:Server:UseItem")
|
||||
AddEventHandler('QBCore:Server:UseItem', function(item)
|
||||
local src = source
|
||||
local Player = QBCore.Functions.GetPlayer(src)
|
||||
if item ~= nil and item.amount > 0 then
|
||||
if QBCore.Functions.CanUseItem(item.name) then
|
||||
QBCore.Functions.UseItem(src, item)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
RegisterServerEvent("QBCore:Server:RemoveItem")
|
||||
AddEventHandler('QBCore:Server:RemoveItem', function(itemName, amount, slot)
|
||||
local src = source
|
||||
local Player = QBCore.Functions.GetPlayer(src)
|
||||
Player.Functions.RemoveItem(itemName, amount, slot)
|
||||
end)
|
||||
|
||||
RegisterServerEvent("QBCore:Server:AddItem")
|
||||
AddEventHandler('QBCore:Server:AddItem', function(itemName, amount, slot, info)
|
||||
local src = source
|
||||
local Player = QBCore.Functions.GetPlayer(src)
|
||||
Player.Functions.AddItem(itemName, amount, slot, info)
|
||||
end)
|
||||
|
||||
RegisterServerEvent('QBCore:Server:SetMetaData')
|
||||
AddEventHandler('QBCore:Server:SetMetaData', function(meta, data)
|
||||
local src = source
|
||||
local Player = QBCore.Functions.GetPlayer(src)
|
||||
if meta == "hunger" or meta == "thirst" then
|
||||
if data > 100 then
|
||||
data = 100
|
||||
end
|
||||
end
|
||||
if Player ~= nil then
|
||||
Player.Functions.SetMetaData(meta, data)
|
||||
end
|
||||
TriggerClientEvent("hud:client:UpdateNeeds", src, Player.PlayerData.metadata["hunger"], Player.PlayerData.metadata["thirst"])
|
||||
end)
|
||||
|
||||
AddEventHandler('chatMessage', function(source, n, message)
|
||||
if string.sub(message, 1, 1) == "/" then
|
||||
local args = QBCore.Shared.SplitStr(message, " ")
|
||||
local command = string.gsub(args[1]:lower(), "/", "")
|
||||
CancelEvent()
|
||||
if QBCore.Commands.List[command] ~= nil then
|
||||
local Player = QBCore.Functions.GetPlayer(tonumber(source))
|
||||
if Player ~= nil then
|
||||
table.remove(args, 1)
|
||||
if (QBCore.Functions.HasPermission(source, "god") or QBCore.Functions.HasPermission(source, QBCore.Commands.List[command].permission)) then
|
||||
if (QBCore.Commands.List[command].argsrequired and #QBCore.Commands.List[command].arguments ~= 0 and args[#QBCore.Commands.List[command].arguments] == nil) then
|
||||
TriggerClientEvent('QBCore:Notify', source, "All arguments must be filled out!", "error")
|
||||
local agus = ""
|
||||
for name, help in pairs(QBCore.Commands.List[command].arguments) do
|
||||
agus = agus .. " ["..help.name.."]"
|
||||
end
|
||||
TriggerClientEvent('chatMessage', source, "/"..command, false, agus)
|
||||
else
|
||||
QBCore.Commands.List[command].callback(source, args)
|
||||
end
|
||||
else
|
||||
TriggerClientEvent('QBCore:Notify', source, "No Access To This Command", "error")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
RegisterServerEvent('QBCore:CallCommand')
|
||||
AddEventHandler('QBCore:CallCommand', function(command, args)
|
||||
if QBCore.Commands.List[command] ~= nil then
|
||||
local Player = QBCore.Functions.GetPlayer(tonumber(source))
|
||||
if Player ~= nil then
|
||||
if (QBCore.Functions.HasPermission(source, "god")) or (QBCore.Functions.HasPermission(source, QBCore.Commands.List[command].permission)) or (QBCore.Commands.List[command].permission == Player.PlayerData.job.name) then
|
||||
if (QBCore.Commands.List[command].argsrequired and #QBCore.Commands.List[command].arguments ~= 0 and args[#QBCore.Commands.List[command].arguments] == nil) then
|
||||
TriggerClientEvent('QBCore:Notify', source, "All arguments must be filled out!", "error")
|
||||
local agus = ""
|
||||
for name, help in pairs(QBCore.Commands.List[command].arguments) do
|
||||
agus = agus .. " ["..help.name.."]"
|
||||
end
|
||||
TriggerClientEvent('chatMessage', source, "/"..command, false, agus)
|
||||
else
|
||||
QBCore.Commands.List[command].callback(source, args)
|
||||
end
|
||||
else
|
||||
TriggerClientEvent('QBCore:Notify', source, "No Access To This Command", "error")
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
RegisterServerEvent("QBCore:AddCommand")
|
||||
AddEventHandler('QBCore:AddCommand', function(name, help, arguments, argsrequired, callback, persmission)
|
||||
QBCore.Commands.Add(name, help, arguments, argsrequired, callback, persmission)
|
||||
end)
|
||||
|
||||
RegisterServerEvent("QBCore:ToggleDuty")
|
||||
AddEventHandler('QBCore:ToggleDuty', function()
|
||||
local src = source
|
||||
local Player = QBCore.Functions.GetPlayer(src)
|
||||
if Player.PlayerData.job.onduty then
|
||||
Player.Functions.SetJobDuty(false)
|
||||
TriggerClientEvent('QBCore:Notify', src, "You are now off duty!")
|
||||
else
|
||||
Player.Functions.SetJobDuty(true)
|
||||
TriggerClientEvent('QBCore:Notify', src, "You are now on duty!")
|
||||
end
|
||||
TriggerClientEvent("QBCore:Client:SetDuty", src, Player.PlayerData.job.onduty)
|
||||
end)
|
||||
|
||||
Citizen.CreateThread(function()
|
||||
QBCore.Functions.ExecuteSql(true, "SELECT * FROM `permissions`", function(result)
|
||||
if result[1] ~= nil then
|
||||
for k, v in pairs(result) do
|
||||
QBCore.Config.Server.PermissionList[v.steam] = {
|
||||
steam = v.steam,
|
||||
license = v.license,
|
||||
permission = v.permission,
|
||||
optin = true,
|
||||
}
|
||||
end
|
||||
end
|
||||
end)
|
||||
end)
|
||||
|
||||
QBCore.Functions.CreateCallback('QBCore:HasItem', function(source, cb, itemName)
|
||||
local retval = false
|
||||
local Player = QBCore.Functions.GetPlayer(source)
|
||||
if Player ~= nil then
|
||||
if Player.Functions.GetItemByName(itemName) ~= nil then
|
||||
retval = true
|
||||
end
|
||||
end
|
||||
|
||||
cb(retval)
|
||||
end)
|
||||
|
||||
RegisterServerEvent('QBCore:Command:CheckOwnedVehicle')
|
||||
AddEventHandler('QBCore:Command:CheckOwnedVehicle', function(VehiclePlate)
|
||||
if VehiclePlate ~= nil then
|
||||
QBCore.Functions.ExecuteSql(false, "SELECT * FROM `player_vehicles` WHERE `plate` = '"..VehiclePlate.."'", function(result)
|
||||
if result[1] ~= nil then
|
||||
QBCore.Functions.ExecuteSql(false, "UPDATE `player_vehicles` SET `state` = '1' WHERE `citizenid` = '"..result[1].citizenid.."'")
|
||||
TriggerEvent('qb-garages:server:RemoveVehicle', result[1].citizenid, VehiclePlate)
|
||||
end
|
||||
end)
|
||||
end
|
||||
end)
|
||||
@@ -0,0 +1,247 @@
|
||||
QBCore.Functions = {}
|
||||
|
||||
QBCore.Functions.ExecuteSql = function(wait, query, cb)
|
||||
local rtndata = {}
|
||||
local waiting = true
|
||||
exports['ghmattimysql']:execute(query, {}, function(data)
|
||||
if cb ~= nil and wait == false then
|
||||
cb(data)
|
||||
end
|
||||
rtndata = data
|
||||
waiting = false
|
||||
end)
|
||||
if wait then
|
||||
while waiting do
|
||||
Citizen.Wait(5)
|
||||
end
|
||||
if cb ~= nil and wait == true then
|
||||
cb(rtndata)
|
||||
end
|
||||
end
|
||||
return rtndata
|
||||
end
|
||||
|
||||
QBCore.Functions.GetIdentifier = function(source, idtype)
|
||||
local idtype = idtype ~=nil and idtype or QBConfig.IdentifierType
|
||||
for _, identifier in pairs(GetPlayerIdentifiers(source)) do
|
||||
if string.find(identifier, idtype) then
|
||||
return identifier
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
QBCore.Functions.GetSource = function(identifier)
|
||||
for src, player in pairs(QBCore.Players) do
|
||||
local idens = GetPlayerIdentifiers(src)
|
||||
for _, id in pairs(idens) do
|
||||
if identifier == id then
|
||||
return src
|
||||
end
|
||||
end
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
||||
QBCore.Functions.GetPlayer = function(source)
|
||||
if type(source) == "number" then
|
||||
return QBCore.Players[source]
|
||||
else
|
||||
return QBCore.Players[QBCore.Functions.GetSource(source)]
|
||||
end
|
||||
end
|
||||
|
||||
QBCore.Functions.GetPlayerByCitizenId = function(citizenid)
|
||||
for src, player in pairs(QBCore.Players) do
|
||||
local cid = citizenid
|
||||
if QBCore.Players[src].PlayerData.citizenid == cid then
|
||||
return QBCore.Players[src]
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
QBCore.Functions.GetPlayerByPhone = function(number)
|
||||
for src, player in pairs(QBCore.Players) do
|
||||
local cid = citizenid
|
||||
if QBCore.Players[src].PlayerData.charinfo.phone == number then
|
||||
return QBCore.Players[src]
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
QBCore.Functions.GetPlayers = function()
|
||||
local sources = {}
|
||||
for k, v in pairs(QBCore.Players) do
|
||||
table.insert(sources, k)
|
||||
end
|
||||
return sources
|
||||
end
|
||||
|
||||
QBCore.Functions.CreateCallback = function(name, cb)
|
||||
QBCore.ServerCallbacks[name] = cb
|
||||
end
|
||||
|
||||
QBCore.Functions.TriggerCallback = function(name, source, cb, ...)
|
||||
if QBCore.ServerCallbacks[name] ~= nil then
|
||||
QBCore.ServerCallbacks[name](source, cb, ...)
|
||||
end
|
||||
end
|
||||
|
||||
QBCore.Functions.CreateUseableItem = function(item, cb)
|
||||
QBCore.UseableItems[item] = cb
|
||||
end
|
||||
|
||||
QBCore.Functions.CanUseItem = function(item)
|
||||
return QBCore.UseableItems[item] ~= nil
|
||||
end
|
||||
|
||||
QBCore.Functions.UseItem = function(source, item)
|
||||
QBCore.UseableItems[item.name](source, item)
|
||||
end
|
||||
|
||||
QBCore.Functions.Kick = function(source, reason, setKickReason, deferrals)
|
||||
local src = source
|
||||
reason = "\n"..reason.."\n🔸 Check our Discord for further information: "..QBCore.Config.Server.discord
|
||||
if(setKickReason ~=nil) then
|
||||
setKickReason(reason)
|
||||
end
|
||||
Citizen.CreateThread(function()
|
||||
if(deferrals ~= nil)then
|
||||
deferrals.update(reason)
|
||||
Citizen.Wait(2500)
|
||||
end
|
||||
if src ~= nil then
|
||||
DropPlayer(src, reason)
|
||||
end
|
||||
local i = 0
|
||||
while (i <= 4) do
|
||||
i = i + 1
|
||||
while true do
|
||||
if src ~= nil then
|
||||
if(GetPlayerPing(src) >= 0) then
|
||||
break
|
||||
end
|
||||
Citizen.Wait(100)
|
||||
Citizen.CreateThread(function()
|
||||
DropPlayer(src, reason)
|
||||
end)
|
||||
end
|
||||
end
|
||||
Citizen.Wait(5000)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
QBCore.Functions.IsWhitelisted = function(source)
|
||||
local identifiers = GetPlayerIdentifiers(source)
|
||||
local rtn = false
|
||||
if (QBCore.Config.Server.whitelist) then
|
||||
QBCore.Functions.ExecuteSql(true, "SELECT * FROM `whitelist` WHERE `"..QBCore.Config.IdentifierType.."` = '".. QBCore.Functions.GetIdentifier(source).."'", function(result)
|
||||
local data = result[1]
|
||||
if data ~= nil then
|
||||
for _, id in pairs(identifiers) do
|
||||
if data.steam == id or data.license == id then
|
||||
rtn = true
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
else
|
||||
rtn = true
|
||||
end
|
||||
return rtn
|
||||
end
|
||||
|
||||
QBCore.Functions.AddPermission = function(source, permission)
|
||||
local Player = QBCore.Functions.GetPlayer(source)
|
||||
if Player ~= nil then
|
||||
QBCore.Config.Server.PermissionList[GetPlayerIdentifiers(source)[1]] = {
|
||||
steam = GetPlayerIdentifiers(source)[1],
|
||||
license = GetPlayerIdentifiers(source)[2],
|
||||
permission = permission:lower(),
|
||||
}
|
||||
QBCore.Functions.ExecuteSql(true, "DELETE FROM `permissions` WHERE `steam` = '"..GetPlayerIdentifiers(source)[1].."'")
|
||||
QBCore.Functions.ExecuteSql(true, "INSERT INTO `permissions` (`name`, `steam`, `license`, `permission`) VALUES ('"..GetPlayerName(source).."', '"..GetPlayerIdentifiers(source)[1].."', '"..GetPlayerIdentifiers(source)[2].."', '"..permission:lower().."')")
|
||||
Player.Functions.UpdatePlayerData()
|
||||
TriggerClientEvent('QBCore:Client:OnPermissionUpdate', source, permission)
|
||||
end
|
||||
end
|
||||
|
||||
QBCore.Functions.RemovePermission = function(source)
|
||||
local Player = QBCore.Functions.GetPlayer(source)
|
||||
if Player ~= nil then
|
||||
QBCore.Config.Server.PermissionList[GetPlayerIdentifiers(source)[1]] = nil
|
||||
QBCore.Functions.ExecuteSql(true, "DELETE FROM `permissions` WHERE `steam` = '"..GetPlayerIdentifiers(source)[1].."'")
|
||||
Player.Functions.UpdatePlayerData()
|
||||
end
|
||||
end
|
||||
|
||||
QBCore.Functions.HasPermission = function(source, permission)
|
||||
local retval = false
|
||||
local steamid = GetPlayerIdentifiers(source)[1]
|
||||
local licenseid = GetPlayerIdentifiers(source)[2]
|
||||
local permission = tostring(permission:lower())
|
||||
if permission == "user" then
|
||||
retval = true
|
||||
else
|
||||
if QBCore.Config.Server.PermissionList[steamid] ~= nil then
|
||||
if QBCore.Config.Server.PermissionList[steamid].steam == steamid and QBCore.Config.Server.PermissionList[steamid].license == licenseid then
|
||||
if QBCore.Config.Server.PermissionList[steamid].permission == permission or QBCore.Config.Server.PermissionList[steamid].permission == "god" then
|
||||
retval = true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return retval
|
||||
end
|
||||
|
||||
QBCore.Functions.GetPermission = function(source)
|
||||
local retval = "user"
|
||||
Player = QBCore.Functions.GetPlayer(source)
|
||||
local steamid = GetPlayerIdentifiers(source)[1]
|
||||
local licenseid = GetPlayerIdentifiers(source)[2]
|
||||
if Player ~= nil then
|
||||
if QBCore.Config.Server.PermissionList[Player.PlayerData.steam] ~= nil then
|
||||
if QBCore.Config.Server.PermissionList[Player.PlayerData.steam].steam == steamid and QBCore.Config.Server.PermissionList[Player.PlayerData.steam].license == licenseid then
|
||||
retval = QBCore.Config.Server.PermissionList[Player.PlayerData.steam].permission
|
||||
end
|
||||
end
|
||||
end
|
||||
return retval
|
||||
end
|
||||
|
||||
QBCore.Functions.IsOptin = function(source)
|
||||
local retval = false
|
||||
local steamid = GetPlayerIdentifiers(source)[1]
|
||||
if QBCore.Functions.HasPermission(source, "admin") then
|
||||
retval = QBCore.Config.Server.PermissionList[steamid].optin
|
||||
end
|
||||
return retval
|
||||
end
|
||||
|
||||
QBCore.Functions.ToggleOptin = function(source)
|
||||
local steamid = GetPlayerIdentifiers(source)[1]
|
||||
if QBCore.Functions.HasPermission(source, "admin") then
|
||||
QBCore.Config.Server.PermissionList[steamid].optin = not QBCore.Config.Server.PermissionList[steamid].optin
|
||||
end
|
||||
end
|
||||
|
||||
QBCore.Functions.IsPlayerBanned = function (source)
|
||||
local retval = false
|
||||
local message = ""
|
||||
QBCore.Functions.ExecuteSql(true, "SELECT * FROM `bans` WHERE `steam` = '"..GetPlayerIdentifiers(source)[1].."' OR `license` = '"..GetPlayerIdentifiers(source)[2].."' OR `ip` = '"..GetPlayerIdentifiers(source)[3].."'", function(result)
|
||||
if result[1] ~= nil then
|
||||
if os.time() < result[1].expire then
|
||||
retval = true
|
||||
local timeTable = os.date("*t", tonumber(result[1].expire))
|
||||
message = "You have been banned from the server:\n"..result[1].reason.."\nJe ban verloopt "..timeTable.day.. "/" .. timeTable.month .. "/" .. timeTable.year .. " " .. timeTable.hour.. ":" .. timeTable.min .. "\n"
|
||||
else
|
||||
QBCore.Functions.ExecuteSql(true, "DELETE FROM `bans` WHERE `id` = "..result[1].id)
|
||||
end
|
||||
end
|
||||
end)
|
||||
return retval, message
|
||||
end
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
QBCore = {}
|
||||
QBCore.Config = QBConfig
|
||||
QBCore.Shared = QBShared
|
||||
QBCore.ServerCallbacks = {}
|
||||
QBCore.UseableItems = {}
|
||||
|
||||
function GetCoreObject()
|
||||
return QBCore
|
||||
end
|
||||
|
||||
RegisterServerEvent('QBCore:GetObject')
|
||||
AddEventHandler('QBCore:GetObject', function(cb)
|
||||
cb(GetCoreObject())
|
||||
end)
|
||||
@@ -0,0 +1,561 @@
|
||||
QBCore.Players = {}
|
||||
QBCore.Player = {}
|
||||
|
||||
QBCore.Player.Login = function(source, citizenid, newData)
|
||||
if source ~= nil then
|
||||
if citizenid then
|
||||
QBCore.Functions.ExecuteSql(true, "SELECT * FROM `players` WHERE `citizenid` = '"..citizenid.."'", function(result)
|
||||
local PlayerData = result[1]
|
||||
if PlayerData ~= nil then
|
||||
PlayerData.money = json.decode(PlayerData.money)
|
||||
PlayerData.job = json.decode(PlayerData.job)
|
||||
PlayerData.position = json.decode(PlayerData.position)
|
||||
PlayerData.metadata = json.decode(PlayerData.metadata)
|
||||
PlayerData.charinfo = json.decode(PlayerData.charinfo)
|
||||
if PlayerData.gang ~= nil then
|
||||
PlayerData.gang = json.decode(PlayerData.gang)
|
||||
else
|
||||
PlayerData.gang = {}
|
||||
end
|
||||
end
|
||||
QBCore.Player.CheckPlayerData(source, PlayerData)
|
||||
end)
|
||||
else
|
||||
QBCore.Player.CheckPlayerData(source, newData)
|
||||
end
|
||||
return true
|
||||
else
|
||||
QBCore.ShowError(GetCurrentResourceName(), "ERROR QBCORE.PLAYER.LOGIN - NO SOURCE GIVEN!")
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
QBCore.Player.CheckPlayerData = function(source, PlayerData)
|
||||
PlayerData = PlayerData ~= nil and PlayerData or {}
|
||||
|
||||
PlayerData.source = source
|
||||
PlayerData.citizenid = PlayerData.citizenid ~= nil and PlayerData.citizenid or QBCore.Player.CreateCitizenId()
|
||||
PlayerData.steam = PlayerData.steam ~= nil and PlayerData.steam or QBCore.Functions.GetIdentifier(source, "steam")
|
||||
PlayerData.license = PlayerData.license ~= nil and PlayerData.license or QBCore.Functions.GetIdentifier(source, "license")
|
||||
PlayerData.name = GetPlayerName(source)
|
||||
PlayerData.cid = PlayerData.cid ~= nil and PlayerData.cid or 1
|
||||
|
||||
PlayerData.money = PlayerData.money ~= nil and PlayerData.money or {}
|
||||
for moneytype, startamount in pairs(QBCore.Config.Money.MoneyTypes) do
|
||||
PlayerData.money[moneytype] = PlayerData.money[moneytype] ~= nil and PlayerData.money[moneytype] or startamount
|
||||
end
|
||||
|
||||
PlayerData.charinfo = PlayerData.charinfo ~= nil and PlayerData.charinfo or {}
|
||||
PlayerData.charinfo.firstname = PlayerData.charinfo.firstname ~= nil and PlayerData.charinfo.firstname or "Firstname"
|
||||
PlayerData.charinfo.lastname = PlayerData.charinfo.lastname ~= nil and PlayerData.charinfo.lastname or "Lastname"
|
||||
PlayerData.charinfo.birthdate = PlayerData.charinfo.birthdate ~= nil and PlayerData.charinfo.birthdate or "00-00-0000"
|
||||
PlayerData.charinfo.gender = PlayerData.charinfo.gender ~= nil and PlayerData.charinfo.gender or 0
|
||||
PlayerData.charinfo.backstory = PlayerData.charinfo.backstory ~= nil and PlayerData.charinfo.backstory or "placeholder backstory"
|
||||
PlayerData.charinfo.nationality = PlayerData.charinfo.nationality ~= nil and PlayerData.charinfo.nationality or "Dutch"
|
||||
PlayerData.charinfo.phone = PlayerData.charinfo.phone ~= nil and PlayerData.charinfo.phone or "06"..math.random(11111111, 99999999)
|
||||
PlayerData.charinfo.account = PlayerData.charinfo.account ~= nil and PlayerData.charinfo.account or "NL0"..math.random(1,9).."QBUS"..math.random(1111,9999)..math.random(1111,9999)..math.random(11,99)
|
||||
|
||||
PlayerData.metadata = PlayerData.metadata ~= nil and PlayerData.metadata or {}
|
||||
PlayerData.metadata["hunger"] = PlayerData.metadata["hunger"] ~= nil and PlayerData.metadata["hunger"] or 100
|
||||
PlayerData.metadata["thirst"] = PlayerData.metadata["thirst"] ~= nil and PlayerData.metadata["thirst"] or 100
|
||||
PlayerData.metadata["stress"] = PlayerData.metadata["stress"] ~= nil and PlayerData.metadata["stress"] or 0
|
||||
PlayerData.metadata["isdead"] = PlayerData.metadata["isdead"] ~= nil and PlayerData.metadata["isdead"] or false
|
||||
PlayerData.metadata["inlaststand"] = PlayerData.metadata["inlaststand"] ~= nil and PlayerData.metadata["inlaststand"] or false
|
||||
PlayerData.metadata["armor"] = PlayerData.metadata["armor"] ~= nil and PlayerData.metadata["armor"] or 0
|
||||
PlayerData.metadata["ishandcuffed"] = PlayerData.metadata["ishandcuffed"] ~= nil and PlayerData.metadata["ishandcuffed"] or false
|
||||
PlayerData.metadata["tracker"] = PlayerData.metadata["tracker"] ~= nil and PlayerData.metadata["tracker"] or false
|
||||
PlayerData.metadata["injail"] = PlayerData.metadata["injail"] ~= nil and PlayerData.metadata["injail"] or 0
|
||||
PlayerData.metadata["jailitems"] = PlayerData.metadata["jailitems"] ~= nil and PlayerData.metadata["jailitems"] or {}
|
||||
PlayerData.metadata["status"] = PlayerData.metadata["status"] ~= nil and PlayerData.metadata["status"] or {}
|
||||
PlayerData.metadata["phone"] = PlayerData.metadata["phone"] ~= nil and PlayerData.metadata["phone"] or {}
|
||||
PlayerData.metadata["fitbit"] = PlayerData.metadata["fitbit"] ~= nil and PlayerData.metadata["fitbit"] or {}
|
||||
PlayerData.metadata["commandbinds"] = PlayerData.metadata["commandbinds"] ~= nil and PlayerData.metadata["commandbinds"] or {}
|
||||
PlayerData.metadata["bloodtype"] = PlayerData.metadata["bloodtype"] ~= nil and PlayerData.metadata["bloodtype"] or QBCore.Config.Player.Bloodtypes[math.random(1, #QBCore.Config.Player.Bloodtypes)]
|
||||
PlayerData.metadata["dealerrep"] = PlayerData.metadata["dealerrep"] ~= nil and PlayerData.metadata["dealerrep"] or 0
|
||||
PlayerData.metadata["craftingrep"] = PlayerData.metadata["craftingrep"] ~= nil and PlayerData.metadata["craftingrep"] or 0
|
||||
PlayerData.metadata["attachmentcraftingrep"] = PlayerData.metadata["attachmentcraftingrep"] ~= nil and PlayerData.metadata["attachmentcraftingrep"] or 0
|
||||
PlayerData.metadata["currentapartment"] = PlayerData.metadata["currentapartment"] ~= nil and PlayerData.metadata["currentapartment"] or nil
|
||||
PlayerData.metadata["jobrep"] = PlayerData.metadata["jobrep"] ~= nil and PlayerData.metadata["jobrep"] or {
|
||||
["tow"] = 0,
|
||||
["trucker"] = 0,
|
||||
["taxi"] = 0,
|
||||
["hotdog"] = 0,
|
||||
}
|
||||
PlayerData.metadata["callsign"] = PlayerData.metadata["callsign"] ~= nil and PlayerData.metadata["callsign"] or "NO CALLSIGN"
|
||||
PlayerData.metadata["fingerprint"] = PlayerData.metadata["fingerprint"] ~= nil and PlayerData.metadata["fingerprint"] or QBCore.Player.CreateFingerId()
|
||||
PlayerData.metadata["walletid"] = PlayerData.metadata["walletid"] ~= nil and PlayerData.metadata["walletid"] or QBCore.Player.CreateWalletId()
|
||||
PlayerData.metadata["criminalrecord"] = PlayerData.metadata["criminalrecord"] ~= nil and PlayerData.metadata["criminalrecord"] or {
|
||||
["hasRecord"] = false,
|
||||
["date"] = nil
|
||||
}
|
||||
PlayerData.metadata["licences"] = PlayerData.metadata["licences"] ~= nil and PlayerData.metadata["licences"] or {
|
||||
["driver"] = true,
|
||||
["business"] = false
|
||||
}
|
||||
PlayerData.metadata["inside"] = PlayerData.metadata["inside"] ~= nil and PlayerData.metadata["inside"] or {
|
||||
house = nil,
|
||||
apartment = {
|
||||
apartmentType = nil,
|
||||
apartmentId = nil,
|
||||
}
|
||||
}
|
||||
PlayerData.metadata["phonedata"] = PlayerData.metadata["phonedata"] ~= nil and PlayerData.metadata["phonedata"] or {
|
||||
SerialNumber = QBCore.Player.CreateSerialNumber(),
|
||||
InstalledApps = {},
|
||||
}
|
||||
|
||||
PlayerData.job = PlayerData.job ~= nil and PlayerData.job or {}
|
||||
PlayerData.job.name = PlayerData.job.name ~= nil and PlayerData.job.name or "unemployed"
|
||||
PlayerData.job.label = PlayerData.job.label ~= nil and PlayerData.job.label or "unemployed"
|
||||
PlayerData.job.payment = PlayerData.job.payment ~= nil and PlayerData.job.payment or 10
|
||||
PlayerData.job.onduty = PlayerData.job.onduty ~= nil and PlayerData.job.onduty or true
|
||||
|
||||
PlayerData.gang = PlayerData.gang ~= nil and PlayerData.gang or {}
|
||||
PlayerData.gang.name = PlayerData.gang.name ~= nil and PlayerData.gang.name or "geen"
|
||||
PlayerData.gang.label = PlayerData.gang.label ~= nil and PlayerData.gang.label or "Geen Gang"
|
||||
|
||||
PlayerData.position = PlayerData.position ~= nil and PlayerData.position or QBConfig.DefaultSpawn
|
||||
PlayerData.LoggedIn = true
|
||||
|
||||
PlayerData = QBCore.Player.LoadInventory(PlayerData)
|
||||
QBCore.Player.CreatePlayer(PlayerData)
|
||||
end
|
||||
|
||||
QBCore.Player.CreatePlayer = function(PlayerData)
|
||||
local self = {}
|
||||
self.Functions = {}
|
||||
self.PlayerData = PlayerData
|
||||
|
||||
self.Functions.UpdatePlayerData = function()
|
||||
TriggerClientEvent("QBCore:Player:SetPlayerData", self.PlayerData.source, self.PlayerData)
|
||||
QBCore.Commands.Refresh(self.PlayerData.source)
|
||||
end
|
||||
|
||||
self.Functions.SetJob = function(job)
|
||||
local job = job:lower()
|
||||
local grade = tonumber(grade)
|
||||
if QBCore.Shared.Jobs[job] ~= nil then
|
||||
self.PlayerData.job.name = job
|
||||
self.PlayerData.job.label = QBCore.Shared.Jobs[job].label
|
||||
self.PlayerData.job.payment = QBCore.Shared.Jobs[job].payment
|
||||
self.PlayerData.job.onduty = QBCore.Shared.Jobs[job].defaultDuty
|
||||
self.Functions.UpdatePlayerData()
|
||||
TriggerClientEvent("QBCore:Client:OnJobUpdate", self.PlayerData.source, self.PlayerData.job)
|
||||
end
|
||||
end
|
||||
|
||||
self.Functions.SetGang = function(gang)
|
||||
local gang = gang:lower()
|
||||
if QBCore.Shared.Gangs[gang] ~= nil then
|
||||
self.PlayerData.gang.name = gang
|
||||
self.PlayerData.gang.label = QBCore.Shared.Gangs[gang].label
|
||||
self.Functions.UpdatePlayerData()
|
||||
TriggerClientEvent("QBCore:Client:OnGangUpdate", self.PlayerData.source, self.PlayerData.gang)
|
||||
end
|
||||
end
|
||||
|
||||
self.Functions.SetJobDuty = function(onDuty)
|
||||
self.PlayerData.job.onduty = onDuty
|
||||
self.Functions.UpdatePlayerData()
|
||||
end
|
||||
|
||||
self.Functions.SetMetaData = function(meta, val)
|
||||
local meta = meta:lower()
|
||||
if val ~= nil then
|
||||
self.PlayerData.metadata[meta] = val
|
||||
self.Functions.UpdatePlayerData()
|
||||
end
|
||||
end
|
||||
|
||||
self.Functions.AddJobReputation = function(amount)
|
||||
local amount = tonumber(amount)
|
||||
self.PlayerData.metadata["jobrep"][self.PlayerData.job.name] = self.PlayerData.metadata["jobrep"][self.PlayerData.job.name] + amount
|
||||
self.Functions.UpdatePlayerData()
|
||||
end
|
||||
|
||||
self.Functions.AddMoney = function(moneytype, amount, reason)
|
||||
reason = reason ~= nil and reason or "unkown"
|
||||
local moneytype = moneytype:lower()
|
||||
local amount = tonumber(amount)
|
||||
if amount < 0 then return end
|
||||
if self.PlayerData.money[moneytype] ~= nil then
|
||||
self.PlayerData.money[moneytype] = self.PlayerData.money[moneytype]+amount
|
||||
self.Functions.UpdatePlayerData()
|
||||
TriggerEvent("qb-log:server:sendLog", self.PlayerData.citizenid, "moneyadded", {amount=amount, moneytype=moneytype, newbalance=self.PlayerData.money[moneytype], reason=reason})
|
||||
if amount > 100000 then
|
||||
TriggerEvent("qb-log:server:CreateLog", "playermoney", "AddMoney", "lightgreen", "**"..GetPlayerName(self.PlayerData.source) .. " (citizenid: "..self.PlayerData.citizenid.." | id: "..self.PlayerData.source..")** €"..amount .. " ("..moneytype..") added, new "..moneytype.." balance: "..self.PlayerData.money[moneytype], true)
|
||||
else
|
||||
TriggerEvent("qb-log:server:CreateLog", "playermoney", "AddMoney", "lightgreen", "**"..GetPlayerName(self.PlayerData.source) .. " (citizenid: "..self.PlayerData.citizenid.." | id: "..self.PlayerData.source..")** €"..amount .. " ("..moneytype..") added, new "..moneytype.." balance: "..self.PlayerData.money[moneytype])
|
||||
end
|
||||
TriggerClientEvent("hud:client:OnMoneyChange", self.PlayerData.source, moneytype, amount, false)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
self.Functions.RemoveMoney = function(moneytype, amount, reason)
|
||||
reason = reason ~= nil and reason or "unkown"
|
||||
local moneytype = moneytype:lower()
|
||||
local amount = tonumber(amount)
|
||||
if amount < 0 then return end
|
||||
if self.PlayerData.money[moneytype] ~= nil then
|
||||
for _, mtype in pairs(QBCore.Config.Money.DontAllowMinus) do
|
||||
if mtype == moneytype then
|
||||
if self.PlayerData.money[moneytype] - amount < 0 then return false end
|
||||
end
|
||||
end
|
||||
self.PlayerData.money[moneytype] = self.PlayerData.money[moneytype] - amount
|
||||
self.Functions.UpdatePlayerData()
|
||||
TriggerEvent("qb-log:server:sendLog", self.PlayerData.citizenid, "moneyremoved", {amount=amount, moneytype=moneytype, newbalance=self.PlayerData.money[moneytype], reason=reason})
|
||||
if amount > 100000 then
|
||||
TriggerEvent("qb-log:server:CreateLog", "playermoney", "RemoveMoney", "red", "**"..GetPlayerName(self.PlayerData.source) .. " (citizenid: "..self.PlayerData.citizenid.." | id: "..self.PlayerData.source..")** €"..amount .. " ("..moneytype..") removed, new "..moneytype.." balance: "..self.PlayerData.money[moneytype], true)
|
||||
else
|
||||
TriggerEvent("qb-log:server:CreateLog", "playermoney", "RemoveMoney", "red", "**"..GetPlayerName(self.PlayerData.source) .. " (citizenid: "..self.PlayerData.citizenid.." | id: "..self.PlayerData.source..")** €"..amount .. " ("..moneytype..") removed, new "..moneytype.." balance: "..self.PlayerData.money[moneytype])
|
||||
end
|
||||
TriggerClientEvent("hud:client:OnMoneyChange", self.PlayerData.source, moneytype, amount, true)
|
||||
TriggerClientEvent('qb-phone_new:client:RemoveBankMoney', self.PlayerData.source, amount)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
self.Functions.SetMoney = function(moneytype, amount, reason)
|
||||
reason = reason ~= nil and reason or "unkown"
|
||||
local moneytype = moneytype:lower()
|
||||
local amount = tonumber(amount)
|
||||
if amount < 0 then return end
|
||||
if self.PlayerData.money[moneytype] ~= nil then
|
||||
self.PlayerData.money[moneytype] = amount
|
||||
self.Functions.UpdatePlayerData()
|
||||
TriggerEvent("qb-log:server:sendLog", self.PlayerData.citizenid, "moneyset", {amount=amount, moneytype=moneytype, newbalance=self.PlayerData.money[moneytype], reason=reason})
|
||||
TriggerEvent("qb-log:server:CreateLog", "playermoney", "SetMoney", "green", "**"..GetPlayerName(self.PlayerData.source) .. " (citizenid: "..self.PlayerData.citizenid.." | id: "..self.PlayerData.source..")** €"..amount .. " ("..moneytype..") gezet, nieuw "..moneytype.." balans: "..self.PlayerData.money[moneytype])
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
self.Functions.AddItem = function(item, amount, slot, info)
|
||||
local totalWeight = QBCore.Player.GetTotalWeight(self.PlayerData.items)
|
||||
local itemInfo = QBCore.Shared.Items[item:lower()]
|
||||
if itemInfo == nil then TriggerClientEvent('QBCore:Notify', source, "Item Does Not Exist", "error") return end
|
||||
local amount = tonumber(amount)
|
||||
local slot = tonumber(slot) ~= nil and tonumber(slot) or QBCore.Player.GetFirstSlotByItem(self.PlayerData.items, item)
|
||||
if itemInfo["type"] == "weapon" and info == nil then
|
||||
info = {
|
||||
serie = tostring(QBCore.Shared.RandomInt(2) .. QBCore.Shared.RandomStr(3) .. QBCore.Shared.RandomInt(1) .. QBCore.Shared.RandomStr(2) .. QBCore.Shared.RandomInt(3) .. QBCore.Shared.RandomStr(4)),
|
||||
}
|
||||
end
|
||||
if (totalWeight + (itemInfo["weight"] * amount)) <= QBCore.Config.Player.MaxWeight then
|
||||
if (slot ~= nil and self.PlayerData.items[slot] ~= nil) and (self.PlayerData.items[slot].name:lower() == item:lower()) and (itemInfo["type"] == "item" and not itemInfo["unique"]) then
|
||||
self.PlayerData.items[slot].amount = self.PlayerData.items[slot].amount + amount
|
||||
self.Functions.UpdatePlayerData()
|
||||
TriggerEvent("qb-log:server:sendLog", self.PlayerData.citizenid, "itemadded", {name=self.PlayerData.items[slot].name, amount=amount, slot=slot, newamount=self.PlayerData.items[slot].amount, reason="unkown"})
|
||||
TriggerEvent("qb-log:server:CreateLog", "playerinventory", "AddItem", "green", "**"..GetPlayerName(self.PlayerData.source) .. " (citizenid: "..self.PlayerData.citizenid.." | id: "..self.PlayerData.source..")** got item: [slot:" ..slot.."], itemname: " .. self.PlayerData.items[slot].name .. ", added amount: " .. amount ..", new total amount: ".. self.PlayerData.items[slot].amount)
|
||||
--TriggerClientEvent('QBCore:Notify', self.PlayerData.source, itemInfo["label"].. " toegevoegd!", "success")
|
||||
return true
|
||||
elseif (not itemInfo["unique"] and slot or slot ~= nil and self.PlayerData.items[slot] == nil) then
|
||||
self.PlayerData.items[slot] = {name = itemInfo["name"], amount = amount, info = info ~= nil and info or "", label = itemInfo["label"], description = itemInfo["description"] ~= nil and itemInfo["description"] or "", weight = itemInfo["weight"], type = itemInfo["type"], unique = itemInfo["unique"], useable = itemInfo["useable"], image = itemInfo["image"], shouldClose = itemInfo["shouldClose"], slot = slot, combinable = itemInfo["combinable"]}
|
||||
self.Functions.UpdatePlayerData()
|
||||
TriggerEvent("qb-log:server:sendLog", self.PlayerData.citizenid, "itemadded", {name=self.PlayerData.items[slot].name, amount=amount, slot=slot, newamount=self.PlayerData.items[slot].amount, reason="unkown"})
|
||||
TriggerEvent("qb-log:server:CreateLog", "playerinventory", "AddItem", "green", "**"..GetPlayerName(self.PlayerData.source) .. " (citizenid: "..self.PlayerData.citizenid.." | id: "..self.PlayerData.source..")** got item: [slot:" ..slot.."], itemname: " .. self.PlayerData.items[slot].name .. ", added amount: " .. amount ..", new total amount: ".. self.PlayerData.items[slot].amount)
|
||||
--TriggerClientEvent('QBCore:Notify', self.PlayerData.source, itemInfo["label"].. " toegevoegd!", "success")
|
||||
return true
|
||||
elseif (itemInfo["unique"]) or (not slot or slot == nil) or (itemInfo["type"] == "weapon") then
|
||||
for i = 1, QBConfig.Player.MaxInvSlots, 1 do
|
||||
if self.PlayerData.items[i] == nil then
|
||||
self.PlayerData.items[i] = {name = itemInfo["name"], amount = amount, info = info ~= nil and info or "", label = itemInfo["label"], description = itemInfo["description"] ~= nil and itemInfo["description"] or "", weight = itemInfo["weight"], type = itemInfo["type"], unique = itemInfo["unique"], useable = itemInfo["useable"], image = itemInfo["image"], shouldClose = itemInfo["shouldClose"], slot = i, combinable = itemInfo["combinable"]}
|
||||
self.Functions.UpdatePlayerData()
|
||||
TriggerEvent("qb-log:server:sendLog", self.PlayerData.citizenid, "itemadded", {name=self.PlayerData.items[i].name, amount=amount, slot=i, newamount=self.PlayerData.items[i].amount, reason="unkown"})
|
||||
TriggerEvent("qb-log:server:CreateLog", "playerinventory", "AddItem", "green", "**"..GetPlayerName(self.PlayerData.source) .. " (citizenid: "..self.PlayerData.citizenid.." | id: "..self.PlayerData.source..")** got item: [slot:" ..i.."], itemname: " .. self.PlayerData.items[i].name .. ", added amount: " .. amount ..", new total amount: ".. self.PlayerData.items[i].amount)
|
||||
--TriggerClientEvent('QBCore:Notify', self.PlayerData.source, itemInfo["label"].. " toegevoegd!", "success")
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
self.Functions.RemoveItem = function(item, amount, slot)
|
||||
local itemInfo = QBCore.Shared.Items[item:lower()]
|
||||
local amount = tonumber(amount)
|
||||
local slot = tonumber(slot)
|
||||
if slot ~= nil then
|
||||
if self.PlayerData.items[slot].amount > amount then
|
||||
self.PlayerData.items[slot].amount = self.PlayerData.items[slot].amount - amount
|
||||
self.Functions.UpdatePlayerData()
|
||||
TriggerEvent("qb-log:server:sendLog", self.PlayerData.citizenid, "itemremoved", {name=self.PlayerData.items[slot].name, amount=amount, slot=slot, newamount=self.PlayerData.items[slot].amount, reason="unkown"})
|
||||
TriggerEvent("qb-log:server:CreateLog", "playerinventory", "RemoveItem", "red", "**"..GetPlayerName(self.PlayerData.source) .. " (citizenid: "..self.PlayerData.citizenid.." | id: "..self.PlayerData.source..")** lost item: [slot:" ..slot.."], itemname: " .. self.PlayerData.items[slot].name .. ", removed amount: " .. amount ..", new total amount: ".. self.PlayerData.items[slot].amount)
|
||||
--TriggerClientEvent('QBCore:Notify', self.PlayerData.source, itemInfo["label"].. " verwijderd!", "error")
|
||||
return true
|
||||
else
|
||||
self.PlayerData.items[slot] = nil
|
||||
self.Functions.UpdatePlayerData()
|
||||
TriggerEvent("qb-log:server:sendLog", self.PlayerData.citizenid, "itemremoved", {name=item, amount=amount, slot=slot, newamount=0, reason="unkown"})
|
||||
TriggerEvent("qb-log:server:CreateLog", "playerinventory", "RemoveItem", "red", "**"..GetPlayerName(self.PlayerData.source) .. " (citizenid: "..self.PlayerData.citizenid.." | id: "..self.PlayerData.source..")** lost item: [slot:" ..slot.."], itemname: " .. item .. ", removed amount: " .. amount ..", item removed")
|
||||
--TriggerClientEvent('QBCore:Notify', self.PlayerData.source, itemInfo["label"].. " verwijderd!", "error")
|
||||
return true
|
||||
end
|
||||
else
|
||||
local slots = QBCore.Player.GetSlotsByItem(self.PlayerData.items, item)
|
||||
local amountToRemove = amount
|
||||
if slots ~= nil then
|
||||
for _, slot in pairs(slots) do
|
||||
if self.PlayerData.items[slot].amount > amountToRemove then
|
||||
self.PlayerData.items[slot].amount = self.PlayerData.items[slot].amount - amountToRemove
|
||||
self.Functions.UpdatePlayerData()
|
||||
TriggerEvent("qb-log:server:sendLog", self.PlayerData.citizenid, "itemremoved", {name=self.PlayerData.items[slot].name, amount=amount, slot=slot, newamount=self.PlayerData.items[slot].amount, reason="unkown"})
|
||||
TriggerEvent("qb-log:server:CreateLog", "playerinventory", "RemoveItem", "red", "**"..GetPlayerName(self.PlayerData.source) .. " (citizenid: "..self.PlayerData.citizenid.." | id: "..self.PlayerData.source..")** lost item: [slot:" ..slot.."], itemname: " .. self.PlayerData.items[slot].name .. ", removed amount: " .. amount ..", new total amount: ".. self.PlayerData.items[slot].amount)
|
||||
--TriggerClientEvent('QBCore:Notify', self.PlayerData.source, itemInfo["label"].. " verwijderd!", "error")
|
||||
return true
|
||||
elseif self.PlayerData.items[slot].amount == amountToRemove then
|
||||
self.PlayerData.items[slot] = nil
|
||||
self.Functions.UpdatePlayerData()
|
||||
TriggerEvent("qb-log:server:sendLog", self.PlayerData.citizenid, "itemremoved", {name=item, amount=amount, slot=slot, newamount=0, reason="unkown"})
|
||||
TriggerEvent("qb-log:server:CreateLog", "playerinventory", "RemoveItem", "red", "**"..GetPlayerName(self.PlayerData.source) .. " (citizenid: "..self.PlayerData.citizenid.." | id: "..self.PlayerData.source..")** lost item: [slot:" ..slot.."], itemname: " .. item .. ", removed amount: " .. amount ..", item removed")
|
||||
--TriggerClientEvent('QBCore:Notify', self.PlayerData.source, itemInfo["label"].. " verwijderd!", "error")
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
self.Functions.SetInventory = function(items)
|
||||
self.PlayerData.items = items
|
||||
self.Functions.UpdatePlayerData()
|
||||
TriggerEvent("qb-log:server:sendLog", self.PlayerData.citizenid, "setinventory", {items=json.encode(items)})
|
||||
TriggerEvent("qb-log:server:CreateLog", "playerinventory", "SetInventory", "blue", "**"..GetPlayerName(self.PlayerData.source) .. " (citizenid: "..self.PlayerData.citizenid.." | id: "..self.PlayerData.source..")** items set: " .. json.encode(items))
|
||||
end
|
||||
|
||||
self.Functions.ClearInventory = function()
|
||||
self.PlayerData.items = {}
|
||||
self.Functions.UpdatePlayerData()
|
||||
TriggerEvent("qb-log:server:sendLog", self.PlayerData.citizenid, "clearinventory", {})
|
||||
TriggerEvent("qb-log:server:CreateLog", "playerinventory", "ClearInventory", "red", "**"..GetPlayerName(self.PlayerData.source) .. " (citizenid: "..self.PlayerData.citizenid.." | id: "..self.PlayerData.source..")** inventory cleared")
|
||||
end
|
||||
|
||||
self.Functions.GetItemByName = function(item)
|
||||
local item = tostring(item):lower()
|
||||
local slot = QBCore.Player.GetFirstSlotByItem(self.PlayerData.items, item)
|
||||
if slot ~= nil then
|
||||
return self.PlayerData.items[slot]
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
self.Functions.GetItemBySlot = function(slot)
|
||||
local slot = tonumber(slot)
|
||||
if self.PlayerData.items[slot] ~= nil then
|
||||
return self.PlayerData.items[slot]
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
self.Functions.Save = function()
|
||||
QBCore.Player.Save(self.PlayerData.source)
|
||||
end
|
||||
|
||||
QBCore.Players[self.PlayerData.source] = self
|
||||
QBCore.Player.Save(self.PlayerData.source)
|
||||
self.Functions.UpdatePlayerData()
|
||||
end
|
||||
|
||||
QBCore.Player.Save = function(source)
|
||||
local PlayerData = QBCore.Players[source].PlayerData
|
||||
if PlayerData ~= nil then
|
||||
QBCore.Functions.ExecuteSql(true, "SELECT * FROM `players` WHERE `citizenid` = '"..PlayerData.citizenid.."'", function(result)
|
||||
if result[1] == nil then
|
||||
QBCore.Functions.ExecuteSql(true, "INSERT INTO `players` (`citizenid`, `cid`, `steam`, `license`, `name`, `money`, `charinfo`, `job`, `gang`, `position`, `metadata`) VALUES ('"..PlayerData.citizenid.."', '"..tonumber(PlayerData.cid).."', '"..PlayerData.steam.."', '"..PlayerData.license.."', '"..PlayerData.name.."', '"..json.encode(PlayerData.money).."', '"..QBCore.EscapeSqli(json.encode(PlayerData.charinfo)).."', '"..json.encode(PlayerData.job).."', '"..json.encode(PlayerData.gang).."', '"..json.encode(PlayerData.position).."', '"..json.encode(PlayerData.metadata).."')")
|
||||
else
|
||||
QBCore.Functions.ExecuteSql(true, "UPDATE `players` SET steam='"..PlayerData.steam.."',license='"..PlayerData.license.."',name='"..PlayerData.name.."',money='"..json.encode(PlayerData.money).."',charinfo='"..QBCore.EscapeSqli(json.encode(PlayerData.charinfo)).."',job='"..json.encode(PlayerData.job).."',gang='"..json.encode(PlayerData.gang).."', position='"..json.encode(PlayerData.position).."',metadata='"..json.encode(PlayerData.metadata).."' WHERE `citizenid` = '"..PlayerData.citizenid.."'")
|
||||
end
|
||||
QBCore.Player.SaveInventory(source)
|
||||
end)
|
||||
QBCore.ShowSuccess(GetCurrentResourceName(), PlayerData.name .." PLAYER SAVED!")
|
||||
else
|
||||
QBCore.ShowError(GetCurrentResourceName(), "ERROR QBCORE.PLAYER.SAVE - PLAYERDATA IS EMPTY!")
|
||||
end
|
||||
end
|
||||
|
||||
QBCore.Player.Logout = function(source)
|
||||
TriggerClientEvent('QBCore:Client:OnPlayerUnload', source)
|
||||
TriggerClientEvent("QBCore:Player:UpdatePlayerData", source)
|
||||
Citizen.Wait(200)
|
||||
-- TriggerEvent('QBCore:Server:OnPlayerUnload')
|
||||
-- QBCore.Players[source].Functions.Save()
|
||||
QBCore.Players[source] = nil
|
||||
end
|
||||
|
||||
QBCore.Player.DeleteCharacter = function(source, citizenid)
|
||||
QBCore.Functions.ExecuteSql(true, "DELETE FROM `players` WHERE `citizenid` = '"..citizenid.."'")
|
||||
TriggerEvent("qb-log:server:sendLog", citizenid, "characterdeleted", {})
|
||||
TriggerEvent("qb-log:server:CreateLog", "joinleave", "Character Deleted", "red", "**".. GetPlayerName(source) .. "** ("..GetPlayerIdentifiers(source)[1]..") deleted **"..citizenid.."**..")
|
||||
end
|
||||
|
||||
QBCore.Player.LoadInventory = function(PlayerData)
|
||||
PlayerData.items = {}
|
||||
QBCore.Functions.ExecuteSql(true, "SELECT * FROM `playeritems` WHERE `citizenid` = '"..PlayerData.citizenid.."'", function(oldInventory)
|
||||
if oldInventory[1] ~= nil then
|
||||
for _, item in pairs(oldInventory) do
|
||||
if item ~= nil then
|
||||
local itemInfo = QBCore.Shared.Items[item.name:lower()]
|
||||
PlayerData.items[item.slot] = {name = itemInfo["name"], amount = item.amount, info = json.decode(item.info) ~= nil and json.decode(item.info) or "", label = itemInfo["label"], description = itemInfo["description"] ~= nil and itemInfo["description"] or "", weight = itemInfo["weight"], type = itemInfo["type"], unique = itemInfo["unique"], useable = itemInfo["useable"], image = itemInfo["image"], shouldClose = itemInfo["shouldClose"], slot = item.slot, combinable = itemInfo["combinable"]}
|
||||
end
|
||||
Citizen.Wait(1)
|
||||
end
|
||||
QBCore.Functions.ExecuteSql(true, "DELETE FROM `playeritems` WHERE `citizenid` = '"..PlayerData.citizenid.."'")
|
||||
else
|
||||
QBCore.Functions.ExecuteSql(true, "SELECT * FROM `players` WHERE `citizenid` = '"..PlayerData.citizenid.."'", function(result)
|
||||
if result[1] ~= nil then
|
||||
if result[1].inventory ~= nil then
|
||||
plyInventory = json.decode(result[1].inventory)
|
||||
if next(plyInventory) ~= nil then
|
||||
for _, item in pairs(plyInventory) do
|
||||
if item ~= nil then
|
||||
local itemInfo = QBCore.Shared.Items[item.name:lower()]
|
||||
PlayerData.items[item.slot] = {
|
||||
name = itemInfo["name"],
|
||||
amount = item.amount,
|
||||
info = item.info ~= nil and item.info or "",
|
||||
label = itemInfo["label"],
|
||||
description = itemInfo["description"] ~= nil and itemInfo["description"] or "",
|
||||
weight = itemInfo["weight"],
|
||||
type = itemInfo["type"],
|
||||
unique = itemInfo["unique"],
|
||||
useable = itemInfo["useable"],
|
||||
image = itemInfo["image"],
|
||||
shouldClose = itemInfo["shouldClose"],
|
||||
slot = item.slot,
|
||||
combinable = itemInfo["combinable"]
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
end)
|
||||
return PlayerData
|
||||
end
|
||||
|
||||
QBCore.Player.SaveInventory = function(source)
|
||||
if QBCore.Players[source] ~= nil then
|
||||
local PlayerData = QBCore.Players[source].PlayerData
|
||||
local items = PlayerData.items
|
||||
local ItemsJson = {}
|
||||
if items ~= nil and next(items) ~= nil then
|
||||
for slot, item in pairs(items) do
|
||||
if items[slot] ~= nil then
|
||||
table.insert(ItemsJson, {
|
||||
name = item.name,
|
||||
amount = item.amount,
|
||||
info = item.info,
|
||||
type = item.type,
|
||||
slot = slot,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
QBCore.Functions.ExecuteSql(true, "UPDATE `players` SET `inventory` = '"..QBCore.EscapeSqli(json.encode(ItemsJson)).."' WHERE `citizenid` = '"..PlayerData.citizenid.."'")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
QBCore.Player.GetTotalWeight = function(items)
|
||||
local weight = 0
|
||||
if items ~= nil then
|
||||
for slot, item in pairs(items) do
|
||||
weight = weight + (item.weight * item.amount)
|
||||
end
|
||||
end
|
||||
return tonumber(weight)
|
||||
end
|
||||
|
||||
QBCore.Player.GetSlotsByItem = function(items, itemName)
|
||||
local slotsFound = {}
|
||||
if items ~= nil then
|
||||
for slot, item in pairs(items) do
|
||||
if item.name:lower() == itemName:lower() then
|
||||
table.insert(slotsFound, slot)
|
||||
end
|
||||
end
|
||||
end
|
||||
return slotsFound
|
||||
end
|
||||
|
||||
QBCore.Player.GetFirstSlotByItem = function(items, itemName)
|
||||
if items ~= nil then
|
||||
for slot, item in pairs(items) do
|
||||
if item.name:lower() == itemName:lower() then
|
||||
return tonumber(slot)
|
||||
end
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
QBCore.Player.CreateCitizenId = function()
|
||||
local UniqueFound = false
|
||||
local CitizenId = nil
|
||||
|
||||
while not UniqueFound do
|
||||
CitizenId = tostring(QBCore.Shared.RandomStr(3) .. QBCore.Shared.RandomInt(5)):upper()
|
||||
QBCore.Functions.ExecuteSql(true, "SELECT COUNT(*) as count FROM `players` WHERE `citizenid` = '"..CitizenId.."'", function(result)
|
||||
if result[1].count == 0 then
|
||||
UniqueFound = true
|
||||
end
|
||||
end)
|
||||
end
|
||||
return CitizenId
|
||||
end
|
||||
|
||||
QBCore.Player.CreateFingerId = function()
|
||||
local UniqueFound = false
|
||||
local FingerId = nil
|
||||
while not UniqueFound do
|
||||
FingerId = tostring(QBCore.Shared.RandomStr(2) .. QBCore.Shared.RandomInt(3) .. QBCore.Shared.RandomStr(1) .. QBCore.Shared.RandomInt(2) .. QBCore.Shared.RandomStr(3) .. QBCore.Shared.RandomInt(4))
|
||||
QBCore.Functions.ExecuteSql(true, "SELECT COUNT(*) as count FROM `players` WHERE `metadata` LIKE '%"..FingerId.."%'", function(result)
|
||||
if result[1].count == 0 then
|
||||
UniqueFound = true
|
||||
end
|
||||
end)
|
||||
end
|
||||
return FingerId
|
||||
end
|
||||
|
||||
QBCore.Player.CreateWalletId = function()
|
||||
local UniqueFound = false
|
||||
local WalletId = nil
|
||||
while not UniqueFound do
|
||||
WalletId = "QB-"..math.random(11111111, 99999999)
|
||||
QBCore.Functions.ExecuteSql(true, "SELECT COUNT(*) as count FROM `players` WHERE `metadata` LIKE '%"..WalletId.."%'", function(result)
|
||||
if result[1].count == 0 then
|
||||
UniqueFound = true
|
||||
end
|
||||
end)
|
||||
end
|
||||
return WalletId
|
||||
end
|
||||
|
||||
QBCore.Player.CreateSerialNumber = function()
|
||||
local UniqueFound = false
|
||||
local SerialNumber = nil
|
||||
|
||||
while not UniqueFound do
|
||||
SerialNumber = math.random(11111111, 99999999)
|
||||
QBCore.Functions.ExecuteSql(true, "SELECT COUNT(*) as count FROM players WHERE metadata LIKE '%"..SerialNumber.."%'", function(result)
|
||||
if result[1].count == 0 then
|
||||
UniqueFound = true
|
||||
end
|
||||
end)
|
||||
end
|
||||
return SerialNumber
|
||||
end
|
||||
|
||||
QBCore.EscapeSqli = function(str)
|
||||
local replacements = { ['"'] = '\\"', ["'"] = "\\'" }
|
||||
return str:gsub( "['\"]", replacements ) -- or string.gsub( source, "['\"]", replacements )
|
||||
end
|
||||
Reference in New Issue
Block a user