Raised This Month: $ Target: $400
 0% 

Health HUD


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Gadzislaw007
Senior Member
Join Date: Nov 2009
Old 07-26-2010 , 05:02   Re: Health HUD
Reply With Quote #1

Code:
#include <amxmodx>
#include <fakemeta>
 
#define UPDATE_INTERVAL 0.3 //time in seconds between hud msg updates
#define RED 255 //hud msg red
#define GREEN 255 //hud msg green
#define BLUE 255 //hud msg blue

#define TID_TIMER 5155

new g_HSO
new g_timer_entid
new Float:g_t_time
new g_max_players

public plugin_init(){
    register_plugin("RealHealthDisplay", "1.0", "Sylwester")
    g_max_players = get_maxplayers()
    create_timer()
    g_HSO = CreateHudSyncObj()
}
 
public create_timer(){
    g_timer_entid = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString,"info_target"))
    for(new i=1; i<4; i++){
        if(pev_valid(g_timer_entid)){
            break
        }else{
            log_amx("Warning: Failed to create timer entity, retrying(%d)", i)
            g_timer_entid = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString,"info_target"))
        }
    }

    if(pev_valid(g_timer_entid)){
        set_pev(g_timer_entid, pev_classname, "hp_display_timer")
        global_get(glb_time, g_t_time)
        set_pev(g_timer_entid, pev_nextthink, g_t_time + UPDATE_INTERVAL)
        register_forward(FM_Think,"fwd_Think")
    }else{
        log_amx("Warning: Failed to create timer entity, using task instead")
        set_task(UPDATE_INTERVAL, "timer_cycle", TID_TIMER, "", 0, "b")
    }
}

public fwd_Think(Ent){
    if(Ent != g_timer_entid)
        return FMRES_IGNORED
    g_t_time += UPDATE_INTERVAL
    set_pev(Ent, pev_nextthink, g_t_time)
    timer_cycle()
    return FMRES_IGNORED
}

public timer_cycle(){
    for(new i=1; i<g_max_players; i++)
        if(is_user_alive(i))
            display_health(i)
}

public display_health(id){
    static msg[64]
    set_hudmessage(RED, GREEN, BLUE, -1.0, 0.9, _, _, UPDATE_INTERVAL, _, _, -1)
    format(msg, 63, "Health: %d", get_user_health(id))
    set_hudmessage(255, 255, 255, 0.30, 0.88, 0, 6.0, 12.0)
    ShowSyncHudMsg(id, g_HSO, msg)
    
}
Try this.

Last edited by Gadzislaw007; 07-26-2010 at 05:06.
Gadzislaw007 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 00:07.


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