]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/mutators/mutator/buffs/sv_buffs.qc
Apply strength sound and buff shield stats to the entity directly rather than player...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mutators / mutator / buffs / sv_buffs.qc
index 50b5d91b50dba9d844b301ea1586319e6e13f662..c2eb01618d5e62828b62b8246b48fb0e2088b2d0 100644 (file)
@@ -1,26 +1,18 @@
 #include "sv_buffs.qh"
 
 #include <common/mapobjects/target/music.qh>
+#include <common/mutators/mutator/powerups/_mod.qh>
 #include <common/gamemodes/_mod.qh>
 #include <server/items/items.qh>
 
-void buffs_DelayedInit(entity this);
-
-AUTOCVAR(g_buffs, int, -1, "Enable buffs, -1: enabled but no auto location or replacing powerups, 1: enabled and can replace them");
-
-REGISTER_MUTATOR(buffs, autocvar_g_buffs)
-{
-       MUTATOR_ONADD
-       {
-               if(autocvar_g_buffs > 0)
-                       InitializeEntity(NULL, buffs_DelayedInit, INITPRIO_FINDTARGET);
-       }
-}
-
 bool buffs_BuffModel_Customize(entity this, entity client)
 {
        entity player = WaypointSprite_getviewentity(client);
        entity myowner = this.owner;
+       entity heldbuff = buff_FirstFromFlags(myowner);
+
+       if(!heldbuff)
+               return false;
 
        if(myowner.alpha <= 0.5 && DIFF_TEAM(player, myowner) && myowner.alpha != 0)
                return false;
@@ -37,11 +29,49 @@ bool buffs_BuffModel_Customize(entity this, entity client)
        else
        {
                this.effects = EF_FULLBRIGHT | EF_LOWPRECISION;
-               this.alpha = 1;
+               this.alpha = myowner.alpha;
        }
        return true;
 }
 
+void buffs_BuffModel_Think(entity this)
+{
+       this.nextthink = time;
+       entity player = this.owner;
+       if(player.alpha < 0 || player.buff_model != this)
+       {
+               if(player) // remnant from ChatBubbleThink, same question... WHY?!
+                       player.buff_model = NULL;
+               delete(this);
+               return;
+       }
+
+       entity heldbuff = buff_FirstFromFlags(player);
+
+       if(!heldbuff)
+       {
+               this.effects = EF_NODRAW;
+               return;
+       }
+
+       this.color = heldbuff.m_color;
+       this.glowmod = heldbuff.m_color;
+       this.skin = heldbuff.m_skin;
+
+       this.effects = player.effects;
+       this.effects |= EF_LOWPRECISION;
+       this.effects = this.effects & EFMASK_CHEAP; // eat performance
+
+       this.alpha = player.alpha;
+}
+
+void buffs_BuffModel_Remove(entity player)
+{
+       if(player.buff_model)
+               delete(player.buff_model);
+       player.buff_model = NULL;
+}
+
 void buffs_BuffModel_Spawn(entity player)
 {
        player.buff_model = new(buff_model);
@@ -50,23 +80,22 @@ void buffs_BuffModel_Spawn(entity player)
        setattachment(player.buff_model, player, "");
        setorigin(player.buff_model, '0 0 1' * (player.buff_model.maxs.z * 1));
        player.buff_model.owner = player;
+       player.buff_model.exteriormodeltoclient = player;
        player.buff_model.scale = 0.7;
        player.buff_model.pflags = PFLAGS_FULLDYNAMIC;
        player.buff_model.light_lev = 200;
+       setthink(player.buff_model, buffs_BuffModel_Think);
+       player.buff_model.nextthink = time;
        setcefc(player.buff_model, buffs_BuffModel_Customize);
 }
 
-void buffs_BuffModel_Remove(entity player)
-{
-       if(player.buff_model)
-               delete(player.buff_model);
-       player.buff_model = NULL;
-}
-
-vector buff_GlowColor(entity buff)
+void buffs_BuffModel_Update(entity this)
 {
-       //if(buff.team) { return Team_ColorRGB(buff.team); }
-       return buff.m_color;
+       if (this.alpha < 0)
+               return;
+       // spawn a buff model entity if needed
+       if (!this.buff_model)
+               buffs_BuffModel_Spawn(this);
 }
 
 void buff_Effect(entity player, string eff)
@@ -83,12 +112,13 @@ void buff_Effect(entity player, string eff)
 // buff item
 bool buff_Waypoint_visible_for_player(entity this, entity player, entity view)
 {
-       if(!this.owner.buff_active && !this.owner.buff_activetime)
+       if(!this.owner.buff_active && !this.owner.buff_activetime || !this.owner.buffdef)
                return false;
 
-       if (STAT(BUFFS, view))
+       entity heldbuff = buff_FirstFromFlags(view); // TODO: cache this information so it isn't performing a loop every frame
+       if (heldbuff) 
        {
-               return CS(view).cvar_cl_buffs_autoreplace == false || STAT(BUFFS, view) != STAT(BUFFS, this.owner);
+               return CS_CVAR(view).cvar_cl_buffs_autoreplace == false || heldbuff != this.owner.buffdef;
        }
 
        return WaypointSprite_visible_for_player(this, player, view);
@@ -98,7 +128,7 @@ void buff_Waypoint_Spawn(entity e)
 {
        if(autocvar_g_buffs_waypoint_distance <= 0) return;
 
-       entity buff = buff_FirstFromFlags(STAT(BUFFS, e));
+       entity buff = e.buffdef;
        entity wp = WaypointSprite_Spawn(WP_Buff, 0, autocvar_g_buffs_waypoint_distance, e, '0 0 1' * e.maxs.z, NULL, e.team, e, buff_waypoint, true, RADARICON_Buff);
        wp.wp_extra = buff.m_id;
        WaypointSprite_UpdateTeamRadar(e.buff_waypoint, RADARICON_Buff, e.glowmod);
@@ -177,24 +207,27 @@ void buff_Touch(entity this, entity toucher)
        if((this.team && DIFF_TEAM(toucher, this))
        || (STAT(FROZEN, toucher))
        || (toucher.vehicle)
-       || (time < PS(toucher).buff_shield)
+       || (!this.buffdef) // TODO: error out or maybe reset type if this occurs?
+       || (time < toucher.buff_shield)
        )
        {
                // can't touch this
                return;
        }
 
-       if (STAT(BUFFS, toucher))
+       entity heldbuff = buff_FirstFromFlags(toucher);
+       entity thebuff = this.buffdef;
+
+       if (heldbuff)
        {
-               if (CS(toucher).cvar_cl_buffs_autoreplace && STAT(BUFFS, toucher) != STAT(BUFFS, this))
+               if (CS_CVAR(toucher).cvar_cl_buffs_autoreplace && heldbuff != thebuff)
                {
                        // TODO: lost-gained notification for this case
-                       int buffid = buff_FirstFromFlags(STAT(BUFFS, toucher)).m_id;
+                       int buffid = heldbuff.m_id;
                        Send_Notification(NOTIF_ONE, toucher, MSG_INFO, INFO_ITEM_BUFF_LOST, toucher.netname, buffid);
                        if(!IS_INDEPENDENT_PLAYER(toucher))
                                Send_Notification(NOTIF_ALL_EXCEPT, toucher, MSG_INFO, INFO_ITEM_BUFF_LOST, toucher.netname, buffid);
 
-                       STAT(BUFFS, toucher) = 0;
                        //sound(toucher, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM);
                }
                else { return; } // do nothing
@@ -203,23 +236,27 @@ void buff_Touch(entity this, entity toucher)
        this.owner = toucher;
        this.buff_active = false;
        this.lifetime = 0;
-       entity thebuff = buff_FirstFromFlags(STAT(BUFFS, this));
        Send_Notification(NOTIF_ONE, toucher, MSG_MULTI, ITEM_BUFF_GOT, thebuff.m_id);
        if(!IS_INDEPENDENT_PLAYER(toucher))
                Send_Notification(NOTIF_ALL_EXCEPT, toucher, MSG_INFO, INFO_ITEM_BUFF, toucher.netname, thebuff.m_id);
 
        Send_Effect(EFFECT_ITEM_PICKUP, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
        sound(toucher, CH_TRIGGER, SND_SHIELD_RESPAWN, VOL_BASE, ATTN_NORM);
-       STAT(BUFFS, toucher) |= (STAT(BUFFS, this));
-       STAT(LAST_PICKUP, toucher) = time;
-       float bufftime = ((this.count) ? this.count : thebuff.m_time(thebuff));
+       float oldtime = StatusEffects_gettime(thebuff, toucher);
+       float bufftime = ((this.buffs_finished) ? this.buffs_finished : thebuff.m_time(thebuff));
+
+       buff_RemoveAll(toucher, STATUSEFFECT_REMOVE_NORMAL); // remove previous buffs so that a new one may be added
        if(bufftime)
-               STAT(BUFF_TIME, toucher) = min(time + bufftime, max(STAT(BUFF_TIME, toucher), time) + bufftime);
+               StatusEffects_apply(thebuff, toucher, min(time + bufftime, max(oldtime, time) + bufftime), 0);
+       else
+               StatusEffects_apply(thebuff, toucher, time + 999, 0); // HACK: zero timer means "infinite"!
+
+       STAT(LAST_PICKUP, toucher) = time;
 }
 
 float buff_Available(entity buff)
 {
-       if (buff == BUFF_Null)
+       if (!buff)
                return false;
        if (buff == BUFF_AMMO && ((start_items & IT_UNLIMITED_AMMO) || cvar("g_melee_only")))
                return false;
@@ -233,15 +270,35 @@ float buff_Available(entity buff)
 void buff_NewType(entity ent)
 {
        RandomSelection_Init();
-       FOREACH(Buffs, buff_Available(it),
+       FOREACH(StatusEffect, it.instanceOfBuff && buff_Available(it),
        {
                // if it's already been chosen, give it a lower priority
                float myseencount = (it.buff_seencount > 0) ? it.buff_seencount : 1; // no division by zero please!
                RandomSelection_AddEnt(it, max(0.2, 1 / myseencount), 1);
        });
        entity newbuff = RandomSelection_chosen_ent;
+       if(!newbuff)
+               return;
        newbuff.buff_seencount += 1; // lower chances of seeing this buff again soon
-       STAT(BUFFS, ent) = newbuff.m_itemid;
+       ent.buffdef = newbuff;
+}
+
+void buff_RemoveAll(entity actor, int removal_type)
+{
+       if(!actor.statuseffects)
+               return;
+       FOREACH(StatusEffect, it.instanceOfBuff,
+       {
+               it.m_remove(it, actor, removal_type);
+       });
+}
+
+entity buff_FirstFromFlags(entity actor)
+{
+       if(!actor.statuseffects)
+               return NULL;
+       FOREACH(StatusEffect, it.instanceOfBuff && it.m_active(it, actor), { return it; });
+       return NULL;
 }
 
 void buff_Think(entity this)
@@ -249,11 +306,11 @@ void buff_Think(entity this)
        if(this.buff_waypoint && autocvar_g_buffs_waypoint_distance <= 0)
                WaypointSprite_Kill(this.buff_waypoint);
 
-       if(STAT(BUFFS, this) != this.oldbuffs)
+       if(this.buffdef != this.oldbuffs)
        {
-               entity buff = buff_FirstFromFlags(STAT(BUFFS, this));
+               entity buff = this.buffdef;
                this.color = buff.m_color;
-               this.glowmod = buff_GlowColor(buff);
+               this.glowmod = buff.m_color;
                this.skin = buff.m_skin;
 
                setmodel(this, MDL_BUFF);
@@ -268,7 +325,7 @@ void buff_Think(entity this)
                                WaypointSprite_UpdateBuildFinished(this.buff_waypoint, time + this.buff_activetime - frametime);
                }
 
-               this.oldbuffs = STAT(BUFFS, this);
+               this.oldbuffs = this.buffdef;
        }
 
        if(!game_stopped)
@@ -280,7 +337,8 @@ void buff_Think(entity this)
        }
 
        if(!this.buff_active && !this.buff_activetime)
-       if(!this.owner || STAT(FROZEN, this.owner) || IS_DEAD(this.owner) || !this.owner.iscreature || this.owner.vehicle || !(STAT(BUFFS, this.owner) & STAT(BUFFS, this)) || this.pickup_anyway > 0 || (this.pickup_anyway >= 0 && autocvar_g_buffs_pickup_anyway))
+       if(!this.owner || STAT(FROZEN, this.owner) || IS_DEAD(this.owner) || !this.owner.iscreature || this.owner.vehicle
+               || this.pickup_anyway > 0 || (this.pickup_anyway >= 0 && autocvar_g_buffs_pickup_anyway) || this.buffdef != buff_FirstFromFlags(this.owner))
        {
                buff_SetCooldown(this, autocvar_g_buffs_cooldown_respawn + frametime);
                this.owner = NULL;
@@ -341,7 +399,7 @@ void buff_Reset(entity this)
 bool buff_Customize(entity this, entity client)
 {
        entity player = WaypointSprite_getviewentity(client);
-       if(!this.buff_active || (this.team && DIFF_TEAM(player, this)))
+       if((!this.buff_active || !this.buffdef) || (this.team && DIFF_TEAM(player, this)))
        {
                this.alpha = 0.3;
                if(this.effects & EF_FULLBRIGHT) { this.effects &= ~(EF_FULLBRIGHT); }
@@ -369,9 +427,9 @@ void buff_Init(entity this)
 
        if(!teamplay && this.team) { this.team = 0; }
 
-       entity buff = buff_FirstFromFlags(STAT(BUFFS, this));
+       entity buff = this.buffdef;
 
-       if(!STAT(BUFFS, this) || !buff_Available(buff))
+       if(!buff || !buff_Available(buff))
                buff_NewType(this);
 
        this.classname = "item_buff";
@@ -383,6 +441,8 @@ void buff_Init(entity this)
        IL_PUSH(g_items, this);
        setthink(this, buff_Think);
        settouch(this, buff_Touch);
+       setmodel(this, MDL_BUFF);
+       setsize(this, BUFF_MIN, BUFF_MAX);
        this.reset = buff_Reset;
        this.nextthink = time + 0.1;
        this.gravity = 1;
@@ -394,21 +454,21 @@ void buff_Init(entity this)
        setcefc(this, buff_Customize);
        //this.gravity = 100;
        this.color = buff.m_color;
-       this.glowmod = buff_GlowColor(this);
+       this.glowmod = buff.m_color;
        buff_SetCooldown(this, autocvar_g_buffs_cooldown_activate + max(0, game_starttime - time));
        this.buff_active = !this.buff_activetime;
        this.pflags = PFLAGS_FULLDYNAMIC;
        this.dtor = buff_Delete;
 
+       if(!this.buffs_finished)
+               this.buffs_finished = this.count; // legacy support
+
        if(this.spawnflags & 1)
                this.noalign = true;
 
        if(this.noalign)
                set_movetype(this, MOVETYPE_NONE); // reset by random location
 
-       setmodel(this, MDL_BUFF);
-       setsize(this, BUFF_MIN, BUFF_MAX);
-
        if(cvar("g_buffs_random_location") || (this.spawnflags & 64))
                buff_Respawn(this);
 }
@@ -420,7 +480,7 @@ void buff_Init_Compat(entity ent, entity replacement)
        else if (ent.spawnflags & 4)
                ent.team = NUM_TEAM_2;
 
-       STAT(BUFFS, ent) = replacement.m_itemid;
+       ent.buffdef = replacement;
 
        buff_Init(ent);
 }
@@ -443,28 +503,152 @@ void buff_Vengeance_DelayedDamage(entity this)
        return;
 }
 
-// note: only really useful in teamplay
-void buff_Medic_Heal(entity this)
+float buff_Inferno_CalculateTime(float damg, float offset_x, float offset_y, float intersect_x, float intersect_y, float base)
 {
-       FOREACH_CLIENT(IS_PLAYER(it) && it != this && vdist(it.origin - this.origin, <=, autocvar_g_buffs_medic_heal_range),
+       return offset_y + (intersect_y - offset_y) * logn(((damg - offset_x) * ((base - 1) / intersect_x)) + 1, base);
+}
+
+METHOD(Buff, m_apply, void(StatusEffects this, entity actor, float eff_time, float eff_flags))
+{
+    if(IS_PLAYER(actor))
+       actor.effects |= EF_NOSHADOW; // does not play well with buff icon
+    SUPER(Buff).m_apply(this, actor, eff_time, eff_flags);
+}
+METHOD(Buff, m_remove, void(StatusEffects this, entity actor, int removal_type))
+{
+       bool wasactive = (actor.statuseffects && (actor.statuseffects.statuseffect_flags[this.m_id] & STATUSEFFECT_FLAG_ACTIVE));
+       if(wasactive)
        {
-               if (DIFF_TEAM(it, this))
+               int buffid = this.m_id;
+               if(removal_type == STATUSEFFECT_REMOVE_TIMEOUT)
                {
-                       continue;
+                       Send_Notification(NOTIF_ONE, actor, MSG_MULTI, ITEM_BUFF_DROP, buffid); // TODO: special timeout message?
+                       sound(actor, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM);
                }
-               float hp = GetResource(it, RES_HEALTH);
-               if(hp >= autocvar_g_balance_health_regenstable)
+               else if(removal_type == STATUSEFFECT_REMOVE_NORMAL && !IS_INDEPENDENT_PLAYER(actor))
+                       Send_Notification(NOTIF_ALL_EXCEPT, actor, MSG_INFO, INFO_ITEM_BUFF_LOST, actor.netname, buffid);
+               actor.buff_shield = time + max(0, autocvar_g_buffs_pickup_delay); // always put in a delay, even if small
+       }
+       if(IS_PLAYER(actor))
+               actor.effects &= ~EF_NOSHADOW;
+       SUPER(Buff).m_remove(this, actor, removal_type);
+}
+
+METHOD(Disabled, m_tick, void(StatusEffects this, entity actor))
+{
+       if(time >= actor.disabled_effect_time)
+       {
+               Send_Effect(EFFECT_SMOKING, actor.origin + ((actor.mins + actor.maxs) * 0.5), '0 0 0', 1);
+               actor.disabled_effect_time = time + 0.5;
+       }
+       SUPER(Disabled).m_tick(this, actor);
+}
+METHOD(Disabled, m_remove, void(StatusEffects this, entity actor, int removal_type))
+{
+       actor.disabled_effect_time = 0;
+       SUPER(Disabled).m_remove(this, actor, removal_type);
+}
+
+METHOD(AmmoBuff, m_apply, void(StatusEffects this, entity actor, float eff_time, float eff_flags))
+{
+    bool wasactive = (actor.statuseffects && (actor.statuseffects.statuseffect_flags[this.m_id] & STATUSEFFECT_FLAG_ACTIVE));
+    if(!wasactive)
+    {
+        actor.buff_ammo_prev_infitems = (actor.items & IT_UNLIMITED_AMMO);
+        actor.items |= IT_UNLIMITED_AMMO;
+        for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
                {
-                       continue;
+                       .entity weaponentity = weaponentities[slot];
+                       if(!actor.(weaponentity))
+                               continue;
+                       if(actor.(weaponentity).clip_load)
+                               actor.(weaponentity).buff_ammo_prev_clipload = actor.(weaponentity).clip_load;
+                       if(actor.(weaponentity).clip_size)
+                               actor.(weaponentity).clip_load = actor.(weaponentity).(weapon_load[actor.(weaponentity).m_switchweapon.m_id]) = actor.(weaponentity).clip_size;
                }
-               Send_Effect(EFFECT_HEALING, it.origin, '0 0 0', 1);
-               SetResource(it, RES_HEALTH, bound(0, hp + autocvar_g_buffs_medic_heal_amount, autocvar_g_balance_health_regenstable));
-       });
+    }
+    SUPER(AmmoBuff).m_apply(this, actor, eff_time, eff_flags);
 }
+METHOD(AmmoBuff, m_remove, void(StatusEffects this, entity actor, int removal_type))
+{
+       bool wasactive = (actor.statuseffects && (actor.statuseffects.statuseffect_flags[this.m_id] & STATUSEFFECT_FLAG_ACTIVE));
+       if(wasactive)
+       {
+               actor.items = BITSET(actor.items, IT_UNLIMITED_AMMO, actor.buff_ammo_prev_infitems);
+               for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
+               {
+                       .entity weaponentity = weaponentities[slot];
+                       if(!actor.(weaponentity))
+                               continue;
+                       if(actor.(weaponentity).buff_ammo_prev_clipload)
+                       {
+                               actor.(weaponentity).clip_load = actor.(weaponentity).buff_ammo_prev_clipload;
+                               actor.(weaponentity).buff_ammo_prev_clipload = 0;
+                       }
+               }
+       }
+       actor.buff_ammo_prev_infitems = 0;
+       SUPER(AmmoBuff).m_remove(this, actor, removal_type);
+}
+METHOD(AmmoBuff, m_tick, void(StatusEffects this, entity actor))
+{
+       if(IS_PLAYER(actor))
+       {
+               for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
+               {
+                       .entity weaponentity = weaponentities[slot];
+                       if(actor.(weaponentity).clip_size)
+                               actor.(weaponentity).clip_load = actor.(weaponentity).(weapon_load[actor.(weaponentity).m_switchweapon.m_id]) = actor.(weaponentity).clip_size;
+               }
+       }
 
-float buff_Inferno_CalculateTime(float damg, float offset_x, float offset_y, float intersect_x, float intersect_y, float base)
+       SUPER(AmmoBuff).m_tick(this, actor);
+}
+
+
+METHOD(FlightBuff, m_apply, void(StatusEffects this, entity actor, float eff_time, float eff_flags))
 {
-       return offset_y + (intersect_y - offset_y) * logn(((damg - offset_x) * ((base - 1) / intersect_x)) + 1, base);
+    bool wasactive = (actor.statuseffects && (actor.statuseffects.statuseffect_flags[this.m_id] & STATUSEFFECT_FLAG_ACTIVE));
+    if(!wasactive)
+    {
+        actor.buff_flight_oldgravity = actor.gravity;
+               if(!actor.gravity)
+                       actor.gravity = 1;
+    }
+    SUPER(FlightBuff).m_apply(this, actor, eff_time, eff_flags);
+}
+METHOD(FlightBuff, m_remove, void(StatusEffects this, entity actor, int removal_type))
+{
+       bool wasactive = (actor.statuseffects && (actor.statuseffects.statuseffect_flags[this.m_id] & STATUSEFFECT_FLAG_ACTIVE));
+       if(wasactive)
+       {
+               actor.gravity = ((actor.trigger_gravity_check) ? actor.trigger_gravity_check.enemy.gravity : actor.buff_flight_oldgravity);
+       }
+       actor.buff_flight_oldgravity = 0;
+       SUPER(FlightBuff).m_remove(this, actor, removal_type);
+}
+
+METHOD(MagnetBuff, m_tick, void(StatusEffects this, entity actor))
+{
+       if(IS_PLAYER(actor))
+       {
+               vector pickup_size;
+               IL_EACH(g_items, it.itemdef,
+               {
+                       if(it.buffdef)
+                               pickup_size = '1 1 1' * autocvar_g_buffs_magnet_range_buff;
+                       else
+                               pickup_size = '1 1 1' * autocvar_g_buffs_magnet_range_item;
+
+                       if(boxesoverlap(actor.absmin - pickup_size, actor.absmax + pickup_size, it.absmin, it.absmax))
+                       {
+                               if(gettouch(it))
+                                       gettouch(it)(it, actor);
+                       }
+               });
+       }
+
+       SUPER(MagnetBuff).m_tick(this, actor);
 }
 
 // mutator hooks
@@ -478,33 +662,29 @@ MUTATOR_HOOKFUNCTION(buffs, Damage_Calculate)
 
        if(frag_deathtype == DEATH_BUFF.m_id) { return; }
 
-       if(STAT(BUFFS, frag_target) & BUFF_RESISTANCE.m_itemid)
+       if(StatusEffects_active(BUFF_RESISTANCE, frag_target))
        {
                float reduced = frag_damage * autocvar_g_buffs_resistance_blockpercent;
                frag_damage = bound(0, frag_damage - reduced, frag_damage);
        }
 
-       if(STAT(BUFFS, frag_target) & BUFF_SPEED.m_itemid)
-       if(frag_target != frag_attacker)
-               frag_damage *= autocvar_g_buffs_speed_damage_take;
-
-       if(STAT(BUFFS, frag_target) & BUFF_MEDIC.m_itemid)
+       if(StatusEffects_active(BUFF_MEDIC, frag_target))
        if((GetResource(frag_target, RES_HEALTH) - frag_damage) <= 0)
        if(!ITEM_DAMAGE_NEEDKILL(frag_deathtype))
        if(frag_attacker)
        if(random() <= autocvar_g_buffs_medic_survive_chance)
                frag_damage = max(5, GetResource(frag_target, RES_HEALTH) - autocvar_g_buffs_medic_survive_health);
 
-       if(STAT(BUFFS, frag_target) & BUFF_JUMP.m_itemid)
+       if(StatusEffects_active(BUFF_JUMP, frag_target))
        if(frag_deathtype == DEATH_FALL.m_id)
                frag_damage = 0;
 
-       if(STAT(BUFFS, frag_target) & BUFF_VENGEANCE.m_itemid)
+       if(StatusEffects_active(BUFF_VENGEANCE, frag_target))
        if(frag_attacker)
        if(frag_attacker != frag_target)
        if(!ITEM_DAMAGE_NEEDKILL(frag_deathtype))
        {
-               entity dmgent = new(dmgent);
+               entity dmgent = new_pure(dmgent);
 
                dmgent.dmg = frag_damage * autocvar_g_buffs_vengeance_damage_multiplier;
                dmgent.enemy = frag_attacker;
@@ -513,11 +693,11 @@ MUTATOR_HOOKFUNCTION(buffs, Damage_Calculate)
                dmgent.nextthink = time + 0.1;
        }
 
-       if(STAT(BUFFS, frag_target) & BUFF_BASH.m_itemid)
+       if(StatusEffects_active(BUFF_BASH, frag_target))
        if(frag_attacker != frag_target)
                frag_force = '0 0 0';
 
-       if(STAT(BUFFS, frag_attacker) & BUFF_BASH.m_itemid)
+       if(StatusEffects_active(BUFF_BASH, frag_attacker))
        if(frag_force)
        {
                if(frag_attacker == frag_target)
@@ -526,11 +706,11 @@ MUTATOR_HOOKFUNCTION(buffs, Damage_Calculate)
                        frag_force *= autocvar_g_buffs_bash_force;
        }
 
-       if(STAT(BUFFS, frag_attacker) & BUFF_DISABILITY.m_itemid)
+       if(StatusEffects_active(BUFF_DISABILITY, frag_attacker))
        if(frag_target != frag_attacker)
-               frag_target.buff_disability_time = time + autocvar_g_buffs_disability_slowtime;
+               StatusEffects_apply(STATUSEFFECT_Disabled, frag_target, time + autocvar_g_buffs_disability_slowtime, 0);
 
-       if(STAT(BUFFS, frag_target) & BUFF_INFERNO.m_itemid)
+       if(StatusEffects_active(BUFF_INFERNO, frag_target))
        {
                if(frag_deathtype == DEATH_FIRE.m_id)
                        frag_damage = 0;
@@ -538,13 +718,13 @@ MUTATOR_HOOKFUNCTION(buffs, Damage_Calculate)
                        frag_damage *= 0.5; // TODO: cvarize?
        }
 
-       if(STAT(BUFFS, frag_attacker) & BUFF_LUCK.m_itemid)
+       if(StatusEffects_active(BUFF_LUCK, frag_attacker))
        if(frag_attacker != frag_target)
        if(autocvar_g_buffs_luck_damagemultiplier > 0)
        if(random() <= autocvar_g_buffs_luck_chance)
                frag_damage *= autocvar_g_buffs_luck_damagemultiplier;
 
-       if(STAT(BUFFS, frag_attacker) & BUFF_INFERNO.m_itemid)
+       if(StatusEffects_active(BUFF_INFERNO, frag_attacker))
        if(frag_target != frag_attacker) {
                float btime = buff_Inferno_CalculateTime(
                        frag_damage,
@@ -557,41 +737,26 @@ MUTATOR_HOOKFUNCTION(buffs, Damage_Calculate)
                Fire_AddDamage(frag_target, frag_attacker, (frag_damage * autocvar_g_buffs_inferno_damagemultiplier), btime, DEATH_BUFF.m_id);
        }
 
-       // this... is ridiculous (TODO: fix!)
-       if(STAT(BUFFS, frag_attacker) & BUFF_VAMPIRE.m_itemid)
-       if(!frag_target.vehicle)
-       if(!ITEM_DAMAGE_NEEDKILL(frag_deathtype))
-       if(!IS_DEAD(frag_target))
-       if(IS_PLAYER(frag_target) || IS_MONSTER(frag_target))
-       if(frag_attacker != frag_target)
-       if(!STAT(FROZEN, frag_target))
-       if(frag_target.takedamage)
-       if(DIFF_TEAM(frag_attacker, frag_target))
-       {
-               float amount = bound(0, frag_damage * autocvar_g_buffs_vampire_damage_steal,
-                       GetResource(frag_target, RES_HEALTH));
-               GiveResourceWithLimit(frag_attacker, RES_HEALTH, amount, g_pickup_healthsmall_max);
-               if (GetResource(frag_target, RES_ARMOR))
-               {
-                       amount = bound(0, frag_damage * autocvar_g_buffs_vampire_damage_steal,
-                               GetResource(frag_target, RES_ARMOR));
-                       GiveResourceWithLimit(frag_attacker, RES_ARMOR, amount, g_pickup_armorsmall_max);
-               }
-       }
-
        M_ARGV(4, float) = frag_damage;
        M_ARGV(6, vector) = frag_force;
 }
 
-MUTATOR_HOOKFUNCTION(buffs, PlayerSpawn)
+MUTATOR_HOOKFUNCTION(buffs, PlayerDamage_SplitHealthArmor)
 {
-       entity player = M_ARGV(0, entity);
+       entity frag_attacker = M_ARGV(1, entity);
+       entity frag_target = M_ARGV(2, entity);
+       if(!StatusEffects_active(BUFF_VAMPIRE, frag_attacker))
+               return;
+       float health_take = bound(0, M_ARGV(4, float), GetResource(frag_target, RES_HEALTH));
 
-       buffs_BuffModel_Remove(player);
-       player.oldbuffs = 0;
-       // reset timers here to prevent them continuing after re-spawn
-       player.buff_disability_time = 0;
-       player.buff_disability_effect_time = 0;
+       if(!StatusEffects_active(STATUSEFFECT_SpawnShield, frag_target) &&
+               frag_target != frag_attacker &&
+               IS_PLAYER(frag_attacker) &&
+               !IS_DEAD(frag_target) && !STAT(FROZEN, frag_target))
+       {
+               GiveResource(frag_attacker, RES_HEALTH,
+                       autocvar_g_buffs_vampire_damage_steal * health_take);
+       }
 }
 
 MUTATOR_HOOKFUNCTION(buffs, PlayerPhysics_UpdateStats)
@@ -599,10 +764,7 @@ MUTATOR_HOOKFUNCTION(buffs, PlayerPhysics_UpdateStats)
        entity player = M_ARGV(0, entity);
        // these automatically reset, no need to worry
 
-       if(STAT(BUFFS, player) & BUFF_SPEED.m_itemid)
-               STAT(MOVEVARS_HIGHSPEED, player) *= autocvar_g_buffs_speed_speed;
-
-       if(time < player.buff_disability_time)
+       if(StatusEffects_active(STATUSEFFECT_Disabled, player))
                STAT(MOVEVARS_HIGHSPEED, player) *= autocvar_g_buffs_disability_speed;
 }
 
@@ -611,7 +773,7 @@ MUTATOR_HOOKFUNCTION(buffs, PlayerPhysics)
        entity player = M_ARGV(0, entity);
        // these automatically reset, no need to worry
 
-       if(STAT(BUFFS, player) & BUFF_JUMP.m_itemid)
+       if(StatusEffects_active(BUFF_JUMP, player))
                STAT(MOVEVARS_JUMPVELOCITY, player) = autocvar_g_buffs_jump_height;
 }
 
@@ -619,45 +781,29 @@ MUTATOR_HOOKFUNCTION(buffs, MonsterMove)
 {
        entity mon = M_ARGV(0, entity);
 
-       if(time < mon.buff_disability_time)
+       if(StatusEffects_active(STATUSEFFECT_Disabled, mon))
        {
                M_ARGV(1, float) *= autocvar_g_buffs_disability_speed; // run speed
                M_ARGV(2, float) *= autocvar_g_buffs_disability_speed; // walk speed
        }
 }
 
-MUTATOR_HOOKFUNCTION(buffs, PlayerDies)
-{
-       entity frag_target = M_ARGV(2, entity);
-
-       if(STAT(BUFFS, frag_target))
-       {
-               int buffid = buff_FirstFromFlags(STAT(BUFFS, frag_target)).m_id;
-               if(!IS_INDEPENDENT_PLAYER(frag_target))
-                       Send_Notification(NOTIF_ALL_EXCEPT, frag_target, MSG_INFO, INFO_ITEM_BUFF_LOST, frag_target.netname, buffid);
-               STAT(BUFFS, frag_target) = 0;
-               STAT(BUFF_TIME, frag_target) = 0;
-
-               buffs_BuffModel_Remove(frag_target);
-       }
-}
-
 MUTATOR_HOOKFUNCTION(buffs, PlayerUseKey, CBC_ORDER_FIRST)
 {
        if(MUTATOR_RETURNVALUE || game_stopped || !autocvar_g_buffs_drop) return;
 
        entity player = M_ARGV(0, entity);
 
-       if(STAT(BUFFS, player))
+       entity heldbuff = buff_FirstFromFlags(player);
+       if(heldbuff)
        {
-               int buffid = buff_FirstFromFlags(STAT(BUFFS, player)).m_id;
+               int buffid = heldbuff.m_id;
                Send_Notification(NOTIF_ONE, player, MSG_MULTI, ITEM_BUFF_DROP, buffid);
                if(!IS_INDEPENDENT_PLAYER(player))
                        Send_Notification(NOTIF_ALL_EXCEPT, player, MSG_INFO, INFO_ITEM_BUFF_LOST, player.netname, buffid);
 
-               STAT(BUFFS, player) = 0;
-               STAT(BUFF_TIME, player) = 0;
-               PS(player).buff_shield = time + max(0, autocvar_g_buffs_pickup_delay);
+               buff_RemoveAll(player, STATUSEFFECT_REMOVE_NORMAL);
+               player.buff_shield = time + max(0, autocvar_g_buffs_pickup_delay);
                sound(player, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM);
                return true;
        }
@@ -668,7 +814,7 @@ MUTATOR_HOOKFUNCTION(buffs, ForbidThrowCurrentWeapon)
        if(MUTATOR_RETURNVALUE || game_stopped) return;
        entity player = M_ARGV(0, entity);
 
-       if(STAT(BUFFS, player) & BUFF_SWAPPER.m_itemid)
+       if(StatusEffects_active(BUFF_SWAPPER, player))
        {
                float best_distance = autocvar_g_buffs_swapper_range;
                entity closest = NULL;
@@ -736,7 +882,7 @@ MUTATOR_HOOKFUNCTION(buffs, ForbidThrowCurrentWeapon)
                        sound(closest, CH_TRIGGER, SND_KA_RESPAWN, VOL_BASE, ATTEN_NORM);
 
                        // TODO: add a counter to handle how many times one can teleport, and a delay to prevent spam
-                       STAT(BUFFS, player) = 0;
+                       buff_RemoveAll(player, STATUSEFFECT_REMOVE_NORMAL);
                        return true;
                }
        }
@@ -746,29 +892,11 @@ bool buffs_RemovePlayer(entity player)
 {
        buffs_BuffModel_Remove(player);
 
-       // also reset timers here to prevent them continuing after spectating
-       player.buff_disability_time = 0;
-       player.buff_disability_effect_time = 0;
-
        return false;
 }
 MUTATOR_HOOKFUNCTION(buffs, MakePlayerObserver) { entity player = M_ARGV(0, entity); return buffs_RemovePlayer(player); }
 MUTATOR_HOOKFUNCTION(buffs, ClientDisconnect) { entity player = M_ARGV(0, entity); return buffs_RemovePlayer(player); }
 
-MUTATOR_HOOKFUNCTION(buffs, CustomizeWaypoint)
-{
-       entity wp = M_ARGV(0, entity);
-       entity player = M_ARGV(1, entity);
-
-       entity e = WaypointSprite_getviewentity(player);
-
-       // if you have the invisibility powerup, sprites ALWAYS are restricted to your team
-       // but only apply this to real players, not to spectators
-       if((wp.owner.flags & FL_CLIENT) && (STAT(BUFFS, wp.owner) & BUFF_INVISIBLE.m_itemid) && (e == player))
-       if(DIFF_TEAM(wp.owner, e))
-               return true;
-}
-
 MUTATOR_HOOKFUNCTION(buffs, FilterItem)
 {
        if(autocvar_g_buffs < 0)
@@ -776,18 +904,11 @@ MUTATOR_HOOKFUNCTION(buffs, FilterItem)
 
        entity item = M_ARGV(0, entity);
 
-       if(autocvar_g_buffs_replace_powerups)
+       if(autocvar_g_buffs_replace_powerups && item.itemdef.instanceOfPowerup)
        {
-               switch(item.classname)
-               {
-                       case "item_strength":
-                       case "item_shield":
-                       {
-                               entity e = spawn();
-                               buff_SpawnReplacement(e, item);
-                               return true;
-                       }
-               }
+               entity e = spawn();
+               buff_SpawnReplacement(e, item);
+               return true;
        }
 
        return false;
@@ -797,10 +918,7 @@ MUTATOR_HOOKFUNCTION(buffs, WeaponRateFactor)
 {
        entity player = M_ARGV(1, entity);
 
-       if(STAT(BUFFS, player) & BUFF_SPEED.m_itemid)
-               M_ARGV(0, float) *= autocvar_g_buffs_speed_rate;
-
-       if(time < player.buff_disability_time)
+       if(StatusEffects_active(STATUSEFFECT_Disabled, player))
                M_ARGV(0, float) *= autocvar_g_buffs_disability_rate;
 }
 
@@ -808,22 +926,24 @@ MUTATOR_HOOKFUNCTION(buffs, WeaponSpeedFactor)
 {
        entity player = M_ARGV(1, entity);
 
-       if(STAT(BUFFS, player) & BUFF_SPEED.m_itemid)
-               M_ARGV(0, float) *= autocvar_g_buffs_speed_weaponspeed;
-
-       if(time < player.buff_disability_time)
+       if(StatusEffects_active(STATUSEFFECT_Disabled, player))
                M_ARGV(0, float) *= autocvar_g_buffs_disability_weaponspeed;
 }
 
-.bool buff_flight_crouchheld;
+MUTATOR_HOOKFUNCTION(buffs, Freeze)
+{
+       entity targ = M_ARGV(0, entity);
+       buff_RemoveAll(targ, STATUSEFFECT_REMOVE_NORMAL);
+}
 
 MUTATOR_HOOKFUNCTION(buffs, PlayerPreThink)
 {
        entity player = M_ARGV(0, entity);
 
-       if(game_stopped || IS_DEAD(player) || frametime || !IS_PLAYER(player)) return;
+       if(game_stopped || IS_DEAD(player) || !IS_PLAYER(player)) return;
 
-       if(STAT(BUFFS, player) & BUFF_FLIGHT.m_itemid)
+       // NOTE: this is kept here to ensure crouches are picked up each player movement frame
+       if(StatusEffects_active(BUFF_FLIGHT, player))
        {
                if(!PHYS_INPUT_BUTTON_CROUCH(player))
                        player.buff_flight_crouchheld = false;
@@ -834,210 +954,20 @@ MUTATOR_HOOKFUNCTION(buffs, PlayerPreThink)
                }
        }
 
-       if(time < player.buff_disability_time)
-       if(time >= player.buff_disability_effect_time)
-       {
-               Send_Effect(EFFECT_SMOKING, player.origin + ((player.mins + player.maxs) * 0.5), '0 0 0', 1);
-               player.buff_disability_effect_time = time + 0.5;
-       }
-
-       // handle buff lost status
-       // 1: notify everyone else
-       // 2: notify carrier as well
-       int buff_lost = 0;
-
-       if(STAT(BUFF_TIME, player) && STAT(BUFFS, player))
-       if(time >= STAT(BUFF_TIME, player))
-       {
-               STAT(BUFF_TIME, player) = 0;
-               buff_lost = 2;
-       }
-
-       if(STAT(FROZEN, player)) { buff_lost = 1; }
-
-       if(buff_lost)
-       {
-               if(STAT(BUFFS, player))
-               {
-                       int buffid = buff_FirstFromFlags(STAT(BUFFS, player)).m_id;
-                       if(buff_lost == 2)
-                       {
-                               Send_Notification(NOTIF_ONE, player, MSG_MULTI, ITEM_BUFF_DROP, buffid); // TODO: special timeout message?
-                               sound(player, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM);
-                       }
-                       else if(!IS_INDEPENDENT_PLAYER(player))
-                               Send_Notification(NOTIF_ALL_EXCEPT, player, MSG_INFO, INFO_ITEM_BUFF_LOST, player.netname, buffid);
-                       STAT(BUFFS, player) = 0;
-                       PS(player).buff_shield = time + max(0, autocvar_g_buffs_pickup_delay); // always put in a delay, even if small
-               }
-       }
-
-       if(STAT(BUFFS, player) & BUFF_MAGNET.m_itemid)
-       {
-               vector pickup_size;
-               IL_EACH(g_items, it.itemdef,
-               {
-                       if(STAT(BUFFS, it))
-                               pickup_size = '1 1 1' * autocvar_g_buffs_magnet_range_buff;
-                       else
-                               pickup_size = '1 1 1' * autocvar_g_buffs_magnet_range_item;
-
-                       if(boxesoverlap(player.absmin - pickup_size, player.absmax + pickup_size, it.absmin, it.absmax))
-                       {
-                               if(gettouch(it))
-                                       gettouch(it)(it, player);
-                       }
-               });
-       }
-
-       if(STAT(BUFFS, player) & BUFF_AMMO.m_itemid)
-       {
-               for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
-               {
-                       .entity weaponentity = weaponentities[slot];
-                       if(player.(weaponentity).clip_size)
-                               player.(weaponentity).clip_load = player.(weaponentity).(weapon_load[player.(weaponentity).m_switchweapon.m_id]) = player.(weaponentity).clip_size;
-               }
-       }
-
-       if((STAT(BUFFS, player) & BUFF_INVISIBLE.m_itemid) && (player.oldbuffs & BUFF_INVISIBLE.m_itemid))
-               player.alpha = ((autocvar_g_buffs_invisible_alpha) ? autocvar_g_buffs_invisible_alpha : -1); // powerups reset alpha, so we must enforce this (TODO)
-
-       if(STAT(BUFFS, player) & BUFF_MEDIC.m_itemid)
-       if(time >= player.buff_medic_healtime)
-       {
-               buff_Medic_Heal(player);
-               player.buff_medic_healtime = time + autocvar_g_buffs_medic_heal_delay;
-       }
-
-#define BUFF_ONADD(b) if ( (STAT(BUFFS, player) & (b).m_itemid) && !(player.oldbuffs & (b).m_itemid))
-#define BUFF_ONREM(b) if (!(STAT(BUFFS, player) & (b).m_itemid) &&  (player.oldbuffs & (b).m_itemid))
-
-       if(STAT(BUFFS, player) != player.oldbuffs)
-       {
-               entity buff = buff_FirstFromFlags(STAT(BUFFS, player));
-               float bufftime = buff != BUFF_Null ? buff.m_time(buff) : 0;
-               if(STAT(BUFF_TIME, player) <= time) // if the player still has a buff countdown, don't reset it!
-                       STAT(BUFF_TIME, player) = (bufftime) ? time + bufftime : 0;
-
-               BUFF_ONADD(BUFF_AMMO)
-               {
-                       player.buff_ammo_prev_infitems = (player.items & IT_UNLIMITED_AMMO);
-                       player.items |= IT_UNLIMITED_AMMO;
-
-                       if(STAT(BUFFS, player) & BUFF_AMMO.m_itemid)
-                       {
-                               for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
-                               {
-                                       .entity weaponentity = weaponentities[slot];
-                                       if(player.(weaponentity).clip_load)
-                                               player.(weaponentity).buff_ammo_prev_clipload = player.(weaponentity).clip_load;
-                                       if(player.(weaponentity).clip_size)
-                                               player.(weaponentity).clip_load = player.(weaponentity).(weapon_load[player.(weaponentity).m_switchweapon.m_id]) = player.(weaponentity).clip_size;
-                               }
-                       }
-               }
-
-               BUFF_ONREM(BUFF_AMMO)
-               {
-                       if(player.buff_ammo_prev_infitems)
-                               player.items |= IT_UNLIMITED_AMMO;
-                       else
-                               player.items &= ~IT_UNLIMITED_AMMO;
-
-                       if(STAT(BUFFS, player) & BUFF_AMMO.m_itemid)
-                       {
-                               for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
-                               {
-                                       .entity weaponentity = weaponentities[slot];
-                                       if(player.(weaponentity).buff_ammo_prev_clipload)
-                                               player.(weaponentity).clip_load = player.(weaponentity).buff_ammo_prev_clipload;
-                               }
-                       }
-               }
-
-               BUFF_ONADD(BUFF_INVISIBLE)
-               {
-                       if(time < STAT(STRENGTH_FINISHED, player) && MUTATOR_IS_ENABLED(mutator_instagib))
-                               player.buff_invisible_prev_alpha = default_player_alpha; // we don't want to save the powerup's alpha, as player may lose the powerup while holding the buff
-                       else
-                               player.buff_invisible_prev_alpha = player.alpha;
-                       player.alpha = autocvar_g_buffs_invisible_alpha;
-               }
-
-               BUFF_ONREM(BUFF_INVISIBLE)
-               {
-                       if(time < STAT(STRENGTH_FINISHED, player) && MUTATOR_IS_ENABLED(mutator_instagib))
-                               player.alpha = autocvar_g_instagib_invis_alpha;
-                       else
-                               player.alpha = player.buff_invisible_prev_alpha;
-               }
-
-               BUFF_ONADD(BUFF_FLIGHT)
-               {
-                       player.buff_flight_oldgravity = player.gravity;
-                       if(!player.gravity)
-                               player.gravity = 1;
-               }
-
-               BUFF_ONREM(BUFF_FLIGHT)
-                       player.gravity = ((player.trigger_gravity_check) ? player.trigger_gravity_check.enemy.gravity : player.buff_flight_oldgravity);
-
-               player.oldbuffs = STAT(BUFFS, player);
-               if(STAT(BUFFS, player))
-               {
-                       if(!player.buff_model)
-                               buffs_BuffModel_Spawn(player);
-
-                       player.buff_model.color = buff.m_color;
-                       player.buff_model.glowmod = buff_GlowColor(player.buff_model);
-                       player.buff_model.skin = buff.m_skin;
-
-                       player.effects |= EF_NOSHADOW;
-               }
-               else
-               {
-                       buffs_BuffModel_Remove(player);
-
-                       player.effects &= ~(EF_NOSHADOW);
-               }
-       }
-
-       if(player.buff_model)
-       {
-               player.buff_model.effects = player.effects;
-               player.buff_model.effects |= EF_LOWPRECISION;
-               player.buff_model.effects = player.buff_model.effects & EFMASK_CHEAP; // eat performance
-
-               player.buff_model.alpha = player.alpha;
-       }
-
-#undef BUFF_ONADD
-#undef BUFF_ONREM
-}
-
-MUTATOR_HOOKFUNCTION(buffs, SpectateCopy)
-{
-       entity spectatee = M_ARGV(0, entity);
-       entity client = M_ARGV(1, entity);
-
-       STAT(BUFFS, client) = STAT(BUFFS, spectatee);
-       STAT(BUFF_TIME, client) = STAT(BUFF_TIME, spectatee);
+       if(IS_PLAYER(player))
+               buffs_BuffModel_Update(player);
 }
 
 MUTATOR_HOOKFUNCTION(buffs, PlayerRegen)
 {
        entity player = M_ARGV(0, entity);
 
-       if(STAT(BUFFS, player) & BUFF_MEDIC.m_itemid)
+       if(StatusEffects_active(BUFF_MEDIC, player))
        {
                M_ARGV(2, float) = autocvar_g_buffs_medic_rot; // rot_mod
                M_ARGV(4, float) = M_ARGV(1, float) = autocvar_g_buffs_medic_max; // limit_mod = max_mod
                M_ARGV(2, float) = autocvar_g_buffs_medic_regen; // regen_mod
        }
-
-       if(STAT(BUFFS, player) & BUFF_SPEED.m_itemid)
-               M_ARGV(2, float) = autocvar_g_buffs_speed_regen; // regen_mod
 }
 
 REPLICATE(cvar_cl_buffs_autoreplace, bool, "cl_buffs_autoreplace");
@@ -1069,3 +999,10 @@ void buffs_DelayedInit(entity this)
                }
        }
 }
+
+void buffs_Initialize()
+{
+       // if buffs are above 0, allow random spawning
+       if(autocvar_g_buffs > 0 && autocvar_g_buffs_spawn_count > 0)
+               InitializeEntity(NULL, buffs_DelayedInit, INITPRIO_FINDTARGET);
+}