Script, witch displays a notification when you sit in car

Hello, I can’t figure out how to fix this issue, I have written a script, but it has one small issue…

Citizen.CreateThread(function()
    while true do
        local sleep = 1000
        local ped = PlayerPedId()
        local vehicle = GetVehiclePedIsIn(ped)

        if IsPedInVehicle(ped, vehicle, true) then
            exports['okokNotify']:Alert("", "Norint prisisegti saugos diržą, spausk [K]!", 5000, 'info')
        end
        Citizen.Wait(sleep)
    end
 end)

This is client sided script

And it spams the notification every 1000ms, but I need it to only send it once per get in vechile…

It looks like this:
Screenshot 2022-01-27 204323

Hello, haven’t tested it, but this should do the trick :slight_smile:

Citizen.CreateThread(function()
    local inVehicle = false
    while true do
        local sleep = 1000
        local ped = PlayerPedId()
        local vehicle = GetVehiclePedIsIn(ped)

        if not inVehicle and IsPedInVehicle(ped, vehicle, true) then
            inVehicle = true
            exports['okokNotify']:Alert("", "Norint prisisegti saugos diržą, spausk [K]!", 5000, 'info')
        elseif inVehicle then
            inVehicle = false
        end
        Citizen.Wait(sleep)
    end
 end)
1 Like

It is doing the same thing, but it is slower…

Here you go.

Citizen.CreateThread(function()
	local wasInVehicle = false
	while true do
		local inVehicle = IsPedInAnyVehicle(PlayerPedId(), false)
		if inVehicle and not wasInVehicle then
			wasInVehicle = true -- Entered vehicle
			exports['okokNotify']:Alert("", "Norint prisisegti saugos diržą, spausk [K]!", 5000, 'info')
		elseif wasInVehicle and not inVehicle then
			wasInVehicle = false -- Left vehicle
		end
		Citizen.Wait(1000)
	end
end)

I helped someone with this in another post here → Native related too cars - #2 by DrAceMisanthrope
But the code above I tweaked to serve your needs. If it works for you, please mark this response as a solution so that others can benefit from it too. Thanks!

3 Likes

My bad, forgot to do a check in the elseif. The answer from @DrAceMisanthrope should be working flawlessly :slight_smile:

Thank you all for helping me :blush:
Have a wonderful day!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.