Raised This Month: $ Target: $400
 0% 

Something wrong with set_user_health?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Randomize
BANNED
Join Date: May 2012
Location: in your heart
Old 07-12-2013 , 05:27   Something wrong with set_user_health?
Reply With Quote #1

It still shows 100 *o* what's wrong?
PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <hamsandwich>

#define PLUGIN "Health"
#define VERSION "1.1"
#define AUTHOR "DavidJr"

#define DEFAULT_HEALTH 100

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
RegisterHam(Ham_Spawn"player""user_spawn")
    
register_cvar("health_enable""1")
}
public 
client_putinserver(id)
{
    
set_user_health(id,  120)
}
public 
user_spawn(id)
{
    if (
get_cvar_num("health_enable") == 1)
    {
        if(
is_user_connected(id) && is_user_alive(id))
        {
            
set_user_health(id,  120)
        }
    }
    else
    {
        if (
is_user_connected(id) && is_user_alive(id))
        {
            
set_user_health(idDEFAULT_HEALTH)
        }
    }


Last edited by Randomize; 07-12-2013 at 05:28.
Randomize is offline
devilicioux
Veteran Member
Join Date: Jun 2013
Location: Delhi,India
Old 07-12-2013 , 05:59   Re: Something wrong with set_user_health?
Reply With Quote #2

client_putinserver is executed as soon as a person enters the server .. There is a possibility a player hasnt join the team yet. Your code executes set user health instantly as the person joins the servers and practically hasnt even joined the team.

Try the file attached. Tested.
Attached Files
File Type: sma Get Plugin or Get Source (health.sma - 532 views - 827 Bytes)
devilicioux is offline
a7811311622
Member
Join Date: Apr 2010
Old 07-12-2013 , 06:00   Re: Something wrong with set_user_health?
Reply With Quote #3

Try to use Ham_Spawn post?
__________________
a7811311622 is offline
~Ice*shOt
Veteran Member
Join Date: Mar 2009
Location: Lithuania
Old 07-12-2013 , 06:20   Re: Something wrong with set_user_health?
Reply With Quote #4

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

public plugin_init()
{
    
register_cvar("health_enable""1")

    
RegisterHam(Ham_Spawn"player""Fwd_Spawn"1)
}

public 
Fwd_Spawn(id)
{
    if (!
is_user_alive(id))
        return

    if (
get_cvar_num("health_enable") == 1)
    {
        
set_user_health(id,  120)
    }

Simple, else if and putinserver is needn't here.

Last edited by ~Ice*shOt; 07-12-2013 at 06:20.
~Ice*shOt is offline
Send a message via Skype™ to ~Ice*shOt
Randomize
BANNED
Join Date: May 2012
Location: in your heart
Old 07-12-2013 , 08:58   Re: Something wrong with set_user_health?
Reply With Quote #5

Iceshot, no, I just want to set the user health to 120 if I enable health_enable to 1, else of 1, it will be set to 100. !is_user_alive is the condition when the player is dead, isn't it? So I guess if alive, it will always set to 120. I am right, aren't I?
Randomize is offline
~Ice*shOt
Veteran Member
Join Date: Mar 2009
Location: Lithuania
Old 07-12-2013 , 09:39   Re: Something wrong with set_user_health?
Reply With Quote #6

Quote:
Originally Posted by Randomize View Post
Iceshot, no, I just want to set the user health to 120 if I enable health_enable to 1, else of 1, it will be set to 100.
So with 'if' you check the cvar status, if it is 1 health sets to 120, if not it will be 100.

Quote:
Originally Posted by Randomize View Post
!is_user_alive is the condition when the player is dead, isn't it? So I guess if alive, it will always set to 120. I am right, aren't I?
Here you should check, because sometimes it can cause problems/errors because you setting health to dead player

Use my code and you'll see..

Last edited by ~Ice*shOt; 07-12-2013 at 09:40.
~Ice*shOt is offline
Send a message via Skype™ to ~Ice*shOt
Randomize
BANNED
Join Date: May 2012
Location: in your heart
Old 07-12-2013 , 17:57   Re: Something wrong with set_user_health?
Reply With Quote #7

It doesn't give any effect, the health is still 100
Randomize is offline
zi443r
Senior Member
Join Date: Mar 2009
Location: Braila,Romania
Old 07-12-2013 , 23:43   Re: Something wrong with set_user_health?
Reply With Quote #8

this is working very well.
Quote:
Originally Posted by ~Ice*shOt View Post
PHP Code:
#include <amxmodx>
#include <fun>
#include <hamsandwich>

public plugin_init()
{
    
register_cvar("health_enable""1")

    
RegisterHam(Ham_Spawn"player""Fwd_Spawn"1)
}

public 
Fwd_Spawn(id)
{
    if (!
is_user_alive(id))
        return

    if (
get_cvar_num("health_enable") == 1)
    {
        
set_user_health(id,  120)
    }

Simple, else if and putinserver is needn't here.
__________________
zi443r is offline
Randomize
BANNED
Join Date: May 2012
Location: in your heart
Old 07-13-2013 , 02:28   Re: Something wrong with set_user_health?
Reply With Quote #9

Okya, thank you all, it works fine now.
Randomize 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 06:28.


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