车改色后存进车库取出后不保存颜色
车改色后存进车库取出后不保存颜色车库用的什么插件 -- server/main.lua
local MySQL = exports['mysql-async']
-- 玩家更改车辆颜色的事件处理
RegisterNetEvent('playerChangeVehicleColor', function(vehicle, primaryColor, secondaryColor)
local player = source
local vehicleId = tonumber(vehicle) -- 假设vehicle是车辆的ID
-- 保存颜色到数据库
MySQL.Async.execute('UPDATE vehicles SET primaryColor = ?, secondaryColor = ? WHERE id = ?', { primaryColor, secondaryColor, vehicleId }, function(rowsChanged)
-- 颜色保存后的逻辑
end)
end)
-- 玩家从车库取出车辆的事件处理
RegisterNetEvent('garage:TakeOutVehicle', function(vehicleId)
local player = source
-- 从数据库加载颜色
MySQL.Async.fetchAll('SELECT primaryColor, secondaryColor FROM vehicles WHERE id = ?', { vehicleId }, function(result)
if result then
local primaryColor = result.primaryColor
local secondaryColor = result.secondaryColor
-- 玩家取出车辆时设置颜色
TriggerClientEvent('setVehicleColor', player, primaryColor, secondaryColor)
end
end)
end)
-- 客户端事件,用于设置车辆颜色
RegisterNetEvent('setVehicleColor', function(primaryColor, secondaryColor)
local playerPed = PlayerPedId()
local vehicle = GetVehiclePedIsIn(playerPed, false)
if DoesEntityExist(vehicle) then
SetVehicleColours(vehicle, primaryColor, secondaryColor)
end
end)
页:
[1]