From b0cf4c6dd97724dabf844d02e0e3252e9bf86655 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 6 May 2020 06:34:03 +1000 Subject: [PATCH] Improve reliability of giving buffs via triggers, fixes some odd cases involving the wrong buffs being given --- qcsrc/common/t_items.qc | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/qcsrc/common/t_items.qc b/qcsrc/common/t_items.qc index 6f385cdb4..7dccf97a2 100644 --- a/qcsrc/common/t_items.qc +++ b/qcsrc/common/t_items.qc @@ -1619,28 +1619,36 @@ float GiveWeapon(entity e, float wpn, float op, float val) bool GiveBuff(entity e, Buff thebuff, int op, int val) { bool had_buff = (STAT(BUFFS, e) & thebuff.m_itemid); + float new_buff_time = ((had_buff) ? STAT(BUFF_TIME, e) : 0); switch (op) { case OP_SET: - STAT(BUFF_TIME, e) = val; + new_buff_time = val; break; case OP_MIN: - STAT(BUFF_TIME, e) = max(STAT(BUFF_TIME, e), val); + new_buff_time = max(new_buff_time, val); break; case OP_MAX: - STAT(BUFF_TIME, e) = min(STAT(BUFF_TIME, e), val); + new_buff_time = min(new_buff_time, val); break; case OP_PLUS: - STAT(BUFF_TIME, e) += val; + new_buff_time += val; break; case OP_MINUS: - STAT(BUFF_TIME, e) -= val; + new_buff_time -= val; break; } - if(STAT(BUFF_TIME, e) <= 0) + if(new_buff_time <= 0) + { + if(had_buff) + STAT(BUFF_TIME, e) = new_buff_time; STAT(BUFFS, e) &= ~thebuff.m_itemid; + } else + { + STAT(BUFF_TIME, e) = new_buff_time; STAT(BUFFS, e) = thebuff.m_itemid; // NOTE: replaces any existing buffs on the player! + } bool have_buff = (STAT(BUFFS, e) & thebuff.m_itemid); return (had_buff != have_buff); } -- 2.39.2