Add vehicle
ในตัวอย่างนี้จะใช้ esx_vehicleshop และ esx_policejob เป็นตัวอย่าง
esx_vehicleshop
ในทุก Event ของการซื้อรถจากร้านขายรถ จะต้องเพิ่มการ Trigger พิเศษเพื่อให้ ZOBYETEAM_GARAGE รับรู้ว่ามีการเพิ่มรถใหม่ ดังตัวอย่าง บรรทัดที่ 16
ESX.RegisterServerCallback('esx_vehicleshop:buyVehicle', function(source, cb, model, plate)
local xPlayer = ESX.GetPlayerFromId(source)
local modelPrice = getVehicleFromModel(model).price
if modelPrice and xPlayer.getMoney() >= modelPrice then
xPlayer.removeMoney(modelPrice, "Vehicle Purchase")
MySQL.insert('INSERT INTO owned_vehicles (owner, plate, vehicle) VALUES (?, ?, ?)', {xPlayer.identifier, plate, json.encode({model = joaat(model), plate = plate})
}, function(rowsChanged)
xPlayer.showNotification(TranslateCap('vehicle_belongs', plate))
ESX.OneSync.SpawnVehicle(joaat(model), Config.Zones.ShopOutside.Pos, Config.Zones.ShopOutside.Heading,{plate = plate}, function(vehicle)
Wait(100)
local vehicle = NetworkGetEntityFromNetworkId(vehicle)
Wait(300)
TaskWarpPedIntoVehicle(GetPlayerPed(source), vehicle, -1)
exports['zobyeteam_garage']:addVehicle(source, xPlayer.identifier, plate, {model = model, plate = plate})
end)
cb(true)
end)
else
cb(false)
end
end)สำหรับ Event ของการซื้อรถ สามารถเรียกใช้ได้ทั้งหมด 3 วิธี โดยมีค่าที่จำเป็นต้องใส่อยู่ 4 ค่า ได้แก่
playerId(ถ้า Trigger จาก Client ใส่เป็น nil ได้), identifier, plate และ props ส่วนอีก 3 ค่า ได้แก่ vehicleType, job และ stored ใส่หรือไม่ก็ได้
ดังโค้ดตัวอย่าง:
playerId (Trigger From Client Can Use nil)
identifier
plate
props
vehicleType(optional)
job (optional)
stored (optional)
และตัวอย่างสำหรับ esx_policejob
Last updated
Was this helpful?