Raised This Month: $ Target: $400
 0% 

hp based glow


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
11922911
Senior Member
Join Date: Dec 2011
Location: Yuen Long Country
Old 01-07-2014 , 00:49   Re: hp based glow
Reply With Quote #1

Just bored to have a quick try.
PHP Code:
#include amxmodx
#include fakemeta
#include hamsandwich

#define IsPlayer(%1) (1 <= %1 <= g_MaxClients)

#define GetBits(%1,%2) (%1 & (1 << (%2 & 31)))
#define SetBits(%1,%2) (%1 |= (1 << (%2 & 31)))
#define ClrBits(%1,%2) (%1 &= ~(1 << (%2 & 31)))

new g_IsAliveg_IsAimingPlayer;
new 
g_RenderTarget[33];
new 
g_PlayerColor[33][3];

new 
g_fnAddToFullPack;
new 
g_MaxClients;

public 
plugin_init()
{
    
register_event("Health""EventHealth""b");
    
    
register_forward(FM_TraceLine"TraceLine_Post"1);
    
    
RegisterHam(Ham_Spawn,  "player""PlayerLife"1);
    
RegisterHam(Ham_Killed"player""PlayerLife"1);
    
    
g_MaxClients get_maxplayers();
}

public 
client_disconnectid )
{
    
ClrBits(g_IsAliveid);
    
ClrAimingPlayer(id);
}

public 
PlayerLifeid )
{
    if( 
is_user_alive(id) )
    {
        
SetBits(g_IsAliveid);
    }
    else
    {
        
ClrBits(g_IsAliveid);
        
ClrAimingPlayer(id);
    }
}

public 
TraceLine_PostFloat:start[3], Float:end[3], conditionsidtrace )
{
    if( 
IsPlayer(id) && GetBits(g_IsAliveid) )
    {
        new 
hit get_tr2(traceTR_pHit);
        if( 
IsPlayer(hit) )
            
SetAimingPlayer(idhit);
        else
            
ClrAimingPlayer(id);
    }
}

public 
AddToFullPack_Posteseenthostflagsplayerset )
{
    if( 
player && g_RenderTarget[host] == ent )
    {
        
set_es(esES_RenderFx     kRenderFxGlowShell);
        
set_es(esES_RenderColorg_PlayerColor[ent]);
    }
}

public 
EventHealthid )
{
    switch( 
read_data(1) )
    {
        case 
.. 24:
            
g_PlayerColor[id] = {25500};
        case 
25 .. 49:
            
g_PlayerColor[id] = {25518959};
        case 
50 .. 74:
            
g_PlayerColor[id] = {597212};
        default:
            
g_PlayerColor[id] = {5116887};
    }
}

SetAimingPlayeridplayer )
{
    
g_RenderTarget[id] = player;
    
    
SetBits(g_IsAimingPlayerid);
    
    if( !
g_fnAddToFullPack )
        
g_fnAddToFullPack register_forward(FM_AddToFullPack"AddToFullPack_Post"1);
}

ClrAimingPlayerid )
{
    
g_RenderTarget[id] = 0;
    
    
ClrBits(g_IsAimingPlayerid);
    
    if( !
g_IsAimingPlayer && g_fnAddToFullPack )
    {
        
unregister_forward(FM_AddToFullPackg_fnAddToFullPack1);
        
g_fnAddToFullPack 0;
    }

Don't know if this is better,.
__________________
youtube:
@holla16

Last edited by 11922911; 01-07-2014 at 00:50.
11922911 is offline
.Dare Devil.
Veteran Member
Join Date: Sep 2010
Old 01-07-2014 , 11:03   Re: hp based glow
Reply With Quote #2

Quote:
Originally Posted by 11922911 View Post
Just bored to have a quick try.
PHP Code:
#include amxmodx
#include fakemeta
#include hamsandwich

#define IsPlayer(%1) (1 <= %1 <= g_MaxClients)

#define GetBits(%1,%2) (%1 & (1 << (%2 & 31)))
#define SetBits(%1,%2) (%1 |= (1 << (%2 & 31)))
#define ClrBits(%1,%2) (%1 &= ~(1 << (%2 & 31)))

new g_IsAliveg_IsAimingPlayer;
new 
g_RenderTarget[33];
new 
g_PlayerColor[33][3];

new 
g_fnAddToFullPack;
new 
g_MaxClients;

public 
plugin_init()
{
    
register_event("Health""EventHealth""b");
    
    
register_forward(FM_TraceLine"TraceLine_Post"1);
    
    
RegisterHam(Ham_Spawn,  "player""PlayerLife"1);
    
RegisterHam(Ham_Killed"player""PlayerLife"1);
    
    
g_MaxClients get_maxplayers();
}

public 
client_disconnectid )
{
    
ClrBits(g_IsAliveid);
    
ClrAimingPlayer(id);
}

public 
PlayerLifeid )
{
    if( 
is_user_alive(id) )
    {
        
SetBits(g_IsAliveid);
    }
    else
    {
        
ClrBits(g_IsAliveid);
        
ClrAimingPlayer(id);
    }
}

public 
TraceLine_PostFloat:start[3], Float:end[3], conditionsidtrace )
{
    if( 
IsPlayer(id) && GetBits(g_IsAliveid) )
    {
        new 
hit get_tr2(traceTR_pHit);
        if( 
IsPlayer(hit) )
            
SetAimingPlayer(idhit);
        else
            
ClrAimingPlayer(id);
    }
}

public 
AddToFullPack_Posteseenthostflagsplayerset )
{
    if( 
player && g_RenderTarget[host] == ent )
    {
        
set_es(esES_RenderFx     kRenderFxGlowShell);
        
set_es(esES_RenderColorg_PlayerColor[ent]);
    }
}

public 
EventHealthid )
{
    switch( 
read_data(1) )
    {
        case 
.. 24:
            
g_PlayerColor[id] = {25500};
        case 
25 .. 49:
            
g_PlayerColor[id] = {25518959};
        case 
50 .. 74:
            
g_PlayerColor[id] = {597212};
        default:
            
g_PlayerColor[id] = {5116887};
    }
}

SetAimingPlayeridplayer )
{
    
g_RenderTarget[id] = player;
    
    
SetBits(g_IsAimingPlayerid);
    
    if( !
g_fnAddToFullPack )
        
g_fnAddToFullPack register_forward(FM_AddToFullPack"AddToFullPack_Post"1);
}

ClrAimingPlayerid )
{
    
g_RenderTarget[id] = 0;
    
    
ClrBits(g_IsAimingPlayerid);
    
    if( !
g_IsAimingPlayer && g_fnAddToFullPack )
    {
        
unregister_forward(FM_AddToFullPackg_fnAddToFullPack1);
        
g_fnAddToFullPack 0;
    }

Don't know if this is better,.
Its not.
You update glow color when player hp is changed what is bad because if player fall, you update glow color but it is useless for this case because you dont show glow for floor right?
You need to update glow color only when player take dmg to ohter player.

Also i dont think its useful to register and unregister that "FM_AddToFullPack" forward.
It wont be getting called if there is no players in the server.
.Dare Devil. is offline
ezio_auditore
Senior Member
Join Date: May 2013
Old 01-16-2014 , 05:28   Re: hp based glow
Reply With Quote #3

Quote:
Originally Posted by .Dare Devil. View Post
Its not.
You update glow color when player hp is changed what is bad because if player fall, you update glow color but it is useless for this case because you dont show glow for floor right?
You need to update glow color only when player take dmg to ohter player.

Also i dont think its useful to register and unregister that "FM_AddToFullPack" forward.
It wont be getting called if there is no players in the server.
I am not glowing the floor or something

It glows user according to his/her HP and that only when we aim
__________________
ezio_auditore is offline
Send a message via Skype™ to ezio_auditore
.Dare Devil.
Veteran Member
Join Date: Sep 2010
Old 01-16-2014 , 07:24   Re: hp based glow
Reply With Quote #4

Quote:
Originally Posted by ezio_auditore View Post
I am not glowing the floor or something

It glows user according to his/her HP and that only when we aim
Or shoot right? Because when i tested your plugin, i had to shoot player to see glow.
My code is also working that way.
.Dare Devil. is offline
ezio_auditore
Senior Member
Join Date: May 2013
Old 01-17-2014 , 01:15   Re: hp based glow
Reply With Quote #5

Quote:
Originally Posted by .Dare Devil. View Post
Or shoot right? Because when i tested your plugin, i had to shoot player to see glow.
My code is also working that way.
not actually

It makes a player glow when you aim at him.

it just works fine
__________________
ezio_auditore is offline
Send a message via Skype™ to ezio_auditore
DavidJr
Senior Member
Join Date: Apr 2012
Old 01-07-2014 , 03:57   Re: hp based glow
Reply With Quote #6

I'd prefer to use stock.
__________________
What are you looking for here?
DavidJr is offline
ezio_auditore
Senior Member
Join Date: May 2013
Old 01-07-2014 , 11:15   Re: hp based glow
Reply With Quote #7

lol...

Dare.Devil, now you are confusing me more than my friend ConnorMcLeod.

Now i must make a competition to find out which is the 'better code'...

L L
__________________
ezio_auditore is offline
Send a message via Skype™ to ezio_auditore
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 01-07-2014 , 12:00   Re: hp based glow
Reply With Quote #8

Quote:
Originally Posted by ezio_auditore View Post
lol...

Dare.Devil, now you are confusing me more than my friend ConnorMcLeod.

Now i must make a competition to find out which is the 'better code'...

L L
Also, don't release something in which there are some code you don't understand or you can't support.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
.Dare Devil.
Veteran Member
Join Date: Sep 2010
Old 01-07-2014 , 11:34   Re: hp based glow
Reply With Quote #9

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <hamsandwich>
#include <cstrike> // cs_get_user_team ...

// 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_max
    
    
// Attacter is not player or attacter is doing dmg for herself
    // That last check i added is blocking team kill glow show
    
if( id == id2 || !is_user_connected(id2) || cs_get_user_team(id) == cs_get_user_team(id2) ) return
    
    
// Check if player have more hp somehow and update max health
    
update_maxhealth(id)
    
    
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 )
    
    
show_glowcolor[id2][0] = 255
    show_glowcolor
[id2][1] = 255
    show_glowcolor
[id2][2] = 255
    
for( 0ArraySize(color_maxpercent); a++ )
    {
        
percent_min ArrayGetCellcolor_minpercent)
        
percent_max ArrayGetCellcolor_maxpercent)
        if( 
percent >= percent_min && percent_max >= percent )
        {
            
show_glowcolor[id2][0] = ArrayGetCellglow_color[0], )
            
show_glowcolor[id2][1] = ArrayGetCellglow_color[1], )
            
show_glowcolor[id2][2] = ArrayGetCellglow_color[2], )
            break
        }
    }
}

public 
player_renderes_handleeenthosthostflagsplayerpSet 
{
    if( !
player || 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

I updated code a bit, it should be little bit better now
.Dare Devil. is offline
11922911
Senior Member
Join Date: Dec 2011
Location: Yuen Long Country
Old 01-07-2014 , 21:20   Re: hp based glow
Reply With Quote #10

Quote:
Originally Posted by .Dare Devil. View Post
Its not.
You update glow color when player hp is changed what is bad because if player fall, you update glow color but it is useless for this case because you dont show glow for floor right?
You need to update glow color only when player take dmg to ohter player.

Also i dont think its useful to register and unregister that "FM_AddToFullPack" forward.
It wont be getting called if there is no players in the server.
I was just confusing what is meant of 'hp based glow', and what I understood in his code is 'glow when aiming player'.
Whatever, I don't care anymore.
__________________
youtube:
@holla16

Last edited by 11922911; 01-07-2014 at 22:30.
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