Raised This Month: $32 Target: $400
 8% 

Displaying GetClientHealth in SendDialogToOne


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Allan Button
New Member
Join Date: Jan 2009
Old 01-11-2009 , 14:23   Displaying GetClientHealth in SendDialogToOne
Reply With Quote #1

Hello,

We are running some mods on our TF2 server, that gives players a starting health of well over the normal limits. This makes it hard to see what your health actually is, because it seems to wrap.

I wrote this plugin ( mostly copy and paste ) to display the health in the top left " tsay " area. but it looks like it is updating way to slowly. I have it set on default to update every second, but it looks like it is always 5 seconds behind. Really, I would like to do this update every .1 second to make it look almost realtime. But I am not sure if this would stress the server at all.

I've posted my code, hoping somebody could help me make this so it would work realtime. I've used the Hint area, which looks like it updates faster, but it makes that anoying sound everytime. I would be fine putting it there, But I don't know how to remove the sound! And the Menu area, that would be bad because we use menus for a lot of other things.

If anybody has a minute to help, that would be great!
Thanks,
Allan Button

Code:
#include <sourcemod>

new Handle:g_hInterval;
new Handle:g_hTimer;
new g_Colors[13][3] = {{255,255,255},{255,0,0},{0,255,0},{0,0,255},{255,255,0},{255,0,255},{0,255,255},{255,128,0},{255,0,128},{128,255,0},{0,255,128},{128,0,255},{0,128,255}};

#define PLUGIN_VERSION "0.3.3"

public Plugin:myinfo = {
    name = "HP HUD",
    author = "Allan Button",
    description = "Provides a HUD for how much health you have",
    version = PLUGIN_VERSION,
    url = "http://www.idlecode.com/"
};

public OnPluginStart()
{
    CreateConVar("sm_hphud", PLUGIN_VERSION, "hphud version", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY)
    g_hInterval       = CreateConVar("sm_hphud_interval", "1",                 "How often to update the hsay.");
    HookConVarChange(g_hInterval, ConVarChange_Interval);
}

public OnMapStart() {
    g_hTimer          = CreateTimer(GetConVarInt(g_hInterval) * 1.0, Timer_ShowInfo, _, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
}

public Action:Timer_ShowInfo(Handle:timer) {


    for (new i = 1, iClients = GetClientCount(); i <= iClients; i++) {
        if (IsClientInGame(i) && !IsFakeClient(i)) {
            //PrintHintText(i, "Health: %d", GetClientHealth(i));
            SendDialogToOne(i, 0, "Health: %d", GetClientHealth(i));
        }
    }


    return Plugin_Continue
}
public ConVarChange_Interval(Handle:convar, const String:oldValue[], const String:newValue[]) {
    if (g_hTimer != INVALID_HANDLE) {
        KillTimer(g_hTimer);
    }
    
    g_hTimer          = CreateTimer(GetConVarInt(g_hInterval) * 1.0, Timer_ShowInfo, _, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
}
SendDialogToOne(client, color, String:text[], any:...)
{
    new String:message[100];
    VFormat(message, sizeof(message), text, 4);    
    
    new Handle:kv = CreateKeyValues("Stuff", "title", message);
    KvSetColor(kv, "color", g_Colors[color][0], g_Colors[color][1], g_Colors[color][2], 255);
    KvSetNum(kv, "level", 1);
    KvSetNum(kv, "time", 10);
    
    CreateDialog(client, kv, DialogType_Msg);
    
    CloseHandle(kv);    
}
Allan Button is offline
HL-SDK
Member
Join Date: Jan 2009
Old 01-11-2009 , 16:14   Re: Displaying GetClientHealth in SendDialogToOne
Reply With Quote #2

KvSetNum(kv, "time", 10);
If that is time to display for, since you are redisplaying it very quickly, I'd make that value smaller as well to test.

Also, in the beginning of your code after the includes, I've always declared handles initially as INVALID_HANDLE

Tis all I can provide
HL-SDK is offline
Allan Button
New Member
Join Date: Jan 2009
Old 01-11-2009 , 17:31   Re: Displaying GetClientHealth in SendDialogToOne
Reply With Quote #3

Thanks HL,

It looks like Hint is the fastest to update. I tryed to copy and paste the Hud display text from the Spray plugin, it compiles, but nothing it displayed. And it made it laggy.

I wonder if its possible to remove the hint sound, as it is anoying as hell!
Allan Button is offline
HL-SDK
Member
Join Date: Jan 2009
Old 01-17-2009 , 16:27   Re: Displaying GetClientHealth in SendDialogToOne
Reply With Quote #4

Also, bump, also, send me your source for latest plugin or ftp it up.


ShowSyncHudText(client, Handle:sync, const String:message, any:...);

Pulled from the API.

So I'm thinking we need to: hHudSync = Handle:CreateHudSynchronizer();

Then either with a timer and do this to all clients, or trigger on player_hurt to the individual clients.

ShowSyncHudText(client, hHudSync, "Yuo gotz %d hps still!", clientHP);

IT looks like it would be best to put in a timer that fires around .5-1 sec, but that can be CVAR'd. Every time the timer fires, we can for 1 through MAXPLAYERS update hHudSync for i, which in this case would be 1 through 18 in our case IIRC.

Would need to get the client's hp in that loop too, oh and also ClearSyncHud before ShowSyncHud might be needed so a clean slate is started with.

Code:
 for(i = 1; i<= maxplayers; i++) 
     {
         if(!IsClientInGame(i) || IsFakeClient(i)) 
            {
                continue;
            }
 
            new clientHP = GetClientHealth(i);
            SetHudTextParams(0.04, 0.4, 1.0, 255, 50, 50, 255);
            ClearSyncHud(i, hHudSync);
            ShowSyncHudText(i, hHudSync, "Your HP is: %d", clientHP);
     }
Vets, feel free to look over this, I haven't compiled it or anything. This code assumes you have created a sync object called hHudSync


---
EDIT

Plugin is completed and working

Last edited by HL-SDK; 01-17-2009 at 21:47.
HL-SDK is offline
Reply


Thread Tools
Display Modes

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 19:57.


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