2026-04-14 17:41:39 +02:00

187 lines
4.6 KiB
Lua

if Config.Framework ~= "qb" then return end
local function CheckQBCoreStatus()
local resourceState = GetResourceState('qb-core')
return resourceState == "started" or resourceState == "starting"
end
Core = nil
local QBCore = nil
if CheckQBCoreStatus() then
local success, result = pcall(function()
return exports['qb-core']:GetCoreObject()
end)
if success and result then
QBCore = result
Core = QBCore
else
Core = nil
print('Error: QB-Core object could not be retrieved')
end
else
Core = nil
print('Error: QB-Core resource not found or not started')
return
end
RegisterNetEvent("QBCore:Client:OnPlayerLoaded")
AddEventHandler("QBCore:Client:OnPlayerLoaded", function()
Wait(100)
if LoadedUI() then
TriggerServerEvent('codem-phone:server:LoadPhone')
end
end)
RegisterNetEvent("QBCore:Client:OnPlayerUnload", function()
PlayerLogout()
end)
function ToggleDuty()
TriggerServerEvent('QBCore:ToggleDuty')
end
function ApplyVehicleMods(vehicle, vehicleData)
if type(vehicleData.mods) == "string" then
vehicleData.mods = json.decode(vehicleData.mods)
end
SetVehicleNumberPlateText(vehicle, vehicleData.plate)
QBCore.Functions.SetVehicleProperties(vehicle, vehicleData.mods)
TriggerEvent("vehiclekeys:client:SetOwner", QBCore.Functions.GetPlate(vehicle))
if GetResourceState("LegacyFuel") == "started" and vehicleData.fuel then
exports.LegacyFuel:SetFuel(vehicle, vehicleData.fuel)
end
if vehicleData.engine then
SetVehicleEngineHealth(vehicle, vehicleData.engine + 0.0)
end
if vehicleData.body then
SetVehicleBodyHealth(vehicle, vehicleData.body + 0.0)
end
end
function LoadModel(model)
model = type(model) == "number" and model or joaat(model)
RequestModel(model)
while not HasModelLoaded(model) do
Wait(0)
end
return model
end
function WaitForNetworkId(netId)
local timer = GetGameTimer() + 5000
while not NetworkDoesNetworkIdExist(netId) do
Wait(0)
if GetGameTimer() > timer then
return
end
end
timer = GetGameTimer() + 5000
while not DoesEntityExist(NetworkGetEntityFromNetworkId(netId)) do
Wait(0)
if GetGameTimer() > timer then
return
end
end
return NetworkGetEntityFromNetworkId(netId)
end
function CreateFrameworkVehicle(vehicleData, coords)
local hash = tonumber(vehicleData.hash)
if not hash then
return
end
local model = LoadModel(hash)
local vehicle = CreateVehicle(model, coords.x, coords.y, coords.z, 0.0, true, false)
SetVehicleOnGroundProperly(vehicle)
ApplyVehicleMods(vehicle, vehicleData)
SetModelAsNoLongerNeeded(model)
return vehicle
end
function TakeControlOfEntity(entity)
if NetworkHasControlOfEntity(entity) then
return true
end
local timer = GetGameTimer() + 5000
while not NetworkHasControlOfEntity(entity) and timer > GetGameTimer() do
NetworkRequestControlOfEntity(entity)
Wait(0)
end
return NetworkHasControlOfEntity(entity)
end
-- todos vehicle keyler düzenlenecek
function GiveVehicleKey(vehicle, plate)
Config.GiveVehicleKey(vehicle, plate)
end
-- todos diğer framerworklare eklenecek
function CanPhoneOpen()
local metadata = QBCore.Functions.GetPlayerData().metadata
if metadata.ishandcuffed or metadata.isdead or metadata.inlaststand then
return false
end
return true
end
local hadPhoneBefore = nil
RegisterNetEvent("QBCore:Player:SetPlayerData", function(newData)
PlayerData = newData
if not Config.ItemRequired then
return
end
if not newData.items then
return
end
if hadPhoneBefore == nil then
hadPhoneBefore = HasPhoneItems()
return
end
local hasPhoneNow = HasPhoneItems()
if hadPhoneBefore and not hasPhoneNow then
Wait(500)
if Config.UniquePhone then
if ClientPhoneNumber then
local result = RPC.execute('codem-phone:server:CheckPhoneAfterDrop', ClientPhoneNumber)
if result and result.shouldClose then
CloseAllPhoneActivities()
end
end
else
if CloseAllPhoneActivities then
CloseAllPhoneActivities()
end
end
end
hadPhoneBefore = hasPhoneNow
end)