117 lines
		
	
	
	
		
			3.6 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
			
		
		
	
	
			117 lines
		
	
	
	
		
			3.6 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
| QBCore.Functions.CreateCallback("roadphone:valet:getCars", function(source, cb)
 | |
| 
 | |
|     local xPlayer = QBCore.Functions.GetPlayer(source)
 | |
| 
 | |
|     if not xPlayer then
 | |
|         return;
 | |
|     end
 | |
| 
 | |
|     local result
 | |
| 
 | |
|     if Config.JGAdvancedGarages then
 | |
|         result = MySQL.Sync.fetchAll("SELECT * FROM " .. Config.OwnedVehiclesTable .. " WHERE `citizenid` = @identifier and `impound` = @impound", {
 | |
|             ['@impound'] = 0,
 | |
|             ['@identifier'] = xPlayer.PlayerData.citizenid
 | |
|         })
 | |
|     else
 | |
|         result = MySQL.Sync.fetchAll("SELECT * FROM " .. Config.OwnedVehiclesTable .. " WHERE `citizenid` = @identifier", {
 | |
|             ['@identifier'] = xPlayer.PlayerData.citizenid
 | |
|         })
 | |
|     end
 | |
| 
 | |
|     local cachedvehicles = {}
 | |
| 
 | |
|     for i = 1, #result do
 | |
| 
 | |
|     local Garage = result[i].garage_id
 | |
| 
 | |
|     table.insert(cachedvehicles, {
 | |
|         plate = result[i].plate,
 | |
|         vehicle = result[i].vehicle,
 | |
|         hash = result[i].hash,
 | |
|         garage = result[i].garage,
 | |
|         stored = result[i].state
 | |
|     })
 | |
| 
 | |
|     end
 | |
| 
 | |
|     cb(cachedvehicles)
 | |
|     
 | |
| end)
 | |
| 
 | |
| 
 | |
| QBCore.Functions.CreateCallback('roadphone:valet:loadVehicle', function(source, cb, plate)
 | |
| 
 | |
|     local valetCheck = valetServerSideCheck(plate)
 | |
|     local xPlayer = QBCore.Functions.GetPlayer(source)
 | |
| 
 | |
|     if valetCheck ~= false then
 | |
|         cb(false, valetCheck)
 | |
|         return;
 | |
|     end
 | |
| 
 | |
|     if not xPlayer then
 | |
|         cb(false)
 | |
|         return;
 | |
|     end
 | |
| 
 | |
|     MySQL.Async.fetchAll('SELECT * FROM ' .. Config.OwnedVehiclesTable .. ' WHERE `plate` = @plate AND `citizenid` = @identifier', {
 | |
|         ['@plate'] = plate,
 | |
|         ['@identifier'] = xPlayer.PlayerData.citizenid
 | |
|     }, function(vehicle)
 | |
|         cb(vehicle)
 | |
|     end)
 | |
| end)
 | |
| 
 | |
| QBCore.Functions.CreateCallback('roadphone:valet:checkMoney', function(source, cb)
 | |
|     local xPlayer = QBCore.Functions.GetPlayer(source)
 | |
| 
 | |
|     if not xPlayer then
 | |
|         return;
 | |
|     end
 | |
| 
 | |
|     if xPlayer.Functions.GetMoney('bank') > Config.ValetDeliveryPrice then
 | |
|         xPlayer.Functions.RemoveMoney('bank', Config.ValetDeliveryPrice, 'Car delivered')
 | |
| 
 | |
|         local number = getNumberFromIdentifier(xPlayer.PlayerData.citizenid)
 | |
| 
 | |
|         TriggerEvent("roadphone:addBankTransfer", number, 0,  Lang:t('info.valet_car_delivered'), Config.ValetDeliveryPrice)
 | |
| 
 | |
|         TriggerClientEvent("roadphone:sendNotification", source, {
 | |
|             apptitle = "APP_VALET_NAME",
 | |
|             title = "APP_VALET_CAR_ONTHEWAY",
 | |
|             img = "/public/img/Apps/valet.jpg"
 | |
|         })
 | |
| 
 | |
|         discordLog("9807270", "Valet", xPlayer.PlayerData.name .. ' ' .. Lang:t('info.valet_car_delivered_2', { value = Config.ValetDeliveryPrice }), 'RoadPhone - Valet', nil, Cfg.ValetWebhook)
 | |
|         cb(true)
 | |
|         return;
 | |
|     else
 | |
|         TriggerClientEvent("roadphone:sendNotification", source, {
 | |
|             apptitle = "APP_VALET_NAME",
 | |
|             title = "APP_VALET_NOTENOUGHMONEY",
 | |
|             img = "/public/img/Apps/valet.jpg"
 | |
|         })
 | |
| 
 | |
|         cb(false)
 | |
|         return;
 | |
|     end
 | |
| 
 | |
| end)
 | |
| 
 | |
| RegisterServerEvent("roadphone:valetCarSetOutside")
 | |
| AddEventHandler("roadphone:valetCarSetOutside", function(plate)
 | |
|     
 | |
|     if Config.cdGarages or Config.JGAdvancedGarages then
 | |
|         MySQL.Async.execute('UPDATE '..Config.OwnedVehiclesTable..' SET `in_garage` = @in_garage WHERE `plate` = @plate', {
 | |
|           ['@plate'] = plate,
 | |
|           ['@in_garage'] = 0,
 | |
|         })
 | |
|         return
 | |
|     end
 | |
| 
 | |
|     MySQL.Async.execute("UPDATE " .. Config.OwnedVehiclesTable .. " SET `state` = @stored WHERE `plate` = @plate", {
 | |
|         ["@plate"] = plate,
 | |
|         ["@stored"] = 0
 | |
|     })
 | |
| end)
 | 
