PHP Code:
// This code is written by me to show you what is the best way (i hope) to do what you want to do.
#include < amxmodx >
public plugin_init( ) {
register_plugin( "Alive Checker", "0.1", "n0br41ner" );
register_clcmd( "say /check", "ClCmd_AliveCheck" );
}
public ClCmd_AliveCheck( iPlayerID ) {
if( is_user_alive( iPlayerID ) ) {
client_print( iPlayerID, print_chat, "You are alive!" );
} else {
client_print( iPlayerID, print_chat, "You are not alive!" );
}
}
-----------------
1. You do not need "engine" so no need to include it.
2. In this case its not "register_event" but rather "register_clcmd", since the "say /check" is a command that user is issuing and not an event. (An event would be like "DeathMsg" a.k.a. when someone dies)
NOTE: you can also use "register_concmd" but in this case its easier to use "register_clcmd"
3. In the arguments of "CheckerAlive", you are NOT obliged to put "id", you can name it whatever you want, in this case you want to name it "user" so the word "user" is good by it self.
4. When using if/else structure means that if the condition stated is not met do everything inside "else", but if the condition is met then do everything inside "if" (when i say inside i mean the body). In this case you are saying that IF user is alive do
PHP Code:
client_print(user,print_chat,"[AMXX] You'r alive!");
BUT if he is not alive do
PHP Code:
client_print(user,print_chat,"[AMXX] You'r dead!");
, so you do not need the extra check, therefore this
PHP Code:
if(!is_user_alive(user))
is not needed.
So,
PHP Code:
if (is_user_alive(user))
{
client_print(user,print_chat,"[AMXX] You'r alive!");
//return;
}
else if(!is_user_alive(user))
{
client_print(user,print_chat,"[AMXX] You'r dead!");
}
would better be ->
PHP Code:
if (is_user_alive(user))
{
client_print(user,print_chat,"[AMXX] You'r alive!");
//return;
}
else { // when we arrive here, that means the user is already dead (since he is not alive - previous check)
client_print(user,print_chat,"[AMXX] You'r dead!");
}