AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [Help] with easy condition (https://forums.alliedmods.net/showthread.php?t=156524)

avril-lavigne 05-08-2011 00:29

[Help] with easy condition
 
Hi, here is cheap_suit regeneration Health function
I add armour. but it has a bug.
when your hp / ap = 200 and enemy hits you. your hp and ap immediately goes to 200. ( should be 10 each 2 secs )


Code:

public Task_HealthRegen(id)

        if(!is_user_alive(id) || !is_user_connected(id) || !g_HPRegen[id] || !g_HPRegen[id])
        {
                if(task_exists(id)) {
                        remove_task(id)
                }
                return PLUGIN_CONTINUE
        }
       
        new iHealth = get_user_health(id)
          new iArmor = get_user_armor(id)
        if(iHealth < 200 || iArmor < 200)  // dont know may be && ?
     
        {
                message_begin(MSG_ONE, get_user_msgid("ScreenFade"), { 0, 0, 0 }, id)
                write_short(1<<10)
                write_short(1<<10)
                write_short(1<<12)
                write_byte(0)
                write_byte(0)
                write_byte(255)
                write_byte(50)
                message_end()
                client_cmd(id,"speak shopmenu3/wearoff.wav")
                iHealth += RegenPoints
                      iArmor += RegenPoints
                set_user_health(id, iHealth)
                set_user_armor(id, iArmor)
// here                if(get_user_health(id) > 200 || get_user_armor(id) > 200) {
                set_user_health(id, 200)
                        set_user_armor(id, 200)
                }         

        }
        return PLUGIN_CONTINUE
}


Emp` 05-08-2011 00:32

Re: [Help] with easy condition
 
Instead you can just use the min native:
Code:

set_user_health( id, min( iHealth, 200 ) )

fysiks 05-08-2011 00:37

Re: [Help] with easy condition
 
I believe that you need to separate this into two separate if statements:

PHP Code:

        if(get_user_health(id) > 200 || get_user_armor(id) > 200)
        {
            
set_user_health(id200)
            
set_user_armor(id200)
        } 

EDIT: Guess I should refresh before replying :). Emp's solution would completely replace this if statement.

avril-lavigne 05-08-2011 01:59

Re: [Help] with easy condition
 
thanks , one time I did so, than deleted. will try again


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

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