[HELP] trying to check if player near boat, and if player on water

I am trying to make it so that it’s always checking if a player is near a boat / water then do something but I don’t get anything on the game once I load it up I have the globals on top of the script this is just the thread I am trying to test

Citizen.CreateThread(function()
    while true do
    local locFishing = posFishing
    posFishing = GetEntityCoords(LocalPed())
	local boat = GetClosestVehicle(posFishing[1], posFishing[2], posFishing[3], 10.000, 0, 12294)
	SetEntityAsMissionEntity(boat, true, true)

        if DoesEntityExist(boat) then
	    drawNotificationBoat("boat Exists")
        while true do
        Wait(0)
            if IsEntityInWater(LocalPed())
            drawTxtBoat('~g~E~s~ to begin fishing',0,1,0.5,0.8,0.6,255,255,255,255)
                if IsControlJustPressed(1, 86) then
				--TriggerServerEvent("fishing:StartFishing")
				drawNotificationBoat("You are now fishing")
                end
            end
        end
	end
end)

I am unsure that GetClosestVehicle() returns boats, where did you find the flag 12294?. Getting entities in the world has proven to be difficult with only natives. I solve this problem with 3D functions like below.

local function GetEntityBelow()
    local Ent = nil
    local CoA = GetEntityCoords(LocalPed(), 1)
    local CoB = GetOffsetFromEntityInWorldCoords(LocalPed(), 0.0, 0.0, 5.0)
    local RayHandle = CastRayPointToPoint(CoA.x, CoA.y, CoA.z, CoB.x, CoB.y, CoB.z, 10, LocalPed(), 0)
    local A,B,C,D,Ent = GetRaycastResult(RayHandle)
    return Ent
end

while true do
  Wait(0)
  local boat = GetEntityModel(GetEntityBelow())
  if DoesEntityExist(boat) then
    IsThisModelABoat(boat) and IsEntityInWater(boat) then
    --- Player is on top of a boat that is in water
    end
  end

end

Would just being near a boat suffice? Is “in water” check necessary?

I don’t think IsEntityInWater(LocalPed()) will return true unless you are swimming (in the water).

The reason I want to check if the boat is on water is to avoid people taking a boat far into the shore away from the water then still being able to use the boat for fishing :slight_smile:

12294 is the number of times it took me to find the right one for being able to store / sell vehicles from “docks” xD

70 is used for most scripters since it only takes cars and motorcycles, but for me that is useless since you can’t have those in the water :slight_smile:

If you want to see what I done so far you’re more than welcome to (modifications of vehshop, vehshop_s, es_garages) They work perfectly with the original scripts they don’t interact with each other at all. I am now working on the fishing side

1 Like

Cool progress so far! Are you trying to make fishing “zones” or be able to fish anywhere in the open water?

Citizen.CreateThread(function()
    while true do
    local locFishing = posFishing --Where is locFishing being used?
    posFishing = GetEntityCoords(LocalPed())
	local boat = GetClosestVehicle(posFishing[1], posFishing[2], posFishing[3], 10.000, 0, 12294)
	--SetEntityAsMissionEntity(boat, true, true) Set as mission entity AFTER you check if it exists

        if DoesEntityExist(boat) then
        SetEntityAsMissionEntity(boat, true, true)
	    drawNotificationBoat("boat Exists")
        --while true do / a while followed by an if can be shortened to below
        while IsEntityInWater(boat) then -- changed to check if the boat is in the water
        Wait(0)
           -- if IsEntityInWater(LocalPed()) -- Does this return true when a ped is ON a boat?
            drawTxtBoat('~g~E~s~ to begin fishing',0,1,0.5,0.8,0.6,255,255,255,255)
                if IsControlJustPressed(1, 86) then
				--TriggerServerEvent("fishing:StartFishing")
				drawNotificationBoat("You are now fishing")
                end
            end
        end
	end
end)

I am trying to get it so if player is near water then the option to fish opens up, but no matter what I do I can’t get it working =/

Where did you find IsThisModelABoat()? Does this even work?

Have you read through my code?

NativeDB. It is also referenced in fivem natives.lua.

Hey buddy :stuck_out_tongue: yeah I got it working now thanks :smiley: I am just playing around with all the natives I find useful haha :stuck_out_tongue:

Hello, is there a way you can share what you did?