IsPlayerInWater issue
#1

Here's my IsPlayerInWater function:

pawn Code:
stock IsPlayerInWater(playerid)
{
    new animlib[10], animname[10];
    GetAnimationName(GetPlayerAnimationIndex(playerid), animlib, sizeof(animlib), animname, sizeof(animname));
    return (!strcmp(animlib, "SWIM")) ? 1 : 0;
}

Here's my test command:

pawn Code:
COMMAND:swimming(playerid, params[]) return SendClientMessageEx(playerid, -1, "%d", IsPlayerInWater(playerid));

IsPlayerInWater is always returning 1. Don't worry about my SendClientMessageEx function, it works for everything else. If you really wanna see it, here:

pawn Code:
SendClientMessageEx(playerid, color, msg[], va_args<>)
{
    new string[128];
    va_format(string, sizeof(string), msg, va_start<3>);
    SendClientMessage(playerid, color, string);
    return 1;
}
It requires a special include by y_less.
Reply
#2

So? Whats the problem?
Reply
#3

Read my post. IsPlayerInWater is always returning 1.
Reply
#4

Quote:
Originally Posted by Ballu Miaa
View Post
So? Whats the problem?
Perhaps you should read his post:
Quote:
Originally Posted by SuperViper
View Post
Here's my IsPlayerInWater function:

pawn Code:
stock IsPlayerInWater(playerid)
{
    new animlib[10], animname[10];
    GetAnimationName(GetPlayerAnimationIndex(playerid), animlib, sizeof(animlib), animname, sizeof(animname));
    return (!strcmp(animlib, "SWIM")) ? 1 : 0;
}

Here's my test command:

pawn Code:
COMMAND:swimming(playerid, params[]) return SendClientMessageEx(playerid, -1, "%d", IsPlayerInWater(playerid));

IsPlayerInWater is always returning 1. Don't worry about my SendClientMessageEx function, it works for everything else. If you really wanna see it, here:

pawn Code:
SendClientMessageEx(playerid, color, msg[], va_args<>)
{
    new string[128];
    va_format(string, sizeof(string), msg, va_start<3>);
    SendClientMessage(playerid, color, string);
    return 1;
}
It requires a special include by y_less.
Reply
#5

I'm just guessing as I don't really see anything wrong, but try this:
pawn Code:
stock IsPlayerInWater(playerid)
{
    new animlib[10], animname[10];
    GetAnimationName(GetPlayerAnimationIndex(playerid), animlib, sizeof(animlib), animname, sizeof(animname));
    if(strcmp(animlib, "SWIM"))
        {
        return 1;
        }
    return 0;
}
Best regards,
Jesse
Reply
#6

Its just got over my mind. Sorry for that.
Reply
#7

Quote:
Originally Posted by jessejanssen
View Post
I'm just guessing as I don't really see anything wrong, but try this:
pawn Code:
stock IsPlayerInWater(playerid)
{
    new animlib[10], animname[10];
    GetAnimationName(GetPlayerAnimationIndex(playerid), animlib, sizeof(animlib), animname, sizeof(animname));
    if(strcmp(animlib, "SWIM"))
        {
        return 1;
        }
    return 0;
}
Best regards,
Jesse
I've already tried to do it without the ternary operator and it made no different. Just a note, strcmp returns 0 when the string matches. So your strcmp check should have a ! before it or == 0 after it.


I've found an alternative solution to this problem by using animation indexes, but I'd still like to know what was wrong with this so that I don't make the same mistake in the future.
Reply
#8

Do not use if(strcmp(animlib, "SWIM"))

Quote:

if(GetPlayerAnimationIndex(playerid))
{
new animlib[32];
new animname[32];
new msg[128];
GetAnimationName(GetPlayerAnimationIndex(playerid) ,animlib,32,animname,32);
format(msg, 128, "Running anim: %s %s", animlib, animname);
SendClientMessage(playerid, 0xFFFFFFFF, msg);
}
return 1;

I think this will help you.
Reply
#9

I highly doubt that will make any difference.
Reply
#10

Use printf or SendClientMessageEx to see what the 'animlib' actually is when using this function. It could be empty and strcmp returns 0 for empty strings.

pawn Code:
stock IsPlayerInWater(playerid)
{
    new animlib[10], animname[10];
    GetAnimationName(GetPlayerAnimationIndex(playerid), animlib, sizeof(animlib), animname, sizeof(animname));
    printf("animlib: %s", animlib);
    return (!strcmp(animlib, "SWIM"));
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)