02.03.2016, 14:51
PHP код:
// This callback gets executed when zcmd receives a command (gets called BEFORE the command is executed)
public OnPlayerCommandReceived(playerid, cmdtext[])
{
// If a player hasn't logged in properly, he cannot use this command
if (APlayerData[playerid][LoggedIn] == false)
{
SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}You cannot use commands if you haven't logged in properly");
return 0;
}
// If the player is on the class-selection menu, block the command
if (Player_InClassSelection(playerid) == 1)
{
SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}You cannot use commands while using class-selection");
return 0;
}
// Allow commands to be performed when the player is logged in, and he's not in class-selection
return 1;
}
// This function checks if the given player is in class-selection screen
Player_InClassSelection(playerid)
{
// If the player has state NONE (entered server and got to class-selection), or if the player's state is WASTED (killed or returned to class-selection), return 1
switch (GetPlayerState(playerid))
{
case PLAYER_STATE_NONE, PLAYER_STATE_WASTED: return 1;
}
// For any other state, return 0 as the player isn't in class-selection
return 0;
}
It blocks all commands and sends a message when the player is still in class selection, or when he hasn't logged in properly (he must have entered the correct password to be logged in).
Returning 0 inside this callback blocks execution of the command.