AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   hp based glow (https://forums.alliedmods.net/showthread.php?t=232866)

ezio_auditore 01-06-2014 01:24

hp based glow
 
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

DavidJr 01-06-2014 01:30

Re: hp based glow
 
You just need to optimize it

I didn't made it, I just help giving two brackets :3

ezio_auditore 01-06-2014 01:34

Re: hp based glow
 
how...

i want ConnorMcLeod to see it suggest a way if there is one

11922911 01-06-2014 01:44

Re: hp based glow
 
As Connor said, learn more and you will able to do it.

ezio_auditore 01-06-2014 01:47

Re: hp based glow
 
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

.Dare Devil. 01-06-2014 13:45

Re: hp based glow
 
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
:


ConnorMcLeod 01-06-2014 15:06

Re: hp based glow
 
His previous code is better than... this

.Dare Devil. 01-06-2014 15:31

Re: hp based glow
 
Quote:

Originally Posted by ConnorMcLeod (Post 2082136)
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 )

11922911 01-07-2014 00:49

Re: hp based glow
 
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,.

ezio_auditore 01-07-2014 01:45

Re: hp based glow
 
Quote:

Originally Posted by ConnorMcLeod (Post 2082136)
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"


All times are GMT -4. The time now is 10:13.

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