PHP Code:
#include <sourcemod>
#include <sdktools>
int g_iEnt = -1;
public void OnPluginStart()
{
RegAdminCmd("sm_hudtext", Hud, ADMFLAG_CONFIG);
}
public void OnMapStart()
{
g_iEnt = -1;
}
public Action Hud(int client, int args)
{
if (args < 2)
{
ReplyToCommand(client, "[SM]Usage: !hud <player> <message> [OPTIONALS -->] <size 1 - 3> <red (RGB)> <green (RGB)> <blue (RGB)> <x pos> <y pos> <hold time> <fadein time> <fateout time>");
return Plugin_Handled;
}
char arg[64];
GetCmdArg(1, arg, sizeof(arg));
char target_name[MAX_TARGET_LENGTH];
int target_list[MAXPLAYERS], target_count;
bool tn_is_ml;
target_count = ProcessTargetString(arg, client, target_list, MAXPLAYERS, COMMAND_FILTER_CONNECTED, target_name, sizeof(target_name), tn_is_ml);
if (target_count <= 0)
{
ReplyToCommand(client, "Target invalid");
return Plugin_Handled;
}
char arg2[32];
GetCmdArg(2, arg2, sizeof(arg2));
int arg3 = GetCmdArgInt(3);
int arg4 = GetCmdArgInt(4);
int arg5 = GetCmdArgInt(5);
int arg6 = GetCmdArgInt(6);
float arg7 = GetCmdArgFloat(7);
float arg8 = GetCmdArgFloat(8);
float arg9 = GetCmdArgFloat(9);
float arg10 = GetCmdArgFloat(10);
float arg11 = GetCmdArgFloat(11);
for (int i = 0; i < target_count; i++)
{
PrintToHud(target_list[i], arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11);
}
return Plugin_Handled;
}
int GetCmdArgInt(int arg)
{
char sBuffer[32];
GetCmdArg(arg, sBuffer, sizeof(sBuffer));
return StringToInt(sBuffer);
}
float GetCmdArgFloat(int arg)
{
char sBuffer[32];
GetCmdArg(arg, sBuffer, sizeof(sBuffer));
return StringToFloat(sBuffer);
}
int PrintToHud(int client, const char[] message, int size = 2, int red = 255, int green = 255, int blue = 255, float x = -1.0, float y = -1.0, float holdtime = 5.0, float fadeintime = 1.0, float fadeouttime = 1.0)
{
if(g_iEnt == -1)
{
g_iEnt = CreateEntityByName("game_text");
}
char color[32];
Format(color, sizeof(color), "%i %i %i", red, green, blue);
if (size == 1)
size = 2;
else if (size == 2)
size = 1;
char channel[32];
char fadein[32];
char fadeout[32];
char sholdtime[32];
char sy[32];
char sx[32];
IntToString(size, channel, sizeof(channel));
FloatToString(fadeintime, fadein, sizeof(fadein));
FloatToString(fadeouttime, fadeout, sizeof(fadeout));
FloatToString(holdtime, sholdtime, sizeof(sholdtime));
FloatToString(y, sy, sizeof(sy));
FloatToString(x, sx, sizeof(sx));
DispatchKeyValue(g_iEnt, "channel", channel);
DispatchKeyValue(g_iEnt, "color", color);
DispatchKeyValue(g_iEnt, "color2", "0 0 0");
DispatchKeyValue(g_iEnt, "effect", "0");
DispatchKeyValue(g_iEnt, "fadein", fadein);
DispatchKeyValue(g_iEnt, "fadeout", fadeout);
DispatchKeyValue(g_iEnt, "fxtime", "0.25");
DispatchKeyValue(g_iEnt, "holdtime", sholdtime);
DispatchKeyValue(g_iEnt, "message", message);
DispatchKeyValue(g_iEnt, "spawnflags", "0");
DispatchKeyValue(g_iEnt, "x", sx);
DispatchKeyValue(g_iEnt, "y", sy);
DispatchKeyValue(g_iEnt, "OnUser1", "!self,Kill,,2.0,-1");
AcceptEntityInput(g_iEnt, "FireUser1");
DispatchSpawn(g_iEnt);
SetVariantString("!activator");
return AcceptEntityInput(g_iEnt, "display", client);
}