From f4bf7a793ee9b85fdf32862c17f4d6385c283f75 Mon Sep 17 00:00:00 2001 From: emmie Date: Mon, 11 Sep 2023 03:20:11 +0000 Subject: [PATCH] spraycan: fix cvar not being updated properly GetCVar returns a per-player copy of the requested cvar, which is only used to have separate values for each player - changes are propagated To it, but not From it. writing to this cvar is only useful if you know what the actual new value is going to be & want the cvar to update Immediately. (in this case, the cvar needs to be updated before A_SetHelpText so the displayed spray name is correct) FindCVar returns the actual cvar for the local player. changes to this cvar Are propagated to other clients. --- zscript/spraycan.zs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/zscript/spraycan.zs b/zscript/spraycan.zs index 6d894b3..08cb591 100644 --- a/zscript/spraycan.zs +++ b/zscript/spraycan.zs @@ -322,8 +322,12 @@ class SnekTechSprayer : HDWeapon int newIndex = (currentIndex + 1) % patternList.size(); // Set the new CVar. - CVar.GetCVar("snektech_spraypattern", owner.player).SetString(patternList[newIndex]); - currentPattern = CVar.GetCVar("snektech_spraypattern", owner.player).GetString(); + currentPattern = patternList[newIndex]; + // first, update the Actual cvar + if (owner.PlayerNumber() == consoleplayer) + CVar.FindCVar("snektech_spraypattern").SetString(currentPattern); + // then update the per-player copy so the help text is correct + CVar.GetCVar("snektech_spraypattern", owner.player).SetString(currentPattern); owner.A_Log("Selected spray pattern: "..currentPattern, true); // Current pattern is referenced in the help text, so reset