create a qbcore caddy rental script using the E key with a marker and caddy spawn at…
- User
create a qbcore caddy rental script using the E key with a marker and caddy spawn at coordinates (x = -1344.56, y = 128.02, z = 56.24)
- Assistant
Sure, here's a script you can use for the QBcore framework in FiveM to create a caddy rental system:
local rentedCaddies = {} RegisterServerEvent('caddyRental:rentCaddy') AddEventHandler('caddyRental:rentCaddy', function() local src = source local player = QBCore.Functions.GetPlayer(src) if not rentedCaddies[player.PlayerData.citizenid] then local caddyHash = GetHashKey('caddy') local caddyModel = IsModelValid(caddyHash) and caddyHash or 1147287684 RequestModel(caddyModel) while not HasModelLoaded(caddyModel) do Citizen.Wait(10) end local caddy = CreateVehicle(caddyModel, -1344.56, 128.02, 56.24, 0.0, true, false) rentedCaddies[player.PlayerData.citizenid] = caddy -- Set the driver and lock the vehicle to the player SetVehicleHasBeenOwnedByPlayer(caddy, true) SetEntityAsMissionEntity(caddy, true, true) TaskWarpPedIntoVehicle(player.PlayerPed, caddy, -1) SetVehicleEngineOn(caddy, true, true, true) SetVehicleDoorsLocked(caddy, 2) -- Add a blip to the caddy local blip = AddBlipForEntity(caddy) SetBlipSprite(blip, 226) SetBlipColour(blip, 5) SetBlipScale(blip, 0.7) BeginTextCommandSetBlipName("STRING") AddTextComponentString("Rental Caddy") EndTextCommandSetBlipName(blip) TriggerClientEvent('mythic_notify:client:SendAlert', src, { type = 'inform', text = 'You rented a caddy.', length = 5000 }) else TriggerClientEvent('mythic_notify:client:SendAlert', src, { type = 'error', text = 'You already rented a caddy.', length = 5000 }) end end) RegisterServerEvent('caddyRental:returnCaddy') AddEventHandler('caddyRental:returnCaddy', function() local src = source local player = QBCore.Functions.GetPlayer(src) if rentedCaddies[player.PlayerData.citizenid] then local caddy = rentedCaddies[player.PlayerData.citizenid] DeleteEntity(caddy) rentedCaddies[player.PlayerData.citizenid] = nil TriggerClientEvent('mythic_notify:client:SendAlert', src, { type = 'inform', text = 'You returned the caddy.', length = 5000 }) else TriggerClientEvent('mythic_notify:client:SendAlert', src, { type = 'error', text = 'You haven\'t rented a caddy yet.', length = 5000 }) end end)Make sure to have a notification system like
mythic_notifyinstalled to display messages to the players. Also, you need to trigger thecaddyRental:rentCaddyevent when the player presses the E key on the marker you mentioned. And trigger thecaddyRental:returnCaddyevent when they want to return the caddy.Hope this helps! Let me know if you have any further questions.
- User
convert to qbcore Citizen.CreateThread(function() marker = CreateMarker(markerData) end)
- Assistant
Certainly! Here's the modified version of the script using the
Citizen.CreateThreadfunction from QBcore:Citizen.CreateThread(function() local rentedCaddies = {} RegisterServerEvent('caddyRental:rentCaddy') AddEventHandler('caddyRental:rentCaddy', function() local src = source local player = QBCore.Functions.GetPlayer(src) if not rentedCaddies[player.PlayerData.citizenid] then local caddyHash = GetHashKey('caddy') local caddyModel = IsModelValid(caddyHash) and caddyHash or 1147287684 RequestModel(caddyModel) while not HasModelLoaded(caddyModel) do Citizen.Wait(10) end local caddy = CreateVehicle(caddyModel, -1344.56, 128.02, 56.24, 0.0, true, false) rentedCaddies[player.PlayerData.citizenid] = caddy -- Set the driver and lock the vehicle to the player SetVehicleHasBeenOwnedByPlayer(caddy, true) SetEntityAsMissionEntity(caddy, true, true) TaskWarpPedIntoVehicle(player.PlayerPed, caddy, -1) SetVehicleEngineOn(caddy, true, true, true) SetVehicleDoorsLocked(caddy, 2) -- Add a blip to the caddy local blip = AddBlipForEntity(caddy) SetBlipSprite(blip, 226) SetBlipColour(blip, 5) SetBlipScale(blip, 0.7) BeginTextCommandSetBlipName("STRING") AddTextComponentString("Rental Caddy") EndTextCommandSetBlipName(blip) TriggerClientEvent('mythic_notify:client:SendAlert', src, { type = 'inform', text = 'You rented a caddy.', length = 5000 }) else TriggerClientEvent('mythic_notify:client:SendAlert', src, { type = 'error', text = 'You already rented a caddy.', length = 5000 }) end end) RegisterServerEvent('caddyRental:returnCaddy') AddEventHandler('caddyRental:returnCaddy', function() local src = source local player = QBCore.Functions.GetPlayer(src) if rentedCaddies[player.PlayerData.citizenid] then local caddy = rentedCaddies[player.PlayerData.citizenid] DeleteEntity(caddy) rentedCaddies[player.PlayerData.citizenid] = nil TriggerClientEvent('mythic_notify:client:SendAlert', src, { type = 'inform', text = 'You returned the caddy.', length = 5000 }) else TriggerClientEvent('mythic_notify:client:SendAlert', src, { type = 'error', text = 'You haven\'t rented a caddy yet.', length = 5000 }) end end) end)Please note that you still need to trigger the
caddyRental:rentCaddyevent when the player interacts with the marker, and thecaddyRental:returnCaddyevent when they want to return the caddy.Let me know if you have any further questions!
- User
fix QBCore.Functions.CreateUseableItem("caddy_rental", function(source) local Player = QBCore.Functions.GetPlayer(source) local price = 100 -- Adjust the price as needed
if Player.Functions.RemoveMoney("cash", price) then TriggerClientEvent('caddy_rental:spawnCaddy', source) else TriggerClientEvent('QBCore:Notify', source, 'You don\'t have enough money to rent a caddy.', 'error') endend)
- Assistant
Here's the fixed code for creating a useable item "caddy_rental" with QBcore:
QBCore.Functions.CreateUseableItem("caddy_rental", function(source) local player = QBCore.Functions.GetPlayer(source) local price = 100 -- Adjust the price as needed if player.PlayerData.money["cash"] >= price then player.Functions.RemoveMoney("cash", price) TriggerClientEvent('caddyRental:rentCaddy', source) else TriggerClientEvent('QBCore:Notify', source, 'You don\'t have enough money to rent a caddy.', 'error') end end)Make sure to replace all instances of
caddy_rentalwith the appropriate item name. Also, ensure that you have theQBCore:Notifyevent implemented on the client-side to display the notification messages.Let me know if you need further assistance!
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.