IsPlayerInWater with boat
#1

How do I check if a player is in the water driving his boat?

Note: I don't want to check if he's swimming or w/e.
Reply
#2

Take this code, I took this code from my OnPlayerFly include, you can also check it for more snippets, also give Credits to Southclaw as he gave me this code whilst I was doing the include.

pawn Код:
stock Float:Distance(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2)
    return floatsqroot((((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2))+((z1-z2)*(z1-z2))));

stock Float:Distance2D(Float:x1, Float:y1, Float:x2, Float:y2)
    return floatsqroot( ((x1-x2)*(x1-x2)) + ((y1-y2)*(y1-y2)) );

new Float:water_places[20][4] =
{
    {30.0,                        2313.0,                -1417.0,        23.0},
    {15.0,                        1280.0,                -773.0,                1083.0},
    {25.0,                        2583.0,                2385.0,                15.0},
    {20.0,                        225.0,                -1187.0,        74.0},
    {50.0,                        1973.0,                -1198.0,        17.0},
    {180.0,                        1937.0,         1589.0,                9.0},
    {55.0,                        2142.0,                1285.0,         8.0},
    {45.0,                        2150.0,                1132.0,                8.0},
    {55.0,                        2089.0,                1915.0,                10.0},
    {32.0,                        2531.0,                1567.0,                9.0},
    {21.0,                        2582.0,                2385.0,                17.0},
    {33.0,                        1768.0,                2853.0,                10.0},
    {47.0,                        -2721.0,        -466.0,                3.0},
    {210.0,                        -671.0,                -1898.0,        6.0},
    {45.0,                        1240.0,                -2381.0,        9.0},
    {50.0,                        1969.0,                -1200.0,        18.0},
    {10.0,                        513.0,                -1105.0,        79.0},
    {20.0,                        193.0,                -1230.0,        77.0},
    {30.0,                        1094.0,                -672.0,                113.0},
    {20.0,                        1278.0,                -805.0,                87.0}
};

stock IsPlayerInWater(playerid)
{
    static Float:PosX, Float:PosY, Float:PosZ, i = -1;
    GetPlayerPos(playerid, PosX, PosY, PosZ);

    if(PosZ < 44.0)
    {
        if(Distance(PosX, PosY, PosZ, -965.0, 2438.0, 42.0) <= 700.0) return true;
    }

    while(++i < sizeof(water_places))
    {
        if(Distance2D(PosX, PosY, water_places[i][1], water_places[i][2]) <= water_places[i][0])
        {
            if(PosZ < water_places[i][3]) return true;
        }
        if(PosZ < 1.9)
        {
            if(Distance(PosX, PosY, PosZ, 618.4129, 863.3164, 1.0839) < 200.0)
            return false;
                else
            return true;
        }
    }
    return false;
}
Reply
#3

Quote:
Originally Posted by pds2k12
Посмотреть сообщение
Take this code, I took this code from my OnPlayerFly include, you can also check it for more snippets, also give Credits to Southclaw as he gave me this code whilst I was doing the include.

pawn Код:
stock Float:Distance(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2)
    return floatsqroot((((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2))+((z1-z2)*(z1-z2))));

stock Float:Distance2D(Float:x1, Float:y1, Float:x2, Float:y2)
    return floatsqroot( ((x1-x2)*(x1-x2)) + ((y1-y2)*(y1-y2)) );

new Float:water_places[20][4] =
{
    {30.0,                        2313.0,                -1417.0,        23.0},
    {15.0,                        1280.0,                -773.0,                1083.0},
    {25.0,                        2583.0,                2385.0,                15.0},
    {20.0,                        225.0,                -1187.0,        74.0},
    {50.0,                        1973.0,                -1198.0,        17.0},
    {180.0,                        1937.0,         1589.0,                9.0},
    {55.0,                        2142.0,                1285.0,         8.0},
    {45.0,                        2150.0,                1132.0,                8.0},
    {55.0,                        2089.0,                1915.0,                10.0},
    {32.0,                        2531.0,                1567.0,                9.0},
    {21.0,                        2582.0,                2385.0,                17.0},
    {33.0,                        1768.0,                2853.0,                10.0},
    {47.0,                        -2721.0,        -466.0,                3.0},
    {210.0,                        -671.0,                -1898.0,        6.0},
    {45.0,                        1240.0,                -2381.0,        9.0},
    {50.0,                        1969.0,                -1200.0,        18.0},
    {10.0,                        513.0,                -1105.0,        79.0},
    {20.0,                        193.0,                -1230.0,        77.0},
    {30.0,                        1094.0,                -672.0,                113.0},
    {20.0,                        1278.0,                -805.0,                87.0}
};

stock IsPlayerInWater(playerid)
{
    static Float:PosX, Float:PosY, Float:PosZ, i = -1;
    GetPlayerPos(playerid, PosX, PosY, PosZ);

    if(PosZ < 44.0)
    {
        if(Distance(PosX, PosY, PosZ, -965.0, 2438.0, 42.0) <= 700.0) return true;
    }

    while(++i < sizeof(water_places))
    {
        if(Distance2D(PosX, PosY, water_places[i][1], water_places[i][2]) <= water_places[i][0])
        {
            if(PosZ < water_places[i][3]) return true;
        }
        if(PosZ < 1.9)
        {
            if(Distance(PosX, PosY, PosZ, 618.4129, 863.3164, 1.0839) < 200.0)
            return false;
                else
            return true;
        }
    }
    return false;
}
Thanks I'll try that code!
Reply
#4

noobie question, but how do I check?

if (IsPlayerInWater == true? 1?) eh.. :P
Reply
#5

If player is in water:
pawn Код:
if (IsPlayerInWater(playerid))
If player is not in water:
pawn Код:
if (!IsPlayerInWater(playerid))
Reply
#6

Quote:
Originally Posted by Markus1337
Посмотреть сообщение
noobie question, but how do I check?

if (IsPlayerInWater == true) eh.. :P
Yes.

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
If player is in water:
pawn Код:
if (IsPlayerInWater(playerid))
If player is not in water:
pawn Код:
if (!IsPlayerInWater(playerid))
Twice you've beat me in two days!
Reply
#7

Ah i'm dumb should've slept tonight =P got !isplayerinboat already.. but well, thanks for fast replies
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)