Anchoring a boat

I’m trying to write a script that anchors a boat, now there’s a native called SET_BOAT_ANCHOR which I’ve tried and it doesn’t work at all, does anyone know why this is or an alternative method?

Freeze it? Perhaps? Not sure if there’s a FreezeEntity native though.

The anchor native indeed does work. Can you show how you have used it

What exactly do you expect when anchoring a boat. What behaviour do you want?

@oxygen I want the boat to sit still in the water as it just drifts away when you get out, it’s annoying when you go diving then come back up to find your boat gone.

@MrDaGree

RegisterNetEvent( 'boatAnchor' )

AddEventHandler( 'boatAnchor', function()
	local ped = GetPlayerPed( -1 )

	if ( DoesEntityExist( ped ) and not IsEntityDead( ped ) ) then 
		if ( IsPedSittingInAnyVehicle( ped ) ) then 
			local vehicle = GetVehiclePedIsIn( ped, false )

			if ( GetVehicleClass( vehicle ) == 14 ) then 
				if ( GetPedInVehicleSeat( vehicle, -1 ) == ped ) then 
					local anchored = GetBoatAnchor( vehicle )
					log( "Boat anchored?: " .. tostring( anchored ) )
					SetBoatAnchor( vehicle, true )
					ShowNotification( "Boat anchored!" )
				end 
			else
				ShowNotification( "The vehicle you're in isn't a boat." )
			end 
		else 
			ShowNotification( "You must be in a boat." )
		end 
	end 
end )

function ShowNotification( text )
    SetNotificationTextEntry( "STRING" )
    AddTextComponentSubstringPlayerName( text )
    DrawNotification( false, false )
end

function log( msg )
    Citizen.Trace( "\n[DEBUG]: " .. msg )
end 

When I get home I will see if I can make you something quick. That looks like it should work but idk…

1 Like

Was this ever something that got made? I’d love it

Has anyone made it until now?

Did this get made? I would like this too.

I’ve been poking at these natives, and I think I have figured something out.

https://runtime.fivem.net/doc/reference.html#_0x75DBEC174AEEAD10
SET_BOAT_ANCHOR(vehicle,boolean)
It seems that while the engine of vehicle is running, nothing happens.
However, if the engine is turned off, and boolean is true, vehicle doesn’t move with the waves the same way, and it’s position changes very little for a while, but then goes back to normal. Tried looping it, but as it seems to move slightly even in the anchored state it is hard to know if it moves around a specific point which gets reset again and again when looping, negating the whole thing.
It might also be that the “anchoring” I’m seeing is pure placebo, and that I’m doing it wrong.

https://runtime.fivem.net/doc/reference.html#_0x26C10ECBDA5D043B
_GET_BOAT_ANCHOR(vehicle) – Seems to always return true if the vehicle has an anchor, or at least it returns true when vehicle is a Tropic, and false when it’s a Glendale.
I haven’t searched for any matching hashes yet, but perhaps this is really named something like DOES_VEHICLE_HAVE_ANCHOR?

Did any of ya’ll ever figure this out? I’d love this feature. Boats floating away sucks!

2 Likes