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.
This commit is contained in:
emmie 2023-09-11 03:20:11 +00:00 committed by Kiri
parent 333c40e46a
commit f4bf7a793e

View File

@ -322,8 +322,12 @@ class SnekTechSprayer : HDWeapon
int newIndex = (currentIndex + 1) % patternList.size(); int newIndex = (currentIndex + 1) % patternList.size();
// Set the new CVar. // Set the new CVar.
CVar.GetCVar("snektech_spraypattern", owner.player).SetString(patternList[newIndex]); currentPattern = patternList[newIndex];
currentPattern = CVar.GetCVar("snektech_spraypattern", owner.player).GetString(); // 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); owner.A_Log("Selected spray pattern: "..currentPattern, true);
// Current pattern is referenced in the help text, so reset // Current pattern is referenced in the help text, so reset