IsPlayerInWater bug HELP !!
#1

Code:
public OnPlayerUpdate(playerid)
   
//FBI Recording Bug
    new  iTargetID;
    if(IsPlayerInWater(playerid))
	{
		if(PlayerInfo[iTargetID][pBugged] == playerid)
    	{
			SendClientMessage(iTargetID, COLOR_LIGHTBLUE, "A bug on you was malfunctioned because it became wet");
		 	PlayerInfo[iTargetID][pBugged] = -1;
  			PlayerInfo[iTargetID][pBugOn] = 0;
  		}
	}
I'm spying on people's chat via FBI command but I want that recording bug to get destroyed when the victim is on water, it seems not working :/
nothing appears when swimming with both players (agent & victim)


Am I doing anything wrong? what should I do, where should I put it, idk , anyone help me



Code:
stock IsPlayerInWater(playerid)
{
	new anim = GetPlayerAnimationIndex(playerid);
	if (anim >=  1538 && anim <= 1542 || anim == 1544 || anim == 1250 || anim == 1062)
	{
		return 1;
	}
	return 0;
}
Reply
#2

Hello there!
You can try to change this :

PHP Code:
stock IsPlayerInWater(playerid)
{
    switch(
GetPlayerAnimationIndex(playerid))    {    case 1543,1538,1539: return true;    }
    return 
false;

Reply
#3

Quote:
Originally Posted by Dayrion
View Post
Hello there!
You can try to change this :

PHP Code:
stock IsPlayerInWater(playerid)
{
    switch(
GetPlayerAnimationIndex(playerid))    {    case 1543,1538,1539: return true;    }
    return 
false;

edit -removed-, beat me to it

Haha, I was just writing the same thing, beat me to it. Yes, in my opinion switch statements are always better than if then in certain situations such as that.
Reply
#4

new iTargetID; is always ID 0
Reply
#5

Quote:
Originally Posted by Jefff
View Post
new iTargetID; is always ID 0
Exactly ^
Use playerid instead of TargetID
Reply
#6

I'm not familiar with what you're trying but I assume you have a variable named "pBugged" that stores another player's ID as the target spy. If that's it, you'll have to loop through all players to see if the target matches. I'm not suggesting you to use OnPlayerUpdate on that case or it's better to have an additional variable which holds the player's ID who have set your target to (if it's only one).

pawn Code:
public ... {
    if(IsPlayerInWater(playerid)) {

        foreach(new iTargetID : Player) {

        if(PlayerInfo[iTargetID][pBugged] == playerid) {

            SendClientMessage(iTargetID, COLOR_LIGHTBLUE, "A bug on you was malfunctioned because it became wet");
            PlayerInfo[iTargetID][pBugged] = -1;
            PlayerInfo[iTargetID][pBugOn] = 0;
        }
          }
    }
I'd also like to note that your function IsPlayerInWater can be tricked if someone's using animation cheats. It's better to have a boundary check or use ColAndreas plugin to perform this check.

pawn Code:
//https://github.com/pds2k12/OnPlayerFly/blob/master/pawno/include/OnPlayerFly.inc
/*
    All functions below are created by Southclaw, thanks to him for sharing this useful function & array of SA water-area.
    This function were taken from his (Scavenge and Survive) script, its free to use and its available on Github!
*/


static 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))));
static stock Float:Distance2D(Float:x1, Float:y1, Float:x2, Float:y2) return floatsqroot( ((x1-x2)*(x1-x2)) + ((y1-y2)*(y1-y2)) );

static 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}
};

static 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;
}


//Or using what ColAndreas lets you to:
//https://github.com/Ino42O/OxygenController/blob/master/OxygenController.inc
stock IsPlayerInWater(playerid)
{
    new Float:x, Float:y, Float:z, Float:retx[2], Float:rety[2], Float:retz[2], Float: retdist[2], modelids[2];
    GetPlayerPos(playerid, x, y, z);
    new collisions = CA_RayCastMultiLine(x, y, z+0.7, x, y, z-0.7, retx, rety, retz, retdist, modelids, 2);

    if (collisions)
    {
        for(new i = 0; i < collisions; i++)
        {
            if (modelids[i] == WATER_OBJECT)
            {
                return (true);
            }
        }
    }
    return (false);
}


stock IsPlayerUnderWater(playerid)
{
    new Float:x, Float:y, Float:z, Float:retx[10], Float:rety[10], Float:retz[10], Float: retdist[10], modelids[10];
    GetPlayerPos(playerid, x, y, z);
    new collisions = CA_RayCastMultiLine(x, y, z+0.7, x, y, z+1000.0, retx, rety, retz, retdist, modelids, 10);

    if (collisions)
    {
        for(new i = 0; i < collisions; i++)
        {
            if (modelids[i] == WATER_OBJECT)
            {
                return (true);
            }
        }
    }
    return (false);
}
Reply
#7

Quote:
Originally Posted by D3vin
View Post
Code:
stock IsPlayerInWater(playerid)
{
	new anim = GetPlayerAnimationIndex(playerid);
	if (anim >=  1538 && anim <= 1542 || anim == 1544 || anim == 1250 || anim == 1062)
	{
		return 1;
	}
	return 0;
}
PHP Code:
&& || //shit
&& (|| c//ok 
Reply
#8

Quote:
Originally Posted by Lordzy
View Post
I'm not familiar with what you're trying but I assume you have a variable named "pBugged" that stores another player's ID as the target spy. If that's it, you'll have to loop through all players to see if the target matches. I'm not suggesting you to use OnPlayerUpdate on that case or it's better to have an additional variable which holds the player's ID who have set your target to (if it's only one).

pawn Code:
public ... {
    if(IsPlayerInWater(playerid)) {

        foreach(new iTargetID : Player) {

        if(PlayerInfo[iTargetID][pBugged] == playerid) {

            SendClientMessage(iTargetID, COLOR_LIGHTBLUE, "A bug on you was malfunctioned because it became wet");
            PlayerInfo[iTargetID][pBugged] = -1;
            PlayerInfo[iTargetID][pBugOn] = 0;
        }
          }
    }
I'd also like to note that your function IsPlayerInWater can be tricked if someone's using animation cheats. It's better to have a boundary check or use ColAndreas plugin to perform this check.

pawn Code:
//https://github.com/pds2k12/OnPlayerFly/blob/master/pawno/include/OnPlayerFly.inc
/*
    All functions below are created by Southclaw, thanks to him for sharing this useful function & array of SA water-area.
    This function were taken from his (Scavenge and Survive) script, its free to use and its available on Github!
*/


static 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))));
static stock Float:Distance2D(Float:x1, Float:y1, Float:x2, Float:y2) return floatsqroot( ((x1-x2)*(x1-x2)) + ((y1-y2)*(y1-y2)) );

static 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}
};

static 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;
}


//Or using what ColAndreas lets you to:
//https://github.com/Ino42O/OxygenController/blob/master/OxygenController.inc
stock IsPlayerInWater(playerid)
{
    new Float:x, Float:y, Float:z, Float:retx[2], Float:rety[2], Float:retz[2], Float: retdist[2], modelids[2];
    GetPlayerPos(playerid, x, y, z);
    new collisions = CA_RayCastMultiLine(x, y, z+0.7, x, y, z-0.7, retx, rety, retz, retdist, modelids, 2);

    if (collisions)
    {
        for(new i = 0; i < collisions; i++)
        {
            if (modelids[i] == WATER_OBJECT)
            {
                return (true);
            }
        }
    }
    return (false);
}


stock IsPlayerUnderWater(playerid)
{
    new Float:x, Float:y, Float:z, Float:retx[10], Float:rety[10], Float:retz[10], Float: retdist[10], modelids[10];
    GetPlayerPos(playerid, x, y, z);
    new collisions = CA_RayCastMultiLine(x, y, z+0.7, x, y, z+1000.0, retx, rety, retz, retdist, modelids, 10);

    if (collisions)
    {
        for(new i = 0; i < collisions; i++)
        {
            if (modelids[i] == WATER_OBJECT)
            {
                return (true);
            }
        }
    }
    return (false);
}
He just wants to know if the player is swimming or not but you are true. It's a way to detect it.
As you said, he needs to replace
PHP Code:
if(IsPlayerInWater(playerid))
    {
        foreach(new 
iTargetID Player)
        {
            if(
PlayerInfo[iTargetID][pBugged] == playerid)
            {
                
SendClientMessage(iTargetIDCOLOR_LIGHTBLUE"A bug on you was malfunctioned because it became wet");
                 
PlayerInfo[iTargetID][pBugged] = -1;
                  
PlayerInfo[iTargetID][pBugOn] = 0;
                  return 
1;
            }
        }
    } 
and this
PHP Code:
stock IsPlayerInWater(playerid

    switch(
GetPlayerAnimationIndex(playerid))    {    case 1543,1538,1539: return true;    } 
    return 
false

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)