AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Something wrong with set_user_health? (https://forums.alliedmods.net/showthread.php?t=220583)

Randomize 07-12-2013 05:27

Something wrong with set_user_health?
 
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)
        }
    }



devilicioux 07-12-2013 05:59

Re: Something wrong with set_user_health?
 
1 Attachment(s)
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.

a7811311622 07-12-2013 06:00

Re: Something wrong with set_user_health?
 
Try to use Ham_Spawn post?

~Ice*shOt 07-12-2013 06:20

Re: Something wrong with set_user_health?
 
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.

Randomize 07-12-2013 08:58

Re: Something wrong with set_user_health?
 
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?

~Ice*shOt 07-12-2013 09:39

Re: Something wrong with set_user_health?
 
Quote:

Originally Posted by Randomize (Post 1989291)
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 (Post 1989291)
!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..

Randomize 07-12-2013 17:57

Re: Something wrong with set_user_health?
 
It doesn't give any effect, the health is still 100

zi443r 07-12-2013 23:43

Re: Something wrong with set_user_health?
 
this is working very well.
Quote:

Originally Posted by ~Ice*shOt (Post 1989229)
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.


Randomize 07-13-2013 02:28

Re: Something wrong with set_user_health?
 
Okya, thank you all, it works fine now.


All times are GMT -4. The time now is 06:27.

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