mirror of
https://github.com/qbcore-fivem/qb-core.git
synced 2026-08-28 17:01:16 +00:00
⚠️ Major Update ⚠️
- Major cleanup of all files including reformatting & notations - Added an optional export to add to scripts as an alternative to import.lua - Added player state to OnPlayerLoaded so no more need for isLoggedIn inside scripts - Updated all events to the new RegisterNetEvent and got rid of unneeded handlers - Added the ability for ACE permissions with commands - Added two new config options for player update interval and status update - Changed players table to use citizenid column as primary key <-- very important - Overall sloppy code cleanup, removal of unused code, got rid of nil checks
This commit is contained in:
@@ -1,3 +0,0 @@
|
||||
QBCore.Debug = function(resource, obj, depth)
|
||||
TriggerServerEvent('QBCore:DebugSomething', resource, obj, depth)
|
||||
end
|
||||
+75
-111
@@ -1,135 +1,99 @@
|
||||
-- QBCore Command Events
|
||||
RegisterNetEvent('QBCore:Command:TeleportToPlayer')
|
||||
AddEventHandler('QBCore:Command:TeleportToPlayer', function(coords)
|
||||
local ped = PlayerPedId()
|
||||
SetPedCoordsKeepVehicle(ped, coords.x, coords.y, coords.z)
|
||||
-- Player load and unload handling
|
||||
-- New method for checking if logged in across all scripts (optional)
|
||||
-- if LocalPlayer.state['isLoggedIn'] then
|
||||
RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
|
||||
ShutdownLoadingScreenNui()
|
||||
LocalPlayer.state:set('isLoggedIn', true, false)
|
||||
SetCanAttackFriendly(PlayerPedId(), true, false)
|
||||
NetworkSetFriendlyFireOption(true)
|
||||
end)
|
||||
|
||||
RegisterNetEvent('QBCore:Command:TeleportToCoords')
|
||||
AddEventHandler('QBCore:Command:TeleportToCoords', function(x, y, z)
|
||||
local ped = PlayerPedId()
|
||||
SetPedCoordsKeepVehicle(ped, x, y, z)
|
||||
RegisterNetEvent('QBCore:Client:OnPlayerUnload', function()
|
||||
LocalPlayer.state:set('isLoggedIn', false, false)
|
||||
end)
|
||||
|
||||
RegisterNetEvent('QBCore:Command:SpawnVehicle')
|
||||
AddEventHandler('QBCore:Command:SpawnVehicle', function(model)
|
||||
QBCore.Functions.SpawnVehicle(model, function(vehicle)
|
||||
TaskWarpPedIntoVehicle(PlayerPedId(), vehicle, -1)
|
||||
TriggerEvent("vehiclekeys:client:SetOwner", GetVehicleNumberPlateText(vehicle))
|
||||
end)
|
||||
-- Teleport Commands
|
||||
|
||||
RegisterNetEvent('QBCore:Command:TeleportToPlayer', function(coords)
|
||||
local ped = PlayerPedId()
|
||||
SetPedCoordsKeepVehicle(ped, coords.x, coords.y, coords.z)
|
||||
end)
|
||||
|
||||
RegisterNetEvent('QBCore:Command:DeleteVehicle')
|
||||
AddEventHandler('QBCore:Command:DeleteVehicle', function()
|
||||
local vehicle = QBCore.Functions.GetClosestVehicle()
|
||||
if IsPedInAnyVehicle(PlayerPedId()) then vehicle = GetVehiclePedIsIn(PlayerPedId(), false) else vehicle = QBCore.Functions.GetClosestVehicle() end
|
||||
-- TriggerServerEvent('QBCore:Command:CheckOwnedVehicle', GetVehicleNumberPlateText(vehicle))
|
||||
QBCore.Functions.DeleteVehicle(vehicle)
|
||||
RegisterNetEvent('QBCore:Command:TeleportToCoords', function(x, y, z)
|
||||
local ped = PlayerPedId()
|
||||
SetPedCoordsKeepVehicle(ped, x, y, z)
|
||||
end)
|
||||
|
||||
RegisterNetEvent('QBCore:Command:Revive')
|
||||
AddEventHandler('QBCore:Command:Revive', function()
|
||||
local coords = QBCore.Functions.GetCoords(PlayerPedId())
|
||||
NetworkResurrectLocalPlayer(coords.x, coords.y, coords.z+0.2, coords.a, true, false)
|
||||
SetPlayerInvincible(PlayerPedId(), false)
|
||||
ClearPedBloodDamage(PlayerPedId())
|
||||
RegisterNetEvent('QBCore:Command:GoToMarker', function()
|
||||
local ped = PlayerPedId()
|
||||
local blip = GetFirstBlipInfoId(8)
|
||||
if DoesBlipExist(blip) then
|
||||
local blipCoords = GetBlipCoords(blip)
|
||||
for height = 1, 1000 do
|
||||
SetPedCoordsKeepVehicle(ped, blipCoords.x, blipCoords.y, height + 0.0)
|
||||
local foundGround, zPos = GetGroundZFor_3dCoord(blipCoords.x, blipCoords.y, height + 0.0)
|
||||
if foundGround then
|
||||
SetPedCoordsKeepVehicle(ped, blipCoords.x, blipCoords.y, height + 0.0)
|
||||
break
|
||||
end
|
||||
Wait(0)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
RegisterNetEvent('QBCore:Command:GoToMarker')
|
||||
AddEventHandler('QBCore:Command:GoToMarker', function()
|
||||
Citizen.CreateThread(function()
|
||||
local entity = PlayerPedId()
|
||||
if IsPedInAnyVehicle(entity, false) then
|
||||
entity = GetVehiclePedIsUsing(entity)
|
||||
end
|
||||
local success = false
|
||||
local blipFound = false
|
||||
local blipIterator = GetBlipInfoIdIterator()
|
||||
local blip = GetFirstBlipInfoId(8)
|
||||
-- Vehicle Commands
|
||||
|
||||
while DoesBlipExist(blip) do
|
||||
if GetBlipInfoIdType(blip) == 4 then
|
||||
cx, cy, cz = table.unpack(Citizen.InvokeNative(0xFA7C7F0AADF25D09, blip, Citizen.ReturnResultAnyway(), Citizen.ResultAsVector())) --GetBlipInfoIdCoord(blip)
|
||||
blipFound = true
|
||||
break
|
||||
end
|
||||
blip = GetNextBlipInfoId(blipIterator)
|
||||
end
|
||||
RegisterNetEvent('QBCore:Command:SpawnVehicle', function(vehName)
|
||||
local ped = PlayerPedId()
|
||||
local hash = GetHashKey(vehName)
|
||||
if not IsModelInCdimage(hash) then return end
|
||||
RequestModel(hash)
|
||||
while not HasModelLoaded(hash) do Wait(10) end
|
||||
local vehicle = CreateVehicle(hash, GetEntityCoords(ped), GetEntityHeading(ped), true, false)
|
||||
TaskWarpPedIntoVehicle(ped, vehicle, -1)
|
||||
SetModelAsNoLongerNeeded(vehicle)
|
||||
TriggerEvent("vehiclekeys:client:SetOwner", GetVehicleNumberPlateText(vehicle))
|
||||
end)
|
||||
|
||||
if blipFound then
|
||||
DoScreenFadeOut(250)
|
||||
while IsScreenFadedOut() do
|
||||
Citizen.Wait(250)
|
||||
end
|
||||
local groundFound = false
|
||||
local yaw = GetEntityHeading(entity)
|
||||
|
||||
for i = 0, 1000, 1 do
|
||||
SetEntityCoordsNoOffset(entity, cx, cy, ToFloat(i), false, false, false)
|
||||
SetEntityRotation(entity, 0, 0, 0, 0 ,0)
|
||||
SetEntityHeading(entity, yaw)
|
||||
SetGameplayCamRelativeHeading(0)
|
||||
Citizen.Wait(0)
|
||||
--groundFound = true
|
||||
if GetGroundZFor_3dCoord(cx, cy, ToFloat(i), cz, false) then --GetGroundZFor3dCoord(cx, cy, i, 0, 0) GetGroundZFor_3dCoord(cx, cy, i)
|
||||
cz = ToFloat(i)
|
||||
groundFound = true
|
||||
break
|
||||
end
|
||||
end
|
||||
if not groundFound then
|
||||
cz = -300.0
|
||||
end
|
||||
success = true
|
||||
end
|
||||
|
||||
if success then
|
||||
SetEntityCoordsNoOffset(entity, cx, cy, cz, false, false, true)
|
||||
SetGameplayCamRelativeHeading(0)
|
||||
if IsPedSittingInAnyVehicle(PlayerPedId()) then
|
||||
if GetPedInVehicleSeat(GetVehiclePedIsUsing(PlayerPedId()), -1) == PlayerPedId() then
|
||||
SetVehicleOnGroundProperly(GetVehiclePedIsUsing(PlayerPedId()))
|
||||
end
|
||||
end
|
||||
--HideLoadingPromt()
|
||||
DoScreenFadeIn(250)
|
||||
end
|
||||
end)
|
||||
RegisterNetEvent('QBCore:Command:DeleteVehicle', function()
|
||||
local ped = PlayerPedId()
|
||||
local veh = GetVehiclePedIsUsing(ped)
|
||||
if veh ~= 0 then
|
||||
SetEntityAsMissionEntity(veh, true, true)
|
||||
DeleteVehicle(veh)
|
||||
else
|
||||
local pcoords = GetEntityCoords(ped)
|
||||
local vehicles = GetGamePool('CVehicle')
|
||||
for k, v in pairs(vehicles) do
|
||||
if #(pcoords - GetEntityCoords(v)) <= 5.0 then
|
||||
SetEntityAsMissionEntity(v, true, true)
|
||||
DeleteVehicle(v)
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
-- Other stuff
|
||||
RegisterNetEvent('QBCore:Player:SetPlayerData')
|
||||
AddEventHandler('QBCore:Player:SetPlayerData', function(val)
|
||||
QBCore.PlayerData = val
|
||||
|
||||
RegisterNetEvent('QBCore:Player:SetPlayerData', function(val)
|
||||
QBCore.PlayerData = val
|
||||
end)
|
||||
|
||||
RegisterNetEvent('QBCore:Player:UpdatePlayerData')
|
||||
AddEventHandler('QBCore:Player:UpdatePlayerData', function()
|
||||
local data = {}
|
||||
data.position = QBCore.Functions.GetCoords(PlayerPedId())
|
||||
TriggerServerEvent('QBCore:UpdatePlayer', data)
|
||||
RegisterNetEvent('QBCore:Player:UpdatePlayerData', function()
|
||||
TriggerServerEvent('QBCore:UpdatePlayer')
|
||||
end)
|
||||
|
||||
RegisterNetEvent('QBCore:Player:UpdatePlayerPosition')
|
||||
AddEventHandler('QBCore:Player:UpdatePlayerPosition', function()
|
||||
local position = QBCore.Functions.GetCoords(PlayerPedId())
|
||||
TriggerServerEvent('QBCore:UpdatePlayerPosition', position)
|
||||
RegisterNetEvent('QBCore:Notify', function(text, type, length)
|
||||
QBCore.Functions.Notify(text, type, length)
|
||||
end)
|
||||
|
||||
RegisterNetEvent('QBCore:Notify')
|
||||
AddEventHandler('QBCore:Notify', function(text, type, length)
|
||||
QBCore.Functions.Notify(text, type, length)
|
||||
RegisterNetEvent('QBCore:Client:TriggerCallback', function(name, ...)
|
||||
if QBCore.ServerCallbacks[name] then
|
||||
QBCore.ServerCallbacks[name](...)
|
||||
QBCore.ServerCallbacks[name] = nil
|
||||
end
|
||||
end)
|
||||
|
||||
RegisterNetEvent('QBCore:Client:TriggerCallback') -- QBCore:Client:TriggerCallback falls under GPL License here: [esxlicense]/LICENSE
|
||||
AddEventHandler('QBCore:Client:TriggerCallback', function(name, ...)
|
||||
if QBCore.ServerCallbacks[name] ~= nil then
|
||||
QBCore.ServerCallbacks[name](...)
|
||||
QBCore.ServerCallbacks[name] = nil
|
||||
end
|
||||
end)
|
||||
|
||||
RegisterNetEvent("QBCore:Client:UseItem") -- QBCore:Client:UseItem falls under GPL License here: [esxlicense]/LICENSE
|
||||
AddEventHandler('QBCore:Client:UseItem', function(item)
|
||||
TriggerServerEvent("QBCore:Server:UseItem", item)
|
||||
RegisterNetEvent('QBCore:Client:UseItem', function(item)
|
||||
TriggerServerEvent('QBCore:Server:UseItem', item)
|
||||
end)
|
||||
|
||||
+236
-490
@@ -1,15 +1,35 @@
|
||||
QBCore.Functions = {}
|
||||
QBCore.RequestId = 0
|
||||
|
||||
QBCore.Functions.GetPlayerData = function(cb) -- QBCore.Functions.GetPlayerData() falls under GPL License here: [esxlicense]/LICENSE
|
||||
if cb ~= nil then
|
||||
-- Player
|
||||
|
||||
function QBCore.Functions.GetPlayerData(cb)
|
||||
if cb then
|
||||
cb(QBCore.PlayerData)
|
||||
else
|
||||
return QBCore.PlayerData
|
||||
end
|
||||
end
|
||||
|
||||
QBCore.Functions.DrawText = function(x, y, width, height, scale, r, g, b, a, text)
|
||||
function QBCore.Functions.GetCoords(entity)
|
||||
local coords = GetEntityCoords(entity, false)
|
||||
local heading = GetEntityHeading(entity)
|
||||
return vector4(coords.x, coords.y, coords.z, heading)
|
||||
end
|
||||
|
||||
function QBCore.Functions.HasItem(item)
|
||||
QBCore.Functions.TriggerCallback('QBCore:HasItem', function(result)
|
||||
if result then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end, item)
|
||||
return false
|
||||
end
|
||||
|
||||
-- Utility
|
||||
|
||||
function QBCore.Functions.DrawText(x, y, width, height, scale, r, g, b, a, text) -- Use local function instead
|
||||
SetTextFont(4)
|
||||
SetTextProportional(0)
|
||||
SetTextScale(scale, scale)
|
||||
@@ -18,17 +38,17 @@ QBCore.Functions.DrawText = function(x, y, width, height, scale, r, g, b, a, tex
|
||||
SetTextEdge(2, 0, 0, 0, 255)
|
||||
SetTextDropShadow()
|
||||
SetTextOutline()
|
||||
SetTextEntry("STRING")
|
||||
SetTextEntry('STRING')
|
||||
AddTextComponentString(text)
|
||||
DrawText(x - width/2, y - height/2 + 0.005)
|
||||
end
|
||||
|
||||
QBCore.Functions.DrawText3D = function(x, y, z, text)
|
||||
function QBCore.Functions.DrawText3D(x, y, z, text) -- Use local function instead
|
||||
SetTextScale(0.35, 0.35)
|
||||
SetTextFont(4)
|
||||
SetTextProportional(1)
|
||||
SetTextColour(255, 255, 255, 215)
|
||||
SetTextEntry("STRING")
|
||||
SetTextEntry('STRING')
|
||||
SetTextCentre(true)
|
||||
AddTextComponentString(text)
|
||||
SetDrawOrigin(x,y,z, 0)
|
||||
@@ -38,211 +58,22 @@ QBCore.Functions.DrawText3D = function(x, y, z, text)
|
||||
ClearDrawOrigin()
|
||||
end
|
||||
|
||||
QBCore.Functions.GetCoords = function(entity)
|
||||
local coords = GetEntityCoords(entity, false)
|
||||
local heading = GetEntityHeading(entity)
|
||||
return {
|
||||
x = coords.x,
|
||||
y = coords.y,
|
||||
z = coords.z,
|
||||
w = heading
|
||||
}
|
||||
function QBCore.Functions.Notify(text, textype, length)
|
||||
local ttype = textype or 'primary'
|
||||
local length = length or 5000
|
||||
SendNUIMessage({action = 'show', type = ttype, length = length, text = text})
|
||||
end
|
||||
|
||||
QBCore.Functions.SpawnVehicle = function(model, cb, coords, isnetworked) -- QBCore.Functions.SpawnVehicle() falls under GPL License here: [esxlicense]/LICENSE
|
||||
local model = (type(model)=="number" and model or GetHashKey(model))
|
||||
local coords = coords ~= nil and coords or QBCore.Functions.GetCoords(PlayerPedId())
|
||||
local isnetworked = isnetworked ~= nil and isnetworked or true
|
||||
|
||||
RequestModel(model)
|
||||
while not HasModelLoaded(model) do
|
||||
Citizen.Wait(10)
|
||||
end
|
||||
|
||||
local veh = CreateVehicle(model, coords.x, coords.y, coords.z, coords.w, isnetworked, false)
|
||||
local netid = NetworkGetNetworkIdFromEntity(veh)
|
||||
|
||||
SetVehicleHasBeenOwnedByPlayer(veh, true)
|
||||
SetNetworkIdCanMigrate(netid, true)
|
||||
SetVehicleNeedsToBeHotwired(veh, false)
|
||||
SetVehRadioStation(veh, "OFF")
|
||||
|
||||
SetModelAsNoLongerNeeded(model)
|
||||
|
||||
if cb ~= nil then
|
||||
cb(veh)
|
||||
end
|
||||
function QBCore.Debug(resource, obj, depth)
|
||||
TriggerServerEvent('QBCore:DebugSomething', resource, obj, depth)
|
||||
end
|
||||
|
||||
QBCore.Functions.DeleteVehicle = function(vehicle)
|
||||
SetEntityAsMissionEntity(vehicle, true, true)
|
||||
DeleteVehicle(vehicle)
|
||||
function QBCore.Functions.TriggerCallback(name, cb, ...)
|
||||
QBCore.ServerCallbacks[name] = cb
|
||||
TriggerServerEvent('QBCore:Server:TriggerCallback', name, ...)
|
||||
end
|
||||
|
||||
QBCore.Functions.Notify = function(text, textype, length)
|
||||
local ttype = textype ~= nil and textype or "primary"
|
||||
local length = length ~= nil and length or 5000
|
||||
SendNUIMessage({
|
||||
action = "show",
|
||||
type = ttype,
|
||||
length = length,
|
||||
text = text,
|
||||
})
|
||||
end
|
||||
|
||||
QBCore.Functions.TriggerCallback = function(name, cb, ...) -- QBCore.Functions.TriggerCallback() falls under GPL License here: [esxlicense]/LICENSE
|
||||
QBCore.ServerCallbacks[name] = cb
|
||||
TriggerServerEvent("QBCore:Server:TriggerCallback", name, ...)
|
||||
end
|
||||
|
||||
QBCore.Functions.GetVehicles = function()
|
||||
local vehiclePool = GetGamePool('CVehicle')
|
||||
local vehicles = {}
|
||||
|
||||
for i = 1, #vehiclePool, 1 do
|
||||
table.insert(vehicles, vehiclePool[i])
|
||||
end
|
||||
|
||||
return vehicles
|
||||
end
|
||||
|
||||
QBCore.Functions.GetPeds = function(ignoreList)
|
||||
local pedPool = GetGamePool('CPed')
|
||||
local ignoreList = ignoreList or {}
|
||||
local peds = {}
|
||||
|
||||
for i = 1, #pedPool, 1 do
|
||||
local found = false
|
||||
|
||||
for j=1, #ignoreList, 1 do
|
||||
if ignoreList[j] == pedPool[i] then
|
||||
found = true
|
||||
end
|
||||
end
|
||||
|
||||
if not found then
|
||||
table.insert(peds, pedPool[i])
|
||||
end
|
||||
end
|
||||
|
||||
return peds
|
||||
end
|
||||
|
||||
QBCore.Functions.GetPlayers = function() -- QBCore.Functions.GetPlayers() falls under GPL License here: [esxlicense]/LICENSE
|
||||
local players = {}
|
||||
for _, player in ipairs(GetActivePlayers()) do
|
||||
local ped = GetPlayerPed(player)
|
||||
if DoesEntityExist(ped) then
|
||||
table.insert(players, player)
|
||||
end
|
||||
end
|
||||
return players
|
||||
end
|
||||
|
||||
QBCore.Functions.GetClosestVehicle = function(coords)
|
||||
local vehicles = QBCore.Functions.GetVehicles()
|
||||
local closestDistance = -1
|
||||
local closestVehicle = -1
|
||||
local coords = coords
|
||||
|
||||
if coords == nil then
|
||||
local playerPed = PlayerPedId()
|
||||
coords = GetEntityCoords(playerPed)
|
||||
end
|
||||
for i=1, #vehicles, 1 do
|
||||
local vehicleCoords = GetEntityCoords(vehicles[i])
|
||||
local distance = #(vehicleCoords - coords)
|
||||
|
||||
if closestDistance == -1 or closestDistance > distance then
|
||||
closestVehicle = vehicles[i]
|
||||
closestDistance = distance
|
||||
end
|
||||
end
|
||||
return closestVehicle
|
||||
end
|
||||
|
||||
QBCore.Functions.GetClosestPed = function(coords, ignoreList)
|
||||
local ignoreList = ignoreList or {}
|
||||
local peds = QBCore.Functions.GetPeds(ignoreList)
|
||||
local closestDistance = -1
|
||||
local closestPed = -1
|
||||
|
||||
if coords == nil then
|
||||
coords = GetEntityCoords(PlayerPedId())
|
||||
end
|
||||
|
||||
for i=1, #peds, 1 do
|
||||
local pedCoords = GetEntityCoords(peds[i])
|
||||
local distance = #(pedCoords - coords)
|
||||
|
||||
if closestDistance == -1 or closestDistance > distance then
|
||||
closestPed = peds[i]
|
||||
closestDistance = distance
|
||||
end
|
||||
end
|
||||
|
||||
return closestPed, closestDistance
|
||||
end
|
||||
|
||||
|
||||
QBCore.Functions.GetClosestPlayer = function(coords)
|
||||
if coords == nil then
|
||||
coords = GetEntityCoords(PlayerPedId())
|
||||
end
|
||||
|
||||
local closestPlayers = QBCore.Functions.GetPlayersFromCoords(coords)
|
||||
local closestDistance = -1
|
||||
local closestPlayer = -1
|
||||
|
||||
for i=1, #closestPlayers, 1 do
|
||||
if closestPlayers[i] ~= PlayerId() and closestPlayers[i] ~= -1 then
|
||||
local pos = GetEntityCoords(GetPlayerPed(closestPlayers[i]))
|
||||
local distance = #(pos - coords)
|
||||
|
||||
if closestDistance == -1 or closestDistance > distance then
|
||||
closestPlayer = closestPlayers[i]
|
||||
closestDistance = distance
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return closestPlayer, closestDistance
|
||||
end
|
||||
|
||||
QBCore.Functions.GetPlayersFromCoords = function(coords, distance)
|
||||
local players = QBCore.Functions.GetPlayers()
|
||||
local closePlayers = {}
|
||||
|
||||
if coords == nil then
|
||||
coords = GetEntityCoords(PlayerPedId())
|
||||
end
|
||||
if distance == nil then
|
||||
distance = 5.0
|
||||
end
|
||||
for _, player in pairs(players) do
|
||||
local target = GetPlayerPed(player)
|
||||
local targetCoords = GetEntityCoords(target)
|
||||
local targetdistance = #(targetCoords - coords)
|
||||
if targetdistance <= distance then
|
||||
table.insert(closePlayers, player)
|
||||
end
|
||||
end
|
||||
|
||||
return closePlayers
|
||||
end
|
||||
|
||||
QBCore.Functions.HasItem = function(source, cb, item)
|
||||
local retval = false
|
||||
QBCore.Functions.TriggerCallback('QBCore:HasItem', function(result)
|
||||
if result then
|
||||
retval = true
|
||||
end
|
||||
return retval
|
||||
end, item)
|
||||
return retval
|
||||
end
|
||||
|
||||
QBCore.Functions.Progressbar = function(name, label, duration, useWhileDead, canCancel, disableControls, animation, prop, propTwo, onFinish, onCancel)
|
||||
function QBCore.Functions.Progressbar(name, label, duration, useWhileDead, canCancel, disableControls, animation, prop, propTwo, onFinish, onCancel)
|
||||
exports['progressbar']:Progress({
|
||||
name = name:lower(),
|
||||
duration = duration,
|
||||
@@ -255,18 +86,116 @@ QBCore.Functions.Progressbar = function(name, label, duration, useWhileDead, can
|
||||
propTwo = propTwo,
|
||||
}, function(cancelled)
|
||||
if not cancelled then
|
||||
if onFinish ~= nil then
|
||||
if onFinish then
|
||||
onFinish()
|
||||
end
|
||||
else
|
||||
if onCancel ~= nil then
|
||||
if onCancel then
|
||||
onCancel()
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
function Round(value, numDecimalPlaces)
|
||||
-- Getters
|
||||
|
||||
function QBCore.Functions.GetVehicles() return GetGamePool('CVehicle') end
|
||||
function QBCore.Functions.GetPeds() return GetGamePool('CPed') end
|
||||
function QBCore.Functions.GetObjects() return GetGamePool('CObject') end
|
||||
function QBCore.Functions.GetPlayers() return GetActivePlayers() end
|
||||
|
||||
function QBCore.Functions.GetClosestPlayer(coords)
|
||||
if coords == nil then
|
||||
coords = GetEntityCoords(PlayerPedId())
|
||||
end
|
||||
local closestPlayers = QBCore.Functions.GetPlayersFromCoords(coords)
|
||||
local closestDistance = -1
|
||||
local closestPlayer = -1
|
||||
for i=1, #closestPlayers, 1 do
|
||||
if closestPlayers[i] ~= PlayerId() and closestPlayers[i] ~= -1 then
|
||||
local pos = GetEntityCoords(GetPlayerPed(closestPlayers[i]))
|
||||
local distance = #(pos - coords)
|
||||
|
||||
if closestDistance == -1 or closestDistance > distance then
|
||||
closestPlayer = closestPlayers[i]
|
||||
closestDistance = distance
|
||||
end
|
||||
end
|
||||
end
|
||||
return closestPlayer, closestDistance
|
||||
end
|
||||
|
||||
function QBCore.Functions.GetPlayersFromCoords(coords, distance)
|
||||
local players = QBCore.Functions.GetPlayers()
|
||||
local coords = coords or GetEntityCoords(PlayerPedId())
|
||||
local distance = distance or 5
|
||||
local closePlayers = {}
|
||||
for _, player in pairs(players) do
|
||||
local target = GetPlayerPed(player)
|
||||
local targetCoords = GetEntityCoords(target)
|
||||
local targetdistance = #(targetCoords - coords)
|
||||
if targetdistance <= distance then
|
||||
closePlayers[player] = player
|
||||
end
|
||||
end
|
||||
return closePlayers
|
||||
end
|
||||
|
||||
function QBCore.Functions.GetClosestVehicle()
|
||||
local ped = PlayerPedId()
|
||||
local coords = GetEntityCoords(ped)
|
||||
local vehicles = GetGamePool('CVehicle')
|
||||
local closestDistance = -1
|
||||
local closestVehicle = -1
|
||||
for i = 1, #vehicles, 1 do
|
||||
local vehicleCoords = GetEntityCoords(vehicles[i])
|
||||
local distance = #(vehicleCoords - coords)
|
||||
if closestDistance == -1 or closestDistance > distance then
|
||||
closestVehicle = vehicles[i]
|
||||
closestDistance = distance
|
||||
end
|
||||
end
|
||||
return closestVehicle
|
||||
end
|
||||
|
||||
function QBCore.Functions.GetClosestObject()
|
||||
local ped = PlayerPedId()
|
||||
local coords = GetEntityCoords(ped)
|
||||
local objects = GetGamePool('CObject')
|
||||
local closestDistance = -1
|
||||
local closestObject = -1
|
||||
for i = 1, #objects, 1 do
|
||||
local objectCoords = GetEntityCoords(objects[i])
|
||||
local distance = #(objectCoords - coords)
|
||||
if closestDistance == -1 or closestDistance > distance then
|
||||
closestObject = objects[i]
|
||||
closestDistance = distance
|
||||
end
|
||||
end
|
||||
return closestObject
|
||||
end
|
||||
|
||||
function QBCore.Functions.GetClosestPed()
|
||||
local ped = PlayerPedId()
|
||||
local coords = GetEntityCoords(ped)
|
||||
local peds = GetGamePool('CPed')
|
||||
local closestDistance = -1
|
||||
local closestPed = -1
|
||||
for i = 1, #peds, 1 do
|
||||
local pedCoords = GetEntityCoords(peds[i])
|
||||
local distance = #(pedCoords - coords)
|
||||
|
||||
if closestDistance == -1 or closestDistance > distance then
|
||||
closestPed = peds[i]
|
||||
closestDistance = distance
|
||||
end
|
||||
end
|
||||
return closestPed
|
||||
end
|
||||
|
||||
-- Vehicle
|
||||
|
||||
local function Round(value, numDecimalPlaces)
|
||||
if numDecimalPlaces then
|
||||
local power = 10^numDecimalPlaces
|
||||
return math.floor((value * power) + 0.5) / (power)
|
||||
@@ -275,16 +204,38 @@ function Round(value, numDecimalPlaces)
|
||||
end
|
||||
end
|
||||
|
||||
function Trim(value)
|
||||
local function Trim(value)
|
||||
if value then
|
||||
return (string.gsub(value, "^%s*(.-)%s*$", "%1"))
|
||||
return (string.gsub(value, '^%s*(.-)%s*$', '%1'))
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
QBCore.Functions.GetVehicleProperties = function(vehicle)
|
||||
if DoesEntityExist(vehicle) then
|
||||
function QBCore.Functions.SpawnVehicle(model, cb, coords, isnetworked)
|
||||
local model = GetHashKey(model)
|
||||
local coords = coords or QBCore.Functions.GetCoords(PlayerPedId())
|
||||
local isnetworked = isnetworked or true
|
||||
if not IsModelInCdimage(model) then return end
|
||||
RequestModel(model)
|
||||
while not HasModelLoaded(model) do Citizen.Wait(10) end
|
||||
local veh = CreateVehicle(model, coords.x, coords.y, coords.z, coords.w, isnetworked, false)
|
||||
local netid = NetworkGetNetworkIdFromEntity(veh)
|
||||
SetVehicleHasBeenOwnedByPlayer(veh, true)
|
||||
SetNetworkIdCanMigrate(netid, true)
|
||||
SetVehicleNeedsToBeHotwired(veh, false)
|
||||
SetVehRadioStation(veh, 'OFF')
|
||||
SetModelAsNoLongerNeeded(model)
|
||||
if cb then cb(veh) end
|
||||
end
|
||||
|
||||
function QBCore.Functions.DeleteVehicle(vehicle)
|
||||
SetEntityAsMissionEntity(vehicle, true, true)
|
||||
DeleteVehicle(vehicle)
|
||||
end
|
||||
|
||||
function QBCore.Functions.GetVehicleProperties(vehicle)
|
||||
if DoesEntityExist(vehicle) then
|
||||
local colorPrimary, colorSecondary = GetVehicleColours(vehicle)
|
||||
local pearlescentColor, wheelColor = GetVehicleExtraColours(vehicle)
|
||||
local extras = {}
|
||||
@@ -298,40 +249,31 @@ QBCore.Functions.GetVehicleProperties = function(vehicle)
|
||||
|
||||
return {
|
||||
model = GetEntityModel(vehicle),
|
||||
|
||||
plate = Trim(GetVehicleNumberPlateText(vehicle)),
|
||||
plateIndex = GetVehicleNumberPlateTextIndex(vehicle),
|
||||
|
||||
bodyHealth = Round(GetVehicleBodyHealth(vehicle), 1),
|
||||
engineHealth = Round(GetVehicleEngineHealth(vehicle), 1),
|
||||
tankHealth = Round(GetVehiclePetrolTankHealth(vehicle), 1),
|
||||
|
||||
fuelLevel = Round(GetVehicleFuelLevel(vehicle), 1),
|
||||
dirtLevel = Round(GetVehicleDirtLevel(vehicle), 1),
|
||||
|
||||
color1 = colorPrimary,
|
||||
color2 = colorSecondary,
|
||||
|
||||
pearlescentColor = pearlescentColor,
|
||||
interiorColor = GetVehicleInteriorColor(vehicle),
|
||||
dashboardColor = GetVehicleDashboardColour(vehicle),
|
||||
interiorColor = GetVehicleInteriorColor(vehicle),
|
||||
dashboardColor = GetVehicleDashboardColour(vehicle),
|
||||
wheelColor = wheelColor,
|
||||
|
||||
wheels = GetVehicleWheelType(vehicle),
|
||||
windowTint = GetVehicleWindowTint(vehicle),
|
||||
xenonColor = GetVehicleXenonLightsColour(vehicle),
|
||||
|
||||
neonEnabled = {
|
||||
IsVehicleNeonLightEnabled(vehicle, 0),
|
||||
IsVehicleNeonLightEnabled(vehicle, 1),
|
||||
IsVehicleNeonLightEnabled(vehicle, 2),
|
||||
IsVehicleNeonLightEnabled(vehicle, 3)
|
||||
},
|
||||
|
||||
neonColor = table.pack(GetVehicleNeonLightsColour(vehicle)),
|
||||
extras = extras,
|
||||
tyreSmokeColor = table.pack(GetVehicleTyreSmokeColor(vehicle)),
|
||||
|
||||
modSpoilers = GetVehicleMod(vehicle, 0),
|
||||
modFrontBumper = GetVehicleMod(vehicle, 1),
|
||||
modRearBumper = GetVehicleMod(vehicle, 2),
|
||||
@@ -343,23 +285,19 @@ QBCore.Functions.GetVehicleProperties = function(vehicle)
|
||||
modFender = GetVehicleMod(vehicle, 8),
|
||||
modRightFender = GetVehicleMod(vehicle, 9),
|
||||
modRoof = GetVehicleMod(vehicle, 10),
|
||||
|
||||
modEngine = GetVehicleMod(vehicle, 11),
|
||||
modBrakes = GetVehicleMod(vehicle, 12),
|
||||
modTransmission = GetVehicleMod(vehicle, 13),
|
||||
modHorns = GetVehicleMod(vehicle, 14),
|
||||
modSuspension = GetVehicleMod(vehicle, 15),
|
||||
modArmor = GetVehicleMod(vehicle, 16),
|
||||
|
||||
modTurbo = IsToggleModOn(vehicle, 18),
|
||||
modSmokeEnabled = IsToggleModOn(vehicle, 20),
|
||||
modXenon = IsToggleModOn(vehicle, 22),
|
||||
|
||||
modFrontWheels = GetVehicleMod(vehicle, 23),
|
||||
modBackWheels = GetVehicleMod(vehicle, 24),
|
||||
modCustomTiresF = GetVehicleModVariation(vehicle, 23),
|
||||
modCustomTiresR = GetVehicleModVariation(vehicle, 24),
|
||||
|
||||
modCustomTiresF = GetVehicleModVariation(vehicle, 23),
|
||||
modCustomTiresR = GetVehicleModVariation(vehicle, 24),
|
||||
modPlateHolder = GetVehicleMod(vehicle, 25),
|
||||
modVanityPlate = GetVehicleMod(vehicle, 26),
|
||||
modTrimA = GetVehicleMod(vehicle, 27),
|
||||
@@ -389,76 +327,32 @@ QBCore.Functions.GetVehicleProperties = function(vehicle)
|
||||
end
|
||||
end
|
||||
|
||||
QBCore.Functions.SetVehicleProperties = function(vehicle, props)
|
||||
if DoesEntityExist(vehicle) then
|
||||
function QBCore.Functions.SetVehicleProperties(vehicle, props)
|
||||
if DoesEntityExist(vehicle) then
|
||||
local colorPrimary, colorSecondary = GetVehicleColours(vehicle)
|
||||
local pearlescentColor, wheelColor = GetVehicleExtraColours(vehicle)
|
||||
SetVehicleModKit(vehicle, 0)
|
||||
|
||||
if props.plate ~= nil then
|
||||
SetVehicleNumberPlateText(vehicle, props.plate)
|
||||
end
|
||||
|
||||
if props.plateIndex ~= nil then
|
||||
SetVehicleNumberPlateTextIndex(vehicle, props.plateIndex)
|
||||
end
|
||||
|
||||
if props.bodyHealth ~= nil then
|
||||
SetVehicleBodyHealth(vehicle, props.bodyHealth + 0.0)
|
||||
end
|
||||
|
||||
if props.engineHealth ~= nil then
|
||||
SetVehicleEngineHealth(vehicle, props.engineHealth + 0.0)
|
||||
end
|
||||
|
||||
if props.fuelLevel ~= nil then
|
||||
SetVehicleFuelLevel(vehicle, props.fuelLevel + 0.0)
|
||||
end
|
||||
|
||||
if props.dirtLevel ~= nil then
|
||||
SetVehicleDirtLevel(vehicle, props.dirtLevel + 0.0)
|
||||
end
|
||||
|
||||
if props.color1 ~= nil then
|
||||
SetVehicleColours(vehicle, props.color1, colorSecondary)
|
||||
end
|
||||
|
||||
if props.color2 ~= nil then
|
||||
SetVehicleColours(vehicle, props.color1 or colorPrimary, props.color2)
|
||||
end
|
||||
|
||||
if props.pearlescentColor ~= nil then
|
||||
SetVehicleExtraColours(vehicle, props.pearlescentColor, wheelColor)
|
||||
end
|
||||
|
||||
if props.interiorColor ~= nil then
|
||||
SetVehicleInteriorColor(vehicle, props.interiorColor)
|
||||
end
|
||||
|
||||
if props.dashboardColor ~= nil then
|
||||
SetVehicleDashboardColour(vehicle, props.dashboardColor)
|
||||
end
|
||||
|
||||
if props.wheelColor ~= nil then
|
||||
SetVehicleExtraColours(vehicle, props.pearlescentColor or pearlescentColor, props.wheelColor)
|
||||
end
|
||||
|
||||
if props.wheels ~= nil then
|
||||
SetVehicleWheelType(vehicle, props.wheels)
|
||||
end
|
||||
|
||||
if props.windowTint ~= nil then
|
||||
SetVehicleWindowTint(vehicle, props.windowTint)
|
||||
end
|
||||
|
||||
if props.neonEnabled ~= nil then
|
||||
if props.plate then SetVehicleNumberPlateText(vehicle, props.plate) end
|
||||
if props.plateIndex then SetVehicleNumberPlateTextIndex(vehicle, props.plateIndex) end
|
||||
if props.bodyHealth then SetVehicleBodyHealth(vehicle, props.bodyHealth + 0.0) end
|
||||
if props.engineHealth then SetVehicleEngineHealth(vehicle, props.engineHealth + 0.0) end
|
||||
if props.fuelLevel then SetVehicleFuelLevel(vehicle, props.fuelLevel + 0.0) end
|
||||
if props.dirtLevel then SetVehicleDirtLevel(vehicle, props.dirtLevel + 0.0) end
|
||||
if props.color1 then SetVehicleColours(vehicle, props.color1, colorSecondary) end
|
||||
if props.color2 then SetVehicleColours(vehicle, props.color1 or colorPrimary, props.color2) end
|
||||
if props.pearlescentColor then SetVehicleExtraColours(vehicle, props.pearlescentColor, wheelColor) end
|
||||
if props.interiorColor then SetVehicleInteriorColor(vehicle, props.interiorColor) end
|
||||
if props.dashboardColor then SetVehicleDashboardColour(vehicle, props.dashboardColor) end
|
||||
if props.wheelColor then SetVehicleExtraColours(vehicle, props.pearlescentColor or pearlescentColor, props.wheelColor) end
|
||||
if props.wheels then SetVehicleWheelType(vehicle, props.wheels) end
|
||||
if props.windowTint then SetVehicleWindowTint(vehicle, props.windowTint) end
|
||||
if props.neonEnabled then
|
||||
SetVehicleNeonLightEnabled(vehicle, 0, props.neonEnabled[1])
|
||||
SetVehicleNeonLightEnabled(vehicle, 1, props.neonEnabled[2])
|
||||
SetVehicleNeonLightEnabled(vehicle, 2, props.neonEnabled[3])
|
||||
SetVehicleNeonLightEnabled(vehicle, 3, props.neonEnabled[4])
|
||||
end
|
||||
|
||||
if props.extras ~= nil then
|
||||
if props.extras then
|
||||
for id,enabled in pairs(props.extras) do
|
||||
if enabled then
|
||||
SetVehicleExtra(vehicle, tonumber(id), 0)
|
||||
@@ -467,206 +361,58 @@ QBCore.Functions.SetVehicleProperties = function(vehicle, props)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if props.neonColor ~= nil then
|
||||
SetVehicleNeonLightsColour(vehicle, props.neonColor[1], props.neonColor[2], props.neonColor[3])
|
||||
end
|
||||
|
||||
if props.modSmokeEnabled ~= nil then
|
||||
ToggleVehicleMod(vehicle, 20, true)
|
||||
end
|
||||
|
||||
if props.tyreSmokeColor ~= nil then
|
||||
SetVehicleTyreSmokeColor(vehicle, props.tyreSmokeColor[1], props.tyreSmokeColor[2], props.tyreSmokeColor[3])
|
||||
end
|
||||
|
||||
if props.modSpoilers ~= nil then
|
||||
SetVehicleMod(vehicle, 0, props.modSpoilers, false)
|
||||
end
|
||||
|
||||
if props.modFrontBumper ~= nil then
|
||||
SetVehicleMod(vehicle, 1, props.modFrontBumper, false)
|
||||
end
|
||||
|
||||
if props.modRearBumper ~= nil then
|
||||
SetVehicleMod(vehicle, 2, props.modRearBumper, false)
|
||||
end
|
||||
|
||||
if props.modSideSkirt ~= nil then
|
||||
SetVehicleMod(vehicle, 3, props.modSideSkirt, false)
|
||||
end
|
||||
|
||||
if props.modExhaust ~= nil then
|
||||
SetVehicleMod(vehicle, 4, props.modExhaust, false)
|
||||
end
|
||||
|
||||
if props.modFrame ~= nil then
|
||||
SetVehicleMod(vehicle, 5, props.modFrame, false)
|
||||
end
|
||||
|
||||
if props.modGrille ~= nil then
|
||||
SetVehicleMod(vehicle, 6, props.modGrille, false)
|
||||
end
|
||||
|
||||
if props.modHood ~= nil then
|
||||
SetVehicleMod(vehicle, 7, props.modHood, false)
|
||||
end
|
||||
|
||||
if props.modFender ~= nil then
|
||||
SetVehicleMod(vehicle, 8, props.modFender, false)
|
||||
end
|
||||
|
||||
if props.modRightFender ~= nil then
|
||||
SetVehicleMod(vehicle, 9, props.modRightFender, false)
|
||||
end
|
||||
|
||||
if props.modRoof ~= nil then
|
||||
SetVehicleMod(vehicle, 10, props.modRoof, false)
|
||||
end
|
||||
|
||||
if props.modEngine ~= nil then
|
||||
SetVehicleMod(vehicle, 11, props.modEngine, false)
|
||||
end
|
||||
|
||||
if props.modBrakes ~= nil then
|
||||
SetVehicleMod(vehicle, 12, props.modBrakes, false)
|
||||
end
|
||||
|
||||
if props.modTransmission ~= nil then
|
||||
SetVehicleMod(vehicle, 13, props.modTransmission, false)
|
||||
end
|
||||
|
||||
if props.modHorns ~= nil then
|
||||
SetVehicleMod(vehicle, 14, props.modHorns, false)
|
||||
end
|
||||
|
||||
if props.modSuspension ~= nil then
|
||||
SetVehicleMod(vehicle, 15, props.modSuspension, false)
|
||||
end
|
||||
|
||||
if props.modArmor ~= nil then
|
||||
SetVehicleMod(vehicle, 16, props.modArmor, false)
|
||||
end
|
||||
|
||||
if props.modTurbo ~= nil then
|
||||
ToggleVehicleMod(vehicle, 18, props.modTurbo)
|
||||
end
|
||||
|
||||
if props.modXenon ~= nil then
|
||||
ToggleVehicleMod(vehicle, 22, props.modXenon)
|
||||
end
|
||||
|
||||
if props.xenonColor ~= nil then
|
||||
SetVehicleXenonLightsColor(vehicle, props.xenonColor)
|
||||
end
|
||||
|
||||
if props.modFrontWheels ~= nil then
|
||||
SetVehicleMod(vehicle, 23, props.modFrontWheels, false)
|
||||
end
|
||||
|
||||
if props.modBackWheels ~= nil then
|
||||
SetVehicleMod(vehicle, 24, props.modBackWheels, false)
|
||||
end
|
||||
|
||||
if props.modCustomTiresF ~= nil then
|
||||
SetVehicleMod(vehicle, 23, props.modFrontWheels, props.modCustomTiresF)
|
||||
end
|
||||
|
||||
if props.modCustomTiresR ~= nil then
|
||||
SetVehicleMod(vehicle, 24, props.modBackWheels, props.modCustomTiresR)
|
||||
end
|
||||
|
||||
if props.modPlateHolder ~= nil then
|
||||
SetVehicleMod(vehicle, 25, props.modPlateHolder, false)
|
||||
end
|
||||
|
||||
if props.modVanityPlate ~= nil then
|
||||
SetVehicleMod(vehicle, 26, props.modVanityPlate, false)
|
||||
end
|
||||
|
||||
if props.modTrimA ~= nil then
|
||||
SetVehicleMod(vehicle, 27, props.modTrimA, false)
|
||||
end
|
||||
|
||||
if props.modOrnaments ~= nil then
|
||||
SetVehicleMod(vehicle, 28, props.modOrnaments, false)
|
||||
end
|
||||
|
||||
if props.modDashboard ~= nil then
|
||||
SetVehicleMod(vehicle, 29, props.modDashboard, false)
|
||||
end
|
||||
|
||||
if props.modDial ~= nil then
|
||||
SetVehicleMod(vehicle, 30, props.modDial, false)
|
||||
end
|
||||
|
||||
if props.modDoorSpeaker ~= nil then
|
||||
SetVehicleMod(vehicle, 31, props.modDoorSpeaker, false)
|
||||
end
|
||||
|
||||
if props.modSeats ~= nil then
|
||||
SetVehicleMod(vehicle, 32, props.modSeats, false)
|
||||
end
|
||||
|
||||
if props.modSteeringWheel ~= nil then
|
||||
SetVehicleMod(vehicle, 33, props.modSteeringWheel, false)
|
||||
end
|
||||
|
||||
if props.modShifterLeavers ~= nil then
|
||||
SetVehicleMod(vehicle, 34, props.modShifterLeavers, false)
|
||||
end
|
||||
|
||||
if props.modAPlate ~= nil then
|
||||
SetVehicleMod(vehicle, 35, props.modAPlate, false)
|
||||
end
|
||||
|
||||
if props.modSpeakers ~= nil then
|
||||
SetVehicleMod(vehicle, 36, props.modSpeakers, false)
|
||||
end
|
||||
|
||||
if props.modTrunk ~= nil then
|
||||
SetVehicleMod(vehicle, 37, props.modTrunk, false)
|
||||
end
|
||||
|
||||
if props.modHydrolic ~= nil then
|
||||
SetVehicleMod(vehicle, 38, props.modHydrolic, false)
|
||||
end
|
||||
|
||||
if props.modEngineBlock ~= nil then
|
||||
SetVehicleMod(vehicle, 39, props.modEngineBlock, false)
|
||||
end
|
||||
|
||||
if props.modAirFilter ~= nil then
|
||||
SetVehicleMod(vehicle, 40, props.modAirFilter, false)
|
||||
end
|
||||
|
||||
if props.modStruts ~= nil then
|
||||
SetVehicleMod(vehicle, 41, props.modStruts, false)
|
||||
end
|
||||
|
||||
if props.modArchCover ~= nil then
|
||||
SetVehicleMod(vehicle, 42, props.modArchCover, false)
|
||||
end
|
||||
|
||||
if props.modAerials ~= nil then
|
||||
SetVehicleMod(vehicle, 43, props.modAerials, false)
|
||||
end
|
||||
|
||||
if props.modTrimB ~= nil then
|
||||
SetVehicleMod(vehicle, 44, props.modTrimB, false)
|
||||
end
|
||||
|
||||
if props.modTank ~= nil then
|
||||
SetVehicleMod(vehicle, 45, props.modTank, false)
|
||||
end
|
||||
|
||||
if props.modWindows ~= nil then
|
||||
SetVehicleMod(vehicle, 46, props.modWindows, false)
|
||||
end
|
||||
|
||||
if props.modLivery ~= nil then
|
||||
if props.neonColor then SetVehicleNeonLightsColour(vehicle, props.neonColor[1], props.neonColor[2], props.neonColor[3]) end
|
||||
if props.modSmokeEnabled then ToggleVehicleMod(vehicle, 20, true) end
|
||||
if props.tyreSmokeColor then SetVehicleTyreSmokeColor(vehicle, props.tyreSmokeColor[1], props.tyreSmokeColor[2], props.tyreSmokeColor[3]) end
|
||||
if props.modSpoilers then SetVehicleMod(vehicle, 0, props.modSpoilers, false) end
|
||||
if props.modFrontBumper then SetVehicleMod(vehicle, 1, props.modFrontBumper, false) end
|
||||
if props.modRearBumper then SetVehicleMod(vehicle, 2, props.modRearBumper, false) end
|
||||
if props.modSideSkirt then SetVehicleMod(vehicle, 3, props.modSideSkirt, false) end
|
||||
if props.modExhaust then SetVehicleMod(vehicle, 4, props.modExhaust, false) end
|
||||
if props.modFrame then SetVehicleMod(vehicle, 5, props.modFrame, false) end
|
||||
if props.modGrille then SetVehicleMod(vehicle, 6, props.modGrille, false) end
|
||||
if props.modHood then SetVehicleMod(vehicle, 7, props.modHood, false) end
|
||||
if props.modFender then SetVehicleMod(vehicle, 8, props.modFender, false) end
|
||||
if props.modRightFender then SetVehicleMod(vehicle, 9, props.modRightFender, false) end
|
||||
if props.modRoof then SetVehicleMod(vehicle, 10, props.modRoof, false) end
|
||||
if props.modEngine then SetVehicleMod(vehicle, 11, props.modEngine, false) end
|
||||
if props.modBrakes then SetVehicleMod(vehicle, 12, props.modBrakes, false) end
|
||||
if props.modTransmission then SetVehicleMod(vehicle, 13, props.modTransmission, false) end
|
||||
if props.modHorns then SetVehicleMod(vehicle, 14, props.modHorns, false) end
|
||||
if props.modSuspension then SetVehicleMod(vehicle, 15, props.modSuspension, false) end
|
||||
if props.modArmor then SetVehicleMod(vehicle, 16, props.modArmor, false) end
|
||||
if props.modTurbo then ToggleVehicleMod(vehicle, 18, props.modTurbo) end
|
||||
if props.modXenon then ToggleVehicleMod(vehicle, 22, props.modXenon) end
|
||||
if props.xenonColor then SetVehicleXenonLightsColor(vehicle, props.xenonColor) end
|
||||
if props.modFrontWheels then SetVehicleMod(vehicle, 23, props.modFrontWheels, false) end
|
||||
if props.modBackWheels then SetVehicleMod(vehicle, 24, props.modBackWheels, false) end
|
||||
if props.modCustomTiresF then SetVehicleMod(vehicle, 23, props.modFrontWheels, props.modCustomTiresF) end
|
||||
if props.modCustomTiresR then SetVehicleMod(vehicle, 24, props.modBackWheels, props.modCustomTiresR) end
|
||||
if props.modPlateHolder then SetVehicleMod(vehicle, 25, props.modPlateHolder, false) end
|
||||
if props.modVanityPlate then SetVehicleMod(vehicle, 26, props.modVanityPlate, false) end
|
||||
if props.modTrimA then SetVehicleMod(vehicle, 27, props.modTrimA, false) end
|
||||
if props.modOrnaments then SetVehicleMod(vehicle, 28, props.modOrnaments, false) end
|
||||
if props.modDashboard then SetVehicleMod(vehicle, 29, props.modDashboard, false) end
|
||||
if props.modDial then SetVehicleMod(vehicle, 30, props.modDial, false) end
|
||||
if props.modDoorSpeaker then SetVehicleMod(vehicle, 31, props.modDoorSpeaker, false) end
|
||||
if props.modSeats then SetVehicleMod(vehicle, 32, props.modSeats, false) end
|
||||
if props.modSteeringWheel then SetVehicleMod(vehicle, 33, props.modSteeringWheel, false) end
|
||||
if props.modShifterLeavers then SetVehicleMod(vehicle, 34, props.modShifterLeavers, false) end
|
||||
if props.modAPlate then SetVehicleMod(vehicle, 35, props.modAPlate, false) end
|
||||
if props.modSpeakers then SetVehicleMod(vehicle, 36, props.modSpeakers, false) end
|
||||
if props.modTrunk then SetVehicleMod(vehicle, 37, props.modTrunk, false) end
|
||||
if props.modHydrolic then SetVehicleMod(vehicle, 38, props.modHydrolic, false) end
|
||||
if props.modEngineBlock then SetVehicleMod(vehicle, 39, props.modEngineBlock, false) end
|
||||
if props.modAirFilter then SetVehicleMod(vehicle, 40, props.modAirFilter, false) end
|
||||
if props.modStruts then SetVehicleMod(vehicle, 41, props.modStruts, false) end
|
||||
if props.modArchCover then SetVehicleMod(vehicle, 42, props.modArchCover, false) end
|
||||
if props.modAerials then SetVehicleMod(vehicle, 43, props.modAerials, false) end
|
||||
if props.modTrimB then SetVehicleMod(vehicle, 44, props.modTrimB, false) end
|
||||
if props.modTank then SetVehicleMod(vehicle, 45, props.modTank, false) end
|
||||
if props.modWindows then SetVehicleMod(vehicle, 46, props.modWindows, false) end
|
||||
if props.modLivery then
|
||||
SetVehicleMod(vehicle, 48, props.modLivery, false)
|
||||
SetVehicleLivery(vehicle, props.modLivery)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
+20
-45
@@ -1,48 +1,23 @@
|
||||
Citizen.CreateThread(function()
|
||||
while true do
|
||||
Citizen.Wait(7)
|
||||
if NetworkIsSessionStarted() then
|
||||
Citizen.Wait(10)
|
||||
TriggerServerEvent('QBCore:PlayerJoined')
|
||||
return
|
||||
end
|
||||
end
|
||||
CreateThread(function()
|
||||
while true do
|
||||
Wait(0)
|
||||
if LocalPlayer.state['isLoggedIn'] then
|
||||
Wait((1000 * 60) * QBCore.Config.UpdateInterval)
|
||||
TriggerServerEvent('QBCore:UpdatePlayer')
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
Citizen.CreateThread(function()
|
||||
while true do
|
||||
Citizen.Wait(7)
|
||||
if isLoggedIn then
|
||||
Citizen.Wait((1000 * 60) * 5)
|
||||
TriggerEvent("QBCore:Player:UpdatePlayerData")
|
||||
else
|
||||
Citizen.Wait(5000)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
Citizen.CreateThread(function()
|
||||
while true do
|
||||
Citizen.Wait(7)
|
||||
if isLoggedIn then
|
||||
Citizen.Wait(30000)
|
||||
TriggerEvent("QBCore:Player:UpdatePlayerPosition")
|
||||
else
|
||||
Citizen.Wait(5000)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
Citizen.CreateThread(function()
|
||||
while true do
|
||||
Citizen.Wait(math.random(3000, 5000))
|
||||
if isLoggedIn then
|
||||
if QBCore.Functions.GetPlayerData().metadata["hunger"] <= 0 or QBCore.Functions.GetPlayerData().metadata["thirst"] <= 0 then
|
||||
local ped = PlayerPedId()
|
||||
local currentHealth = GetEntityHealth(ped)
|
||||
|
||||
SetEntityHealth(ped, currentHealth - math.random(5, 10))
|
||||
end
|
||||
end
|
||||
end
|
||||
CreateThread(function()
|
||||
while true do
|
||||
Wait(QBCore.Config.StatusInterval)
|
||||
if LocalPlayer.state['isLoggedIn'] then
|
||||
if QBCore.Functions.GetPlayerData().metadata['hunger'] <= 0 or
|
||||
QBCore.Functions.GetPlayerData().metadata['thirst'] <= 0 then
|
||||
local ped = PlayerPedId()
|
||||
local currentHealth = GetEntityHealth(ped)
|
||||
SetEntityHealth(ped, currentHealth - math.random(5, 10))
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
+4
-20
@@ -4,26 +4,10 @@ QBCore.Config = QBConfig
|
||||
QBCore.Shared = QBShared
|
||||
QBCore.ServerCallbacks = {}
|
||||
|
||||
isLoggedIn = false
|
||||
|
||||
function GetCoreObject()
|
||||
exports('GetCoreObject', function()
|
||||
return QBCore
|
||||
end
|
||||
|
||||
RegisterNetEvent('QBCore:GetObject')
|
||||
AddEventHandler('QBCore:GetObject', function(cb)
|
||||
cb(GetCoreObject())
|
||||
end)
|
||||
|
||||
RegisterNetEvent('QBCore:Client:OnPlayerLoaded')
|
||||
AddEventHandler('QBCore:Client:OnPlayerLoaded', function()
|
||||
ShutdownLoadingScreenNui()
|
||||
isLoggedIn = true
|
||||
SetCanAttackFriendly(PlayerPedId(), true, false)
|
||||
NetworkSetFriendlyFireOption(true)
|
||||
end)
|
||||
|
||||
RegisterNetEvent('QBCore:Client:OnPlayerUnload')
|
||||
AddEventHandler('QBCore:Client:OnPlayerUnload', function()
|
||||
isLoggedIn = false
|
||||
end)
|
||||
-- To use this export in a script instead of manifest method
|
||||
-- Just put this line of code below at the very top of the script
|
||||
-- local QBCore = exports['qb-core']:GetCoreObject()
|
||||
@@ -2,6 +2,8 @@ QBConfig = {}
|
||||
|
||||
QBConfig.MaxPlayers = GetConvarInt('sv_maxclients', 64) -- Gets max players from config file, default 32
|
||||
QBConfig.DefaultSpawn = vector4(-1035.71, -2731.87, 12.86, 0.0)
|
||||
QBConfig.UpdateInterval = 5 -- how often to update player data in minutes
|
||||
QBConfig.StatusInterval = 5000 -- how often to check hunger/thirst status in ms
|
||||
|
||||
QBConfig.Money = {}
|
||||
QBConfig.Money.MoneyTypes = {['cash'] = 500, ['bank'] = 5000, ['crypto'] = 0 } -- ['type']=startamount - Add or remove money types for your server (for ex. ['blackmoney']=0), remember once added it will not be removed from the database!
|
||||
|
||||
+6
-10
@@ -4,7 +4,7 @@ game 'gta5'
|
||||
description 'QB-Core'
|
||||
version '1.0.0'
|
||||
|
||||
shared_scripts {
|
||||
shared_scripts {
|
||||
'import.lua',
|
||||
'config.lua',
|
||||
'shared.lua'
|
||||
@@ -14,25 +14,19 @@ client_scripts {
|
||||
'client/main.lua',
|
||||
'client/functions.lua',
|
||||
'client/loops.lua',
|
||||
'client/events.lua',
|
||||
'client/debug.lua'
|
||||
'client/events.lua'
|
||||
}
|
||||
|
||||
server_scripts {
|
||||
'server/main.lua',
|
||||
'server/functions.lua',
|
||||
'server/loops.lua',
|
||||
'server/player.lua',
|
||||
'server/events.lua',
|
||||
'server/commands.lua',
|
||||
'server/debug.lua'
|
||||
}
|
||||
|
||||
ui_page {
|
||||
'html/ui.html'
|
||||
}
|
||||
|
||||
lua54 'yes'
|
||||
ui_page 'html/ui.html'
|
||||
|
||||
files {
|
||||
'html/ui.html',
|
||||
@@ -43,4 +37,6 @@ files {
|
||||
dependencies {
|
||||
'progressbar',
|
||||
'connectqueue'
|
||||
}
|
||||
}
|
||||
|
||||
lua54 'yes'
|
||||
+4
-2
@@ -1,4 +1,6 @@
|
||||
if GetCurrentResourceName() == 'qb-core' then
|
||||
-- This might eventually be deprecated for the export system
|
||||
|
||||
if GetCurrentResourceName() == 'qb-core' then
|
||||
function GetSharedObject()
|
||||
return QBCore
|
||||
end
|
||||
@@ -6,4 +8,4 @@ if GetCurrentResourceName() == 'qb-core' then
|
||||
exports('GetSharedObject', GetSharedObject)
|
||||
end
|
||||
|
||||
QBCore = exports['qb-core']:GetSharedObject()
|
||||
QBCore = exports['qb-core']:GetSharedObject()
|
||||
+175
-136
@@ -1,157 +1,196 @@
|
||||
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,
|
||||
}
|
||||
-- Register & Refresh Commands
|
||||
|
||||
function QBCore.Commands.Add(name, help, arguments, argsrequired, callback, permission)
|
||||
if type(permission) == 'string' then
|
||||
permission = permission:lower()
|
||||
else
|
||||
permission = 'user'
|
||||
end
|
||||
QBCore.Commands.List[name:lower()] = {
|
||||
name = name:lower(),
|
||||
permission = permission,
|
||||
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
|
||||
function QBCore.Commands.Refresh(source)
|
||||
local src = source
|
||||
local Player = QBCore.Functions.GetPlayer(src)
|
||||
if Player then
|
||||
for command, info in pairs(QBCore.Commands.List) do
|
||||
local isGod = QBCore.Functions.HasPermission(src, 'god')
|
||||
local hasPerm = QBCore.Functions.HasPermission(src, QBCore.Commands.List[command].permission)
|
||||
local isPrincipal = IsPrincipalAceAllowed('group.admin', 'command')
|
||||
if isGod or hasPerm or isPrincipal then
|
||||
TriggerClientEvent('chat:addSuggestion', src, '/' .. command, info.help, info.arguments)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
QBCore.Commands.Add("tp", "TP To Player or Coords (Admin Only)", {{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
|
||||
local player = GetPlayerPed(source)
|
||||
local target = GetPlayerPed(tonumber(args[1]))
|
||||
if target ~= 0 then
|
||||
local coords = GetEntityCoords(target)
|
||||
TriggerClientEvent('QBCore:Command:TeleportToPlayer', source, coords)
|
||||
else
|
||||
TriggerClientEvent('QBCore:Notify', source, "Player Not Online", "error")
|
||||
end
|
||||
else
|
||||
if args[1] ~= nil and args[2] ~= nil and args[3] ~= nil then
|
||||
local player = GetPlayerPed(source)
|
||||
local x = tonumber(args[1])
|
||||
local y = tonumber(args[2])
|
||||
local z = tonumber(args[3])
|
||||
if (x ~= 0) and (y ~= 0) and (z ~= 0) then
|
||||
TriggerClientEvent('QBCore:Command:TeleportToCoords', source, x, y, z)
|
||||
else
|
||||
TriggerClientEvent('QBCore:Notify', source, "Incorrect Format", "error")
|
||||
end
|
||||
else
|
||||
TriggerClientEvent('QBCore:Notify', source, "Not every argument has been entered (x, y, z)", "error")
|
||||
end
|
||||
end
|
||||
end, "admin")
|
||||
-- Teleport
|
||||
|
||||
QBCore.Commands.Add("addpermission", "Give Player Permissions (God Only)", {{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 Not Online", "error")
|
||||
end
|
||||
end, "god")
|
||||
QBCore.Commands.Add('tp', 'TP To Player or Coords (Admin Only)', {{name = 'id/x', help = 'ID of player or X position'},{name = 'y', help = 'Y position'}, {name = 'z', help = 'Z position'}}, false, function(source, args)
|
||||
local src = source
|
||||
if args[1] and not args[2] and not args[3] then
|
||||
local target = GetPlayerPed(tonumber(args[1]))
|
||||
if target ~= 0 then
|
||||
local coords = GetEntityCoords(target)
|
||||
TriggerClientEvent('QBCore:Command:TeleportToPlayer', src, coords)
|
||||
else
|
||||
TriggerClientEvent('QBCore:Notify', src, 'Player Not Online', 'error')
|
||||
end
|
||||
else
|
||||
if args[1] and args[2] and args[3] then
|
||||
local x = tonumber(args[1])
|
||||
local y = tonumber(args[2])
|
||||
local z = tonumber(args[3])
|
||||
if (x ~= 0) and (y ~= 0) and (z ~= 0) then
|
||||
TriggerClientEvent('QBCore:Command:TeleportToCoords', src, x, y, z)
|
||||
else
|
||||
TriggerClientEvent('QBCore:Notify', src, 'Incorrect Format', 'error')
|
||||
end
|
||||
else
|
||||
TriggerClientEvent('QBCore:Notify', src, 'Not every argument has been entered (x, y, z)', 'error')
|
||||
end
|
||||
end
|
||||
end, 'admin')
|
||||
|
||||
QBCore.Commands.Add("removepermission", "Remove Players Permissions (God Only)", {{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 Not Online", "error")
|
||||
end
|
||||
end, "god")
|
||||
QBCore.Commands.Add('tpm', 'TP To Marker (Admin Only)', {}, false, function(source)
|
||||
local src = source
|
||||
TriggerClientEvent('QBCore:Command:GoToMarker', src)
|
||||
end, 'admin')
|
||||
|
||||
QBCore.Commands.Add("car", "Spawn Vehicle (Admin Only)", {{name="model", help="Model name of the vehicle"}}, true, function(source, args)
|
||||
TriggerClientEvent('QBCore:Command:SpawnVehicle', source, args[1])
|
||||
end, "admin")
|
||||
-- Permissions
|
||||
|
||||
QBCore.Commands.Add("dv", "Delete Vehicle (Admin Only)", {}, false, function(source, args)
|
||||
TriggerClientEvent('QBCore:Command:DeleteVehicle', source)
|
||||
end, "admin")
|
||||
QBCore.Commands.Add('addpermission', 'Give Player Permissions (God Only)', {{name = 'id', help = 'ID of player'},{name = 'permission', help = 'Permission level'}}, true, function(source, args)
|
||||
local src = source
|
||||
local Player = QBCore.Functions.GetPlayer(tonumber(args[1]))
|
||||
local permission = tostring(args[2]):lower()
|
||||
if Player then
|
||||
QBCore.Functions.AddPermission(Player.PlayerData.source, permission)
|
||||
else
|
||||
TriggerClientEvent('QBCore:Notify', src, 'Player Not Online', 'error')
|
||||
end
|
||||
end, 'god')
|
||||
|
||||
QBCore.Commands.Add("tpm", "TP To Marker (Admin Only)", {}, false, function(source, args)
|
||||
TriggerClientEvent('QBCore:Command:GoToMarker', source)
|
||||
end, "admin")
|
||||
QBCore.Commands.Add('removepermission', 'Remove Players Permissions (God Only)', {{name = 'id', help = 'ID of player'}}, true, function(source, args)
|
||||
local src = source
|
||||
local Player = QBCore.Functions.GetPlayer(tonumber(args[1]))
|
||||
if Player then
|
||||
QBCore.Functions.RemovePermission(Player.PlayerData.source)
|
||||
else
|
||||
TriggerClientEvent('QBCore:Notify', src, 'Player Not Online', 'error')
|
||||
end
|
||||
end, 'god')
|
||||
|
||||
QBCore.Commands.Add("givemoney", "Give A Player Money (Admin Only)", {{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 Not Online", "error")
|
||||
end
|
||||
end, "admin")
|
||||
-- Vehicle
|
||||
|
||||
QBCore.Commands.Add("setmoney", "Set Players Money Amount (Admin Only)", {{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 Not Online", "error")
|
||||
end
|
||||
end, "admin")
|
||||
QBCore.Commands.Add('car', 'Spawn Vehicle (Admin Only)',{{name = 'model', help = 'Model name of the vehicle'}}, true, function(source, args)
|
||||
local src = source
|
||||
TriggerClientEvent('QBCore:Command:SpawnVehicle', src, args[1])
|
||||
end, 'admin')
|
||||
|
||||
QBCore.Commands.Add("setjob", "Set A Players Job (Admin Only)", {{name="id", help="Player ID"}, {name="job", help="Job name"}, {name="grade", help="Grade"}}, true, function(source, args)
|
||||
local Player = QBCore.Functions.GetPlayer(tonumber(args[1]))
|
||||
if Player == nil then
|
||||
TriggerClientEvent('QBCore:Notify', source, "Player Not Online", "error")
|
||||
else
|
||||
Player.Functions.SetJob(tostring(args[2]), tonumber(args[3]))
|
||||
end
|
||||
end, "admin")
|
||||
QBCore.Commands.Add('dv', 'Delete Vehicle (Admin Only)', {}, false, function(source)
|
||||
local src = source
|
||||
TriggerClientEvent('QBCore:Command:DeleteVehicle', src)
|
||||
end, 'admin')
|
||||
|
||||
QBCore.Commands.Add("job", "Check Your Job", {}, false, function(source, args)
|
||||
local PlayerJob = QBCore.Functions.GetPlayer(source).PlayerData.job
|
||||
TriggerClientEvent('QBCore:Notify', source, string.format("[Job]: %s [Grade]: %s [On Duty]: %s", PlayerJob.label, PlayerJob.grade.name, PlayerJob.onduty))
|
||||
end)
|
||||
-- Money
|
||||
|
||||
QBCore.Commands.Add("setgang", "Set A Players Gang (Admin Only)", {{name="id", help="Player ID"}, {name="gang", help="Name of a gang"}, {name="grade", help="Grade"}}, true, function(source, args)
|
||||
local Player = QBCore.Functions.GetPlayer(tonumber(args[1]))
|
||||
if Player == nil then
|
||||
TriggerClientEvent('QBCore:Notify', source, "Player Not Online", "error")
|
||||
else
|
||||
Player.Functions.SetGang(tostring(args[2]), tonumber(args[3]))
|
||||
end
|
||||
end, "admin")
|
||||
QBCore.Commands.Add('givemoney', 'Give A Player Money (Admin Only)', {{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 src = source
|
||||
local Player = QBCore.Functions.GetPlayer(tonumber(args[1]))
|
||||
if Player then
|
||||
Player.Functions.AddMoney(tostring(args[2]), tonumber(args[3]))
|
||||
else
|
||||
TriggerClientEvent('QBCore:Notify', src, 'Player Not Online', 'error')
|
||||
end
|
||||
end, 'admin')
|
||||
|
||||
QBCore.Commands.Add("gang", "Check Your Gang", {}, false, function(source, args)
|
||||
local PlayerGang = QBCore.Functions.GetPlayer(source).PlayerData.gang
|
||||
TriggerClientEvent('QBCore:Notify', source, string.format("[Gang]: %s [Grade]: %s", PlayerGang.label, PlayerGang.grade.name))
|
||||
end)
|
||||
QBCore.Commands.Add('setmoney', 'Set Players Money Amount (Admin Only)', {{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 src = source
|
||||
local Player = QBCore.Functions.GetPlayer(tonumber(args[1]))
|
||||
if Player then
|
||||
Player.Functions.SetMoney(tostring(args[2]), tonumber(args[3]))
|
||||
else
|
||||
TriggerClientEvent('QBCore:Notify', src, 'Player Not Online', 'error')
|
||||
end
|
||||
end, 'admin')
|
||||
|
||||
QBCore.Commands.Add("clearinv", "Clear Players Inventory (Admin Only)", {{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 Not Online", "error")
|
||||
end
|
||||
end, "admin")
|
||||
-- Job
|
||||
|
||||
QBCore.Commands.Add("ooc", "OOC Chat Message", {}, false, function(source, args)
|
||||
local message = table.concat(args, " ")
|
||||
local Players = QBCore.Functions.GetPlayers()
|
||||
local Player = QBCore.Functions.GetPlayer(source)
|
||||
QBCore.Commands.Add('job', 'Check Your Job', {}, false, function(source)
|
||||
local src = source
|
||||
local PlayerJob = QBCore.Functions.GetPlayer(src).PlayerData.job
|
||||
TriggerClientEvent('QBCore:Notify', src, string.format('[Job]: %s [Grade]: %s [On Duty]: %s', PlayerJob.label, PlayerJob.grade.name, PlayerJob.onduty))
|
||||
end, 'user')
|
||||
|
||||
for k, v in pairs(QBCore.Functions.GetPlayers()) do
|
||||
if v == source then
|
||||
TriggerClientEvent('chatMessage', v, "OOC " .. GetPlayerName(source), "normal", message)
|
||||
elseif #(GetEntityCoords(GetPlayerPed(source)) - GetEntityCoords(GetPlayerPed(v))) < 20.0 then
|
||||
TriggerClientEvent('chatMessage', v, "OOC " .. GetPlayerName(source), "normal", message)
|
||||
elseif QBCore.Functions.HasPermission(v, "admin") then
|
||||
if QBCore.Functions.IsOptin(v) then
|
||||
TriggerClientEvent('chatMessage', v, "Proximity 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)
|
||||
QBCore.Commands.Add('setjob', 'Set A Players Job (Admin Only)', {{name = 'id', help = 'Player ID'}, {name = 'job', help = 'Job name'},{name = 'grade', help = 'Grade'}}, true, function(source, args)
|
||||
local src = source
|
||||
local Player = QBCore.Functions.GetPlayer(tonumber(args[1]))
|
||||
if Player then
|
||||
Player.Functions.SetJob(tostring(args[2]), tonumber(args[3]))
|
||||
else
|
||||
TriggerClientEvent('QBCore:Notify', src, 'Player Not Online', 'error')
|
||||
end
|
||||
end, 'admin')
|
||||
|
||||
-- Gang
|
||||
|
||||
QBCore.Commands.Add('gang', 'Check Your Gang', {}, false, function(source)
|
||||
local src = source
|
||||
local PlayerGang = QBCore.Functions.GetPlayer(source).PlayerData.gang
|
||||
TriggerClientEvent('QBCore:Notify', src, string.format('[Gang]: %s [Grade]: %s', PlayerGang.label, PlayerGang.grade.name))
|
||||
end, 'user')
|
||||
|
||||
QBCore.Commands.Add('setgang', 'Set A Players Gang (Admin Only)', {{name = 'id', help = 'Player ID'}, {name = 'gang', help = 'Name of a gang'},{name = 'grade', help = 'Grade'}}, true, function(source, args)
|
||||
local src = source
|
||||
local Player = QBCore.Functions.GetPlayer(tonumber(args[1]))
|
||||
if Player then
|
||||
Player.Functions.SetGang(tostring(args[2]), tonumber(args[3]))
|
||||
else
|
||||
TriggerClientEvent('QBCore:Notify', src, 'Player Not Online', 'error')
|
||||
end
|
||||
end, 'admin')
|
||||
|
||||
-- Inventory (should be in qb-inventory?)
|
||||
|
||||
QBCore.Commands.Add('clearinv', 'Clear Players Inventory (Admin Only)',{{name = 'id', help = 'Player ID'}}, false, function(source, args)
|
||||
local src = source
|
||||
local playerId = args[1] or src
|
||||
local Player = QBCore.Functions.GetPlayer(tonumber(playerId))
|
||||
if Player then
|
||||
Player.Functions.ClearInventory()
|
||||
else
|
||||
TriggerClientEvent('QBCore:Notify', src, 'Player Not Online', 'error')
|
||||
end
|
||||
end, 'admin')
|
||||
|
||||
-- Out of Character Chat
|
||||
|
||||
QBCore.Commands.Add('ooc', 'OOC Chat Message', {}, false, function(source, args)
|
||||
local src = source
|
||||
local message = table.concat(args, ' ')
|
||||
local Players = QBCore.Functions.GetPlayers()
|
||||
local Player = QBCore.Functions.GetPlayer(src)
|
||||
for k, v in pairs(Players) do
|
||||
if v == src then
|
||||
TriggerClientEvent('chat:addMessage', v, 'OOC ' .. GetPlayerName(src), 'normal', message)
|
||||
elseif #(GetEntityCoords(GetPlayerPed(src)) -
|
||||
GetEntityCoords(GetPlayerPed(v))) < 20.0 then
|
||||
TriggerClientEvent('chat:addMessage', v, 'OOC ' .. GetPlayerName(src), 'normal', message)
|
||||
elseif QBCore.Functions.HasPermission(v, 'admin') then
|
||||
if QBCore.Functions.IsOptin(v) then
|
||||
TriggerClientEvent('chat:addMessage', v, 'Proximity OOC ' .. GetPlayerName(src), 'normal', message)
|
||||
TriggerEvent('qb-log:server:CreateLog', 'ooc', 'OOC', 'white', '**' .. GetPlayerName(src) .. '** (CitizenID: ' ..Player.PlayerData.citizenid .. ' | ID: ' .. src ..') **Message:** ' .. message, false)
|
||||
end
|
||||
end
|
||||
end
|
||||
end, 'user')
|
||||
+18
-20
@@ -1,36 +1,34 @@
|
||||
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 = "{"
|
||||
RegisterServerEvent('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
|
||||
if type(v) == 'table' then
|
||||
for ik, iv in pairs(v) do
|
||||
str = str.."\n["..k.."] -> ["..ik.."] -> "..tostring(iv)
|
||||
str = str .. '\n[' .. k .. '] -> [' .. ik .. '] -> ' .. tostring(iv)
|
||||
end
|
||||
else
|
||||
str = str.."\n["..k.."] -> "..tostring(v)
|
||||
str = str .. '\n[' .. k .. '] -> ' .. tostring(v)
|
||||
end
|
||||
end
|
||||
|
||||
print(str.."\n}")
|
||||
print(str .. '\n}')
|
||||
else
|
||||
local success, value = pcall(function() return tostring(obj) end)
|
||||
print((success and value or "<!!error in __tostring metamethod!!>"))
|
||||
print((success and value or '<!!error in __tostring metamethod!!>'))
|
||||
end
|
||||
print("\x1b[4m\x1b[36mEND OF DEBUG\x1b[0m")
|
||||
print('\x1b[4m\x1b[36mEND OF DEBUG\x1b[0m')
|
||||
end)
|
||||
|
||||
QBCore.Debug = function(resource, obj, depth)
|
||||
function QBCore.Debug(resource, obj, depth)
|
||||
TriggerEvent('QBCore:DebugSomething', resource, obj, depth)
|
||||
end
|
||||
|
||||
QBCore.ShowError = function(resource, msg)
|
||||
print("\x1b[31m["..resource..":ERROR]\x1b[0m "..msg)
|
||||
function QBCore.ShowError(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
|
||||
function QBCore.ShowSuccess(resource, msg)
|
||||
print('\x1b[32m[' .. resource .. ':LOG]\x1b[0m ' .. msg)
|
||||
end
|
||||
+135
-179
@@ -1,20 +1,44 @@
|
||||
-- Player joined
|
||||
RegisterServerEvent("QBCore:PlayerJoined")
|
||||
AddEventHandler('QBCore:PlayerJoined', function()
|
||||
local src = source
|
||||
SetPlayerRoutingBucket(src, 0)
|
||||
end)
|
||||
-- Event Handler
|
||||
|
||||
AddEventHandler('playerDropped', function(reason)
|
||||
AddEventHandler('playerDropped', function()
|
||||
local src = source
|
||||
if QBCore.Players[src] then
|
||||
local Player = QBCore.Players[src]
|
||||
TriggerEvent("qb-log:server:CreateLog", "joinleave", "Dropped", "red", "**".. GetPlayerName(src) .. "** ("..Player.PlayerData.license..") left..")
|
||||
TriggerEvent('qb-log:server:CreateLog', 'joinleave', 'Dropped', 'red', '**'.. GetPlayerName(src) .. '** ('..Player.PlayerData.license..') left..')
|
||||
Player.Functions.Save()
|
||||
QBCore.Players[src] = nil
|
||||
end
|
||||
end)
|
||||
|
||||
AddEventHandler('chatMessage', function(source, n, message)
|
||||
local src = source
|
||||
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] then
|
||||
local Player = QBCore.Functions.GetPlayer(src)
|
||||
if Player then
|
||||
local isGod = QBCore.Functions.HasPermission(src, 'god')
|
||||
local hasPerm = QBCore.Functions.HasPermission(src, QBCore.Commands.List[command].permission)
|
||||
local isPrincipal = IsPrincipalAceAllowed('group.admin', 'command')
|
||||
table.remove(args, 1)
|
||||
if isGod or hasPerm or isPrincipal 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', src, 'All arguments must be filled out!', 'error')
|
||||
else
|
||||
QBCore.Commands.List[command].callback(src, args)
|
||||
end
|
||||
else
|
||||
TriggerClientEvent('QBCore:Notify', src, 'No Access To This Command', 'error')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
-- Player Connecting
|
||||
|
||||
local function OnPlayerConnecting(name, setKickReason, deferrals)
|
||||
local player = source
|
||||
local license
|
||||
@@ -24,7 +48,7 @@ local function OnPlayerConnecting(name, setKickReason, deferrals)
|
||||
-- mandatory wait!
|
||||
Wait(0)
|
||||
|
||||
deferrals.update(string.format("Hello %s. Validating Your Rockstar License", name))
|
||||
deferrals.update(string.format('Hello %s. Validating Your Rockstar License', name))
|
||||
|
||||
for _, v in pairs(identifiers) do
|
||||
if string.find(v, 'license') then
|
||||
@@ -36,14 +60,14 @@ local function OnPlayerConnecting(name, setKickReason, deferrals)
|
||||
-- mandatory wait!
|
||||
Wait(2500)
|
||||
|
||||
deferrals.update(string.format("Hello %s. We are checking if you are banned.", name))
|
||||
|
||||
deferrals.update(string.format('Hello %s. We are checking if you are banned.', name))
|
||||
|
||||
local isBanned, Reason = QBCore.Functions.IsPlayerBanned(player)
|
||||
local isLicenseAlreadyInUse = QBCore.Functions.IsLicenseInUse(license)
|
||||
|
||||
|
||||
Wait(2500)
|
||||
|
||||
deferrals.update(string.format("Welcome %s to {Server Name}.", name))
|
||||
|
||||
deferrals.update(string.format('Welcome %s to {Server Name}.', name))
|
||||
|
||||
if not license then
|
||||
deferrals.done('No Valid Rockstar License Found')
|
||||
@@ -54,212 +78,156 @@ local function OnPlayerConnecting(name, setKickReason, deferrals)
|
||||
else
|
||||
deferrals.done()
|
||||
Wait(1000)
|
||||
TriggerEvent("connectqueue:playerConnect", name, setKickReason, deferrals)
|
||||
TriggerEvent('connectqueue:playerConnect', name, setKickReason, deferrals)
|
||||
end
|
||||
--Add any additional defferals you may need!
|
||||
end
|
||||
|
||||
AddEventHandler("playerConnecting", OnPlayerConnecting)
|
||||
AddEventHandler('playerConnecting', OnPlayerConnecting)
|
||||
|
||||
RegisterServerEvent("QBCore:server:CloseServer")
|
||||
AddEventHandler('QBCore:server:CloseServer', function(reason)
|
||||
local src = source
|
||||
local Player = QBCore.Functions.GetPlayer(src)
|
||||
-- Open & Close Server (prevents players from joining)
|
||||
|
||||
if QBCore.Functions.HasPermission(source, "admin") or QBCore.Functions.HasPermission(source, "god") then
|
||||
local reason = reason ~= nil and reason or "No reason specified..."
|
||||
RegisterNetEvent('QBCore:server:CloseServer', function(reason)
|
||||
local src = source
|
||||
if QBCore.Functions.HasPermission(src, 'admin') or QBCore.Functions.HasPermission(src, 'god') then
|
||||
local reason = reason or 'No reason specified'
|
||||
QBCore.Config.Server.closed = true
|
||||
QBCore.Config.Server.closedReason = reason
|
||||
TriggerClientEvent("qbadmin:client:SetServerStatus", -1, true)
|
||||
TriggerClientEvent('qbadmin:client:SetServerStatus', -1, true)
|
||||
else
|
||||
QBCore.Functions.Kick(src, "You don't have permissions for this..", nil, nil)
|
||||
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)
|
||||
RegisterNetEvent('QBCore:server:OpenServer', function()
|
||||
local src = source
|
||||
if QBCore.Functions.HasPermission(src, 'admin') or QBCore.Functions.HasPermission(src, '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)
|
||||
|
||||
-- Callbacks
|
||||
|
||||
RegisterNetEvent('QBCore:Server:TriggerCallback', function(name, ...)
|
||||
local src = source
|
||||
QBCore.Functions.TriggerCallback(name, src, function(...)
|
||||
TriggerClientEvent('QBCore:Client:TriggerCallback', src, name, ...)
|
||||
end, ...)
|
||||
end)
|
||||
|
||||
-- Player
|
||||
|
||||
RegisterNetEvent('QBCore:UpdatePlayer', function()
|
||||
local src = source
|
||||
local ped = GetPlayerPed(src)
|
||||
local Player = QBCore.Functions.GetPlayer(src)
|
||||
if Player ~= nil then
|
||||
Player.PlayerData.position = data.position
|
||||
local newHunger = Player.PlayerData.metadata["hunger"] - QBCore.Config.Player.HungerRate
|
||||
local newThirst = Player.PlayerData.metadata["thirst"] - QBCore.Config.Player.ThirstRate
|
||||
if Player then
|
||||
Player.PlayerData.position = GetEntityCoords(ped)
|
||||
local newHunger = Player.PlayerData.metadata['hunger'] - QBCore.Config.Player.HungerRate
|
||||
local newThirst = Player.PlayerData.metadata['thirst'] - QBCore.Config.Player.ThirstRate
|
||||
if newHunger <= 0 then newHunger = 0 end
|
||||
if newThirst <= 0 then newThirst = 0 end
|
||||
Player.Functions.SetMetaData("thirst", newThirst)
|
||||
Player.Functions.SetMetaData("hunger", newHunger)
|
||||
TriggerClientEvent("hud:client:UpdateNeeds", src, newHunger, newThirst)
|
||||
Player.Functions.SetMetaData('thirst', newThirst)
|
||||
Player.Functions.SetMetaData('hunger', newHunger)
|
||||
TriggerClientEvent('hud:client:UpdateNeeds', src, newHunger, newThirst)
|
||||
Player.Functions.Save()
|
||||
end
|
||||
end)
|
||||
|
||||
RegisterServerEvent("QBCore:UpdatePlayerPosition")
|
||||
AddEventHandler("QBCore:UpdatePlayerPosition", function(position)
|
||||
local src = source
|
||||
RegisterNetEvent('QBCore:Server:SetMetaData', function(meta, data)
|
||||
local src = source
|
||||
local Player = QBCore.Functions.GetPlayer(src)
|
||||
if Player ~= nil then
|
||||
Player.PlayerData.position = position
|
||||
if meta == 'hunger' or meta == 'thirst' then
|
||||
if data > 100 then
|
||||
data = 100
|
||||
end
|
||||
end
|
||||
if Player then
|
||||
Player.Functions.SetMetaData(meta, data)
|
||||
end
|
||||
TriggerClientEvent('hud:client:UpdateNeeds', src, Player.PlayerData.metadata['hunger'], Player.PlayerData.metadata['thirst'])
|
||||
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)
|
||||
RegisterNetEvent('QBCore:ToggleDuty', function()
|
||||
local src = source
|
||||
local Player = QBCore.Functions.GetPlayer(src)
|
||||
if item ~= nil and item.amount > 0 then
|
||||
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)
|
||||
|
||||
-- Items
|
||||
|
||||
RegisterNetEvent('QBCore:Server:UseItem', function(item)
|
||||
local src = source
|
||||
if item 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)
|
||||
RegisterNetEvent('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)
|
||||
RegisterNetEvent('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)
|
||||
-- Non-Chat Command Calling (ex: qb-adminmenu)
|
||||
|
||||
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
|
||||
RegisterNetEvent('QBCore:CallCommand', function(command, args)
|
||||
local src = source
|
||||
if QBCore.Commands.List[command] then
|
||||
local Player = QBCore.Functions.GetPlayer(src)
|
||||
if Player then
|
||||
local isGod = QBCore.Functions.HasPermission(src, 'god')
|
||||
local hasPerm = QBCore.Functions.HasPermission(src, QBCore.Commands.List[command].permission)
|
||||
local isPrincipal = IsPrincipalAceAllowed('group.admin', 'command')
|
||||
if (QBCore.Commands.List[command].permission == Player.PlayerData.job.name) or isGod or hasPerm or isPrincipal 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)
|
||||
TriggerClientEvent('QBCore:Notify', src, 'All arguments must be filled out!', 'error')
|
||||
else
|
||||
QBCore.Commands.List[command].callback(source, args)
|
||||
QBCore.Commands.List[command].callback(src, args)
|
||||
end
|
||||
else
|
||||
TriggerClientEvent('QBCore:Notify', source, "No Access To This Command", "error")
|
||||
TriggerClientEvent('QBCore:Notify', src, '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()
|
||||
local result = exports.oxmysql:fetchSync('SELECT * FROM permissions', {})
|
||||
if result[1] ~= nil then
|
||||
for k, v in pairs(result) do
|
||||
QBCore.Config.Server.PermissionList[v.license] = {
|
||||
license = v.license,
|
||||
permission = v.permission,
|
||||
optin = true,
|
||||
}
|
||||
end
|
||||
end
|
||||
end)
|
||||
-- Has Item Callback (can also use client function - QBCore.Functions.HasItem(item))
|
||||
|
||||
QBCore.Functions.CreateCallback('QBCore:HasItem', function(source, cb, items, amount)
|
||||
local src = source
|
||||
local retval = false
|
||||
local Player = QBCore.Functions.GetPlayer(source)
|
||||
if Player ~= nil then
|
||||
local Player = QBCore.Functions.GetPlayer(src)
|
||||
if Player then
|
||||
if type(items) == 'table' then
|
||||
local count = 0
|
||||
local finalcount = 0
|
||||
local finalcount = 0
|
||||
for k, v in pairs(items) do
|
||||
if type(k) == 'string' then
|
||||
finalcount = 0
|
||||
for i, _ in pairs(items) do
|
||||
if i then finalcount = finalcount + 1 end
|
||||
end
|
||||
if type(k) == 'string' then
|
||||
finalcount = 0
|
||||
for i, _ in pairs(items) do
|
||||
if i then finalcount = finalcount + 1 end
|
||||
end
|
||||
local item = Player.Functions.GetItemByName(k)
|
||||
if item ~= nil then
|
||||
if item then
|
||||
if item.amount >= v then
|
||||
count = count + 1
|
||||
if count == finalcount then
|
||||
@@ -268,10 +236,10 @@ QBCore.Functions.CreateCallback('QBCore:HasItem', function(source, cb, items, am
|
||||
end
|
||||
end
|
||||
else
|
||||
finalcount = #items
|
||||
finalcount = #items
|
||||
local item = Player.Functions.GetItemByName(v)
|
||||
if item ~= nil then
|
||||
if amount ~= nil then
|
||||
if item then
|
||||
if amount then
|
||||
if item.amount >= amount then
|
||||
count = count + 1
|
||||
if count == finalcount then
|
||||
@@ -289,8 +257,8 @@ QBCore.Functions.CreateCallback('QBCore:HasItem', function(source, cb, items, am
|
||||
end
|
||||
else
|
||||
local item = Player.Functions.GetItemByName(items)
|
||||
if item ~= nil then
|
||||
if amount ~= nil then
|
||||
if item then
|
||||
if amount then
|
||||
if item.amount >= amount then
|
||||
retval = true
|
||||
end
|
||||
@@ -300,17 +268,5 @@ QBCore.Functions.CreateCallback('QBCore:HasItem', function(source, cb, items, am
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
cb(retval)
|
||||
end)
|
||||
|
||||
RegisterServerEvent('QBCore:Command:CheckOwnedVehicle')
|
||||
AddEventHandler('QBCore:Command:CheckOwnedVehicle', function(VehiclePlate)
|
||||
if VehiclePlate ~= nil then
|
||||
local result = exports.oxmysql:fetchSync('SELECT * FROM player_vehicles WHERE plate = ?', { VehiclePlate })
|
||||
if result[1] ~= nil then
|
||||
exports.oxmysql:execute('UPDATE player_vehicles SET state = ? WHERE citizenid = ?', { 1, result[1].citizenid })
|
||||
TriggerEvent('qb-garages:server:RemoveVehicle', result[1].citizenid, VehiclePlate)
|
||||
end
|
||||
end
|
||||
end)
|
||||
end)
|
||||
+142
-99
@@ -1,19 +1,20 @@
|
||||
QBCore.Functions = {}
|
||||
|
||||
QBCore.Functions.GetEntityCoords = function(entity)
|
||||
-- Getters
|
||||
-- Get your player first and then trigger a function on them
|
||||
-- ex: local player = QBCore.Functions.GetPlayer(source)
|
||||
-- ex: local example = player.Functions.functionname(parameter)
|
||||
|
||||
function QBCore.Functions.GetCoords(entity)
|
||||
local coords = GetEntityCoords(entity, false)
|
||||
local heading = GetEntityHeading(entity)
|
||||
return {
|
||||
x = coords.x,
|
||||
y = coords.y,
|
||||
z = coords.z,
|
||||
a = heading
|
||||
}
|
||||
return vector4(coords.x, coords.y, coords.z, heading)
|
||||
end
|
||||
|
||||
QBCore.Functions.GetIdentifier = function(source, idtype)
|
||||
local idtype = idtype ~=nil and idtype or QBConfig.IdentifierType
|
||||
for _, identifier in pairs(GetPlayerIdentifiers(source)) do
|
||||
function QBCore.Functions.GetIdentifier(source, idtype)
|
||||
local src = source
|
||||
local idtype = idtype or QBConfig.IdentifierType
|
||||
for _, identifier in pairs(GetPlayerIdentifiers(src)) do
|
||||
if string.find(identifier, idtype) then
|
||||
return identifier
|
||||
end
|
||||
@@ -21,7 +22,7 @@ QBCore.Functions.GetIdentifier = function(source, idtype)
|
||||
return nil
|
||||
end
|
||||
|
||||
QBCore.Functions.GetSource = function(identifier)
|
||||
function QBCore.Functions.GetSource(identifier)
|
||||
for src, player in pairs(QBCore.Players) do
|
||||
local idens = GetPlayerIdentifiers(src)
|
||||
for _, id in pairs(idens) do
|
||||
@@ -33,15 +34,16 @@ QBCore.Functions.GetSource = function(identifier)
|
||||
return 0
|
||||
end
|
||||
|
||||
QBCore.Functions.GetPlayer = function(source)
|
||||
if type(source) == "number" then
|
||||
return QBCore.Players[source]
|
||||
function QBCore.Functions.GetPlayer(source)
|
||||
local src = source
|
||||
if type(src) == 'number' then
|
||||
return QBCore.Players[src]
|
||||
else
|
||||
return QBCore.Players[QBCore.Functions.GetSource(source)]
|
||||
return QBCore.Players[QBCore.Functions.GetSource(src)]
|
||||
end
|
||||
end
|
||||
|
||||
QBCore.Functions.GetPlayerByCitizenId = function(citizenid)
|
||||
function QBCore.Functions.GetPlayerByCitizenId(citizenid)
|
||||
for src, player in pairs(QBCore.Players) do
|
||||
local cid = citizenid
|
||||
if QBCore.Players[src].PlayerData.citizenid == cid then
|
||||
@@ -51,7 +53,7 @@ QBCore.Functions.GetPlayerByCitizenId = function(citizenid)
|
||||
return nil
|
||||
end
|
||||
|
||||
QBCore.Functions.GetPlayerByPhone = function(number)
|
||||
function QBCore.Functions.GetPlayerByPhone(number)
|
||||
for src, player in pairs(QBCore.Players) do
|
||||
local cid = citizenid
|
||||
if QBCore.Players[src].PlayerData.charinfo.phone == number then
|
||||
@@ -61,7 +63,7 @@ QBCore.Functions.GetPlayerByPhone = function(number)
|
||||
return nil
|
||||
end
|
||||
|
||||
QBCore.Functions.GetPlayers = function()
|
||||
function QBCore.Functions.GetPlayers()
|
||||
local sources = {}
|
||||
for k, v in pairs(QBCore.Players) do
|
||||
table.insert(sources, k)
|
||||
@@ -69,174 +71,215 @@ QBCore.Functions.GetPlayers = function()
|
||||
return sources
|
||||
end
|
||||
|
||||
QBCore.Functions.CreateCallback = function(name, cb)
|
||||
-- Paychecks (standalone - don't touch)
|
||||
|
||||
function PaycheckLoop()
|
||||
local Players = QBCore.Functions.GetPlayers()
|
||||
for i=1, #Players, 1 do
|
||||
local Player = QBCore.Functions.GetPlayer(Players[i])
|
||||
if Player.PlayerData.job and Player.PlayerData.job.payment > 0 then
|
||||
Player.Functions.AddMoney('bank', Player.PlayerData.job.payment)
|
||||
TriggerClientEvent('QBCore:Notify', Players[i], 'You received your paycheck of $'..Player.PlayerData.job.payment)
|
||||
end
|
||||
end
|
||||
SetTimeout(QBCore.Config.Money.PayCheckTimeOut * (60 * 1000), PaycheckLoop)
|
||||
end
|
||||
|
||||
-- Callbacks
|
||||
|
||||
function QBCore.Functions.CreateCallback(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, ...)
|
||||
function QBCore.Functions.TriggerCallback(name, source, cb, ...)
|
||||
local src = source
|
||||
if QBCore.ServerCallbacks[name] then
|
||||
QBCore.ServerCallbacks[name](src, cb, ...)
|
||||
end
|
||||
end
|
||||
|
||||
QBCore.Functions.CreateUseableItem = function(item, cb)
|
||||
-- Items
|
||||
|
||||
function QBCore.Functions.CreateUseableItem(item, cb)
|
||||
QBCore.UseableItems[item] = cb
|
||||
end
|
||||
|
||||
QBCore.Functions.CanUseItem = function(item)
|
||||
return QBCore.UseableItems[item] ~= nil
|
||||
function QBCore.Functions.CanUseItem(item)
|
||||
return QBCore.UseableItems[item]
|
||||
end
|
||||
|
||||
QBCore.Functions.UseItem = function(source, item)
|
||||
QBCore.UseableItems[item.name](source, item)
|
||||
end
|
||||
|
||||
QBCore.Functions.Kick = function(source, reason, setKickReason, deferrals)
|
||||
function QBCore.Functions.UseItem(source, item)
|
||||
local src = source
|
||||
reason = "\n"..reason.."\n🔸 Check our Discord for further information: "..QBCore.Config.Server.discord
|
||||
if(setKickReason ~=nil) then
|
||||
QBCore.UseableItems[item.name](src, item)
|
||||
end
|
||||
|
||||
-- Kick Player
|
||||
|
||||
function QBCore.Functions.Kick(source, reason, setKickReason, deferrals)
|
||||
local src = source
|
||||
reason = '\n'..reason..'\n🔸 Check our Discord for further information: '..QBCore.Config.Server.discord
|
||||
if setKickReason then
|
||||
setKickReason(reason)
|
||||
end
|
||||
Citizen.CreateThread(function()
|
||||
if(deferrals ~= nil)then
|
||||
CreateThread(function()
|
||||
if deferrals then
|
||||
deferrals.update(reason)
|
||||
Citizen.Wait(2500)
|
||||
Wait(2500)
|
||||
end
|
||||
if src ~= nil then
|
||||
if src then
|
||||
DropPlayer(src, reason)
|
||||
end
|
||||
local i = 0
|
||||
while (i <= 4) do
|
||||
i = i + 1
|
||||
while true do
|
||||
if src ~= nil then
|
||||
if src then
|
||||
if(GetPlayerPing(src) >= 0) then
|
||||
break
|
||||
end
|
||||
Citizen.Wait(100)
|
||||
Citizen.CreateThread(function()
|
||||
Wait(100)
|
||||
CreateThread(function()
|
||||
DropPlayer(src, reason)
|
||||
end)
|
||||
end
|
||||
end
|
||||
Citizen.Wait(5000)
|
||||
Wait(5000)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
QBCore.Functions.IsWhitelisted = function(source)
|
||||
local identifiers = GetPlayerIdentifiers(source)
|
||||
local rtn = false
|
||||
if (QBCore.Config.Server.whitelist) then
|
||||
local result = exports.oxmysql:fetchSync('SELECT * FROM whitelist WHERE license = ?', { QBCore.Functions.GetIdentifier(source, 'license') })
|
||||
local data = result[1]
|
||||
if data ~= nil then
|
||||
-- Check if player is whitelisted (not used anywhere)
|
||||
|
||||
function QBCore.Functions.IsWhitelisted(source)
|
||||
local src = source
|
||||
local plicense = QBCore.Functions.GetIdentifier(src, 'license')
|
||||
local identifiers = GetPlayerIdentifiers(src)
|
||||
if QBCore.Config.Server.whitelist then
|
||||
local result = exports.oxmysql:fetchSync('SELECT * FROM whitelist WHERE license = ?', {plicense})
|
||||
if result[1] then
|
||||
for _, id in pairs(identifiers) do
|
||||
if data.license == id then
|
||||
rtn = true
|
||||
if result[1].license == id then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
rtn = true
|
||||
return true
|
||||
end
|
||||
return rtn
|
||||
return false
|
||||
end
|
||||
|
||||
QBCore.Functions.AddPermission = function(source, permission)
|
||||
local Player = QBCore.Functions.GetPlayer(source)
|
||||
if Player ~= nil then
|
||||
QBCore.Config.Server.PermissionList[QBCore.Functions.GetIdentifier(source, 'license')] = {
|
||||
license = QBCore.Functions.GetIdentifier(source, 'license'),
|
||||
-- Setting & Removing Permissions
|
||||
|
||||
function QBCore.Functions.AddPermission(source, permission)
|
||||
local src = source
|
||||
local Player = QBCore.Functions.GetPlayer(src)
|
||||
local plicense = Player.PlayerData.license
|
||||
if Player then
|
||||
QBCore.Config.Server.PermissionList[plicense] = {
|
||||
license = plicense,
|
||||
permission = permission:lower(),
|
||||
}
|
||||
exports.oxmysql:execute('DELETE FROM permissions WHERE license = ?', { QBCore.Functions.GetIdentifier(source, 'license') })
|
||||
exports.oxmysql:execute('DELETE FROM permissions WHERE license = ?', {plicense})
|
||||
|
||||
exports.oxmysql:insert('INSERT INTO permissions (name, license, permission) VALUES (?, ?, ?)', {
|
||||
GetPlayerName(source),
|
||||
QBCore.Functions.GetIdentifier(source, 'license'),
|
||||
GetPlayerName(src),
|
||||
plicense,
|
||||
permission:lower()
|
||||
})
|
||||
|
||||
Player.Functions.UpdatePlayerData()
|
||||
TriggerClientEvent('QBCore:Client:OnPermissionUpdate', source, permission)
|
||||
TriggerClientEvent('QBCore:Client:OnPermissionUpdate', src, permission)
|
||||
end
|
||||
end
|
||||
|
||||
QBCore.Functions.RemovePermission = function(source)
|
||||
local Player = QBCore.Functions.GetPlayer(source)
|
||||
if Player ~= nil then
|
||||
QBCore.Config.Server.PermissionList[QBCore.Functions.GetIdentifier(source, 'license')] = nil
|
||||
exports.oxmysql:execute('DELETE FROM permissions WHERE license = ?', { QBCore.Functions.GetIdentifier(source, 'license') })
|
||||
function QBCore.Functions.RemovePermission(source)
|
||||
local src = source
|
||||
local Player = QBCore.Functions.GetPlayer(src)
|
||||
local license = Player.PlayerData.license
|
||||
if Player then
|
||||
QBCore.Config.Server.PermissionList[license] = nil
|
||||
exports.oxmysql:execute('DELETE FROM permissions WHERE license = ?', {license})
|
||||
Player.Functions.UpdatePlayerData()
|
||||
end
|
||||
end
|
||||
|
||||
QBCore.Functions.HasPermission = function(source, permission)
|
||||
local retval = false
|
||||
local license = QBCore.Functions.GetIdentifier(source, 'license')
|
||||
-- Checking for Permission Level
|
||||
|
||||
function QBCore.Functions.HasPermission(source, permission)
|
||||
local src = source
|
||||
local license = QBCore.Functions.GetIdentifier(src, 'license')
|
||||
local permission = tostring(permission:lower())
|
||||
if permission == "user" then
|
||||
retval = true
|
||||
if permission == 'user' then
|
||||
return true
|
||||
else
|
||||
if QBCore.Config.Server.PermissionList[license] ~= nil then
|
||||
if QBCore.Config.Server.PermissionList[license] then
|
||||
if QBCore.Config.Server.PermissionList[license].license == license then
|
||||
if QBCore.Config.Server.PermissionList[license].permission == permission or QBCore.Config.Server.PermissionList[license].permission == "god" then
|
||||
retval = true
|
||||
if QBCore.Config.Server.PermissionList[license].permission == permission or QBCore.Config.Server.PermissionList[license].permission == 'god' then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return retval
|
||||
return false
|
||||
end
|
||||
|
||||
QBCore.Functions.GetPermission = function(source)
|
||||
local retval = "user"
|
||||
Player = QBCore.Functions.GetPlayer(source)
|
||||
local license = QBCore.Functions.GetIdentifier(source, 'license')
|
||||
if Player ~= nil then
|
||||
if QBCore.Config.Server.PermissionList[Player.PlayerData.license] ~= nil then
|
||||
if QBCore.Config.Server.PermissionList[Player.PlayerData.license].license == license then
|
||||
retval = QBCore.Config.Server.PermissionList[Player.PlayerData.license].permission
|
||||
function QBCore.Functions.GetPermission(source)
|
||||
local src = source
|
||||
local license = QBCore.Functions.GetIdentifier(src, 'license')
|
||||
if license then
|
||||
if QBCore.Config.Server.PermissionList[license] then
|
||||
if QBCore.Config.Server.PermissionList[license].license == license then
|
||||
return QBCore.Config.Server.PermissionList[license].permission
|
||||
end
|
||||
end
|
||||
end
|
||||
return retval
|
||||
return 'user'
|
||||
end
|
||||
|
||||
QBCore.Functions.IsOptin = function(source)
|
||||
local retval = false
|
||||
local license = QBCore.Functions.GetIdentifier(source, 'license')
|
||||
if QBCore.Functions.HasPermission(source, "admin") then
|
||||
-- Opt in or out of admin reports
|
||||
|
||||
function QBCore.Functions.IsOptin(source)
|
||||
local src = source
|
||||
local license = QBCore.Functions.GetIdentifier(src, 'license')
|
||||
if QBCore.Functions.HasPermission(src, 'admin') then
|
||||
retval = QBCore.Config.Server.PermissionList[license].optin
|
||||
return true
|
||||
end
|
||||
return retval
|
||||
return false
|
||||
end
|
||||
|
||||
QBCore.Functions.ToggleOptin = function(source)
|
||||
local license = QBCore.Functions.GetIdentifier(source, 'license')
|
||||
if QBCore.Functions.HasPermission(source, "admin") then
|
||||
function QBCore.Functions.ToggleOptin(source)
|
||||
local src = source
|
||||
local license = QBCore.Functions.GetIdentifier(src, 'license')
|
||||
if QBCore.Functions.HasPermission(src, 'admin') then
|
||||
QBCore.Config.Server.PermissionList[license].optin = not QBCore.Config.Server.PermissionList[license].optin
|
||||
end
|
||||
end
|
||||
|
||||
QBCore.Functions.IsPlayerBanned = function (source)
|
||||
-- Check if player is banned
|
||||
|
||||
function QBCore.Functions.IsPlayerBanned(source)
|
||||
local src = source
|
||||
local retval = false
|
||||
local message = ""
|
||||
local result = exports.oxmysql:fetchSync('SELECT * FROM bans WHERE license = ?', { QBCore.Functions.GetIdentifier(source, 'license') })
|
||||
if result[1] ~= nil then
|
||||
local message = ''
|
||||
local plicense = QBCore.Functions.GetIdentifier(src, 'license')
|
||||
local result = exports.oxmysql:fetchSync('SELECT * FROM bans WHERE license = ?', {plicense})
|
||||
if result[1] then
|
||||
if os.time() < result[1].expire then
|
||||
retval = true
|
||||
local timeTable = os.date("*t", tonumber(result.expire))
|
||||
message = "You have been banned from the server:\n"..result[1].reason.."\nYour ban expires "..timeTable.day.. "/" .. timeTable.month .. "/" .. timeTable.year .. " " .. timeTable.hour.. ":" .. timeTable.min .. "\n"
|
||||
local timeTable = os.date('*t', tonumber(result.expire))
|
||||
message = 'You have been banned from the server:\n'..result[1].reason..'\nYour ban expires '..timeTable.day.. '/' .. timeTable.month .. '/' .. timeTable.year .. ' ' .. timeTable.hour.. ':' .. timeTable.min .. '\n'
|
||||
else
|
||||
exports.oxmysql:execute('DELETE FROM bans WHERE id = ?', { result[1].id })
|
||||
exports.oxmysql:execute('DELETE FROM bans WHERE id = ?', {result[1].id})
|
||||
end
|
||||
end
|
||||
return retval, message
|
||||
end
|
||||
|
||||
QBCore.Functions.IsLicenseInUse = function(license)
|
||||
-- Check for duplicate license
|
||||
|
||||
function QBCore.Functions.IsLicenseInUse(license)
|
||||
local players = GetPlayers()
|
||||
for _, player in pairs(players) do
|
||||
local identifiers = GetPlayerIdentifiers(player)
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
PaycheckLoop = function()
|
||||
local Players = QBCore.Functions.GetPlayers()
|
||||
|
||||
for i=1, #Players, 1 do
|
||||
local Player = QBCore.Functions.GetPlayer(Players[i])
|
||||
|
||||
if Player.PlayerData.job ~= nil and Player.PlayerData.job.payment > 0 then
|
||||
Player.Functions.AddMoney('bank', Player.PlayerData.job.payment)
|
||||
TriggerClientEvent('QBCore:Notify', Players[i], "You received your paycheck of $"..Player.PlayerData.job.payment)
|
||||
end
|
||||
end
|
||||
SetTimeout(QBCore.Config.Money.PayCheckTimeOut * (60 * 1000), PaycheckLoop)
|
||||
end
|
||||
+19
-5
@@ -4,11 +4,25 @@ QBCore.Shared = QBShared
|
||||
QBCore.ServerCallbacks = {}
|
||||
QBCore.UseableItems = {}
|
||||
|
||||
function GetCoreObject()
|
||||
exports('GetCoreObject', function()
|
||||
return QBCore
|
||||
end
|
||||
end)
|
||||
|
||||
RegisterServerEvent('QBCore:GetObject')
|
||||
AddEventHandler('QBCore:GetObject', function(cb)
|
||||
cb(GetCoreObject())
|
||||
-- To use this export in a script instead of manifest method
|
||||
-- Just put this line of code below at the very top of the script
|
||||
-- local QBCore = exports['qb-core']:GetCoreObject()
|
||||
|
||||
-- Get permissions on server start
|
||||
|
||||
CreateThread(function()
|
||||
local result = exports.oxmysql:fetchSync('SELECT * FROM permissions', {})
|
||||
if result[1] then
|
||||
for k, v in pairs(result) do
|
||||
QBCore.Config.Server.PermissionList[v.license] = {
|
||||
license = v.license,
|
||||
permission = v.permission,
|
||||
optin = true,
|
||||
}
|
||||
end
|
||||
end
|
||||
end)
|
||||
+240
-240
@@ -1,142 +1,157 @@
|
||||
QBCore.Players = {}
|
||||
QBCore.Player = {}
|
||||
|
||||
QBCore.Player.Login = function(source, citizenid, newData)
|
||||
if source ~= nil then
|
||||
-- On player login get their data or set defaults
|
||||
-- Don't touch any of this unless you know what you are doing
|
||||
-- Will cause major issues!
|
||||
|
||||
function QBCore.Player.Login(source, citizenid, newData)
|
||||
local src = source
|
||||
if src then
|
||||
if citizenid then
|
||||
local result = exports.oxmysql:fetchSync('SELECT * FROM players WHERE citizenid = ?', { citizenid })
|
||||
local PlayerData = result[1]
|
||||
if PlayerData ~= nil then
|
||||
if PlayerData 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
|
||||
if PlayerData.gang then
|
||||
PlayerData.gang = json.decode(PlayerData.gang)
|
||||
else
|
||||
PlayerData.gang = {}
|
||||
end
|
||||
end
|
||||
QBCore.Player.CheckPlayerData(source, PlayerData)
|
||||
QBCore.Player.CheckPlayerData(src, PlayerData)
|
||||
else
|
||||
QBCore.Player.CheckPlayerData(source, newData)
|
||||
QBCore.Player.CheckPlayerData(src, newData)
|
||||
end
|
||||
return true
|
||||
else
|
||||
QBCore.ShowError(GetCurrentResourceName(), "ERROR QBCORE.PLAYER.LOGIN - NO SOURCE GIVEN!")
|
||||
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.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 {}
|
||||
function QBCore.Player.CheckPlayerData(source, PlayerData)
|
||||
local src = source
|
||||
PlayerData = PlayerData or {}
|
||||
PlayerData.source = src
|
||||
PlayerData.citizenid = PlayerData.citizenid or QBCore.Player.CreateCitizenId()
|
||||
PlayerData.license = PlayerData.license or QBCore.Functions.GetIdentifier(src, 'license')
|
||||
PlayerData.name = GetPlayerName(src)
|
||||
PlayerData.cid = PlayerData.cid or 1
|
||||
PlayerData.money = 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
|
||||
PlayerData.money[moneytype] = 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 "USA"
|
||||
PlayerData.charinfo.phone = PlayerData.charinfo.phone ~= nil and PlayerData.charinfo.phone or "1"..math.random(111111111, 999999999)
|
||||
PlayerData.charinfo.account = PlayerData.charinfo.account ~= nil and PlayerData.charinfo.account or "US0"..math.random(1,9).."QBCore"..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,
|
||||
-- Charinfo
|
||||
PlayerData.charinfo = PlayerData.charinfo or {}
|
||||
PlayerData.charinfo.firstname = PlayerData.charinfo.firstname or 'Firstname'
|
||||
PlayerData.charinfo.lastname = PlayerData.charinfo.lastname or 'Lastname'
|
||||
PlayerData.charinfo.birthdate = PlayerData.charinfo.birthdate or '00-00-0000'
|
||||
PlayerData.charinfo.gender = PlayerData.charinfo.gender or 0
|
||||
PlayerData.charinfo.backstory = PlayerData.charinfo.backstory or 'placeholder backstory'
|
||||
PlayerData.charinfo.nationality = PlayerData.charinfo.nationality or 'USA'
|
||||
PlayerData.charinfo.phone = PlayerData.charinfo.phone ~= nil and PlayerData.charinfo.phone or '1'..math.random(111111111, 999999999)
|
||||
PlayerData.charinfo.account = PlayerData.charinfo.account ~= nil and PlayerData.charinfo.account or 'US0'..math.random(1,9)..'QBCore'..math.random(1111,9999)..math.random(1111,9999)..math.random(11,99)
|
||||
-- Metadata
|
||||
PlayerData.metadata = PlayerData.metadata or {}
|
||||
PlayerData.metadata['hunger'] = PlayerData.metadata['hunger'] or 100
|
||||
PlayerData.metadata['thirst'] = PlayerData.metadata['thirst'] or 100
|
||||
PlayerData.metadata['stress'] = PlayerData.metadata['stress'] or 0
|
||||
PlayerData.metadata['isdead'] = PlayerData.metadata['isdead'] or false
|
||||
PlayerData.metadata['inlaststand'] = PlayerData.metadata['inlaststand'] or false
|
||||
PlayerData.metadata['armor'] = PlayerData.metadata['armor'] or 0
|
||||
PlayerData.metadata['ishandcuffed'] = PlayerData.metadata['ishandcuffed'] or false
|
||||
PlayerData.metadata['tracker'] = PlayerData.metadata['tracker'] or false
|
||||
PlayerData.metadata['injail'] = PlayerData.metadata['injail'] or 0
|
||||
PlayerData.metadata['jailitems'] = PlayerData.metadata['jailitems'] or {}
|
||||
PlayerData.metadata['status'] = PlayerData.metadata['status'] or {}
|
||||
PlayerData.metadata['phone'] = PlayerData.metadata['phone'] or {}
|
||||
PlayerData.metadata['fitbit'] = PlayerData.metadata['fitbit'] or {}
|
||||
PlayerData.metadata['commandbinds'] = PlayerData.metadata['commandbinds'] or {}
|
||||
PlayerData.metadata['bloodtype'] = PlayerData.metadata['bloodtype'] or QBCore.Config.Player.Bloodtypes[math.random(1, #QBCore.Config.Player.Bloodtypes)]
|
||||
PlayerData.metadata['dealerrep'] = PlayerData.metadata['dealerrep'] or 0
|
||||
PlayerData.metadata['craftingrep'] = PlayerData.metadata['craftingrep'] or 0
|
||||
PlayerData.metadata['attachmentcraftingrep'] = PlayerData.metadata['attachmentcraftingrep'] or 0
|
||||
PlayerData.metadata['currentapartment'] = PlayerData.metadata['currentapartment'] or nil
|
||||
PlayerData.metadata['jobrep'] = 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['callsign'] = PlayerData.metadata['callsign'] or 'NO CALLSIGN'
|
||||
PlayerData.metadata['fingerprint'] = PlayerData.metadata['fingerprint'] or QBCore.Player.CreateFingerId()
|
||||
PlayerData.metadata['walletid'] = PlayerData.metadata['walletid'] or QBCore.Player.CreateWalletId()
|
||||
PlayerData.metadata['criminalrecord'] = PlayerData.metadata['criminalrecord'] or {
|
||||
['hasRecord'] = false,
|
||||
['date'] = nil
|
||||
}
|
||||
PlayerData.metadata["licences"] = PlayerData.metadata["licences"] ~= nil and PlayerData.metadata["licences"] or {
|
||||
["driver"] = true,
|
||||
["business"] = false,
|
||||
["weapon"] = false
|
||||
PlayerData.metadata['licences'] = PlayerData.metadata['licences'] or {
|
||||
['driver'] = true,
|
||||
['business'] = false,
|
||||
['weapon'] = false
|
||||
}
|
||||
PlayerData.metadata["inside"] = PlayerData.metadata["inside"] ~= nil and PlayerData.metadata["inside"] or {
|
||||
PlayerData.metadata['inside'] = PlayerData.metadata['inside'] or {
|
||||
house = nil,
|
||||
apartment = {
|
||||
apartmentType = nil,
|
||||
apartmentId = nil,
|
||||
}
|
||||
}
|
||||
PlayerData.metadata["phonedata"] = PlayerData.metadata["phonedata"] ~= nil and PlayerData.metadata["phonedata"] or {
|
||||
PlayerData.metadata['phonedata'] = 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 "Civilian"
|
||||
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
|
||||
-- Added for grade system
|
||||
PlayerData.job.isboss = PlayerData.job.isboss ~= nil and PlayerData.job.isboss or false
|
||||
PlayerData.job.grade = PlayerData.job.grade ~= nil and PlayerData.job.grade or {}
|
||||
PlayerData.job.grade.name = PlayerData.job.grade.name ~= nil and PlayerData.job.grade.name or "Freelancer"
|
||||
PlayerData.job.grade.level = PlayerData.job.grade.level ~= nil and PlayerData.job.grade.level or 0
|
||||
|
||||
PlayerData.gang = PlayerData.gang ~= nil and PlayerData.gang or {}
|
||||
PlayerData.gang.name = PlayerData.gang.name ~= nil and PlayerData.gang.name or "none"
|
||||
PlayerData.gang.label = PlayerData.gang.label ~= nil and PlayerData.gang.label or "No Gang Affiliaton"
|
||||
-- Added for grade system
|
||||
PlayerData.gang.isboss = PlayerData.gang.isboss ~= nil and PlayerData.gang.isboss or false
|
||||
PlayerData.gang.grade = PlayerData.gang.grade ~= nil and PlayerData.gang.grade or {}
|
||||
PlayerData.gang.grade.name = PlayerData.gang.grade.name ~= nil and PlayerData.gang.grade.name or "none"
|
||||
PlayerData.gang.grade.level = PlayerData.gang.grade.level ~= nil and PlayerData.gang.grade.level or 0
|
||||
|
||||
PlayerData.position = PlayerData.position ~= nil and PlayerData.position or QBConfig.DefaultSpawn
|
||||
-- Job
|
||||
PlayerData.job = PlayerData.job or {}
|
||||
PlayerData.job.name = PlayerData.job.name or 'unemployed'
|
||||
PlayerData.job.label = PlayerData.job.label or 'Civilian'
|
||||
PlayerData.job.payment = PlayerData.job.payment or 10
|
||||
PlayerData.job.onduty = PlayerData.job.onduty or true
|
||||
PlayerData.job.isboss = PlayerData.job.isboss or false
|
||||
PlayerData.job.grade = PlayerData.job.grade or {}
|
||||
PlayerData.job.grade.name = PlayerData.job.grade.name or 'Freelancer'
|
||||
PlayerData.job.grade.level = PlayerData.job.grade.level or 0
|
||||
-- Gang
|
||||
PlayerData.gang = PlayerData.gang or {}
|
||||
PlayerData.gang.name = PlayerData.gang.name or 'none'
|
||||
PlayerData.gang.label = PlayerData.gang.label or 'No Gang Affiliaton'
|
||||
PlayerData.gang.isboss = PlayerData.gang.isboss or false
|
||||
PlayerData.gang.grade = PlayerData.gang.grade or {}
|
||||
PlayerData.gang.grade.name = PlayerData.gang.grade.name or 'none'
|
||||
PlayerData.gang.grade.level = PlayerData.gang.grade.level or 0
|
||||
-- Other
|
||||
PlayerData.position = PlayerData.position or QBConfig.DefaultSpawn
|
||||
PlayerData.LoggedIn = true
|
||||
|
||||
PlayerData = QBCore.Player.LoadInventory(PlayerData)
|
||||
QBCore.Player.CreatePlayer(PlayerData)
|
||||
end
|
||||
|
||||
QBCore.Player.CreatePlayer = function(PlayerData)
|
||||
-- On player logout
|
||||
|
||||
function QBCore.Player.Logout(source)
|
||||
local src = source
|
||||
TriggerClientEvent('QBCore:Client:OnPlayerUnload', src)
|
||||
TriggerClientEvent('QBCore:Player:UpdatePlayerData', src)
|
||||
Citizen.Wait(200)
|
||||
QBCore.Players[src] = nil
|
||||
end
|
||||
|
||||
-- Create a new character
|
||||
-- Don't touch any of this unless you know what you are doing
|
||||
-- Will cause major issues!
|
||||
|
||||
function QBCore.Player.CreatePlayer(PlayerData)
|
||||
local self = {}
|
||||
self.Functions = {}
|
||||
self.PlayerData = PlayerData
|
||||
|
||||
self.Functions.UpdatePlayerData = function(dontUpdateChat)
|
||||
TriggerClientEvent("QBCore:Player:SetPlayerData", self.PlayerData.source, self.PlayerData)
|
||||
TriggerClientEvent('QBCore:Player:SetPlayerData', self.PlayerData.source, self.PlayerData)
|
||||
if dontUpdateChat == nil then
|
||||
QBCore.Commands.Refresh(self.PlayerData.source)
|
||||
end
|
||||
@@ -144,20 +159,20 @@ QBCore.Player.CreatePlayer = function(PlayerData)
|
||||
|
||||
self.Functions.SetJob = function(job, grade)
|
||||
local job = job:lower()
|
||||
local grade = tostring(grade) ~= nil and tostring(grade) or '0'
|
||||
local grade = tostring(grade) or '0'
|
||||
|
||||
if QBCore.Shared.Jobs[job] ~= nil then
|
||||
if QBCore.Shared.Jobs[job] then
|
||||
self.PlayerData.job.name = job
|
||||
self.PlayerData.job.label = QBCore.Shared.Jobs[job].label
|
||||
self.PlayerData.job.onduty = QBCore.Shared.Jobs[job].defaultDuty
|
||||
|
||||
|
||||
if QBCore.Shared.Jobs[job].grades[grade] then
|
||||
local jobgrade = QBCore.Shared.Jobs[job].grades[grade]
|
||||
self.PlayerData.job.grade = {}
|
||||
self.PlayerData.job.grade.name = jobgrade.name
|
||||
self.PlayerData.job.grade.level = tonumber(grade)
|
||||
self.PlayerData.job.payment = jobgrade.payment ~= nil and jobgrade.payment or 30
|
||||
self.PlayerData.job.isboss = jobgrade.isboss ~= nil and jobgrade.isboss or false
|
||||
self.PlayerData.job.payment = jobgrade.payment or 30
|
||||
self.PlayerData.job.isboss = jobgrade.isboss or false
|
||||
else
|
||||
self.PlayerData.job.grade = {}
|
||||
self.PlayerData.job.grade.name = 'No Grades'
|
||||
@@ -167,7 +182,7 @@ QBCore.Player.CreatePlayer = function(PlayerData)
|
||||
end
|
||||
|
||||
self.Functions.UpdatePlayerData()
|
||||
TriggerClientEvent("QBCore:Client:OnJobUpdate", self.PlayerData.source, self.PlayerData.job)
|
||||
TriggerClientEvent('QBCore:Client:OnJobUpdate', self.PlayerData.source, self.PlayerData.job)
|
||||
return true
|
||||
end
|
||||
|
||||
@@ -176,9 +191,9 @@ QBCore.Player.CreatePlayer = function(PlayerData)
|
||||
|
||||
self.Functions.SetGang = function(gang, grade)
|
||||
local gang = gang:lower()
|
||||
local grade = tostring(grade) ~= nil and tostring(grade) or '0'
|
||||
local grade = tostring(grade) or '0'
|
||||
|
||||
if QBCore.Shared.Gangs[gang] ~= nil then
|
||||
if QBCore.Shared.Gangs[gang] then
|
||||
self.PlayerData.gang.name = gang
|
||||
self.PlayerData.gang.label = QBCore.Shared.Gangs[gang].label
|
||||
if QBCore.Shared.Gangs[gang].grades[grade] then
|
||||
@@ -186,7 +201,7 @@ QBCore.Player.CreatePlayer = function(PlayerData)
|
||||
self.PlayerData.gang.grade = {}
|
||||
self.PlayerData.gang.grade.name = ganggrade.name
|
||||
self.PlayerData.gang.grade.level = tonumber(grade)
|
||||
self.PlayerData.gang.isboss = ganggrade.isboss ~= nil and ganggrade.isboss or false
|
||||
self.PlayerData.gang.isboss = ganggrade.isboss or false
|
||||
else
|
||||
self.PlayerData.gang.grade = {}
|
||||
self.PlayerData.gang.grade.name = 'No Grades'
|
||||
@@ -195,7 +210,7 @@ QBCore.Player.CreatePlayer = function(PlayerData)
|
||||
end
|
||||
|
||||
self.Functions.UpdatePlayerData()
|
||||
TriggerClientEvent("QBCore:Client:OnGangUpdate", self.PlayerData.source, self.PlayerData.gang)
|
||||
TriggerClientEvent('QBCore:Client:OnGangUpdate', self.PlayerData.source, self.PlayerData.gang)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
@@ -216,35 +231,35 @@ QBCore.Player.CreatePlayer = function(PlayerData)
|
||||
|
||||
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.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"
|
||||
reason = reason or 'unknown'
|
||||
local moneytype = moneytype:lower()
|
||||
local amount = tonumber(amount)
|
||||
if amount < 0 then return end
|
||||
if self.PlayerData.money[moneytype] ~= nil then
|
||||
if self.PlayerData.money[moneytype] then
|
||||
self.PlayerData.money[moneytype] = self.PlayerData.money[moneytype]+amount
|
||||
self.Functions.UpdatePlayerData()
|
||||
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)
|
||||
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])
|
||||
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)
|
||||
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"
|
||||
reason = reason or 'unknown'
|
||||
local moneytype = moneytype:lower()
|
||||
local amount = tonumber(amount)
|
||||
if amount < 0 then return end
|
||||
if self.PlayerData.money[moneytype] ~= nil then
|
||||
if self.PlayerData.money[moneytype] 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
|
||||
@@ -253,12 +268,12 @@ QBCore.Player.CreatePlayer = function(PlayerData)
|
||||
self.PlayerData.money[moneytype] = self.PlayerData.money[moneytype] - amount
|
||||
self.Functions.UpdatePlayerData()
|
||||
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)
|
||||
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])
|
||||
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)
|
||||
if moneytype == "bank" then
|
||||
TriggerClientEvent('hud:client:OnMoneyChange', self.PlayerData.source, moneytype, amount, true)
|
||||
if moneytype == 'bank' then
|
||||
TriggerClientEvent('qb-phone:client:RemoveBankMoney', self.PlayerData.source, amount)
|
||||
end
|
||||
return true
|
||||
@@ -267,21 +282,21 @@ QBCore.Player.CreatePlayer = function(PlayerData)
|
||||
end
|
||||
|
||||
self.Functions.SetMoney = function(moneytype, amount, reason)
|
||||
reason = reason ~= nil and reason or "unkown"
|
||||
reason = reason or 'unknown'
|
||||
local moneytype = moneytype:lower()
|
||||
local amount = tonumber(amount)
|
||||
if amount < 0 then return end
|
||||
if self.PlayerData.money[moneytype] ~= nil then
|
||||
if self.PlayerData.money[moneytype] then
|
||||
self.PlayerData.money[moneytype] = amount
|
||||
self.Functions.UpdatePlayerData()
|
||||
TriggerEvent("qb-log:server:CreateLog", "playermoney", "SetMoney", "green", "**"..GetPlayerName(self.PlayerData.source) .. " (citizenid: "..self.PlayerData.citizenid.." | id: "..self.PlayerData.source..")** $"..amount .. " ("..moneytype..") set, new "..moneytype.." balance: "..self.PlayerData.money[moneytype])
|
||||
TriggerEvent('qb-log:server:CreateLog', 'playermoney', 'SetMoney', 'green', '**'..GetPlayerName(self.PlayerData.source) .. ' (citizenid: '..self.PlayerData.citizenid..' | id: '..self.PlayerData.source..')** $'..amount .. ' ('..moneytype..') set, new '..moneytype..' balance: '..self.PlayerData.money[moneytype])
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
self.Functions.GetMoney = function(moneytype)
|
||||
if moneytype ~= nil then
|
||||
if moneytype then
|
||||
local moneytype = moneytype:lower()
|
||||
return self.PlayerData.money[moneytype]
|
||||
end
|
||||
@@ -291,72 +306,71 @@ QBCore.Player.CreatePlayer = function(PlayerData)
|
||||
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
|
||||
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
|
||||
local slot = 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
|
||||
if (totalWeight + (itemInfo['weight'] * amount)) <= QBCore.Config.Player.MaxWeight then
|
||||
if (slot and self.PlayerData.items[slot]) 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: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)
|
||||
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)
|
||||
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"]}
|
||||
elseif (not itemInfo['unique'] and slot or slot and self.PlayerData.items[slot] == nil) then
|
||||
self.PlayerData.items[slot] = {name = itemInfo['name'], amount = amount, info = info or '', label = itemInfo['label'], description = 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: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)
|
||||
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)
|
||||
return true
|
||||
elseif (itemInfo["unique"]) or (not slot or slot == nil) or (itemInfo["type"] == "weapon") then
|
||||
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.PlayerData.items[i] = {name = itemInfo['name'], amount = amount, info = info or '', label = itemInfo['label'], description = 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: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")
|
||||
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
|
||||
else
|
||||
TriggerClientEvent('QBCore:Notify', self.PlayerData.source, "Your inventory is too heavy!", "error")
|
||||
TriggerClientEvent('QBCore:Notify', self.PlayerData.source, 'Your inventory is too heavy!', 'error')
|
||||
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 slot 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: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)
|
||||
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)
|
||||
return true
|
||||
else
|
||||
self.PlayerData.items[slot] = nil
|
||||
self.Functions.UpdatePlayerData()
|
||||
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")
|
||||
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')
|
||||
return true
|
||||
end
|
||||
else
|
||||
local slots = QBCore.Player.GetSlotsByItem(self.PlayerData.items, item)
|
||||
local amountToRemove = amount
|
||||
if slots ~= nil then
|
||||
if slots 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: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)
|
||||
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)
|
||||
return true
|
||||
elseif self.PlayerData.items[slot].amount == amountToRemove then
|
||||
self.PlayerData.items[slot] = nil
|
||||
self.Functions.UpdatePlayerData()
|
||||
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")
|
||||
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')
|
||||
return true
|
||||
end
|
||||
end
|
||||
@@ -368,19 +382,19 @@ QBCore.Player.CreatePlayer = function(PlayerData)
|
||||
self.Functions.SetInventory = function(items, dontUpdateChat)
|
||||
self.PlayerData.items = items
|
||||
self.Functions.UpdatePlayerData(dontUpdateChat)
|
||||
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))
|
||||
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:CreateLog", "playerinventory", "ClearInventory", "red", "**"..GetPlayerName(self.PlayerData.source) .. " (citizenid: "..self.PlayerData.citizenid.." | id: "..self.PlayerData.source..")** inventory cleared")
|
||||
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
|
||||
if slot then
|
||||
return self.PlayerData.items[slot]
|
||||
end
|
||||
return nil
|
||||
@@ -391,7 +405,7 @@ QBCore.Player.CreatePlayer = function(PlayerData)
|
||||
local items = {}
|
||||
local slots = QBCore.Player.GetSlotsByItem(self.PlayerData.items, item)
|
||||
for _, slot in pairs(slots) do
|
||||
if slot ~= nil then
|
||||
if slot then
|
||||
table.insert(items, self.PlayerData.items[slot])
|
||||
end
|
||||
end
|
||||
@@ -407,7 +421,7 @@ QBCore.Player.CreatePlayer = function(PlayerData)
|
||||
local item = tostring(cardType):lower()
|
||||
local slots = QBCore.Player.GetSlotsByItem(self.PlayerData.items, item)
|
||||
for _, slot in pairs(slots) do
|
||||
if slot ~= nil then
|
||||
if slot then
|
||||
if self.PlayerData.items[slot].info.cardNumber == cardNumber then
|
||||
return slot
|
||||
end
|
||||
@@ -418,7 +432,7 @@ QBCore.Player.CreatePlayer = function(PlayerData)
|
||||
|
||||
self.Functions.GetItemBySlot = function(slot)
|
||||
local slot = tonumber(slot)
|
||||
if self.PlayerData.items[slot] ~= nil then
|
||||
if self.PlayerData.items[slot] then
|
||||
return self.PlayerData.items[slot]
|
||||
end
|
||||
return nil
|
||||
@@ -436,106 +450,91 @@ QBCore.Player.CreatePlayer = function(PlayerData)
|
||||
self.Functions.UpdatePlayerData()
|
||||
end
|
||||
|
||||
QBCore.Player.Save = function(source)
|
||||
local PlayerData = QBCore.Players[source].PlayerData
|
||||
if PlayerData ~= nil then
|
||||
-- TODO: Merge these 3 queries into 1 with an on duplicate (citizenid isn't primary so https://stackoverflow.com/a/33495408/3200040 might need to be used)
|
||||
local result = exports.oxmysql:fetchSync('SELECT * FROM players WHERE citizenid = ?', { PlayerData.citizenid })
|
||||
if result[1] == nil then
|
||||
exports.oxmysql:insert('INSERT INTO players (citizenid, cid, license, name, money, charinfo, job, gang, position, metadata) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', {
|
||||
PlayerData.citizenid,
|
||||
tonumber(PlayerData.cid),
|
||||
PlayerData.license,
|
||||
PlayerData.name,
|
||||
json.encode(PlayerData.money),
|
||||
json.encode(PlayerData.charinfo),
|
||||
json.encode(PlayerData.job),
|
||||
json.encode(PlayerData.gang),
|
||||
json.encode(PlayerData.position),
|
||||
json.encode(PlayerData.metadata)
|
||||
})
|
||||
else
|
||||
exports.oxmysql:execute('UPDATE players SET license = ?, name = ?, money = ?, charinfo = ?, job = ?, gang = ?, position = ?, metadata = ? WHERE citizenid = ?', {
|
||||
PlayerData.license,
|
||||
PlayerData.name,
|
||||
json.encode(PlayerData.money),
|
||||
json.encode(PlayerData.charinfo),
|
||||
json.encode(PlayerData.job),
|
||||
json.encode(PlayerData.gang),
|
||||
json.encode(PlayerData.position),
|
||||
json.encode(PlayerData.metadata),
|
||||
PlayerData.citizenid
|
||||
})
|
||||
end
|
||||
QBCore.Player.SaveInventory(source)
|
||||
QBCore.ShowSuccess(GetCurrentResourceName(), PlayerData.name .." PLAYER SAVED!")
|
||||
-- Save player info to database (make sure citizenid is the primary key in your database)
|
||||
|
||||
function QBCore.Player.Save(source)
|
||||
local src = source
|
||||
local PlayerData = QBCore.Players[src].PlayerData
|
||||
if PlayerData then
|
||||
exports.oxmysql:insert('INSERT INTO players (citizenid, cid, license, name, money, charinfo, job, gang, position, metadata) VALUES (:citizenid, :cid, :license, :name, :money, :charinfo, :job, :gang, :position, :metadata) ON DUPLICATE KEY UPDATE cid = :cid, name = :name, money = :money, charinfo = :charinfo, job = :job, gang = :gang, position = :position, metadata = :metadata', {
|
||||
citizenid = PlayerData.citizenid,
|
||||
cid = tonumber(PlayerData.cid),
|
||||
license = PlayerData.license,
|
||||
name = PlayerData.name,
|
||||
money = json.encode(PlayerData.money),
|
||||
charinfo = json.encode(PlayerData.charinfo),
|
||||
job = json.encode(PlayerData.job),
|
||||
gang = json.encode(PlayerData.gang),
|
||||
position = json.encode(PlayerData.position),
|
||||
metadata = json.encode(PlayerData.metadata)
|
||||
})
|
||||
QBCore.Player.SaveInventory(src)
|
||||
QBCore.ShowSuccess(GetCurrentResourceName(), PlayerData.name ..' PLAYER SAVED!')
|
||||
else
|
||||
QBCore.ShowError(GetCurrentResourceName(), "ERROR QBCORE.PLAYER.SAVE - PLAYERDATA IS EMPTY!")
|
||||
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)
|
||||
QBCore.Players[source] = nil
|
||||
end
|
||||
-- Delete character
|
||||
|
||||
local playertables = {
|
||||
{table = "players"},
|
||||
{table = "apartments"},
|
||||
{table = "bank_accounts"},
|
||||
{table = "crypto_transactions"},
|
||||
{table = "phone_invoices"},
|
||||
{table = "phone_messages"},
|
||||
{table = "playerskins"},
|
||||
{table = "player_boats"},
|
||||
{table = "player_contacts"},
|
||||
{table = "player_houses"},
|
||||
{table = "player_mails"},
|
||||
{table = "player_outfits"},
|
||||
{table = "player_vehicles"}
|
||||
local playertables = { -- Add tables as needed
|
||||
{table = 'players'},
|
||||
{table = 'apartments'},
|
||||
{table = 'bank_accounts'},
|
||||
{table = 'crypto_transactions'},
|
||||
{table = 'phone_invoices'},
|
||||
{table = 'phone_messages'},
|
||||
{table = 'playerskins'},
|
||||
{table = 'player_boats'},
|
||||
{table = 'player_contacts'},
|
||||
{table = 'player_houses'},
|
||||
{table = 'player_mails'},
|
||||
{table = 'player_outfits'},
|
||||
{table = 'player_vehicles'}
|
||||
}
|
||||
|
||||
QBCore.Player.DeleteCharacter = function(source, citizenid)
|
||||
local license = QBCore.Functions.GetIdentifier(source, 'license')
|
||||
function QBCore.Player.DeleteCharacter(source, citizenid)
|
||||
local src = source
|
||||
local license = QBCore.Functions.GetIdentifier(src, 'license')
|
||||
local result = exports.oxmysql:scalarSync('SELECT license FROM players where citizenid = ?', { citizenid })
|
||||
if license == result then
|
||||
for k,v in pairs(playertables) do
|
||||
exports.oxmysql:execute('DELETE FROM '..v.table..' WHERE citizenid = ?', { citizenid })
|
||||
end
|
||||
TriggerEvent("qb-log:server:CreateLog", "joinleave", "Character Deleted", "red", "**".. GetPlayerName(source) .. "** ("..QBCore.Functions.GetIdentifier(source, 'license')..") deleted **"..citizenid.."**..")
|
||||
TriggerEvent('qb-log:server:CreateLog', 'joinleave', 'Character Deleted', 'red', '**'.. GetPlayerName(src) .. '** '..license..' deleted **'..citizenid..'**..')
|
||||
else
|
||||
DropPlayer(source, 'You Have Been Kicked For Exploitation')
|
||||
TriggerEvent("qb-log:server:CreateLog", "anticheat", "Anti-Cheat", "white", GetPlayerName(source).." Has Been Dropped For Character Deletion Exploit", false)
|
||||
DropPlayer(src, 'You Have Been Kicked For Exploitation')
|
||||
TriggerEvent('qb-log:server:CreateLog', 'anticheat', 'Anti-Cheat', 'white', GetPlayerName(src)..' Has Been Dropped For Character Deletion Exploit', false)
|
||||
end
|
||||
end
|
||||
|
||||
-- Inventory
|
||||
|
||||
QBCore.Player.LoadInventory = function(PlayerData)
|
||||
PlayerData.items = {}
|
||||
local result = exports.oxmysql:fetchSync('SELECT * FROM players WHERE citizenid = ?', { PlayerData.citizenid })
|
||||
if result[1] ~= nil then
|
||||
if result[1].inventory ~= nil then
|
||||
local result = exports.oxmysql:fetchSync('SELECT * FROM players WHERE citizenid = ?', {PlayerData.citizenid})
|
||||
if result[1] then
|
||||
if result[1].inventory then
|
||||
plyInventory = json.decode(result[1].inventory)
|
||||
if next(plyInventory) ~= nil then
|
||||
if next(plyInventory) then
|
||||
for _, item in pairs(plyInventory) do
|
||||
if item ~= nil then
|
||||
if item then
|
||||
local itemInfo = QBCore.Shared.Items[item.name:lower()]
|
||||
if itemInfo ~= nil then
|
||||
if itemInfo then
|
||||
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"]
|
||||
name = itemInfo['name'],
|
||||
amount = item.amount,
|
||||
info = item.info or '',
|
||||
label = itemInfo['label'],
|
||||
description = 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
|
||||
@@ -547,13 +546,14 @@ QBCore.Player.LoadInventory = function(PlayerData)
|
||||
end
|
||||
|
||||
QBCore.Player.SaveInventory = function(source)
|
||||
if QBCore.Players[source] ~= nil then
|
||||
local PlayerData = QBCore.Players[source].PlayerData
|
||||
local src = source
|
||||
if QBCore.Players[src] then
|
||||
local PlayerData = QBCore.Players[src].PlayerData
|
||||
local items = PlayerData.items
|
||||
local ItemsJson = {}
|
||||
if items ~= nil and next(items) ~= nil then
|
||||
if items and next(items) then
|
||||
for slot, item in pairs(items) do
|
||||
if items[slot] ~= nil then
|
||||
if items[slot] then
|
||||
table.insert(ItemsJson, {
|
||||
name = item.name,
|
||||
amount = item.amount,
|
||||
@@ -570,9 +570,11 @@ QBCore.Player.SaveInventory = function(source)
|
||||
end
|
||||
end
|
||||
|
||||
QBCore.Player.GetTotalWeight = function(items)
|
||||
-- Util Functions
|
||||
|
||||
function QBCore.Player.GetTotalWeight(items)
|
||||
local weight = 0
|
||||
if items ~= nil then
|
||||
if items then
|
||||
for slot, item in pairs(items) do
|
||||
weight = weight + (item.weight * item.amount)
|
||||
end
|
||||
@@ -580,9 +582,9 @@ QBCore.Player.GetTotalWeight = function(items)
|
||||
return tonumber(weight)
|
||||
end
|
||||
|
||||
QBCore.Player.GetSlotsByItem = function(items, itemName)
|
||||
function QBCore.Player.GetSlotsByItem(items, itemName)
|
||||
local slotsFound = {}
|
||||
if items ~= nil then
|
||||
if items then
|
||||
for slot, item in pairs(items) do
|
||||
if item.name:lower() == itemName:lower() then
|
||||
table.insert(slotsFound, slot)
|
||||
@@ -592,8 +594,8 @@ QBCore.Player.GetSlotsByItem = function(items, itemName)
|
||||
return slotsFound
|
||||
end
|
||||
|
||||
QBCore.Player.GetFirstSlotByItem = function(items, itemName)
|
||||
if items ~= nil then
|
||||
function QBCore.Player.GetFirstSlotByItem(items, itemName)
|
||||
if items then
|
||||
for slot, item in pairs(items) do
|
||||
if item.name:lower() == itemName:lower() then
|
||||
return tonumber(slot)
|
||||
@@ -603,10 +605,9 @@ QBCore.Player.GetFirstSlotByItem = function(items, itemName)
|
||||
return nil
|
||||
end
|
||||
|
||||
QBCore.Player.CreateCitizenId = function()
|
||||
function QBCore.Player.CreateCitizenId()
|
||||
local UniqueFound = false
|
||||
local CitizenId = nil
|
||||
|
||||
while not UniqueFound do
|
||||
CitizenId = tostring(QBCore.Shared.RandomStr(3) .. QBCore.Shared.RandomInt(5)):upper()
|
||||
local result = exports.oxmysql:fetchSync('SELECT COUNT(*) as count FROM players WHERE citizenid = ?', { CitizenId })
|
||||
@@ -617,7 +618,7 @@ QBCore.Player.CreateCitizenId = function()
|
||||
return CitizenId
|
||||
end
|
||||
|
||||
QBCore.Player.CreateFingerId = function()
|
||||
function QBCore.Player.CreateFingerId()
|
||||
local UniqueFound = false
|
||||
local FingerId = nil
|
||||
while not UniqueFound do
|
||||
@@ -631,11 +632,11 @@ QBCore.Player.CreateFingerId = function()
|
||||
return FingerId
|
||||
end
|
||||
|
||||
QBCore.Player.CreateWalletId = function()
|
||||
function QBCore.Player.CreateWalletId()
|
||||
local UniqueFound = false
|
||||
local WalletId = nil
|
||||
while not UniqueFound do
|
||||
WalletId = "QB-"..math.random(11111111, 99999999)
|
||||
WalletId = 'QB-'..math.random(11111111, 99999999)
|
||||
local query = '%'..WalletId..'%'
|
||||
local result = exports.oxmysql:fetchSync('SELECT COUNT(*) as count FROM players WHERE metadata LIKE ?', { query })
|
||||
if result[1].count == 0 then
|
||||
@@ -645,10 +646,9 @@ QBCore.Player.CreateWalletId = function()
|
||||
return WalletId
|
||||
end
|
||||
|
||||
QBCore.Player.CreateSerialNumber = function()
|
||||
function QBCore.Player.CreateSerialNumber()
|
||||
local UniqueFound = false
|
||||
local SerialNumber = nil
|
||||
|
||||
while not UniqueFound do
|
||||
SerialNumber = math.random(11111111, 99999999)
|
||||
local query = '%'..SerialNumber..'%'
|
||||
@@ -660,4 +660,4 @@ QBCore.Player.CreateSerialNumber = function()
|
||||
return SerialNumber
|
||||
end
|
||||
|
||||
PaycheckLoop()
|
||||
PaycheckLoop() -- This just starts the paycheck system
|
||||
+4207
-4207
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user