New Member
|
01-11-2009
, 14:23
Displaying GetClientHealth in SendDialogToOne
|
#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);
}
|
|