06.03.2014, 04:14
Check if the player swims
Step 1
Make sure to have the a_samp include and those definitions in the top of your script.
PHP Code:
#include <a_samp>
#define PLAYER_SWIM (1)
#define PLAYER_WALK (2)
Step 2
Defining varaibles and callbacks.
PHP Code:
new animName[32], animLib[32], Float:playerGPos[MAX_PLAYERS][3];
forward OnPlayerSwim(playerid, status);
Step 3
Checking the status of a player whether is swimming or not, in order to do so you have to use the public OnPlayerUpdate, yet it is not preferable and you sure want to use a timer instead.
PHP Code:
public OnPlayerUpdate(playerid)
{
GetAnimationName(GetPlayerAnimationIndex(playerid), animLib, sizeof(animLib), animName, sizeof(animName));
GetPlayerPos(playerid, playerGPos[playerid][0], playerGPos[playerid][1], playerGPos[playerid][2]);
if(strcmp(animLib, "SWIM", false) || playerGPos[playerid][2] <= 1.5)
OnPlayerSwim(playerid, PLAYER_SWIM);
else
OnPlayerSwim(playerid, PLAYER_WALK);
return 1;
}
PHP Code:
GetAnimationName(GetPlayerAnimationIndex(playerid), animLib, sizeof(animLib), animName, sizeof(animName));
PHP Code:
GetPlayerPos(playerid, playerGPos[playerid][0], playerGPos[playerid][1], playerGPos[playerid][2]);
PHP Code:
if(strcmp(animLib, "SWIM", false) || playerGPos[playerid][2] <= 1.5)
PHP Code:
OnPlayerSwim(playerid, PLAYER_SWIM);
PHP Code:
OnPlayerSwim(playerid, PLAYER_WALK);
Step 4
Setting up the OnPlayerSwim callback.
You can use whether switch or elses, it doesn't really matter just a matter of comfort.
PHP Code:
public OnPlayerSwim(playerid, status)
{
switch(status)
{
case PLAYER_SWIM:
{
// SWIM action
}
case PLAYER_WALK:
{
// WALK Action
}
}
return 1;
}
What will happen to the player that swims, you can use any script code you'd like.
WALK Action
The same thing, just if the player walks.