Raised This Month: $ Target: $400
 0% 

[HELP] alive vs. dead (is_user_alive)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
leonardo_
Member
Join Date: Nov 2012
Location: Moscow, right now in Vic
Old 02-08-2013 , 17:44   [HELP] alive vs. dead (is_user_alive)
Reply With Quote #1

I am not a good programmer, so please don't judge me

Ok I wrote that code and I wanted to make it like: when player writes /check in chat:

that line starts working: (if player alive)
PHP Code:
client_print(userprint_chat"[AMXX] you'r alive!"); 
that line starts working: (if player dead)
PHP Code:
client_print(user,print_chat,"[AMXX] You'r dead!"); 

PHP Code:
#include <amxmodx> 
#include <engine> 

 
public plugin_init(){ 
    
register_plugin("Checker""0.1""Alex")
    
register_event("say /check""CheckerAlive""a")
}

public 
CheckerAlive(id:user) {
    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!");
}

What am I doing wrong?

Last edited by leonardo_; 02-08-2013 at 17:45.
leonardo_ is offline
Send a message via ICQ to leonardo_ Send a message via Skype™ to leonardo_
n0br41ner
Senior Member
Join Date: May 2012
Location: Planet Earth
Old 02-08-2013 , 17:57   Re: [HELP] alive vs. dead (is_user_alive)
Reply With Quote #2

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_AliveCheckiPlayerID ) {
    if( 
is_user_aliveiPlayerID ) ) {
        
client_printiPlayerIDprint_chat"You are alive!" );
    } else {
        
client_printiPlayerIDprint_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!");

__________________

Last edited by n0br41ner; 02-08-2013 at 18:04.
n0br41ner is offline
leonardo_
Member
Join Date: Nov 2012
Location: Moscow, right now in Vic
Old 02-08-2013 , 18:10   Re: [HELP] alive vs. dead (is_user_alive)
Reply With Quote #3

Quote:
Originally Posted by n0br41ner View Post
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_AliveCheckiPlayerID ) {
    if( 
is_user_aliveiPlayerID ) ) {
        
client_printiPlayerIDprint_chat"You are alive!" );
    } else {
        
client_printiPlayerIDprint_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!");

ohhhh, ok! Thank you so much! I will try to make it right now!, and I'll post it here If it works!
leonardo_ is offline
Send a message via ICQ to leonardo_ Send a message via Skype™ to leonardo_
n0br41ner
Senior Member
Join Date: May 2012
Location: Planet Earth
Old 02-08-2013 , 18:13   Re: [HELP] alive vs. dead (is_user_alive)
Reply With Quote #4

I have already gave you the working plugin. No need to write it again O.o
__________________
n0br41ner is offline
leonardo_
Member
Join Date: Nov 2012
Location: Moscow, right now in Vic
Old 02-08-2013 , 18:32   Re: [HELP] alive vs. dead (is_user_alive)
Reply With Quote #5

Quote:
Originally Posted by n0br41ner View Post
I have already gave you the working plugin. No need to write it again O.o
I know

What about this one?

PHP Code:
#include < amxmodx >  
#include < fun >

new CurrentRound

 
public 
plugin_init(){ 
    
register_plugin"Alive Checker""0.1""Alex" );
    
register_clcmd"say /check""ClCmd_AliveCheck" );
}



public 
ClCmd_AliveCheck(user) {
    
CurrentRound++;
    new 
players[32], playerboom;
    
get_players(playersboom"a");
    for(new 
0boomi++)
        {
        
player players[i]    

    if (
is_user_alive(user))
    {
        
client_print(user,print_chat,"[AMXX] You'r alive, and now you can use VIP previleges!");
    
strip_user_weaponsplayer )
    
give_item(player"weapon_deagle")
    
give_item(player"ammo_50ae")
         
give_item(player"ammo_50ae")
         
give_item(player"ammo_50ae")
    
give_item(player"ammo_50ae")
    
give_item(player"weapon_hegrenade")
    
give_item(player"weapon_flashbang")
    
give_item(player"weapon_flashbang")
    
give_item(player"weapon_smokegrenade")
    
give_item(player"item_assaultsuit")
    
give_item(player"item_thighpack")
        return;
    }
    else {
        
client_print(user,print_chat,"[AMXX] You'r dead!");
    }
}

I wrote like, when user types "/check" he gets deagle, grenades. But when I am dead and I am writing "/check" it doesn't show me message that "I am dead"...

I am confused..
leonardo_ is offline
Send a message via ICQ to leonardo_ Send a message via Skype™ to leonardo_
n0br41ner
Senior Member
Join Date: May 2012
Location: Planet Earth
Old 02-08-2013 , 20:41   Re: [HELP] alive vs. dead (is_user_alive)
Reply With Quote #6

Alright first if all there is no use checking if the player is alive or not, because when u used this:
PHP Code:
new players[32], playerboom
    
get_players(playersboom"a"); 
You are getting all ALIVE players, so dead ones are not gonna be included.

Second, these WILL NOT work:
PHP Code:
 strip_user_weaponsplayer 
    
give_item(player"weapon_deagle"
    
give_item(player"ammo_50ae"
         
give_item(player"ammo_50ae"
         
give_item(player"ammo_50ae"
    
give_item(player"ammo_50ae"
    
give_item(player"weapon_hegrenade"
    
give_item(player"weapon_flashbang"
    
give_item(player"weapon_flashbang"
    
give_item(player"weapon_smokegrenade"
    
give_item(player"item_assaultsuit"
    
give_item(player"item_thighpack"
because you are giving those items to "player" and you really want to give them "user".
so change all "player" to "user". I am pretty sure you copied and pasted this code from somewhere and its not a good habit.

Third you do not need the return, remove it.
__________________
n0br41ner is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 20:32.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode