Skip to content

Commit 2e8880a

Browse files
committed
Add a VGuiVscropt function
1. Add a client side vscript function void ForceSync() to CRD_VGui_VScript. This function discards all client predictions and force syncing with server. 2. Update traitors challenge to prevent frequently spawning vgui entities for data syncing.
1 parent f1ed077 commit 2e8880a

4 files changed

Lines changed: 21 additions & 13 deletions

File tree

reactivedrop/content/traitors_challenge/scripts/vscripts/challenge_traitors.nut

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -408,19 +408,18 @@ function RefreshMenu(hMarine) {
408408
foreach(tempMarine in g_marine_Total_Unshuffled) {
409409
i++;
410410
local strVGuiRefresh = "VGui_Refresh" + i.tostring();
411-
local hVGuiRefresh = Entities.FindByName(null, strVGuiRefresh);
412-
if (hVGuiRefresh != null) {
413-
hVGuiRefresh.Destroy();
414-
}
415-
hVGuiRefresh = Entities.CreateByClassname("rd_vgui_vscript");
416-
hVGuiRefresh.__KeyValueFromString("client_vscript", "challenge_traitors_client_refresh_menu.nut");
417-
hVGuiRefresh.ValidateScriptScope();
418-
hVGuiRefresh.GetScriptScope().Input <- Input;
419-
hVGuiRefresh.Spawn();
420-
hVGuiRefresh.SetName(strVGuiRefresh);
421-
hVGuiRefresh.Activate();
422-
hVGuiRefresh.SetEntity(0, hMarine);
423-
hVGuiRefresh.SetInteracter(null);
411+
local hVGuiRefresh = null;
412+
if (!(hVGuiRefresh = Entities.FindByName(hVGuiRefresh, strVGuiRefresh))) {
413+
hVGuiRefresh = Entities.CreateByClassname("rd_vgui_vscript");
414+
hVGuiRefresh.__KeyValueFromString("client_vscript", "challenge_traitors_client_refresh_menu.nut");
415+
hVGuiRefresh.ValidateScriptScope();
416+
hVGuiRefresh.GetScriptScope().Input <- Input;
417+
hVGuiRefresh.Spawn();
418+
hVGuiRefresh.SetName(strVGuiRefresh);
419+
hVGuiRefresh.Activate();
420+
hVGuiRefresh.SetEntity(0, hMarine);
421+
hVGuiRefresh.SetInteracter(null);
422+
}
424423

425424
hVGuiRefresh.SetInt(0, i);
426425
hVGuiRefresh.SetInt(1, (g_lst_MenuProps[i].scannerIsRevealed) ? g_lst_MenuProps[i].role : ROLE.NONE);

reactivedrop/content/traitors_challenge/scripts/vscripts/challenge_traitors_client_refresh_menu.nut

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ function Paint() {}
1818
function Control(tbl) {}
1919

2020
function OnUpdate() {
21+
self.ForceSync();
2122
local idx = self.GetInt(0);
2223
if (!("marine_info" in getconsttable())) {
2324
getconsttable()["marine_info"] <- [];

src/game/shared/swarm/rd_vgui_vscript_shared.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ END_NETWORK_TABLE();
4747

4848
BEGIN_ENT_SCRIPTDESC( CRD_VGui_VScript, CRD_HUD_VScript, "Alien Swarm: Reactive Drop scriptable interactive UI" )
4949
#ifdef CLIENT_DLL
50+
DEFINE_SCRIPTFUNC( ForceSync, "Discard all client predictions and force syncing with server." )
5051
DEFINE_SCRIPTFUNC( SendInput, "Sends a numeric input to the server." )
5152
DEFINE_SCRIPTFUNC( SetEntity, "Predict a change to the value of an entity parameter. (Only during Input.)" )
5253
DEFINE_SCRIPTFUNC( SetInt, "Predict a change to the value of an integer parameter. (Only during Input.)" )
@@ -224,6 +225,12 @@ CRD_VGui_VScript::~CRD_VGui_VScript()
224225
}
225226

226227
#ifdef CLIENT_DLL
228+
229+
inline void CRD_VGui_VScript::ForceSync()
230+
{
231+
ResetPrediction();
232+
}
233+
227234
void CRD_VGui_VScript::SendInput( int value )
228235
{
229236
if ( !m_bIsControlling )

src/game/shared/swarm/rd_vgui_vscript_shared.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class CRD_VGui_VScript : public CRD_HUD_VScript
2525
#ifdef CLIENT_DLL
2626
static CUtlVector<CRD_VGui_VScript *> s_InteractiveHUDEntities;
2727

28+
void ForceSync();
2829
void SendInput( int value );
2930
void SetEntity( int i, HSCRIPT entity );
3031
void SetInt( int i, int value );

0 commit comments

Comments
 (0)