AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Set_user_health (https://forums.alliedmods.net/showthread.php?t=128872)

reinert 06-06-2010 11:04

Set_user_health
 
Why this plugin isn't working properly ?

when I'm holding a knife it should restore my Health every 10 seconds, but it doesn't.

code:

PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <cstrike>

#define PLUGIN "knife heal"
#define VERSION "1.0"
#define AUTHOR "addinol"
new gtimegmaxgadd
public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_event("CurWeapon""Event_CurWeapon""be","1=1");
    
gtime register_cvar("inch_khptime","10.0")
    
gmax register_cvar("inch_khpmax","200")
    
gadd register_cvar("inch_khprestore","3")
}

public 
Event_CurWeapon(id)
{
    new 
clipammoweapon get_user_weapon(id,clip,ammo);
    if(
weapon == CSW_KNIFE) { 
    
set_task(get_pcvar_float(gtime), "hp")
}
}

public 
hp(id){
    new 
userHp get_user_health(id)
    if(
userHp >= get_pcvar_num(gmax))
    {
        
set_user_health(idget_pcvar_num(gmax))
    }else{
    
set_user_health(iduserHp get_pcvar_num(gadd))
    
set_task(get_pcvar_float(gtime), "hp")
    }



RedRobster 06-06-2010 12:48

Re: Set_user_health
 
PHP Code:

public hp(id){
    new 
userHp get_user_health(id)
    if(
userHp >= get_pcvar_num(gmax))
    {
        
set_user_health(idget_pcvar_num(gmax))
    }else{
    
set_user_health(iduserHp get_pcvar_num(gadd))
    
set_task(get_pcvar_float(gtime), "hp")
    }


You never defined (id) in hp(id). I don't believe.

Kreation 06-06-2010 13:49

Re: Set_user_health
 
Quote:

Originally Posted by RedRobster (Post 1201458)
PHP Code:

public hp(id){
    new 
userHp get_user_health(id)
    if(
userHp >= get_pcvar_num(gmax))
    {
        
set_user_health(idget_pcvar_num(gmax))
    }else{
    
set_user_health(iduserHp get_pcvar_num(gadd))
    
set_task(get_pcvar_float(gtime), "hp")
    }


You never defined (id) in hp(id). I don't believe.

What you posted is the exact same.

GXLZPGX 06-06-2010 13:52

Re: Set_user_health
 
Quote:

Originally Posted by Kreation (Post 1201495)
What you posted is the exact same.

I don't believe he was posting a fix. He quoted the area he thought needed to be fixed and said:

Quote:

You never defined (id) in hp(id). I don't believe.
So that the topic creator knew which part of the code he was talking about.

Kreation 06-06-2010 13:55

Re: Set_user_health
 
Quote:

Originally Posted by GXLZPGX (Post 1201496)
So that the topic creator knew which part of the code he was talking about.

But he did define id. :o I'm am just off today, I swear. I must've taken stupid pills.

RedRobster 06-06-2010 15:08

Re: Set_user_health
 
Quote:

Originally Posted by Kreation (Post 1201500)
But he did define id. :o I'm am just off today, I swear. I must've taken stupid pills.

I don't think when he first set the task that he defined id. He just did
PHP Code:

set_task(get_pcvar_float(gtime), "hp" 

He never defines what the "id" is that he is using when he actually executes the function.

I do think that:
PHP Code:

set_task(get_pcvar_float(gtime), "hp"id 

would work... o.o

reinert 06-06-2010 15:09

Re: Set_user_health
 
So whats exactly wrong ? I don't see anything :( maybe problem is in my server ;D

EDIT: i will try.

fysiks 06-06-2010 17:09

Re: Set_user_health
 
Quote:

Originally Posted by RedRobster (Post 1201564)
I do think that:
PHP Code:

set_task(get_pcvar_float(gtime), "hp"id 

would work... o.o

Correct afaik. But, when you correct this it won't work correctly. Infinite loop.

RedRobster 06-06-2010 20:41

Re: Set_user_health
 
PHP Code:

public Event_CurWeapon(id)
{
    new 
clipammoweapon get_user_weapon(id,clip,ammo);
    if(
weapon == CSW_KNIFE) { 
        
set_task(get_pcvar_float(gtime), "hp"id)
    } else {
        
remove_task(id)
    }


Do you think that'd work if he removed the task if it wasn't a knife? I don't think it would matter if that task is not already going.

fysiks 06-06-2010 21:54

Re: Set_user_health
 
Quote:

Originally Posted by RedRobster (Post 1201864)
Do you think that'd work if he removed the task if it wasn't a knife? I don't think it would matter if that task is not already going.

I think that might work.


All times are GMT -4. The time now is 05:21.

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