3 #include <common/triggers/target/music.qh>
4 #include <common/gamemodes/_mod.qh>
6 .float buff_time = _STAT(BUFF_TIME);
7 void buffs_DelayedInit(entity this);
9 REGISTER_MUTATOR(buffs, cvar("g_buffs"))
13 InitializeEntity(NULL, buffs_DelayedInit, INITPRIO_FINDTARGET);
17 bool buffs_BuffModel_Customize(entity this, entity client)
19 entity player, myowner;
22 player = WaypointSprite_getviewentity(client);
24 same_team = (SAME_TEAM(player, myowner) || SAME_TEAM(player, myowner));
26 if(myowner.alpha <= 0.5 && !same_team && myowner.alpha != 0)
29 if(MUTATOR_CALLHOOK(BuffModel_Customize, this, player))
32 if(player == myowner || (IS_SPEC(client) && client.enemy == myowner))
34 // somewhat hide the model, but keep the glow
40 this.effects = EF_FULLBRIGHT | EF_LOWPRECISION;
46 void buffs_BuffModel_Spawn(entity player)
48 player.buff_model = spawn();
49 setmodel(player.buff_model, MDL_BUFF);
50 setsize(player.buff_model, '0 0 -40', '0 0 40');
51 setattachment(player.buff_model, player, "");
52 setorigin(player.buff_model, '0 0 1' * (player.buff_model.maxs.z * 1));
53 player.buff_model.owner = player;
54 player.buff_model.scale = 0.7;
55 player.buff_model.pflags = PFLAGS_FULLDYNAMIC;
56 player.buff_model.light_lev = 200;
57 setcefc(player.buff_model, buffs_BuffModel_Customize);
60 vector buff_GlowColor(entity buff)
62 //if(buff.team) { return Team_ColorRGB(buff.team); }
66 void buff_Effect(entity player, string eff)
68 if(!autocvar_g_buffs_effects) { return; }
70 if(time >= player.buff_effect_delay)
72 Send_Effect_(eff, player.origin + ((player.mins + player.maxs) * 0.5), '0 0 0', 1);
73 player.buff_effect_delay = time + 0.05; // prevent spam
78 bool buff_Waypoint_visible_for_player(entity this, entity player, entity view)
80 if(!this.owner.buff_active && !this.owner.buff_activetime)
85 return view.cvar_cl_buffs_autoreplace == false || view.buffs != this.owner.buffs;
88 return WaypointSprite_visible_for_player(this, player, view);
91 void buff_Waypoint_Spawn(entity e)
93 entity buff = buff_FirstFromFlags(e.buffs);
94 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);
95 wp.wp_extra = buff.m_id;
96 WaypointSprite_UpdateTeamRadar(e.buff_waypoint, RADARICON_Buff, e.glowmod);
97 e.buff_waypoint.waypointsprite_visible_for_player = buff_Waypoint_visible_for_player;
100 void buff_SetCooldown(entity this, float cd)
104 if(!this.buff_waypoint)
105 buff_Waypoint_Spawn(this);
107 WaypointSprite_UpdateBuildFinished(this.buff_waypoint, time + cd);
108 this.buff_activetime = cd;
109 this.buff_active = !cd;
112 void buff_Respawn(entity this)
114 if(gameover) { return; }
116 vector oldbufforigin = this.origin;
117 this.velocity = '0 0 200';
119 if(!MoveToRandomMapLocation(this, DPCONTENTS_SOLID | DPCONTENTS_CORPSE | DPCONTENTS_PLAYERCLIP, DPCONTENTS_SLIME | DPCONTENTS_LAVA | DPCONTENTS_SKY | DPCONTENTS_BODY | DPCONTENTS_DONOTENTER, Q3SURFACEFLAG_SKY,
120 ((autocvar_g_buffs_random_location_attempts > 0) ? autocvar_g_buffs_random_location_attempts : 10), 1024, 256))
122 entity spot = SelectSpawnPoint(this, true);
123 setorigin(this, spot.origin);
124 this.velocity = ((randomvec() * 100) + '0 0 200');
125 this.angles = spot.angles;
128 tracebox(this.origin, this.mins * 1.5, this.maxs * 1.5, this.origin, MOVE_NOMONSTERS, this);
130 setorigin(this, trace_endpos); // attempt to unstick
132 set_movetype(this, MOVETYPE_TOSS);
134 makevectors(this.angles);
135 this.angles = '0 0 0';
136 if(autocvar_g_buffs_random_lifetime > 0)
137 this.lifetime = time + autocvar_g_buffs_random_lifetime;
139 Send_Effect(EFFECT_ELECTRO_COMBO, oldbufforigin + ((this.mins + this.maxs) * 0.5), '0 0 0', 1);
140 Send_Effect(EFFECT_ELECTRO_COMBO, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
142 WaypointSprite_Ping(this.buff_waypoint);
144 sound(this, CH_TRIGGER, SND_KA_RESPAWN, VOL_BASE, ATTEN_NONE); // ATTEN_NONE (it's a sound intended to be heard anywhere)
147 void buff_Touch(entity this, entity toucher)
149 if(gameover) { return; }
151 if(ITEM_TOUCH_NEEDKILL())
157 if((this.team && DIFF_TEAM(toucher, this))
158 || (STAT(FROZEN, toucher))
160 || (!this.buff_active)
167 if(MUTATOR_CALLHOOK(BuffTouch, this, toucher))
169 toucher = M_ARGV(1, entity);
171 if(!IS_PLAYER(toucher))
172 return; // incase mutator changed toucher
176 if (toucher.cvar_cl_buffs_autoreplace && toucher.buffs != this.buffs)
178 int buffid = buff_FirstFromFlags(toucher.buffs).m_id;
179 //Send_Notification(NOTIF_ONE, toucher, MSG_MULTI, ITEM_BUFF_DROP, toucher.buffs);
180 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_ITEM_BUFF_LOST, toucher.netname, buffid);
183 //sound(toucher, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM);
185 else { return; } // do nothing
188 this.owner = toucher;
189 this.buff_active = false;
191 int buffid = buff_FirstFromFlags(this.buffs).m_id;
192 Send_Notification(NOTIF_ONE, toucher, MSG_MULTI, ITEM_BUFF_GOT, buffid);
193 Send_Notification(NOTIF_ALL_EXCEPT, toucher, MSG_INFO, INFO_ITEM_BUFF, toucher.netname, buffid);
195 Send_Effect(EFFECT_ITEM_PICKUP, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
196 sound(toucher, CH_TRIGGER, SND_SHIELD_RESPAWN, VOL_BASE, ATTN_NORM);
197 toucher.buffs |= (this.buffs);
200 float buff_Available(entity buff)
202 if (buff == BUFF_Null)
204 if (buff == BUFF_AMMO && ((start_items & IT_UNLIMITED_WEAPON_AMMO) || (start_items & IT_UNLIMITED_AMMO) || (cvar("g_melee_only"))))
206 if (buff == BUFF_VAMPIRE && cvar("g_vampire"))
208 return cvar(strcat("g_buffs_", buff.m_name));
213 void buff_NewType(entity ent, float cb)
215 RandomSelection_Init();
216 FOREACH(Buffs, buff_Available(it), LAMBDA(
217 it.buff_seencount += 1;
218 // if it's already been chosen, give it a lower priority
219 RandomSelection_AddFloat(it.m_itemid, 1, max(0.2, 1 / it.buff_seencount));
221 ent.buffs = RandomSelection_chosen_float;
224 void buff_Think(entity this)
226 if(this.buffs != this.oldbuffs)
228 entity buff = buff_FirstFromFlags(this.buffs);
229 this.color = buff.m_color;
230 this.glowmod = buff_GlowColor(buff);
231 this.skin = buff.m_skin;
233 setmodel(this, MDL_BUFF);
234 setsize(this, BUFF_MIN, BUFF_MAX);
236 if(this.buff_waypoint)
238 //WaypointSprite_Disown(this.buff_waypoint, 1);
239 WaypointSprite_Kill(this.buff_waypoint);
240 buff_Waypoint_Spawn(this);
241 if(this.buff_activetime)
242 WaypointSprite_UpdateBuildFinished(this.buff_waypoint, time + this.buff_activetime - frametime);
245 this.oldbuffs = this.buffs;
249 if((round_handler_IsActive() && !round_handler_IsRoundStarted()) || time >= game_starttime)
250 if(!this.buff_activetime_updated)
252 buff_SetCooldown(this, this.buff_activetime);
253 this.buff_activetime_updated = true;
256 if(!this.buff_active && !this.buff_activetime)
257 if(!this.owner || STAT(FROZEN, this.owner) || IS_DEAD(this.owner) || !this.owner.iscreature || !(this.owner.buffs & this.buffs))
259 buff_SetCooldown(this, autocvar_g_buffs_cooldown_respawn + frametime);
261 if(autocvar_g_buffs_randomize)
262 buff_NewType(this, this.buffs);
264 if(autocvar_g_buffs_random_location || (this.spawnflags & 64))
268 if(this.buff_activetime)
270 if((round_handler_IsActive() && !round_handler_IsRoundStarted()) || time >= game_starttime)
272 this.buff_activetime = max(0, this.buff_activetime - frametime);
274 if(!this.buff_activetime)
276 this.buff_active = true;
277 sound(this, CH_TRIGGER, SND_STRENGTH_RESPAWN, VOL_BASE, ATTN_NORM);
278 Send_Effect(EFFECT_ITEM_RESPAWN, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
284 if(this.team && !this.buff_waypoint)
285 buff_Waypoint_Spawn(this);
288 if(time >= this.lifetime)
292 this.nextthink = time;
293 //this.angles_y = time * 110.1;
296 void buff_Waypoint_Reset(entity this)
298 WaypointSprite_Kill(this.buff_waypoint);
300 if(this.buff_activetime) { buff_Waypoint_Spawn(this); }
303 void buff_Reset(entity this)
305 if(autocvar_g_buffs_randomize)
306 buff_NewType(this, this.buffs);
308 buff_SetCooldown(this, autocvar_g_buffs_cooldown_activate);
309 buff_Waypoint_Reset(this);
310 this.buff_activetime_updated = false;
312 if(autocvar_g_buffs_random_location || (this.spawnflags & 64))
316 bool buff_Customize(entity this, entity client)
318 entity player = WaypointSprite_getviewentity(client);
319 if(!this.buff_active || (this.team && DIFF_TEAM(player, this)))
322 if(this.effects & EF_FULLBRIGHT) { this.effects &= ~(EF_FULLBRIGHT); }
328 if(!(this.effects & EF_FULLBRIGHT)) { this.effects |= EF_FULLBRIGHT; }
329 this.light_lev = 220 + 36 * sin(time);
330 this.pflags = PFLAGS_FULLDYNAMIC;
335 void buff_Init(entity this)
337 if(!cvar("g_buffs")) { delete(this); return; }
339 if(!teamplay && this.team) { this.team = 0; }
341 entity buff = buff_FirstFromFlags(this.buffs);
343 if(!this.buffs || buff_Available(buff))
344 buff_NewType(this, 0);
346 this.classname = "item_buff";
347 this.solid = SOLID_TRIGGER;
348 this.flags = FL_ITEM;
349 this.bot_pickup = true;
350 this.bot_pickupevalfunc = commodity_pickupevalfunc;
351 this.bot_pickupbasevalue = 1000;
352 IL_PUSH(g_items, this);
353 setthink(this, buff_Think);
354 settouch(this, buff_Touch);
355 this.reset = buff_Reset;
356 this.nextthink = time + 0.1;
358 set_movetype(this, MOVETYPE_TOSS);
360 this.skin = buff.m_skin;
361 this.effects = EF_FULLBRIGHT | EF_STARDUST | EF_NOSHADOW;
362 this.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY;
363 setcefc(this, buff_Customize);
364 //this.gravity = 100;
365 this.color = buff.m_color;
366 this.glowmod = buff_GlowColor(this);
367 buff_SetCooldown(this, autocvar_g_buffs_cooldown_activate + game_starttime);
368 this.buff_active = !this.buff_activetime;
369 this.pflags = PFLAGS_FULLDYNAMIC;
371 if(this.spawnflags & 1)
375 set_movetype(this, MOVETYPE_NONE); // reset by random location
377 setmodel(this, MDL_BUFF);
378 setsize(this, BUFF_MIN, BUFF_MAX);
380 if(cvar("g_buffs_random_location") || (this.spawnflags & 64))
384 void buff_Init_Compat(entity ent, entity replacement)
386 if (ent.spawnflags & 2)
387 ent.team = NUM_TEAM_1;
388 else if (ent.spawnflags & 4)
389 ent.team = NUM_TEAM_2;
391 ent.buffs = replacement.m_itemid;
396 void buff_SpawnReplacement(entity ent, entity old)
398 setorigin(ent, old.origin);
399 ent.angles = old.angles;
400 ent.noalign = (old.noalign || (old.spawnflags & 1));
405 void buff_Vengeance_DelayedDamage(entity this)
408 Damage(this.enemy, this.owner, this.owner, this.dmg, DEATH_BUFF.m_id, this.enemy.origin, '0 0 0');
414 // note: only really useful in teamplay
415 void buff_Medic_Heal(entity this)
417 FOREACH_CLIENT(IS_PLAYER(it) && it != this && vdist(it.origin - this.origin, <=, autocvar_g_buffs_medic_heal_range),
419 if(SAME_TEAM(it, this))
420 if(it.health < autocvar_g_balance_health_regenstable)
422 Send_Effect(EFFECT_HEALING, it.origin, '0 0 0', 1);
423 it.health = bound(0, it.health + autocvar_g_buffs_medic_heal_amount, autocvar_g_balance_health_regenstable);
428 float buff_Inferno_CalculateTime(float damg, float offset_x, float offset_y, float intersect_x, float intersect_y, float base)
430 return offset_y + (intersect_y - offset_y) * logn(((damg - offset_x) * ((base - 1) / intersect_x)) + 1, base);
434 MUTATOR_HOOKFUNCTION(buffs, PlayerDamage_SplitHealthArmor)
436 entity frag_target = M_ARGV(2, entity);
437 float frag_deathtype = M_ARGV(6, float);
438 float frag_damage = M_ARGV(7, float);
440 if(frag_deathtype == DEATH_BUFF.m_id) { return; }
442 if(frag_target.buffs & BUFF_RESISTANCE.m_itemid)
444 vector v = healtharmor_applydamage(50, autocvar_g_buffs_resistance_blockpercent, frag_deathtype, frag_damage);
445 M_ARGV(4, float) = v.x; // take
446 M_ARGV(5, float) = v.y; // save
450 MUTATOR_HOOKFUNCTION(buffs, PlayerDamage_Calculate)
452 entity frag_attacker = M_ARGV(1, entity);
453 entity frag_target = M_ARGV(2, entity);
454 float frag_deathtype = M_ARGV(3, float);
455 float frag_damage = M_ARGV(4, float);
456 vector frag_force = M_ARGV(6, vector);
458 if(frag_deathtype == DEATH_BUFF.m_id) { return; }
460 if(frag_target.buffs & BUFF_SPEED.m_itemid)
461 if(frag_target != frag_attacker)
462 frag_damage *= autocvar_g_buffs_speed_damage_take;
464 if(frag_target.buffs & BUFF_MEDIC.m_itemid)
465 if((frag_target.health - frag_damage) <= 0)
466 if(!ITEM_DAMAGE_NEEDKILL(frag_deathtype))
468 if(random() <= autocvar_g_buffs_medic_survive_chance)
469 frag_damage = max(5, frag_target.health - autocvar_g_buffs_medic_survive_health);
471 if(frag_target.buffs & BUFF_JUMP.m_itemid)
472 if(frag_deathtype == DEATH_FALL.m_id)
475 if(frag_target.buffs & BUFF_VENGEANCE.m_itemid)
477 if(frag_attacker != frag_target)
478 if(!ITEM_DAMAGE_NEEDKILL(frag_deathtype))
480 entity dmgent = spawn();
482 dmgent.dmg = frag_damage * autocvar_g_buffs_vengeance_damage_multiplier;
483 dmgent.enemy = frag_attacker;
484 dmgent.owner = frag_target;
485 setthink(dmgent, buff_Vengeance_DelayedDamage);
486 dmgent.nextthink = time + 0.1;
489 if(frag_target.buffs & BUFF_BASH.m_itemid)
490 if(frag_attacker != frag_target)
491 frag_force = '0 0 0';
493 if(frag_attacker.buffs & BUFF_BASH.m_itemid)
495 if(frag_attacker == frag_target)
496 frag_force *= autocvar_g_buffs_bash_force_self;
498 frag_force *= autocvar_g_buffs_bash_force;
500 if(frag_attacker.buffs & BUFF_DISABILITY.m_itemid)
501 if(frag_target != frag_attacker)
502 frag_target.buff_disability_time = time + autocvar_g_buffs_disability_slowtime;
504 if(frag_target.buffs & BUFF_INFERNO.m_itemid)
506 if(frag_deathtype == DEATH_FIRE.m_id)
508 if(frag_deathtype == DEATH_LAVA.m_id)
509 frag_damage *= 0.5; // TODO: cvarize?
512 if(frag_attacker.buffs & BUFF_LUCK.m_itemid)
513 if(frag_attacker != frag_target)
514 if(autocvar_g_buffs_luck_damagemultiplier > 0)
515 if(random() <= autocvar_g_buffs_luck_chance)
516 frag_damage *= autocvar_g_buffs_luck_damagemultiplier;
518 if(frag_attacker.buffs & BUFF_INFERNO.m_itemid)
519 if(frag_target != frag_attacker) {
520 float btime = buff_Inferno_CalculateTime(
523 autocvar_g_buffs_inferno_burntime_min_time,
524 autocvar_g_buffs_inferno_burntime_target_damage,
525 autocvar_g_buffs_inferno_burntime_target_time,
526 autocvar_g_buffs_inferno_burntime_factor
528 Fire_AddDamage(frag_target, frag_attacker, (frag_damage * autocvar_g_buffs_inferno_damagemultiplier), btime, DEATH_BUFF.m_id);
531 // this... is ridiculous (TODO: fix!)
532 if(frag_attacker.buffs & BUFF_VAMPIRE.m_itemid)
533 if(!frag_target.vehicle)
534 if(!ITEM_DAMAGE_NEEDKILL(frag_deathtype))
535 if(!IS_DEAD(frag_target))
536 if(IS_PLAYER(frag_target) || IS_MONSTER(frag_target))
537 if(frag_attacker != frag_target)
538 if(!STAT(FROZEN, frag_target))
539 if(frag_target.takedamage)
540 if(DIFF_TEAM(frag_attacker, frag_target))
542 frag_attacker.health = bound(0, frag_attacker.health + bound(0, frag_damage * autocvar_g_buffs_vampire_damage_steal, frag_target.health), g_pickup_healthsmall_max);
543 if(frag_target.armorvalue)
544 frag_attacker.armorvalue = bound(0, frag_attacker.armorvalue + bound(0, frag_damage * autocvar_g_buffs_vampire_damage_steal, frag_target.armorvalue), g_pickup_armorsmall_max);
547 M_ARGV(4, float) = frag_damage;
548 M_ARGV(6, vector) = frag_force;
551 MUTATOR_HOOKFUNCTION(buffs, PlayerSpawn)
553 entity player = M_ARGV(0, entity);
556 player.buff_time = 0;
557 // reset timers here to prevent them continuing after re-spawn
558 player.buff_disability_time = 0;
559 player.buff_disability_effect_time = 0;
562 .float stat_sv_maxspeed;
563 .float stat_sv_airspeedlimit_nonqw;
564 .float stat_sv_jumpvelocity;
566 MUTATOR_HOOKFUNCTION(buffs, PlayerPhysics)
568 entity player = M_ARGV(0, entity);
570 if(player.buffs & BUFF_SPEED.m_itemid)
572 player.stat_sv_maxspeed *= autocvar_g_buffs_speed_speed;
573 player.stat_sv_airspeedlimit_nonqw *= autocvar_g_buffs_speed_speed;
576 if(time < player.buff_disability_time)
578 player.stat_sv_maxspeed *= autocvar_g_buffs_disability_speed;
579 player.stat_sv_airspeedlimit_nonqw *= autocvar_g_buffs_disability_speed;
582 if(player.buffs & BUFF_JUMP.m_itemid)
584 // automatically reset, no need to worry
585 player.stat_sv_jumpvelocity = autocvar_g_buffs_jump_height;
589 MUTATOR_HOOKFUNCTION(buffs, PlayerJump)
591 entity player = M_ARGV(0, entity);
593 if(player.buffs & BUFF_JUMP.m_itemid)
594 M_ARGV(1, float) = autocvar_g_buffs_jump_height;
597 MUTATOR_HOOKFUNCTION(buffs, MonsterMove)
599 entity mon = M_ARGV(0, entity);
601 if(time < mon.buff_disability_time)
603 M_ARGV(1, float) *= autocvar_g_buffs_disability_speed; // run speed
604 M_ARGV(2, float) *= autocvar_g_buffs_disability_speed; // walk speed
608 MUTATOR_HOOKFUNCTION(buffs, PlayerDies)
610 entity frag_target = M_ARGV(2, entity);
612 if(frag_target.buffs)
614 int buffid = buff_FirstFromFlags(frag_target.buffs).m_id;
615 Send_Notification(NOTIF_ALL_EXCEPT, frag_target, MSG_INFO, INFO_ITEM_BUFF_LOST, frag_target.netname, buffid);
616 frag_target.buffs = 0;
618 if(frag_target.buff_model)
620 delete(frag_target.buff_model);
621 frag_target.buff_model = NULL;
626 MUTATOR_HOOKFUNCTION(buffs, PlayerUseKey, CBC_ORDER_FIRST)
628 if(MUTATOR_RETURNVALUE || gameover) { return; }
630 entity player = M_ARGV(0, entity);
634 int buffid = buff_FirstFromFlags(player.buffs).m_id;
635 Send_Notification(NOTIF_ONE, player, MSG_MULTI, ITEM_BUFF_DROP, buffid);
636 Send_Notification(NOTIF_ALL_EXCEPT, player, MSG_INFO, INFO_ITEM_BUFF_LOST, player.netname, buffid);
639 player.buff_time = 0; // already notified
640 sound(player, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM);
645 MUTATOR_HOOKFUNCTION(buffs, ForbidThrowCurrentWeapon)
647 if(MUTATOR_RETURNVALUE || gameover) { return; }
648 entity player = M_ARGV(0, entity);
650 if(player.buffs & BUFF_SWAPPER.m_itemid)
652 float best_distance = autocvar_g_buffs_swapper_range;
653 entity closest = NULL;
654 FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(
655 if(!IS_DEAD(it) && !STAT(FROZEN, it) && !it.vehicle)
656 if(DIFF_TEAM(it, player))
658 float test = vlen2(player.origin - it.origin);
659 if(test <= best_distance * best_distance)
661 best_distance = sqrt(test);
669 vector my_org, my_vel, my_ang, their_org, their_vel, their_ang;
671 my_org = player.origin;
672 my_vel = player.velocity;
673 my_ang = player.angles;
674 their_org = closest.origin;
675 their_vel = closest.velocity;
676 their_ang = closest.angles;
678 Drop_Special_Items(closest);
680 MUTATOR_CALLHOOK(PortalTeleport, player); // initiate flag dropper
682 setorigin(player, their_org);
683 setorigin(closest, my_org);
685 closest.velocity = my_vel;
686 closest.angles = my_ang;
687 closest.fixangle = true;
688 closest.oldorigin = my_org;
689 closest.oldvelocity = my_vel;
690 player.velocity = their_vel;
691 player.angles = their_ang;
692 player.fixangle = true;
693 player.oldorigin = their_org;
694 player.oldvelocity = their_vel;
696 // set pusher so player gets the kill if they fall into void
697 closest.pusher = player;
698 closest.pushltime = time + autocvar_g_maxpushtime;
699 closest.istypefrag = PHYS_INPUT_BUTTON_CHAT(closest);
701 Send_Effect(EFFECT_ELECTRO_COMBO, their_org, '0 0 0', 1);
702 Send_Effect(EFFECT_ELECTRO_COMBO, my_org, '0 0 0', 1);
704 sound(player, CH_TRIGGER, SND_KA_RESPAWN, VOL_BASE, ATTEN_NORM);
705 sound(closest, CH_TRIGGER, SND_KA_RESPAWN, VOL_BASE, ATTEN_NORM);
707 // TODO: add a counter to handle how many times one can teleport, and a delay to prevent spam
714 bool buffs_RemovePlayer(entity player)
716 if(player.buff_model)
718 delete(player.buff_model);
719 player.buff_model = NULL;
722 // also reset timers here to prevent them continuing after spectating
723 player.buff_disability_time = 0;
724 player.buff_disability_effect_time = 0;
728 MUTATOR_HOOKFUNCTION(buffs, MakePlayerObserver) { entity player = M_ARGV(0, entity); return buffs_RemovePlayer(player); }
729 MUTATOR_HOOKFUNCTION(buffs, ClientDisconnect) { entity player = M_ARGV(0, entity); return buffs_RemovePlayer(player); }
731 MUTATOR_HOOKFUNCTION(buffs, CustomizeWaypoint)
733 entity wp = M_ARGV(0, entity);
734 entity player = M_ARGV(1, entity);
736 entity e = WaypointSprite_getviewentity(player);
738 // if you have the invisibility powerup, sprites ALWAYS are restricted to your team
739 // but only apply this to real players, not to spectators
740 if((wp.owner.flags & FL_CLIENT) && (wp.owner.buffs & BUFF_INVISIBLE.m_itemid) && (e == player))
741 if(DIFF_TEAM(wp.owner, e))
745 MUTATOR_HOOKFUNCTION(buffs, OnEntityPreSpawn, CBC_ORDER_LAST)
747 entity ent = M_ARGV(0, entity);
749 if(autocvar_g_buffs_replace_powerups)
750 switch(ent.classname)
752 case "item_strength":
753 case "item_invincible":
756 buff_SpawnReplacement(e, ent);
762 MUTATOR_HOOKFUNCTION(buffs, WeaponRateFactor)
764 entity player = M_ARGV(1, entity);
766 if(player.buffs & BUFF_SPEED.m_itemid)
767 M_ARGV(0, float) *= autocvar_g_buffs_speed_rate;
769 if(time < player.buff_disability_time)
770 M_ARGV(0, float) *= autocvar_g_buffs_disability_rate;
773 MUTATOR_HOOKFUNCTION(buffs, WeaponSpeedFactor)
775 entity player = M_ARGV(1, entity);
777 if(player.buffs & BUFF_SPEED.m_itemid)
778 M_ARGV(0, float) *= autocvar_g_buffs_speed_weaponspeed;
780 if(time < player.buff_disability_time)
781 M_ARGV(0, float) *= autocvar_g_buffs_disability_weaponspeed;
784 MUTATOR_HOOKFUNCTION(buffs, PlayerPreThink)
786 entity player = M_ARGV(0, entity);
788 if(gameover || IS_DEAD(player)) { return; }
790 if(time < player.buff_disability_time)
791 if(time >= player.buff_disability_effect_time)
793 Send_Effect(EFFECT_SMOKING, player.origin + ((player.mins + player.maxs) * 0.5), '0 0 0', 1);
794 player.buff_disability_effect_time = time + 0.5;
797 // handle buff lost status
798 // 1: notify everyone else
799 // 2: notify carrier as well
802 if(player.buff_time && player.buffs)
803 if(time >= player.buff_time)
805 player.buff_time = 0;
809 if(STAT(FROZEN, player)) { buff_lost = 1; }
815 int buffid = buff_FirstFromFlags(player.buffs).m_id;
818 Send_Notification(NOTIF_ONE, player, MSG_MULTI, ITEM_BUFF_DROP, buffid); // TODO: special timeout message?
819 sound(player, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM);
822 Send_Notification(NOTIF_ALL_EXCEPT, player, MSG_INFO, INFO_ITEM_BUFF_LOST, player.netname, buffid);
827 if(player.buffs & BUFF_MAGNET.m_itemid)
830 IL_EACH(g_items, it.itemdef,
833 pickup_size = '1 1 1' * autocvar_g_buffs_magnet_range_buff;
835 pickup_size = '1 1 1' * autocvar_g_buffs_magnet_range_item;
837 if(boxesoverlap(player.absmin - pickup_size, player.absmax + pickup_size, it.absmin, it.absmax))
840 gettouch(it)(it, player);
845 if(player.buffs & BUFF_AMMO.m_itemid)
847 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
849 .entity weaponentity = weaponentities[slot];
850 if(player.(weaponentity).clip_size)
851 player.(weaponentity).clip_load = player.(weaponentity).(weapon_load[player.(weaponentity).m_switchweapon.m_id]) = player.(weaponentity).clip_size;
855 if((player.buffs & BUFF_INVISIBLE.m_itemid) && (player.oldbuffs & BUFF_INVISIBLE.m_itemid))
856 if(player.alpha != autocvar_g_buffs_invisible_alpha)
857 player.alpha = autocvar_g_buffs_invisible_alpha; // powerups reset alpha, so we must enforce this (TODO)
859 if(player.buffs & BUFF_MEDIC.m_itemid)
860 if(time >= player.buff_medic_healtime)
862 buff_Medic_Heal(player);
863 player.buff_medic_healtime = time + autocvar_g_buffs_medic_heal_delay;
866 #define BUFF_ONADD(b) if ( (player.buffs & (b).m_itemid) && !(player.oldbuffs & (b).m_itemid))
867 #define BUFF_ONREM(b) if (!(player.buffs & (b).m_itemid) && (player.oldbuffs & (b).m_itemid))
869 if(player.buffs != player.oldbuffs)
871 entity buff = buff_FirstFromFlags(player.buffs);
872 float bufftime = buff != BUFF_Null ? buff.m_time(buff) : 0;
873 player.buff_time = (bufftime) ? time + bufftime : 0;
875 BUFF_ONADD(BUFF_AMMO)
877 player.buff_ammo_prev_infitems = (player.items & IT_UNLIMITED_WEAPON_AMMO);
878 player.items |= IT_UNLIMITED_WEAPON_AMMO;
880 if(player.buffs & BUFF_AMMO.m_itemid)
882 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
884 .entity weaponentity = weaponentities[slot];
885 if(player.(weaponentity).clip_load)
886 player.(weaponentity).buff_ammo_prev_clipload = player.(weaponentity).clip_load;
887 if(player.(weaponentity).clip_size)
888 player.(weaponentity).clip_load = player.(weaponentity).(weapon_load[player.(weaponentity).m_switchweapon.m_id]) = player.(weaponentity).clip_size;
893 BUFF_ONREM(BUFF_AMMO)
895 if(player.buff_ammo_prev_infitems)
896 player.items |= IT_UNLIMITED_WEAPON_AMMO;
898 player.items &= ~IT_UNLIMITED_WEAPON_AMMO;
900 if(player.buffs & BUFF_AMMO.m_itemid)
902 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
904 .entity weaponentity = weaponentities[slot];
905 if(player.(weaponentity).buff_ammo_prev_clipload)
906 player.(weaponentity).clip_load = player.(weaponentity).buff_ammo_prev_clipload;
911 BUFF_ONADD(BUFF_INVISIBLE)
913 if(time < player.strength_finished && g_instagib)
914 player.alpha = autocvar_g_instagib_invis_alpha;
916 player.alpha = player.buff_invisible_prev_alpha;
917 player.alpha = autocvar_g_buffs_invisible_alpha;
920 BUFF_ONREM(BUFF_INVISIBLE)
921 player.alpha = player.buff_invisible_prev_alpha;
923 player.oldbuffs = player.buffs;
926 if(!player.buff_model)
927 buffs_BuffModel_Spawn(player);
929 player.buff_model.color = buff.m_color;
930 player.buff_model.glowmod = buff_GlowColor(player.buff_model);
931 player.buff_model.skin = buff.m_skin;
933 player.effects |= EF_NOSHADOW;
937 delete(player.buff_model);
938 player.buff_model = NULL;
940 player.effects &= ~(EF_NOSHADOW);
944 if(player.buff_model)
946 player.buff_model.effects = player.effects;
947 player.buff_model.effects |= EF_LOWPRECISION;
948 player.buff_model.effects = player.buff_model.effects & EFMASK_CHEAP; // eat performance
950 player.buff_model.alpha = player.alpha;
957 MUTATOR_HOOKFUNCTION(buffs, SpectateCopy)
959 entity spectatee = M_ARGV(0, entity);
960 entity client = M_ARGV(1, entity);
962 client.buffs = spectatee.buffs;
965 MUTATOR_HOOKFUNCTION(buffs, VehicleEnter)
967 entity player = M_ARGV(0, entity);
968 entity veh = M_ARGV(1, entity);
970 veh.buffs = player.buffs;
972 veh.buff_time = max(0, player.buff_time - time);
973 player.buff_time = 0;
976 MUTATOR_HOOKFUNCTION(buffs, VehicleExit)
978 entity player = M_ARGV(0, entity);
979 entity veh = M_ARGV(1, entity);
981 player.buffs = player.oldbuffs = veh.buffs;
983 player.buff_time = time + veh.buff_time;
987 MUTATOR_HOOKFUNCTION(buffs, PlayerRegen)
989 entity player = M_ARGV(0, entity);
991 if(player.buffs & BUFF_MEDIC.m_itemid)
993 M_ARGV(2, float) = autocvar_g_buffs_medic_rot; // rot_mod
994 M_ARGV(4, float) = M_ARGV(1, float) = autocvar_g_buffs_medic_max; // limit_mod = max_mod
995 M_ARGV(2, float) = autocvar_g_buffs_medic_regen; // regen_mod
998 if(player.buffs & BUFF_SPEED.m_itemid)
999 M_ARGV(2, float) = autocvar_g_buffs_speed_regen; // regen_mod
1002 REPLICATE(cvar_cl_buffs_autoreplace, bool, "cl_buffs_autoreplace");
1004 MUTATOR_HOOKFUNCTION(buffs, BuildMutatorsString)
1006 M_ARGV(0, string) = strcat(M_ARGV(0, string), ":Buffs");
1009 MUTATOR_HOOKFUNCTION(buffs, BuildMutatorsPrettyString)
1011 M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Buffs");
1014 void buffs_DelayedInit(entity this)
1016 if(autocvar_g_buffs_spawn_count > 0)
1017 if(find(NULL, classname, "item_buff") == NULL)
1020 for(i = 0; i < autocvar_g_buffs_spawn_count; ++i)
1023 e.spawnflags |= 64; // always randomize
1024 e.velocity = randomvec() * 250; // this gets reset anyway if random location works