Close to water
#1

Is possible to detect player if is close to any seas/water from San Andreas?
Reply
#2

Refer to this thread: https://sampforum.blast.hk/showthread.php?tid=533094

pawn Код:
//By Pottus//
#include <a_samp>
#include <zcmd>
#include <mapandreas>

#define         MAX_Z_FISH_THRESHOLD            4.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;
}

CMD:wcheck(playerid, arg[])
{
    if(IsPlayerNearWater(playerid)) SendClientMessage(playerid, -1, "Near water!");
    else SendClientMessage(playerid, -1, "Not Near water!");
    return 1;
}
Reply
#3

There will be even a better way once ColAndreas is released.
Reply
#4

Quote:
Originally Posted by De4dpOol
Посмотреть сообщение
Refer to this thread: https://sampforum.blast.hk/showthread.php?tid=533094

pawn Код:
//By Pottus//
#include <a_samp>
#include <zcmd>
#include <mapandreas>

#define         MAX_Z_FISH_THRESHOLD            4.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;
}

CMD:wcheck(playerid, arg[])
{
    if(IsPlayerNearWater(playerid)) SendClientMessage(playerid, -1, "Near water!");
    else SendClientMessage(playerid, -1, "Not Near water!");
    return 1;
}
NICE I will come back with a comment if it work fine.

Quote:
Originally Posted by Pottus
Посмотреть сообщение
There will be even a better way once ColAndreas is released.
For sure.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)