To simple check if the player swims -
CrazyFrenzy - 06.03.2014
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)
These definitions are here to replace numbers to make it look badass.
Step 2
Defining varaibles and callbacks.
PHP Code:
new animName[32], animLib[32], Float:playerGPos[MAX_PLAYERS][3];
forward OnPlayerSwim(playerid, status);
This will help us further.
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;
}
Explainition of each and every line:
PHP Code:
GetAnimationName(GetPlayerAnimationIndex(playerid), animLib, sizeof(animLib), animName, sizeof(animName));
It's basically used to reterive the anim libary and name into varaibles so I can make a comparsion.
PHP Code:
GetPlayerPos(playerid, playerGPos[playerid][0], playerGPos[playerid][1], playerGPos[playerid][2]);
Gets the player position in XYZ coordinates, stores it into 3 Float varaibles.
PHP Code:
if(strcmp(animLib, "SWIM", false) || playerGPos[playerid][2] <= 1.5)
Compare if the anim libary name is SWIM which is basically called when a player is swimming or is underwater.
PHP Code:
OnPlayerSwim(playerid, PLAYER_SWIM);
If the player swims or is underwater, it returns the player swim within the OnPlayerSwim callback.
PHP Code:
OnPlayerSwim(playerid, PLAYER_WALK);
If the player does not swim, it returns the player walk within the OnPlayerSwim callback.
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;
}
SWIM Action
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.
Re: To simple check if the player swims -
GalaxyHostFree - 06.03.2014
Dear this isn't really a tutorial. You must explain them line by line.
Re: To simple check if the player swims -
CrazyFrenzy - 06.03.2014
Quote:
Originally Posted by GalaxyHostFree
Dear this isn't really a tutorial. You must explain them line by line.
|
You're right buddy, I managed to adjust it a little.
Re: To simple check if the player swims -
GalaxyHostFree - 06.03.2014
Quote:
Originally Posted by CrazyFrenzy
You're right buddy, I managed to adjust it a little.
|
Good job! Now I can learn something from your script. Looking forward to your new tutorials soon!