Raised This Month: $ Target: $400
 0% 

hp based glow


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ezio_auditore
Senior Member
Join Date: May 2013
Old 01-06-2014 , 01:24   hp based glow
Reply With Quote #1

me and DavidJr made this plugin...

https://forums.alliedmods.net/showthread.php?t=232865

it got unapproved...

can someone code it better than the original sma
__________________
ezio_auditore is offline
Send a message via Skype™ to ezio_auditore
DavidJr
Senior Member
Join Date: Apr 2012
Old 01-06-2014 , 01:30   Re: hp based glow
Reply With Quote #2

You just need to optimize it

I didn't made it, I just help giving two brackets
__________________
What are you looking for here?

Last edited by DavidJr; 01-06-2014 at 01:32.
DavidJr is offline
ezio_auditore
Senior Member
Join Date: May 2013
Old 01-06-2014 , 01:34   Re: hp based glow
Reply With Quote #3

how...

i want ConnorMcLeod to see it suggest a way if there is one
__________________
ezio_auditore is offline
Send a message via Skype™ to ezio_auditore
11922911
Senior Member
Join Date: Dec 2011
Location: Yuen Long Country
Old 01-06-2014 , 01:44   Re: hp based glow
Reply With Quote #4

As Connor said, learn more and you will able to do it.
__________________
youtube:
@holla16
11922911 is offline
ezio_auditore
Senior Member
Join Date: May 2013
Old 01-06-2014 , 01:47   Re: hp based glow
Reply With Quote #5

but can you please take a view...

https://forums.alliedmods.net/showthread.php?t=232865

connor is right at his place, but it doesn't mean if i am a beginner, the plugin must be badly coded
__________________
ezio_auditore is offline
Send a message via Skype™ to ezio_auditore
.Dare Devil.
Veteran Member
Join Date: Sep 2010
Old 01-06-2014 , 13:45   Re: hp based glow
Reply With Quote #6

This code will support reading .ini
so you can easily edit or add colors.

Also i added glow fade out feature.

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <hamsandwich>

// For testing...
// #include <fun>


#define cfg_file "addons/amxmodx/configs/hp_based_glow.ini"

new Array:color_maxpercent
new Array:color_minpercent
new Array:glow_color[3]
new 
player_maxhealth[33]
new 
show_glow[33]
new 
Float:show_glowtime[33]
new 
show_glowcolor[33][3]

public 
plugin_init()
{
    
register_plugin("Glow color based on HP""1.0""Gyiove(Daredevil) & ezio_auditore")
    
RegisterHam(Ham_Spawn"player""player_spawn"1)
    
RegisterHam(Ham_TakeDamage"player""player_takedamage")
    
register_forwardFM_AddToFullPack"player_render")
    
cfg_loadcolors()
}

// For bots...
public client_putinserver(id) if (is_user_bot(id)) set_task0.5"ham_forbots"id )
public 
ham_forbots(id)
{
    
RegisterHamFromEntity(Ham_TakeDamageid"player_takedamage")
    
RegisterHamFromEntity(Ham_Spawnid"player_spawn"1)
}


// id2 is attacker
public player_takedamage(idinflictorid2Float:damagedamage_type)
{
    static 
Float:hpFloat:maxhppercentapercent_minpercent_maxd= -1
    
// Attacter is not player or attacter is doing dmg for herself
    
if( id == id2 || !is_user_connected(id2) ) return
    
show_glow[id2] = id
    show_glowtime
[id2] = 2.0
    
    hp 
float(update_maxhealth(id))
    
maxhp float(player_maxhealth[id])
    
percent floatround( (hp maxhp) * 100.0 )
    for( 
0ArraySize(color_maxpercent); a++ )
    {
        
percent_min ArrayGetCellcolor_minpercent)
        
percent_max ArrayGetCellcolor_maxpercent)
        if( 
percent >= percent_min && percent_max >= percent )
        {
            
a
            show_glowcolor
[id2][0] = ArrayGetCellglow_color[0], )
            
show_glowcolor[id2][1] = ArrayGetCellglow_color[1], )
            
show_glowcolor[id2][2] = ArrayGetCellglow_color[2], )
            break
        }
    }
    if(
== -1) for( 03a++ ) show_glowcolor[id2][a] = 255
}

public 
player_renderes_handleeenthosthostflagsplayerpSet 
{
    if( !
player || !show_glow[host] || show_glow[host] != ent ) return
    if( 
show_glowtime[host] < 0.0 )
    {
        
set_es(es_handleES_RenderFxkRenderNormal)
        
set_es(es_handleES_RenderColor, { 00} )
        
show_glow[host] = 0
        
return
    }
    
    static 
rgb[3], Float:d
    d 
show_glowtime[host]
    if( 
1.0 1.0
    rgb
[0] = floatround(float(show_glowcolor[host][0]) * d)
    
rgb[1] = floatround(float(show_glowcolor[host][1]) * d)
    
rgb[2] = floatround(float(show_glowcolor[host][2]) * d)
    
    
set_es(es_handleES_RenderFxkRenderFxGlowShell)
    
set_es(es_handleES_RenderColorrgb )
    
set_es(es_handleES_RenderAmt80 )
    
show_glowtime[host] -= 0.01
}

public 
player_spawn(id)
{
    
// for testing...
    // if( id == 1) set_user_health(id, 99000)
    
    
player_maxhealth[id] = get_user_health(id
    
set_task0.1"check_hpagain"id // Maybe some mod will increase hp, lets check that
}

public 
check_hpagain(idupdate_maxhealth(id)

cfg_loadcolors()
{
    new 
afline[64], maxpre[4], minpre[4], cdrgb
    f 
fopen(cfg_file"rt")
    
    
// Create arrays where we push ur loaded data
    
color_maxpercent ArrayCreate(1,1)
    
color_minpercent ArrayCreate(1,1)
    for( 
03a++ ) glow_color[a] = ArrayCreate(1,1)
    
    
// Starding loop, loop end when file ends.
    // Also if ur file dont exists or for some ohter reason file was unable to open when we dont start the loop and skip everything
    
while (&& !feof(f)) 
    {
        
fgets(flinecharsmax(line)) // Reading lines from file 'cfg_file'
        
replace(linecharsmax(line), "^n"""// Cutting next line so we read only one line at the time
        
        // If line first char is / or whitespace or nothing then skip that line
        
if( line[0] == '/' || line[0] == ' ' || !line[0] ) continue
        
        
/*
            If line first char is G then we assume that line look something like this:
            Glow color Red:51
         */
        
if( rgb == rgb 0
        
if( line[0] == 'G' )
        {
            
0
            d 
0
            
for( 064a++ )
            {
                if( !
line[a] ) break // no chars in line anymore? Lets stop the loop then ...
                
if(&& isdigit(line[a]))
                {
                    if( 
== ) break // there is no room in variable where we put or numbers
                    
minpre[c] = line[a// lets use random variable to hold that color
                    
minpre[1] = 0
                    c
++
                }
                if(
line[a] == ':'// we found a place where comes color value
            
}
            
            
// push ur readed data to array
            
ArrayPushCellglow_color[rgb], str_to_num(minpre) )
            
rgb++
            continue
        }
        
        
/*
            If line first char is H then we assume that line look something like this:
            HP:100% - 70%
        */
        
if( line[0] == 'H' )
        {
            
// Lets get first numbers into maxpre variable
            
0
            d 
0
            
for( 064a++ )
            {
                if( !
line[a] ) break // no chars in line anymore? Lets stop the loop then ...
                
if( == && ) break // there is no room in variable where we put or numbers
                
                
if( line[a] == '-' )  // If char in a pos is - then it means we have to copy numbers into ohter variable
                
{
                    
d++
                    
0
                    
continue
                }
                
                if( 
== 3  ) continue // we cant stop loop, so we wait...
                
if(isdigit(line[a])) // Char in a pos is number, lets copy that into ur variable
                
{
                    if(
d
                    {
                        
minpre[c] = line[a]
                        
minpre[1] = 0
                    
}
                    else 
                    {
                        
maxpre[c] = line[a]
                        
maxpre[1] = 0
                    
}
                    
c++
                }
            }
            
            
// Lets push ur loaded data into arrays
            
ArrayPushCellcolor_maxpercentstr_to_num(maxpre) )
            
ArrayPushCellcolor_minpercentstr_to_num(minpre) )
        }
    }
}


stock update_maxhealth(id)
{
    static 
h
    h 
get_user_health(id)
    if( 
player_maxhealth[id] ) player_maxhealth[id] = h
    
return h

PS: use this code not what i PM-d you.
I forgot some things

uh, also inside of .ini

PHP Code:
// if you do something like this:
// HP:100% - 70%
// Glow color Red:51
// Glow color Green:168
// Glow color Blue:87
//
// HP:60% - 50%
// Glow color Red:5
// Glow color Green:97
// Glow color Blue:212
//
// then if player have 70% - 60% health, her glow color will be white
// So to avoid this make sure you fill all possible % with colors


HP:100% - 70%
Glow color Red:51
Glow color Green
:168
Glow color Blue
:87

HP
:70% - 50%
Glow color Red:5
Glow color Green
:97
Glow color Blue
:212

HP
:50% - 25%
Glow color Red:255
Glow color Green
:189
Glow color Blue
:59

HP
:25% - 0%
Glow color Red:255
Glow color Green
:0
Glow color Blue
:

Last edited by .Dare Devil.; 01-06-2014 at 13:46.
.Dare Devil. is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 01-06-2014 , 15:06   Re: hp based glow
Reply With Quote #7

His previous code is better than... this
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
.Dare Devil.
Veteran Member
Join Date: Sep 2010
Old 01-06-2014 , 15:31   Re: hp based glow
Reply With Quote #8

Quote:
Originally Posted by ConnorMcLeod View Post
His previous code is better than... this
Now im confused.
Which parts do you think are baddly coded?
Or, what is the definition of better code or bad code?
I made plugin easy to use for users and it is alot faster that his old code.
( Well, i included some new stuff in it but this is not that bad )
.Dare Devil. is offline
ezio_auditore
Senior Member
Join Date: May 2013
Old 01-07-2014 , 01:45   Re: hp based glow
Reply With Quote #9

Quote:
Originally Posted by ConnorMcLeod View Post
His previous code is better than... this

now what part in the previous code is bad...


as per DavidJr's explaination, a bad code is something which can be coded by anyone else...

Now, Dare.Devil has suggested a harder code, and the last reply is much harder.

So, Connor my friend, what exactly is "badly coded"
__________________

Last edited by ezio_auditore; 01-07-2014 at 02:12.
ezio_auditore is offline
Send a message via Skype™ to ezio_auditore
11922911
Senior Member
Join Date: Dec 2011
Location: Yuen Long Country
Old 01-07-2014 , 02:33   Re: hp based glow
Reply With Quote #10

Quote:
Originally Posted by ezio_auditore View Post
now what part in the previous code is bad...


as per DavidJr's explaination, a bad code is something which can be coded by anyone else...

Now, Dare.Devil has suggested a harder code, and the last reply is much harder.

So, Connor my friend, what exactly is "baldy coded"
Something like:
PHP Code:
    new HP get_user_health(ent)
    if (
HP >= 100)
    {
        
set_es es_handleES_RenderColor, { 5116887 } )
    }
    else if (
HP 100 && HP >= 75)
    {
        
set_es es_handleES_RenderColor, { 5116887 } )
    }
    else if (
HP 75 && HP >= 50)
    {
        
set_es es_handleES_RenderColor, { 597212 } )
    }
    else if (
HP 50 && HP >= 25)
    {
        
set_es es_handleES_RenderColor, { 25518959 } )
    }
    else if (
HP 25)
    {
        
set_es es_handleES_RenderColor, { 2550} )
    } 
You can optimize like this:
PHP Code:
    new HP get_user_health(ent)
    if (
HP >= 75)
    {
        
set_es es_handleES_RenderColor, { 5116887 } )
    }
    else if (
HP >= 50)
    {
        
set_es es_handleES_RenderColor, { 597212 } )
    }
    else if (
HP >= 25)
    {
        
set_es es_handleES_RenderColor, { 25518959 } )
    }
    else
    {
        
set_es es_handleES_RenderColor, { 2550} )
    } 
And don't use too much check or native inside a forward which is called many times (like AddToFullPack), it's faster and better to use a global variable instead of a native function.

That's what I think about "badly coded".
__________________
youtube:
@holla16

Last edited by 11922911; 01-07-2014 at 02:38.
11922911 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 10:13.


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