RegisterServerEvent("truck_logistics:startContract")
AddEventHandler("truck_logistics:startContract",function(data)
local id = data.id
local distance = data.distance
local reward = data.reward
local source = source
if debug_cooldown[source] == nil then
debug_cooldown[source] = true
local xPlayer = QBCore.Functions.GetPlayer(source)
local user_id = xPlayer.PlayerData.citizenid
if user_id then
QBCore.Functions.Notify('' .. user_id, 'success', 5000)
local query = exports['ghmattimysql']:execute("SELECT * FROM `trucker_available_contracts` WHERE contract_id = @id",{['@id'] = id}, function(query)
if query and query[1] then
query_users = exports['ghmattimysql']:execute("SELECT * FROM `trucker_users` WHERE user_id = @user_id", {['@user_id'] = user_id}, function(query_users)
if query_users and query_users[1] then
if tonumber(query_users[1].product_type) >= tonumber(query[1].cargo_type) then
if tonumber(query_users[1].fragile) >= tonumber(query[1].fragile) then
if tonumber(query_users[1].valuable) >= tonumber(query[1].valuable) then
if tonumber(query_users[1].fast) >= tonumber(query[1].fast) then
if Config.habilidade_distancia[tonumber(query_users[1].distance)] >= tonumber(distance) then
if tonumber(query[1].contract_type) == 0 then
-- Inicia o trabalho
TriggerClientEvent("truck_logistics:startContract",source,query[1],distance,reward,{})
else
-- Checa se tem caminhão
query_truck = exports['ghmattimysql']:execute("SELECT * FROM `trucker_trucks` WHERE driver = 0 AND user_id = @user_id", {['@user_id'] = user_id}, function(query_truck)
if query_truck and query_truck[1] then
TriggerClientEvent("truck_logistics:startContract",source,query[1],distance,reward,query_truck[1])
else
TriggerClientEvent("QBCore:Notify",source, Lang[Config.lang]['own_truck'], "error")
end
end)
end
else
TriggerClientEvent("QBCore:Notify",source, Lang[Config.lang]['no_skill_1'], "error")
end
else
TriggerClientEvent("QBCore:Notify",source,Lang[Config.lang]['no_skill_2'], "error")
end
else
TriggerClientEvent("QBCore:Notify",source,Lang[Config.lang]['no_skill_3'], "error")
end
else
TriggerClientEvent("QBCore:Notify",source,Lang[Config.lang]['no_skill_4'], "error")
end
else
TriggerClientEvent("QBCore:Notify",source,Lang[Config.lang]['no_skill_5'], "error")
end
end
end)
else
TriggerClientEvent("QBCore:Notify",source,Lang[Config.lang]['job_already_started'], "error")
end
end)
end
debug_cooldown[source] = nil
end
end)