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

Displaying vscript


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
kahdeg
Junior Member
Join Date: Oct 2021
Old 10-25-2021 , 07:08   Displaying vscript
Reply With Quote #1

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_RunVscriptADMFLAG_ROOT);
    
    
char sPath[PLATFORM_MAX_PATH];
    
strcopy(sPathsizeof(sPath), "scripts/vscripts");
    if (
DirExists(sPath) == false)
    {
        
CreateDirectory(sPath511);
    }
    
    
Format(sPath_VscriptHUDsizeof(sPath_VscriptHUD), "scripts/vscripts/testvs.nut");
    if (
FileExists(sPath_VscriptHUD) == false || FileSize(sPath_VscriptHUD) == 0)
    {
        
SaveVscriptHUD();
    }
    
    
CreateTimer(1.0UpdateKillFeed_TIMER_REPEAT);
}

/**
* Callback method for the command toggle display
*/
public Action Command_ToggleDisplay(int clientint args) {
    
    
//ClientSpeaking[client] = !ClientSpeaking[client];
    
    
killFeedChanged = !killFeedChanged;
    
    return 
Plugin_Handled;
}

public 
Action Command_RunVscript(int clientint args)
{
    if (
args 1)
    {
        return 
Plugin_Handled;
    }
    
    
char vscriptFile[40];
    
GetCmdArg(1vscriptFilesizeof(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[] formatany...)
{
    
char buffer[200];
    
VFormat(buffersizeof(buffer), format2);
    
    
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);
    }

kahdeg is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 10-25-2021 , 08:16   Re: Displaying vscript
Reply With Quote #2

From my personal experience, you may have some addon installed that replaces the "coop.nut" file. (e.g: "Admin System" addon by Rayman1103)

May worth checking these threads.
__________________

Last edited by Marttt; 10-25-2021 at 08:16.
Marttt 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:23.


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