I was trying to make a l4d2 killfeed.
In below code is a minimal code that should display "test" on the top right of the screen.
When i test it with the tumtara map, the "test" is displayed.
When i test it with a normal campaign map like c1m1, no text "test" is displayed.
Is there anything wrong with my below implementation or is there any specific thing i need to watch out when working with vscript?
Thanks.
PHP Code:
#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#include <sdktools>
#define PLUGINS_NAME "test_vs"
#define PLUGIN_VERSION "1.0"
bool killFeedChanged = false;
char sPath_VscriptHUD[PLATFORM_MAX_PATH];
public Plugin myinfo =
{
name = PLUGINS_NAME,
author = "kahdeg",
description = "Player killfeed List in Hud",
version = PLUGIN_VERSION,
url = "n/a"
}
public void OnPluginStart()
{
RegConsoleCmd("sm_kf_toggle_display", Command_ToggleDisplay, "Toggle display killfeed");
RegAdminCmd("sm_kf_runvscript", Command_RunVscript, ADMFLAG_ROOT);
char sPath[PLATFORM_MAX_PATH];
strcopy(sPath, sizeof(sPath), "scripts/vscripts");
if (DirExists(sPath) == false)
{
CreateDirectory(sPath, 511);
}
Format(sPath_VscriptHUD, sizeof(sPath_VscriptHUD), "scripts/vscripts/testvs.nut");
if (FileExists(sPath_VscriptHUD) == false || FileSize(sPath_VscriptHUD) == 0)
{
SaveVscriptHUD();
}
CreateTimer(1.0, UpdateKillFeed, _, TIMER_REPEAT);
}
/**
* Callback method for the command toggle display
*/
public Action Command_ToggleDisplay(int client, int args) {
//ClientSpeaking[client] = !ClientSpeaking[client];
killFeedChanged = !killFeedChanged;
return Plugin_Handled;
}
public Action Command_RunVscript(int client, int args)
{
if (args < 1)
{
return Plugin_Handled;
}
char vscriptFile[40];
GetCmdArg(1, vscriptFile, sizeof(vscriptFile));
int entity = CreateEntityByName("logic_script");
if (entity != -1)
{
DispatchKeyValue(entity, "vscripts", vscriptFile);
DispatchSpawn(entity);
SetVariantString("OnUser1 !self:RunScriptCode::0:-1");
AcceptEntityInput(entity, "AddOutput");
SetVariantString("OnUser1 !self:Kill::1:-1");
AcceptEntityInput(entity, "AddOutput");
AcceptEntityInput(entity, "FireUser1");
}
return Plugin_Handled;
}
public Action UpdateKillFeed(Handle timer)
{
if (killFeedChanged) {
PrintToChatAll("update kf");
UpdateDatavalHUD("test");
ServerCommand("sm_kf_runvscript testvs");
//ServerCommand("script_execute testvs.nut"); //Try this if the previous command does not work
}
else
{
PrintToChatAll("clear kf");
ResetHUD();
ServerCommand("sm_kf_runvscript testvs");
//ServerCommand("script_execute testvs.nut"); //Try this if the previous command does not work
}
}
void UpdateDatavalHUD(const char[] format, any...)
{
char buffer[200];
VFormat(buffer, sizeof(buffer), format, 2);
SaveVscriptHUD(buffer);
}
void ResetHUD()
{
SaveVscriptHUD();
}
void SaveVscriptHUD(const char[] dataval = "")
{
Handle hFile = OpenFile(sPath_VscriptHUD, "w");
if (hFile)
{
WriteFileLine(hFile, "ModeHUD <-");
WriteFileLine(hFile, "{");
WriteFileLine(hFile, " Fields = ");
WriteFileLine(hFile, " {");
if (!StrEqual(dataval, "", false))
{
WriteFileLine(hFile, " killfeed = ");
WriteFileLine(hFile, " {");
WriteFileLine(hFile, " slot = g_ModeScript.HUD_MID_BOX,");
WriteFileLine(hFile, " dataval = \"test\",", dataval);
WriteFileLine(hFile, " flags = g_ModeScript.HUD_FLAG_ALIGN_LEFT | g_ModeScript.HUD_FLAG_NOBG,");
WriteFileLine(hFile, " name = \"killfeed\" ");
WriteFileLine(hFile, " }");
}
WriteFileLine(hFile, " }");
WriteFileLine(hFile, "}");
WriteFileLine(hFile, "");
WriteFileLine(hFile, "HUDSetLayout( ModeHUD )");
if (!StrEqual(dataval, "", false))
{
WriteFileLine(hFile, "HUDPlace( g_ModeScript.HUD_MID_BOX , 0.75 , 0.0 , 0.25 , 0.1 )");
}
WriteFileLine(hFile, "g_ModeScript");
CloseHandle(hFile);
}
}