IsPlayerInWater issue -
SuperViper - 31.05.2012
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.
Re: IsPlayerInWater issue -
Ballu Miaa - 31.05.2012
So? Whats the problem?
Re: IsPlayerInWater issue -
SuperViper - 31.05.2012
Read my post. IsPlayerInWater is always returning 1.
Re: IsPlayerInWater issue -
MP2 - 31.05.2012
Quote:
Originally Posted by Ballu Miaa
So? Whats the problem?
|
Perhaps you should read his post:
Quote:
Originally Posted by SuperViper
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.
|
Re: IsPlayerInWater issue -
jessejanssen - 31.05.2012
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
Re: IsPlayerInWater issue -
Ballu Miaa - 31.05.2012
Its just got over my mind. Sorry for that.
Re: IsPlayerInWater issue -
SuperViper - 31.05.2012
Quote:
Originally Posted by jessejanssen
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.
Re: IsPlayerInWater issue -
Azazelo - 31.05.2012
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.
Re: IsPlayerInWater issue -
SuperViper - 31.05.2012
I highly doubt that will make any difference.
Re: IsPlayerInWater issue -
MadeMan - 31.05.2012
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"));
}