AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   check victim health (https://forums.alliedmods.net/showthread.php?t=319256)

LearninG 10-21-2019 17:09

check victim health
 
Hi , i want to check if current victim health (gondor health) is lower than (main health / 2) and also (/3) , however as you can see below i made it work , but it's not efficient , hope that you give me an efficient way of checking victim health.

Code:
new g_gondor_health = 1600 // an example

Code:
public On_Player_Take_Damage(victim, inflictor, attacker, Float:dmg, dmgbits) {     if (attacker == victim)       return HAM_IGNORED     if (check_user_class(g_gondar_class , victim))     {         check_health(victim) // checking victim (gondor) health     }      return HAM_HANDLED }

Code:
check_health(index) {     new current_health     current_health = get_user_health(index)     if ((g_gondar_health / 2) >= current_health)     {         set_user_maxspeed(index , 450.0)         set_user_rendering(index, kRenderFxGlowShell, 0, 0, 0, kRenderTransAlpha,155)         message_begin(MSG_ALL,iconstatus,{0,0,0},index)         write_byte(1) // status (0=hide, 1=show, 2=flash)         write_string("dmg_poison") // sprite name         write_byte(255) // red         write_byte(255) // green         write_byte(0) // blue         message_end()     }     if((g_gondar_health / 3) >= current_health)     {         set_user_maxspeed(index , 800.0)         set_user_rendering(index, kRenderFxGlowShell, 0, 0, 0, kRenderTransAlpha,55)         message_begin(MSG_ALL,iconstatus,{0,0,0},index)         write_byte(1) // status (0=hide, 1=show, 2=flash)         write_string("dmg_poison") // sprite name         write_byte(255) // red         write_byte(0) // green         write_byte(0) // blue         message_end()     } }

JocAnis 10-21-2019 18:02

Re: check victim health
 
whats is the problem exactly?
atleast add some client_prints debug by yourself to see whats called what is not?

LearninG 10-21-2019 23:33

Re: check victim health
 
ok , let's say gondar ( a hero ) has 1800 hp on new round. i want to check if it's health becomes lower than 900 , then i will add some effects and if it becomes lower than 600 i will disable that effects and will add new effects.
basically this is how i'm checking :
Code:
(if ((g_gondar_health / 2) >= current_health)
and at the same
Code:
(if ((g_gondar_health / 3) >= current_health)

so both sentence becomes true when gondar health reaches 599 and effects will be activated. problem is both sentence will be excuted while the health is under (main health /3 ). and 1 of them is unnnessesary.
Code:
check_health(index) {     new current_health     current_health = get_user_health(index)     if ((g_gondar_health / 2) >= current_health)     {         set_user_maxspeed(index , 450.0)         set_user_rendering(index, kRenderFxGlowShell, 0, 0, 0, kRenderTransAlpha,155)         message_begin(MSG_ALL,iconstatus,{0,0,0},index)         write_byte(1) // status (0=hide, 1=show, 2=flash)         write_string("dmg_poison") // sprite name         write_byte(255) // red         write_byte(255) // green         write_byte(0) // blue         message_end()     }     if((g_gondar_health / 3) >= current_health)     {         set_user_maxspeed(index , 800.0)         set_user_rendering(index, kRenderFxGlowShell, 0, 0, 0, kRenderTransAlpha,55)         message_begin(MSG_ALL,iconstatus,{0,0,0},index)         write_byte(1) // status (0=hide, 1=show, 2=flash)         write_string("dmg_poison") // sprite name         write_byte(255) // red         write_byte(0) // green         write_byte(0) // blue         message_end()     } }

iceeedr 10-22-2019 00:02

Re: check victim health
 
I'm tired and sleepy, but the logic would be this, maybe some adjustment is needed.

PHP Code:

check_health(index)
{
    new 
current_health
    current_health 
get_user_health(index)

    if ((
g_gondar_health 2) >= current_health && (g_gondar_health 3) < current_health)
    {
        
set_user_maxspeed(index 450.0)
        
set_user_rendering(indexkRenderFxGlowShell000kRenderTransAlpha,155)
        
message_begin(MSG_ALL,iconstatus,{0,0,0},index)
        
write_byte(1// status (0=hide, 1=show, 2=flash)
        
write_string("dmg_poison"// sprite name
        
write_byte(255// red
        
write_byte(255// green
        
write_byte(0// blue
        
message_end()
    }
    else if ((
g_gondar_health 3) >= current_health)
    {
        
set_user_maxspeed(index 800.0)
        
set_user_rendering(indexkRenderFxGlowShell000kRenderTransAlpha,55)
        
message_begin(MSG_ALL,iconstatus,{0,0,0},index)
        
write_byte(1// status (0=hide, 1=show, 2=flash)
        
write_string("dmg_poison"// sprite name
        
write_byte(255// red
        
write_byte(0// green
        
write_byte(0// blue
        
message_end()
    }



E1_531G 10-22-2019 00:27

Re: check victim health
 
Let say
PHP Code:

g_gondar_health 3000 

PHP Code:

if ( current_health < (g_gondar_health 3) ) // less than 1000?
    //code
else if ( current_health < (g_gondar_health 2) ) // we are here, so it's not less than 1000. maybe less than 1500?
    //code
else // we are here, so it's not less than 1000 or 1500. it's more
    //code, if needed 

Also, for only one player MSG_ALL is the wrong type.


All times are GMT -4. The time now is 02:53.

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