Help notification when enter Boat

Hi, this is my first try to make a script on my own, Im trying to make a script that tells you a notification when you enter a BOAT class vehicle, saying “Press ‘.’ to drop anchor”

But it loops and i cant figure it out how to make it not loop xD

Citizen.CreateThread(function()
    while true do
           Citizen.Wait(0)
           local playerPed = GetPlayerPed(-1)
           local vehicle = GetVehiclePedIsIn(playerPed, false)
           local vehicleClass = GetVehicleClass(vehicle)
  
           if vehicleClass == 14 then -- class #14 boats
            --ESX.ShowNotification("~b~Bajate y presiona ~o~[ . ] ~b~ para ~y~ANCLAR~b~ el bote...")
			
			exports.notif:SendNotification({
				text = "~b~Bajate y presiona ~o~[ . ] ~b~ para ~y~ANCLAR~b~ el bote...",
				type = 'bottomLeft',
				timeout = 5000,
			}) 
           end
    end
end)

Thanks in advance!

Hey :slight_smile:
I’m not sure it’s the most efficient way to do that, but I don’t have any alternative that comes to mind right now (I checked ESX and the gameEvents to see if an event of the sort existed but apparently not).
I made the change you were looking for though :

Citizen.CreateThread(function()
    while true do
	
           Citizen.Wait(0)
           
		   local playerPed = PlayerPedId()
           local vehicle = GetVehiclePedIsEntering(playerPed)
		   
		   if(vehicle ~= nil and vehicle > 0) then
		   
			   local vehicleClass = GetVehicleClass(vehicle)
	  
			   if vehicleClass == 14 then -- class #14 boats
					exports.notif:SendNotification({
						text = "~b~Bajate y presiona ~o~[ . ] ~b~ para ~y~ANCLAR~b~ el bote...",
						type = 'bottomLeft',
						timeout = 5000,
					}) 
                    Citizen.Wait(2500)
			   end
			   
			end
		   
    end
end)

Should do the trick for now (check’s only when the player enters the vehicle, so it won’t loop the notification when he’s inside).

1 Like

Hey!
There is a game event that gets fired when a player enters a vehicle. Here is an example of how you could use it:

local function DisplayAnchorHelpText()
    local playerPed = PlayerPedId()
    local vehicle = GetVehiclePedIsIn(playerPed, false)
    if vehicle ~= nil and vehicle ~= 0 then
        local vehicleClass = GetVehicleClass(vehicle)
        if vehicleClass == 14 then -- class #14 boats
            exports.notif:SendNotification({
                text = "~b~Bajate y presiona ~o~[ . ] ~b~ para ~y~ANCLAR~b~ el bote...",
                type = 'bottomLeft',
                timeout = 5000,
            })
        end
    end
end

AddEventHandler('gameEventTriggered', function(event, args)
    if event == "CEventNetworkPlayerEnteredVehicle" then
        if args[1] == PlayerId() then
            DisplayAnchorHelpText()
        end
    end
end)
1 Like

:hushed: I did not see it when I was looking through the list of game events, nice :slight_smile:

1 Like

Thank you guys for your help!, I have it working like a charm!. Also i’ve added one for each class to say “press M to fasten your seatbelt” (excluding bikes, planes, helis, etc). Its kind of rought and repetitive, Sure you can do better. but hey, it works! xD. Thank you again!!!


--- Boat anchor msg
local function DisplayAnchorHelpText()
    local playerPed = PlayerPedId()
    local vehicle = GetVehiclePedIsIn(playerPed, false)
    if vehicle ~= nil and vehicle ~= 0 then
        local vehicleClass = GetVehicleClass(vehicle)
        if vehicleClass == 14 then -- class #14 boats
            exports.notif:SendNotification({
                text = "~o~Presiona ~y~[ . ] ~o~ para ~y~ANCLAR~o~ el bote...",
                type = 'centerRight',
                timeout = 15000,
            })
        end
    end
end

-- Cars seatbelt msg
local function DisplaySeatbeltHelpText0()
    local playerPed = PlayerPedId()
    local vehicle = GetVehiclePedIsIn(playerPed, false)
    if vehicle ~= nil and vehicle ~= 0 then
        local vehicleClass = GetVehicleClass(vehicle)
        if vehicleClass == 0 then -- compacts 
            exports.notif:SendNotification({
                text = "~o~Presiona ~y~[ M ]~o~ para ponerte el cinturón",
                type = 'centerRight',
                timeout = 5000,
            })
        end
    end
end

local function DisplaySeatbeltHelpText1()
    local playerPed = PlayerPedId()
    local vehicle = GetVehiclePedIsIn(playerPed, false)
    if vehicle ~= nil and vehicle ~= 0 then
        local vehicleClass = GetVehicleClass(vehicle)
        if vehicleClass == 1 then -- sedans 
            exports.notif:SendNotification({
                text = "~o~Presiona ~y~[ M ]~o~ para ponerte el cinturón",
                type = 'centerRight',
                timeout = 5000,
            })
        end
    end
end


local function DisplaySeatbeltHelpText2()
    local playerPed = PlayerPedId()
    local vehicle = GetVehiclePedIsIn(playerPed, false)
    if vehicle ~= nil and vehicle ~= 0 then
        local vehicleClass = GetVehicleClass(vehicle)
        if vehicleClass == 2 then -- SUVs 
            exports.notif:SendNotification({
                text = "~o~Presiona ~y~[ M ]~o~ para ponerte el cinturón",
                type = 'centerRight',
                timeout = 5000,
            })
        end
    end
end

local function DisplaySeatbeltHelpText3()
    local playerPed = PlayerPedId()
    local vehicle = GetVehiclePedIsIn(playerPed, false)
    if vehicle ~= nil and vehicle ~= 0 then
        local vehicleClass = GetVehicleClass(vehicle)
        if vehicleClass == 3 then -- Coupes 
            exports.notif:SendNotification({
                text = "~o~Presiona ~y~[ M ]~o~ para ponerte el cinturón",
                type = 'centerRight',
                timeout = 5000,
            })
        end
    end
end

local function DisplaySeatbeltHelpText4()
    local playerPed = PlayerPedId()
    local vehicle = GetVehiclePedIsIn(playerPed, false)
    if vehicle ~= nil and vehicle ~= 0 then
        local vehicleClass = GetVehicleClass(vehicle)
        if vehicleClass == 4 then -- Muscle 
            exports.notif:SendNotification({
                text = "~o~Presiona ~y~[ M ]~o~ para ponerte el cinturón",
                type = 'centerRight',
                timeout = 5000,
            })
        end
    end
end

local function DisplaySeatbeltHelpText5()
    local playerPed = PlayerPedId()
    local vehicle = GetVehiclePedIsIn(playerPed, false)
    if vehicle ~= nil and vehicle ~= 0 then
        local vehicleClass = GetVehicleClass(vehicle)
        if vehicleClass == 5 then -- Sports Classics 
            exports.notif:SendNotification({
                text = "~o~Presiona ~y~[ M ]~o~ para ponerte el cinturón",
                type = 'centerRight',
                timeout = 5000,
            })
        end
    end
end

local function DisplaySeatbeltHelpText6()
    local playerPed = PlayerPedId()
    local vehicle = GetVehiclePedIsIn(playerPed, false)
    if vehicle ~= nil and vehicle ~= 0 then
        local vehicleClass = GetVehicleClass(vehicle)
        if vehicleClass == 6 then -- Sports 
            exports.notif:SendNotification({
                text = "~o~Presiona ~y~[ M ]~o~ para ponerte el cinturón",
                type = 'centerRight',
                timeout = 5000,
            })
        end
    end
end

local function DisplaySeatbeltHelpText7()
    local playerPed = PlayerPedId()
    local vehicle = GetVehiclePedIsIn(playerPed, false)
    if vehicle ~= nil and vehicle ~= 0 then
        local vehicleClass = GetVehicleClass(vehicle)
        if vehicleClass == 7 then -- Super 
            exports.notif:SendNotification({
                text = "~o~Presiona ~y~[ M ]~o~ para ponerte el cinturón",
                type = 'centerRight',
                timeout = 5000,
            })
        end
    end
end

local function DisplaySeatbeltHelpText9()
    local playerPed = PlayerPedId()
    local vehicle = GetVehiclePedIsIn(playerPed, false)
    if vehicle ~= nil and vehicle ~= 0 then
        local vehicleClass = GetVehicleClass(vehicle)
        if vehicleClass == 9 then -- offroad 
            exports.notif:SendNotification({
                text = "~o~Presiona ~y~[ M ]~o~ para ponerte el cinturón",
                type = 'centerRight',
                timeout = 5000,
            })
        end
    end
end

local function DisplaySeatbeltHelpText10()
    local playerPed = PlayerPedId()
    local vehicle = GetVehiclePedIsIn(playerPed, false)
    if vehicle ~= nil and vehicle ~= 0 then
        local vehicleClass = GetVehicleClass(vehicle)
        if vehicleClass == 10 then -- Industrial
            exports.notif:SendNotification({
                text = "~o~Presiona ~y~[ M ]~o~ para ponerte el cinturón",
                type = 'centerRight',
                timeout = 5000,
            })
        end
    end
end

local function DisplaySeatbeltHelpText11()
    local playerPed = PlayerPedId()
    local vehicle = GetVehiclePedIsIn(playerPed, false)
    if vehicle ~= nil and vehicle ~= 0 then
        local vehicleClass = GetVehicleClass(vehicle)
        if vehicleClass == 11 then -- Utility 
            exports.notif:SendNotification({
                text = "~o~Presiona ~y~[ M ]~o~ para ponerte el cinturón",
                type = 'centerRight',
                timeout = 5000,
            })
        end
    end
end

local function DisplaySeatbeltHelpText12()
    local playerPed = PlayerPedId()
    local vehicle = GetVehiclePedIsIn(playerPed, false)
    if vehicle ~= nil and vehicle ~= 0 then
        local vehicleClass = GetVehicleClass(vehicle)
        if vehicleClass == 12 then -- Vans 
            exports.notif:SendNotification({
                text = "~o~Presiona ~y~[ M ]~o~ para ponerte el cinturón",
                type = 'centerRight',
                timeout = 5000,
            })
        end
    end
end



local function DisplaySeatbeltHelpText17()
    local playerPed = PlayerPedId()
    local vehicle = GetVehiclePedIsIn(playerPed, false)
    if vehicle ~= nil and vehicle ~= 0 then
        local vehicleClass = GetVehicleClass(vehicle)
        if vehicleClass == 17 then -- Service 
            exports.notif:SendNotification({
                text = "~o~Presiona ~y~[ M ]~o~ para ponerte el cinturón",
                type = 'centerRight',
                timeout = 5000,
            })
        end
    end
end

local function DisplaySeatbeltHelpText18()
    local playerPed = PlayerPedId()
    local vehicle = GetVehiclePedIsIn(playerPed, false)
    if vehicle ~= nil and vehicle ~= 0 then
        local vehicleClass = GetVehicleClass(vehicle)
        if vehicleClass == 18 then -- Emergency 
            exports.notif:SendNotification({
                text = "~o~Presiona ~y~[ M ]~o~ para ponerte el cinturón",
                type = 'centerRight',
                timeout = 5000,
            })
        end
    end
end

local function DisplaySeatbeltHelpText19()
    local playerPed = PlayerPedId()
    local vehicle = GetVehiclePedIsIn(playerPed, false)
    if vehicle ~= nil and vehicle ~= 0 then
        local vehicleClass = GetVehicleClass(vehicle)
        if vehicleClass == 19 then -- Militar 
            exports.notif:SendNotification({
                text = "~o~Presiona ~y~[ M ]~o~ para ponerte el cinturón",
                type = 'centerRight',
                timeout = 5000,
            })
        end
    end
end

local function DisplaySeatbeltHelpText20()
    local playerPed = PlayerPedId()
    local vehicle = GetVehiclePedIsIn(playerPed, false)
    if vehicle ~= nil and vehicle ~= 0 then
        local vehicleClass = GetVehicleClass(vehicle)
        if vehicleClass == 20 then -- Comercial
            exports.notif:SendNotification({
                text = "~o~Presiona ~y~[ M ]~o~ para ponerte el cinturón",
                type = 'centerRight',
                timeout = 5000,
            })
        end
    end
end




-------------------------------------

AddEventHandler('gameEventTriggered', function(event, args)
    if event == "CEventNetworkPlayerEnteredVehicle" then
        if args[1] == PlayerId() then
            DisplayAnchorHelpText()
        end
    end
end)


AddEventHandler('gameEventTriggered', function(event, args)
    if event == "CEventNetworkPlayerEnteredVehicle" then
        if args[1] == PlayerId() then
            DisplaySeatbeltHelpText0()
        end
    end
end)

AddEventHandler('gameEventTriggered', function(event, args)
    if event == "CEventNetworkPlayerEnteredVehicle" then
        if args[1] == PlayerId() then
            DisplaySeatbeltHelpText1()
        end
    end
end)

AddEventHandler('gameEventTriggered', function(event, args)
    if event == "CEventNetworkPlayerEnteredVehicle" then
        if args[1] == PlayerId() then
            DisplaySeatbeltHelpText2()
        end
    end
end)

AddEventHandler('gameEventTriggered', function(event, args)
    if event == "CEventNetworkPlayerEnteredVehicle" then
        if args[1] == PlayerId() then
            DisplaySeatbeltHelpText3()
        end
    end
end)

AddEventHandler('gameEventTriggered', function(event, args)
    if event == "CEventNetworkPlayerEnteredVehicle" then
        if args[1] == PlayerId() then
            DisplaySeatbeltHelpText4()
        end
    end
end)

AddEventHandler('gameEventTriggered', function(event, args)
    if event == "CEventNetworkPlayerEnteredVehicle" then
        if args[1] == PlayerId() then
            DisplaySeatbeltHelpText5()
        end
    end
end)

AddEventHandler('gameEventTriggered', function(event, args)
    if event == "CEventNetworkPlayerEnteredVehicle" then
        if args[1] == PlayerId() then
            DisplaySeatbeltHelpText6()
        end
    end
end)

AddEventHandler('gameEventTriggered', function(event, args)
    if event == "CEventNetworkPlayerEnteredVehicle" then
        if args[1] == PlayerId() then
            DisplaySeatbeltHelpText7()
        end
    end
end)

AddEventHandler('gameEventTriggered', function(event, args)
    if event == "CEventNetworkPlayerEnteredVehicle" then
        if args[1] == PlayerId() then
            DisplaySeatbeltHelpText9()
        end
    end
end)

AddEventHandler('gameEventTriggered', function(event, args)
    if event == "CEventNetworkPlayerEnteredVehicle" then
        if args[1] == PlayerId() then
            DisplaySeatbeltHelpText10()
        end
    end
end)

AddEventHandler('gameEventTriggered', function(event, args)
    if event == "CEventNetworkPlayerEnteredVehicle" then
        if args[1] == PlayerId() then
            DisplaySeatbeltHelpText11()
        end
    end
end)

AddEventHandler('gameEventTriggered', function(event, args)
    if event == "CEventNetworkPlayerEnteredVehicle" then
        if args[1] == PlayerId() then
            DisplaySeatbeltHelpText12()
        end
    end
end)

AddEventHandler('gameEventTriggered', function(event, args)
    if event == "CEventNetworkPlayerEnteredVehicle" then
        if args[1] == PlayerId() then
            DisplaySeatbeltHelpText17()
        end
    end
end)

AddEventHandler('gameEventTriggered', function(event, args)
    if event == "CEventNetworkPlayerEnteredVehicle" then
        if args[1] == PlayerId() then
            DisplaySeatbeltHelpText18()
        end
    end
end)

AddEventHandler('gameEventTriggered', function(event, args)
    if event == "CEventNetworkPlayerEnteredVehicle" then
        if args[1] == PlayerId() then
            DisplaySeatbeltHelpText19()
        end
    end
end)

AddEventHandler('gameEventTriggered', function(event, args)
    if event == "CEventNetworkPlayerEnteredVehicle" then
        if args[1] == PlayerId() then
            DisplaySeatbeltHelpText20()
        end
    end
end)

You could tweek the code to implement only one function to which you’ll pass the ‘vehicleClass’ as an argument, like that :

AddEventHandler('gameEventTriggered', function(event, args)
    if event == "CEventNetworkPlayerEnteredVehicle" then
        if args[1] == PlayerId() then
		
		    local playerPed = PlayerPedId()
			local vehicle = GetVehiclePedIsIn(playerPed, false)
			local vehicleClass = GetVehicleClass(vehicle)
			if vehicle ~= nil and vehicle ~= 0 then
				DisplayVehicleHelpText(vehicleClass)
			end
			
        end
    end
end)

local function DisplayVehicleHelpText(vehicleClass)

        if (vehicleClass == 14) then --If the Vehicle is a boat (display anchor message)
            exports.notif:SendNotification({
                text = "~b~Bajate y presiona ~o~[ . ] ~b~ para ~y~ANCLAR~b~ el bote...",
                type = 'bottomLeft',
                timeout = 5000,
            })
        elseif (vehicleClass == 13 or vehicleClass == 14 or vehicleClass == 15 or vehicleClass == 16 or vehicleClass == 21) then
			--Else if the vehicle is cycle, plane, helicopter etc.. (display nothing)
			return
		else --Else is the vehicle is a car from the known categories (display belt message)
			exports.notif:SendNotification({
                text = "~o~Presiona ~y~[ M ]~o~ para ponerte el cinturón",
                type = 'centerRight',
                timeout = 5000,
            })
		end
		
end
1 Like

Awesome!! I couldn’t figure out how to represent the ones i was going to exclude!, thank you for opening my eyes!

As you can see, im not a regular programmer,just playing with lua and learning :D.

Again, thank you. If you dont have any problems, can I upload it as a Release? since there’s no other script and it might be useful for other implementations. Thank you!

No prob :wink:
Yeah sure you can upload it if you want (I don’t think MadsL won’t have an issue with you uploading it either) :slight_smile: