Raised This Month: $51 Target: $400
 12% 

[HELP] Static bartime


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
bat
Veteran Member
Join Date: Jul 2012
Old 08-22-2014 , 16:58   [HELP] Static bartime
Reply With Quote #1

Hello World. Just one question can I make static bartime?

More descriptive: When i look on survivor i see bartime with loading, but i need bartime with his health.

Start code...
Code:
#include <amxmodx>
#include <zombieplague>

new g_MaxHealth[33]

public plugin_init()
{
	register_event("StatusValue", "client", "be", "1=2", "2!0")

}

public zp_user_humanized_post(id, Sur)
{
	if(Sur) g_MaxHealth[id] = get_user_health(id)
}

public client(id)
{	
	static BarTime2; if(!BarTime2) BarTime2 = get_user_msgid("BarTime2")
	
	if(is_user_alive(id) && zp_get_user_zombie(id))
	{
                new pid = read_data(2)
		if (zp_get_user_survivor(pid))
		{
                   static MyHealth, MaxHealth, Percent
		   MyHealth = get_user_health(pid)
		   MaxHealth = g_MaxHealth[pid]
		   Percent = (MyHealth / MaxHealth) * 100
		
		   message_begin(MSG_ONE_UNRELIABLE, BarTime2, _, id)
		   write_short(1)
		   write_short(clamp(Percent, 0, 100))
		   message_end()
                }
	}  
}
__________________

Last edited by bat; 08-22-2014 at 16:59. Reason: delete one include
bat is offline
Send a message via Skype™ to bat
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 08-23-2014 , 10:58   Re: [HELP] Static bartime
Reply With Quote #2

I found a code snippet that I wrote a year and 4 months ago:
PHP Code:
#include <amxmodx>
#include <fakemeta>

#define PLUGIN "Status Bar"
#define VERSION "1.0"
#define AUTHOR "KliPPy"

new const g_classname[] = "barent";

new 
status = -1;
new 
g_msgBarTime;
new 
g_maxplayers;

public 
plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("oduzmi""cmdOduzmi");
    
register_clcmd("say pocni""cmdPocni");
    
    
g_msgBarTime get_user_msgid("BarTime2");
    
    new 
ent engfunc(EngFunc_CreateNamedEntityengfunc(EngFunc_AllocString"info_target"));
    
set_pev(entpev_classnameg_classname);
    
set_pev(entpev_nextthink3.0);
    
register_forward(FM_Think"fwThink");
    
    
g_maxplayers get_maxplayers();
}

public 
cmdOduzmi()
    
status -= 1

public cmdPocni()
    
status 99;

public 
fwThink(ent)
{
    if(!
pev_valid(ent))
        return 
FMRES_IGNORED;
        
    static 
szClassname[32];
    
pev(entpev_classnameszClassnamecharsmax(szClassname));
    if(!
equal(szClassnameg_classname))
        return 
FMRES_IGNORED;
        
    for(new 
0g_maxplayersi++)
    {
        if(!
is_user_alive(i) || !is_user_connected(i))
            continue;
            
        
message_begin(MSG_ONEg_msgBarTime_i)
        
write_short(10000);
        
write_short(status);
        
message_end();
    }
    
    
set_pev(entpev_nextthinkget_gametime() + 0.5);
    
    return 
FMRES_IGNORED;

(Don't you dare to critique coding style and inefficiency, it all was written quickly for testing purposes).
I hope you can see what have I done in here to keep the bar static, and you should use 65535 in write_short() instead of 10000(again, it was all for testing purposes so I input a random number), than you can update it even slower than 0.5 seconds I think.
And I am curious right now, why did VALVe put second parameter as short instead of byte, since you shouldn't go over 100(percents) anyway.

Last edited by klippy; 08-23-2014 at 10:59.
klippy 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 13:19.


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