This script is an addon for esx_vehicleshop
and allows users to transfer their cars to each other. Had this script for about 3 - 4 months now so I decided to release it as it had no more use to me. This works with any sort of plate variation as well as custom plates, just make sure to have the correct version of esx_vehicleshop which indexes the vehicle plates in a separate column in the database (picture showing that below)
Credit also goes to Kuzkay for helping me with writing this at the time.
How it works?
Get a vehicle you own (it wonât work if you donât own it), then type /transfervehicle ID plate
E.G. I want to transfer my car with the plate 45FGH495 to ID 5 -> /transfervehicle 5 45FGH495
Copy paste this script in the server.lua file from your esx_vehicleshop
resource
--type in chat /transfervehicle <player-id number> "car plate"
--Example /transfervehicle 1 "ABC 123" will transfer the car with plate "ABC 123" to the player
-- who has the id 1 (the player of course needs to be online)
RegisterCommand('transfervehicle', function(source, args)
myself = source
other = args[1]
if(GetPlayerName(tonumber(args[1])))then
else
TriggerClientEvent('chatMessage', source, "SYSTEM", {255, 0, 0}, "Incorrect player ID!")
return
end
local plate1 = args[2]
local plate2 = args[3]
local plate3 = args[4]
local plate4 = args[5]
if plate1 ~= nil then plate01 = plate1 else plate01 = "" end
if plate2 ~= nil then plate02 = plate2 else plate02 = "" end
if plate3 ~= nil then plate03 = plate3 else plate03 = "" end
if plate4 ~= nil then plate04 = plate4 else plate04 = "" end
local plate = (plate01 .. " " .. plate02 .. " " .. plate03 .. " " .. plate04)
mySteamID = GetPlayerIdentifiers(source)
mySteam = mySteamID[1]
myID = ESX.GetPlayerFromId(source).identifier
myName = ESX.GetPlayerFromId(source).name
targetSteamID = GetPlayerIdentifiers(args[1])
targetSteamName = ESX.GetPlayerFromId(args[1]).name
targetSteam = targetSteamID[1]
MySQL.Async.fetchAll(
'SELECT * FROM owned_vehicles WHERE plate = @plate',
{
['@plate'] = plate
},
function(result)
if result[1] ~= nil then
local playerName = ESX.GetPlayerFromIdentifier(result[1].owner).identifier
local pName = ESX.GetPlayerFromIdentifier(result[1].owner).name
CarOwner = playerName
print("Car Transfer ", myID, CarOwner)
if myID == CarOwner then
print("Transfered")
data = {}
TriggerClientEvent('chatMessage', other, "^4Vehicle with the plate ^*^1" .. plate .. "^r^4was transfered to you by: ^*^2" .. myName)
MySQL.Sync.execute("UPDATE owned_vehicles SET owner=@owner WHERE plate=@plate", {['@owner'] = targetSteam, ['@plate'] = plate})
TriggerClientEvent('chatMessage', source, "^4You have ^*^3transfered^0^4 your vehicle with the plate ^*^1" .. plate .. "\" ^r^4to ^*^2".. targetSteamName)
else
print("Did not transfer")
TriggerClientEvent('chatMessage', source, "^*^1You do not own the vehicle")
end
else
TriggerClientEvent('chatMessage', source, "^1^*ERROR: ^r^0This vehicle plate does not exist or the plate was incorrectly written.")
end
end
)
end)
Some screenshots
Hope you enjoy