IsPlayerNearWater not working as it should
#1

Hi

I have put this isplayernearwater function for my fishing system
But i dont Think it checks if the player is near the water, only the Z coordinate
Because i Can /fish everywhere i just have to be inder Z 15, i Can even fish at lspd

I Really hope that anybody Can help me😊

pawn Код:
if (strcmp("/fish", cmdtext, true, 10) == 0)
    {
        if(IsPlayerConnected(playerid))
        }
            if((IsPlayerNearWater(playerid)) || IsPlayerInWater(playerid))
            }
                if(Fishes[playerid][pWeight1] > 0 && Fishes[playerid][pWeight2] > 0 && Fishes[playerid][pWeight3] > 0 && Fishes[playerid][pWeight4] > 0 && Fishes[playerid][pWeight5] > 0)
                {
                    SendClientMessage(playerid, COLOR_GREY, "   You've already caught five fish, sell / eat / release them before catching more!");
                    return 1;
                }
                if(Fishing[playerid] == 0)
                {
                    //Fishing[playerid] = 1;
                    SetTimerEx("FishTimer", 5000, false, "i", playerid);
                    SendClientMessage(playerid,0xFFFFFFFF, "You threw the line in the water.");
                }
                else
                {
                    SendClientMessage(playerid,COLOR_GREY, "You already Fishing !");
                }
                return 1;
            }
            return SendClientMessage(playerid,COLOR_GREY, "You aren't at the water!");
        }
        return 1;
    }
pawn Код:
#define         MAX_Z_FISH_THRESHOLD            15.0
#define         WATER_CHECK_RADIUS              5.0


IsPlayerNearWater(playerid)
{
    new Float:x, Float:y, Float:z, Float:checkx, Float:checky, Float:checkz, Float:angle;

    GetPlayerPos(playerid, x, y, z);

    // Make sure player is at correct Z-Height (Will not work near the dam)
    if(z > 0.0 && z < MAX_Z_FISH_THRESHOLD)
    {
        // Check North/East/South/West for water
        for(new i = 0; i < 4; i++)
        {
            checkx = x + (WATER_CHECK_RADIUS * floatsin(-angle, degrees));
            checky = y + (WATER_CHECK_RADIUS * floatcos(-angle, degrees));
            angle += 90.0;

            // Find the Z
            MapAndreas_FindZ_For2DCoord(checkx, checky, checkz);

            // Doesn't work under bridges
            if(checkz == 0.0) return 1;
        }
    }
    return 0; //return 0;
}
Reply
#2

Can anyone help me please, its very important for me
Reply
#3

Still not fixed, i Will +rep
Reply
#4

stop double posting, read forum rules :3.
Reply
#5

Try with MapAndreas plugin:

pawn Код:
stock IsWaterInFrontOfPlayer(playerid, Float: range = 1.0)
{
    new Float:fPX, Float:fPY, Float:fPZ,
        Float:fVX, Float:fVY, Float:fVZ,
        Float:object_x, Float:object_y, Float:object_z;

    GetPlayerCameraPos(playerid, fPX, fPY, fPZ);
    GetPlayerCameraFrontVector(playerid, fVX, fVY, fVZ);

    object_x = fPX + floatmul(fVX, range);
    object_y = fPY + floatmul(fVY, range);

    MapAndreas_FindZ_For2DCoord(object_x, object_y, object_z);

    if(object_z <= 0.0) return true;
    return false;
}
Directly from my server code Lost Springs Roleplay (ITA)
Reply
#6

Quote:
Originally Posted by DarK_FeneR
Посмотреть сообщение
Try with MapAndreas plugin:

pawn Код:
stock IsWaterInFrontOfPlayer(playerid, Float: range = 1.0)
{
    new Float:fPX, Float:fPY, Float:fPZ,
        Float:fVX, Float:fVY, Float:fVZ,
        Float:object_x, Float:object_y, Float:object_z;

    GetPlayerCameraPos(playerid, fPX, fPY, fPZ);
    GetPlayerCameraFrontVector(playerid, fVX, fVY, fVZ);

    object_x = fPX + floatmul(fVX, range);
    object_y = fPY + floatmul(fVY, range);

    MapAndreas_FindZ_For2DCoord(object_x, object_y, object_z);

    if(object_z <= 0.0) return true;
    return false;
}
Directly from my server code Lost Springs Roleplay (ITA)
I put that stock to my server, but i can still fish everywhere, i got this in my fish command

pawn Код:
if((IsWaterInFrontOfPlayer(playerid)) || IsPlayerInWater(playerid))
Reply
#7

Command:
PHP код:
if (strcmp("/fish"cmdtexttrue10) == 0)
{
    if(
IsPlayerConnected(playerid)){
    
        if(
IsPointInWaterFrontOfPlayer(playerid,2.0)) //<--- detection range
        
{
            if(
Fishes[playerid][pWeight1] > && Fishes[playerid][pWeight2] > && Fishes[playerid][pWeight3] > && Fishes[playerid][pWeight4] > && Fishes[playerid][pWeight5] > 0)
            {
                
SendClientMessage(playeridCOLOR_GREY"   You've already caught five fish, sell / eat / release them before catching more!");
                return 
1;
            }
            if(
Fishing[playerid] == 0)
            {
                
//Fishing[playerid] = 1;
                
SetTimerEx("FishTimer"5000false"i"playerid);
                
SendClientMessage(playerid,0xFFFFFFFF"You threw the line in the water.");
            }
            else
            {
                
SendClientMessage(playerid,COLOR_GREY"You already Fishing !");
            }
            return 
1;
        } else {
            return 
SendClientMessage(playerid,COLOR_GREY"You aren't at the water!");
        }
    }
    return 
1;

Function IsPointInWaterFrontOfPlayer(playerid,Float:radius) for MapAndreas / ColAndreas Precision
https://sampforum.blast.hk/showthread.php?pid=3591517#pid3591517
Tested, you can also change the range, now is 2.0
Reply
#8

Quote:
Originally Posted by AbyssMorgan
Посмотреть сообщение
Command:
PHP код:
if (strcmp("/fish"cmdtexttrue10) == 0)
{
    if(
IsPlayerConnected(playerid)){
    
        if(
IsPointInWaterFrontOfPlayer(playerid,2.0)) //<--- detection range
        
{
            if(
Fishes[playerid][pWeight1] > && Fishes[playerid][pWeight2] > && Fishes[playerid][pWeight3] > && Fishes[playerid][pWeight4] > && Fishes[playerid][pWeight5] > 0)
            {
                
SendClientMessage(playeridCOLOR_GREY"   You've already caught five fish, sell / eat / release them before catching more!");
                return 
1;
            }
            if(
Fishing[playerid] == 0)
            {
                
//Fishing[playerid] = 1;
                
SetTimerEx("FishTimer"5000false"i"playerid);
                
SendClientMessage(playerid,0xFFFFFFFF"You threw the line in the water.");
            }
            else
            {
                
SendClientMessage(playerid,COLOR_GREY"You already Fishing !");
            }
            return 
1;
        } else {
            return 
SendClientMessage(playerid,COLOR_GREY"You aren't at the water!");
        }
    }
    return 
1;

Function IsPointInWaterFrontOfPlayer(playerid,Float:radius) for MapAndreas / ColAndreas Precision
https://sampforum.blast.hk/showthread.php?pid=3591517#pid3591517
Tested, you can also change the range, now is 2.0
This is so wierd, neither this is working
i can still fish everywhere
Reply
#9

Quote:
Originally Posted by MayaEU
Посмотреть сообщение
This is so wierd, neither this is working
i can still fish everywhere
No, you can fish only with water. Initiated the Mapandreas ?

MapAndreas_Init(MAP_ANDREAS_MODE_FULL); //ongamemodeinit
Reply
#10

Quote:
Originally Posted by AbyssMorgan
Посмотреть сообщение
No, you can fish only with water. Initiated the Mapandreas ?

MapAndreas_Init(MAP_ANDREAS_MODE_FULL); //ongamemodeinit
I have this on ongamemodeinit

pawn Код:
MapAndreas_Init(MAP_ANDREAS_MODE_FULL);
This beween my stocks

pawn Код:
stock IsWaterInFrontOfPlayer(playerid, Float: range = 5.0)
{
    new Float:fPX, Float:fPY, Float:fPZ,
        Float:fVX, Float:fVY, Float:fVZ,
        Float:object_x, Float:object_y, Float:object_z;

    GetPlayerCameraPos(playerid, fPX, fPY, fPZ);
    GetPlayerCameraFrontVector(playerid, fVX, fVY, fVZ);

    object_x = fPX + floatmul(fVX, range);
    object_y = fPY + floatmul(fVY, range);

    MapAndreas_FindZ_For2DCoord(object_x, object_y, object_z);

    if(object_z <= 0.0) return true;
    return false;
}
And this is my fish command

pawn Код:
if (strcmp("/fish", cmdtext, true, 10) == 0)
    {
        if(IsPlayerConnected(playerid)){

            if(IsWaterInFrontOfPlayer(playerid,5.0)) //<--- detection range
            {
                if(Fishes[playerid][pWeight1] > 0 && Fishes[playerid][pWeight2] > 0 && Fishes[playerid][pWeight3] > 0 && Fishes[playerid][pWeight4] > 0 && Fishes[playerid][pWeight5] > 0)
                {
                    SendClientMessage(playerid, COLOR_GREY, "   You've already caught five fish, sell / eat / release them before catching more!");
                    return 1;
                }
                if(Fishing[playerid] == 0)
                {
                    //Fishing[playerid] = 1;
                    SetTimerEx("FishTimer", 5000, false, "i", playerid);
                    SendClientMessage(playerid,0xFFFFFFFF, "You threw the line in the water.");
                }
                else
                {
                    SendClientMessage(playerid,COLOR_GREY, "You already Fishing !");
                }
                return 1;
            } else {
                return SendClientMessage(playerid,COLOR_GREY, "You aren't at the water!");
            }
        }
        return 1;
    }
and i have MapAnreas plugins and added it to server.cfg, but i can still /fish everywhere
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)