Skip to content

Timeout checking for returning the gasnozzle #66

@Eightu

Description

@Eightu

I found an interesting issue where when the player finished filling up the gasnozzle and forgot to return it, the gasnozzle would remain in the character's hand.
Add timeout checking and error handling where appropriate. For example, check if the gasnozzle has been returned when the refueling is completed or canceled, delete it if it is not, and display the appropriate notification to the player.

ps-fuel/client/client.lua

RegisterNetEvent('ps-fuel:client:takenozzle', function ()
	if hasNozzle then return end
	local ped = PlayerPedId()
	local nozzleProp = "prop_cs_fuel_nozle"
	RequestAnimDict("anim@am_hold_up@male")
	while not HasAnimDictLoaded('anim@am_hold_up@male') do
		Wait(100)
	end
	TaskPlayAnim(ped, "anim@am_hold_up@male", "shoplift_high", 2.0, 8.0, 1000, 50, 0, 0, 0, 0)
	TriggerServerEvent("InteractSound_SV:PlayWithinDistance", 5, "pickupnozzle", 0.6)
	QBCore.Functions.LoadModel(nozzleProp)
	gasNozzle = CreateObject(nozzleProp, 1.0, 1.0, 1.0, 1, 1, 0)
	if DoesEntityExist(gasNozzle) then
		hasNozzle = true
		AttachEntityToEntity(gasNozzle, ped, GetPedBoneIndex(ped, 18905), 0.13, 0.04, 0.01, -42.0, -115.0, -63.42, 0, 1, 0, 1, 0, 1)
		-- Set the timeout check for the gasnozzle
		Citizen.CreateThread(function()
			Wait(120000) -- Set the timeout period, which can be adjusted according to actual needs
			if hasNozzle then
				DeleteObject(gasNozzle)
				gasNozzle = nil
				hasNozzle = false
				QBCore.Functions.Notify("You forgot to return the gas nozzle!", "error")
			end
		end)
	end
end)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions