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);
235 if(this.buff_waypoint)
237 //WaypointSprite_Disown(this.buff_waypoint, 1);
238 WaypointSprite_Kill(this.buff_waypoint);
239 buff_Waypoint_Spawn(this);
240 if(this.buff_activetime)
241 WaypointSprite_UpdateBuildFinished(this.buff_waypoint, time + this.buff_activetime - frametime);
244 this.oldbuffs = this.buffs;
248 if((round_handler_IsActive() && !round_handler_IsRoundStarted()) || time >= game_starttime)
249 if(!this.buff_activetime_updated)
251 buff_SetCooldown(this, this.buff_activetime);
252 this.buff_activetime_updated = true;
255 if(!this.buff_active && !this.buff_activetime)
256 if(!this.owner || STAT(FROZEN, this.owner) || IS_DEAD(this.owner) || !this.owner.iscreature || !(this.owner.buffs & this.buffs))
258 buff_SetCooldown(this, autocvar_g_buffs_cooldown_respawn + frametime);
260 if(autocvar_g_buffs_randomize)
261 buff_NewType(this, this.buffs);
263 if(autocvar_g_buffs_random_location || (this.spawnflags & 64))
267 if(this.buff_activetime)
269 if((round_handler_IsActive() && !round_handler_IsRoundStarted()) || time >= game_starttime)
271 this.buff_activetime = max(0, this.buff_activetime - frametime);
273 if(!this.buff_activetime)
275 this.buff_active = true;
276 sound(this, CH_TRIGGER, SND_STRENGTH_RESPAWN, VOL_BASE, ATTN_NORM);
277 Send_Effect(EFFECT_ITEM_RESPAWN, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
283 if(this.team && !this.buff_waypoint)
284 buff_Waypoint_Spawn(this);
287 if(time >= this.lifetime)
291 this.nextthink = time;
292 //this.angles_y = time * 110.1;
295 void buff_Waypoint_Reset(entity this)
297 WaypointSprite_Kill(this.buff_waypoint);
299 if(this.buff_activetime) { buff_Waypoint_Spawn(this); }
302 void buff_Reset(entity this)
304 if(autocvar_g_buffs_randomize)
305 buff_NewType(this, this.buffs);
307 buff_SetCooldown(this, autocvar_g_buffs_cooldown_activate);
308 buff_Waypoint_Reset(this);
309 this.buff_activetime_updated = false;
311 if(autocvar_g_buffs_random_location || (this.spawnflags & 64))
315 bool buff_Customize(entity this, entity client)
317 entity player = WaypointSprite_getviewentity(client);
318 if(!this.buff_active || (this.team && DIFF_TEAM(player, this)))
321 if(this.effects & EF_FULLBRIGHT) { this.effects &= ~(EF_FULLBRIGHT); }
327 if(!(this.effects & EF_FULLBRIGHT)) { this.effects |= EF_FULLBRIGHT; }
328 this.light_lev = 220 + 36 * sin(time);
329 this.pflags = PFLAGS_FULLDYNAMIC;
334 void buff_Init(entity this)
336 if(!cvar("g_buffs")) { delete(this); return; }
338 if(!teamplay && this.team) { this.team = 0; }
340 entity buff = buff_FirstFromFlags(this.buffs);
342 if(!this.buffs || buff_Available(buff))
343 buff_NewType(this, 0);
345 this.classname = "item_buff";
346 this.solid = SOLID_TRIGGER;
347 this.flags = FL_ITEM;
348 this.bot_pickup = true;
349 this.bot_pickupevalfunc = commodity_pickupevalfunc;
350 this.bot_pickupbasevalue = 1000;
351 IL_PUSH(g_items, this);
352 setthink(this, buff_Think);
353 settouch(this, buff_Touch);
354 this.reset = buff_Reset;
355 this.nextthink = time + 0.1;
357 set_movetype(this, MOVETYPE_TOSS);
359 this.skin = buff.m_skin;
360 this.effects = EF_FULLBRIGHT | EF_STARDUST | EF_NOSHADOW;
361 this.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY;
362 setcefc(this, buff_Customize);
363 //this.gravity = 100;
364 this.color = buff.m_color;
365 this.glowmod = buff_GlowColor(this);
366 buff_SetCooldown(this, autocvar_g_buffs_cooldown_activate + game_starttime);
367 this.buff_active = !this.buff_activetime;
368 this.pflags = PFLAGS_FULLDYNAMIC;
370 if(this.spawnflags & 1)
374 set_movetype(this, MOVETYPE_NONE); // reset by random location
376 setmodel(this, MDL_BUFF);
377 setsize(this, BUFF_MIN, BUFF_MAX);
379 if(cvar("g_buffs_random_location") || (this.spawnflags & 64))
383 void buff_Init_Compat(entity ent, entity replacement)
385 if (ent.spawnflags & 2)
386 ent.team = NUM_TEAM_1;
387 else if (ent.spawnflags & 4)
388 ent.team = NUM_TEAM_2;
390 ent.buffs = replacement.m_itemid;
395 void buff_SpawnReplacement(entity ent, entity old)
397 setorigin(ent, old.origin);
398 ent.angles = old.angles;
399 ent.noalign = (old.noalign || (old.spawnflags & 1));
404 void buff_Vengeance_DelayedDamage(entity this)
407 Damage(this.enemy, this.owner, this.owner, this.dmg, DEATH_BUFF.m_id, this.enemy.origin, '0 0 0');
413 // note: only really useful in teamplay
414 void buff_Medic_Heal(entity this)
416 FOREACH_CLIENT(IS_PLAYER(it) && it != this && vdist(it.origin - this.origin, <=, autocvar_g_buffs_medic_heal_range),
418 if(SAME_TEAM(it, this))
419 if(it.health < autocvar_g_balance_health_regenstable)
421 Send_Effect(EFFECT_HEALING, it.origin, '0 0 0', 1);
422 it.health = bound(0, it.health + autocvar_g_buffs_medic_heal_amount, autocvar_g_balance_health_regenstable);
427 float buff_Inferno_CalculateTime(float x, float offset_x, float offset_y, float intersect_x, float intersect_y, float base)
429 return offset_y + (intersect_y - offset_y) * logn(((x - offset_x) * ((base - 1) / intersect_x)) + 1, base);
433 MUTATOR_HOOKFUNCTION(buffs, PlayerDamage_SplitHealthArmor)
435 entity frag_target = M_ARGV(2, entity);
436 float frag_deathtype = M_ARGV(6, float);
437 float frag_damage = M_ARGV(7, float);
439 if(frag_deathtype == DEATH_BUFF.m_id) { return; }
441 if(frag_target.buffs & BUFF_RESISTANCE.m_itemid)
443 vector v = healtharmor_applydamage(50, autocvar_g_buffs_resistance_blockpercent, frag_deathtype, frag_damage);
444 M_ARGV(4, float) = v.x; // take
445 M_ARGV(5, float) = v.y; // save
449 MUTATOR_HOOKFUNCTION(buffs, PlayerDamage_Calculate)
451 entity frag_attacker = M_ARGV(1, entity);
452 entity frag_target = M_ARGV(2, entity);
453 float frag_deathtype = M_ARGV(3, float);
454 float frag_damage = M_ARGV(4, float);
455 vector frag_force = M_ARGV(6, vector);
457 if(frag_deathtype == DEATH_BUFF.m_id) { return; }
459 if(frag_target.buffs & BUFF_SPEED.m_itemid)
460 if(frag_target != frag_attacker)
461 frag_damage *= autocvar_g_buffs_speed_damage_take;
463 if(frag_target.buffs & BUFF_MEDIC.m_itemid)
464 if((frag_target.health - frag_damage) <= 0)
465 if(!ITEM_DAMAGE_NEEDKILL(frag_deathtype))
467 if(random() <= autocvar_g_buffs_medic_survive_chance)
468 frag_damage = max(5, frag_target.health - autocvar_g_buffs_medic_survive_health);
470 if(frag_target.buffs & BUFF_JUMP.m_itemid)
471 if(frag_deathtype == DEATH_FALL.m_id)
474 if(frag_target.buffs & BUFF_VENGEANCE.m_itemid)
476 if(frag_attacker != frag_target)
477 if(!ITEM_DAMAGE_NEEDKILL(frag_deathtype))
479 entity dmgent = spawn();
481 dmgent.dmg = frag_damage * autocvar_g_buffs_vengeance_damage_multiplier;
482 dmgent.enemy = frag_attacker;
483 dmgent.owner = frag_target;
484 setthink(dmgent, buff_Vengeance_DelayedDamage);
485 dmgent.nextthink = time + 0.1;
488 if(frag_target.buffs & BUFF_BASH.m_itemid)
489 if(frag_attacker != frag_target)
490 frag_force = '0 0 0';
492 if(frag_attacker.buffs & BUFF_BASH.m_itemid)
494 if(frag_attacker == frag_target)
495 frag_force *= autocvar_g_buffs_bash_force_self;
497 frag_force *= autocvar_g_buffs_bash_force;
499 if(frag_attacker.buffs & BUFF_DISABILITY.m_itemid)
500 if(frag_target != frag_attacker)
501 frag_target.buff_disability_time = time + autocvar_g_buffs_disability_slowtime;
503 if(frag_target.buffs & BUFF_INFERNO.m_itemid)
505 if(frag_deathtype == DEATH_FIRE.m_id)
507 if(frag_deathtype == DEATH_LAVA.m_id)
508 frag_damage *= 0.5; // TODO: cvarize?
511 if(frag_attacker.buffs & BUFF_LUCK.m_itemid)
512 if(frag_attacker != frag_target)
513 if(autocvar_g_buffs_luck_damagemultiplier > 0)
514 if(random() <= autocvar_g_buffs_luck_chance)
515 frag_damage *= autocvar_g_buffs_luck_damagemultiplier;
517 if(frag_attacker.buffs & BUFF_INFERNO.m_itemid)
518 if(frag_target != frag_attacker) {
519 float btime = buff_Inferno_CalculateTime(
522 autocvar_g_buffs_inferno_burntime_min_time,
523 autocvar_g_buffs_inferno_burntime_target_damage,
524 autocvar_g_buffs_inferno_burntime_target_time,
525 autocvar_g_buffs_inferno_burntime_factor
527 Fire_AddDamage(frag_target, frag_attacker, (frag_damage * autocvar_g_buffs_inferno_damagemultiplier), btime, DEATH_BUFF.m_id);
530 // this... is ridiculous (TODO: fix!)
531 if(frag_attacker.buffs & BUFF_VAMPIRE.m_itemid)
532 if(!frag_target.vehicle)
533 if(!ITEM_DAMAGE_NEEDKILL(frag_deathtype))
534 if(!IS_DEAD(frag_target))
535 if(IS_PLAYER(frag_target) || IS_MONSTER(frag_target))
536 if(frag_attacker != frag_target)
537 if(!STAT(FROZEN, frag_target))
538 if(frag_target.takedamage)
539 if(DIFF_TEAM(frag_attacker, frag_target))
541 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);
542 if(frag_target.armorvalue)
543 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);
546 M_ARGV(4, float) = frag_damage;
547 M_ARGV(6, vector) = frag_force;
550 MUTATOR_HOOKFUNCTION(buffs, PlayerSpawn)
552 entity player = M_ARGV(0, entity);
555 player.buff_time = 0;
556 // reset timers here to prevent them continuing after re-spawn
557 player.buff_disability_time = 0;
558 player.buff_disability_effect_time = 0;
561 .float stat_sv_maxspeed;
562 .float stat_sv_airspeedlimit_nonqw;
563 .float stat_sv_jumpvelocity;
565 MUTATOR_HOOKFUNCTION(buffs, PlayerPhysics)
567 entity player = M_ARGV(0, entity);
569 if(player.buffs & BUFF_SPEED.m_itemid)
571 player.stat_sv_maxspeed *= autocvar_g_buffs_speed_speed;
572 player.stat_sv_airspeedlimit_nonqw *= autocvar_g_buffs_speed_speed;
575 if(time < player.buff_disability_time)
577 player.stat_sv_maxspeed *= autocvar_g_buffs_disability_speed;
578 player.stat_sv_airspeedlimit_nonqw *= autocvar_g_buffs_disability_speed;
581 if(player.buffs & BUFF_JUMP.m_itemid)
583 // automatically reset, no need to worry
584 player.stat_sv_jumpvelocity = autocvar_g_buffs_jump_height;
588 MUTATOR_HOOKFUNCTION(buffs, PlayerJump)
590 entity player = M_ARGV(0, entity);
592 if(player.buffs & BUFF_JUMP.m_itemid)
593 M_ARGV(1, float) = autocvar_g_buffs_jump_height;
596 MUTATOR_HOOKFUNCTION(buffs, MonsterMove)
598 entity mon = M_ARGV(0, entity);
600 if(time < mon.buff_disability_time)
602 M_ARGV(1, float) *= autocvar_g_buffs_disability_speed; // run speed
603 M_ARGV(2, float) *= autocvar_g_buffs_disability_speed; // walk speed
607 MUTATOR_HOOKFUNCTION(buffs, PlayerDies)
609 entity frag_target = M_ARGV(2, entity);
611 if(frag_target.buffs)
613 int buffid = buff_FirstFromFlags(frag_target.buffs).m_id;
614 Send_Notification(NOTIF_ALL_EXCEPT, frag_target, MSG_INFO, INFO_ITEM_BUFF_LOST, frag_target.netname, buffid);
615 frag_target.buffs = 0;
617 if(frag_target.buff_model)
619 delete(frag_target.buff_model);
620 frag_target.buff_model = NULL;
625 MUTATOR_HOOKFUNCTION(buffs, PlayerUseKey, CBC_ORDER_FIRST)
627 if(MUTATOR_RETURNVALUE || gameover) { return; }
629 entity player = M_ARGV(0, entity);
633 int buffid = buff_FirstFromFlags(player.buffs).m_id;
634 Send_Notification(NOTIF_ONE, player, MSG_MULTI, ITEM_BUFF_DROP, buffid);
635 Send_Notification(NOTIF_ALL_EXCEPT, player, MSG_INFO, INFO_ITEM_BUFF_LOST, player.netname, buffid);
638 player.buff_time = 0; // already notified
639 sound(player, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM);
644 MUTATOR_HOOKFUNCTION(buffs, ForbidThrowCurrentWeapon)
646 if(MUTATOR_RETURNVALUE || gameover) { return; }
647 entity player = M_ARGV(0, entity);
649 if(player.buffs & BUFF_SWAPPER.m_itemid)
651 float best_distance = autocvar_g_buffs_swapper_range;
652 entity closest = NULL;
653 FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(
654 if(!IS_DEAD(it) && !STAT(FROZEN, it) && !it.vehicle)
655 if(DIFF_TEAM(it, player))
657 float test = vlen2(player.origin - it.origin);
658 if(test <= best_distance * best_distance)
660 best_distance = sqrt(test);
668 vector my_org, my_vel, my_ang, their_org, their_vel, their_ang;
670 my_org = player.origin;
671 my_vel = player.velocity;
672 my_ang = player.angles;
673 their_org = closest.origin;
674 their_vel = closest.velocity;
675 their_ang = closest.angles;
677 Drop_Special_Items(closest);
679 MUTATOR_CALLHOOK(PortalTeleport, player); // initiate flag dropper
681 setorigin(player, their_org);
682 setorigin(closest, my_org);
684 closest.velocity = my_vel;
685 closest.angles = my_ang;
686 closest.fixangle = true;
687 closest.oldorigin = my_org;
688 closest.oldvelocity = my_vel;
689 player.velocity = their_vel;
690 player.angles = their_ang;
691 player.fixangle = true;
692 player.oldorigin = their_org;
693 player.oldvelocity = their_vel;
695 // set pusher so player gets the kill if they fall into void
696 closest.pusher = player;
697 closest.pushltime = time + autocvar_g_maxpushtime;
698 closest.istypefrag = PHYS_INPUT_BUTTON_CHAT(closest);
700 Send_Effect(EFFECT_ELECTRO_COMBO, their_org, '0 0 0', 1);
701 Send_Effect(EFFECT_ELECTRO_COMBO, my_org, '0 0 0', 1);
703 sound(player, CH_TRIGGER, SND_KA_RESPAWN, VOL_BASE, ATTEN_NORM);
704 sound(closest, CH_TRIGGER, SND_KA_RESPAWN, VOL_BASE, ATTEN_NORM);
706 // TODO: add a counter to handle how many times one can teleport, and a delay to prevent spam
713 bool buffs_RemovePlayer(entity player)
715 if(player.buff_model)
717 delete(player.buff_model);
718 player.buff_model = NULL;
721 // also reset timers here to prevent them continuing after spectating
722 player.buff_disability_time = 0;
723 player.buff_disability_effect_time = 0;
727 MUTATOR_HOOKFUNCTION(buffs, MakePlayerObserver) { entity player = M_ARGV(0, entity); return buffs_RemovePlayer(player); }
728 MUTATOR_HOOKFUNCTION(buffs, ClientDisconnect) { entity player = M_ARGV(0, entity); return buffs_RemovePlayer(player); }
730 MUTATOR_HOOKFUNCTION(buffs, CustomizeWaypoint)
732 entity wp = M_ARGV(0, entity);
733 entity player = M_ARGV(1, entity);
735 entity e = WaypointSprite_getviewentity(player);
737 // if you have the invisibility powerup, sprites ALWAYS are restricted to your team
738 // but only apply this to real players, not to spectators
739 if((wp.owner.flags & FL_CLIENT) && (wp.owner.buffs & BUFF_INVISIBLE.m_itemid) && (e == player))
740 if(DIFF_TEAM(wp.owner, e))
744 MUTATOR_HOOKFUNCTION(buffs, OnEntityPreSpawn, CBC_ORDER_LAST)
746 entity ent = M_ARGV(0, entity);
748 if(autocvar_g_buffs_replace_powerups)
749 switch(ent.classname)
751 case "item_strength":
752 case "item_invincible":
755 buff_SpawnReplacement(e, ent);
761 MUTATOR_HOOKFUNCTION(buffs, WeaponRateFactor)
763 entity player = M_ARGV(1, entity);
765 if(player.buffs & BUFF_SPEED.m_itemid)
766 M_ARGV(0, float) *= autocvar_g_buffs_speed_rate;
768 if(time < player.buff_disability_time)
769 M_ARGV(0, float) *= autocvar_g_buffs_disability_rate;
772 MUTATOR_HOOKFUNCTION(buffs, WeaponSpeedFactor)
774 entity player = M_ARGV(1, entity);
776 if(player.buffs & BUFF_SPEED.m_itemid)
777 M_ARGV(0, float) *= autocvar_g_buffs_speed_weaponspeed;
779 if(time < player.buff_disability_time)
780 M_ARGV(0, float) *= autocvar_g_buffs_disability_weaponspeed;
783 MUTATOR_HOOKFUNCTION(buffs, PlayerPreThink)
785 entity player = M_ARGV(0, entity);
787 if(gameover || IS_DEAD(player)) { return; }
789 if(time < player.buff_disability_time)
790 if(time >= player.buff_disability_effect_time)
792 Send_Effect(EFFECT_SMOKING, player.origin + ((player.mins + player.maxs) * 0.5), '0 0 0', 1);
793 player.buff_disability_effect_time = time + 0.5;
796 // handle buff lost status
797 // 1: notify everyone else
798 // 2: notify carrier as well
801 if(player.buff_time && player.buffs)
802 if(time >= player.buff_time)
804 player.buff_time = 0;
808 if(STAT(FROZEN, player)) { buff_lost = 1; }
814 int buffid = buff_FirstFromFlags(player.buffs).m_id;
817 Send_Notification(NOTIF_ONE, player, MSG_MULTI, ITEM_BUFF_DROP, buffid); // TODO: special timeout message?
818 sound(player, CH_TRIGGER, SND_BUFF_LOST, VOL_BASE, ATTN_NORM);
821 Send_Notification(NOTIF_ALL_EXCEPT, player, MSG_INFO, INFO_ITEM_BUFF_LOST, player.netname, buffid);
826 if(player.buffs & BUFF_MAGNET.m_itemid)
829 IL_EACH(g_items, it.itemdef,
832 pickup_size = '1 1 1' * autocvar_g_buffs_magnet_range_buff;
834 pickup_size = '1 1 1' * autocvar_g_buffs_magnet_range_item;
836 if(boxesoverlap(player.absmin - pickup_size, player.absmax + pickup_size, it.absmin, it.absmax))
839 gettouch(it)(it, player);
844 if(player.buffs & BUFF_AMMO.m_itemid)
846 player.clip_load = player.(weapon_load[PS(player).m_switchweapon.m_id]) = player.clip_size;
848 if((player.buffs & BUFF_INVISIBLE.m_itemid) && (player.oldbuffs & BUFF_INVISIBLE.m_itemid))
849 if(player.alpha != autocvar_g_buffs_invisible_alpha)
850 player.alpha = autocvar_g_buffs_invisible_alpha; // powerups reset alpha, so we must enforce this (TODO)
852 if(player.buffs & BUFF_MEDIC.m_itemid)
853 if(time >= player.buff_medic_healtime)
855 buff_Medic_Heal(player);
856 player.buff_medic_healtime = time + autocvar_g_buffs_medic_heal_delay;
859 #define BUFF_ONADD(b) if ( (player.buffs & (b).m_itemid) && !(player.oldbuffs & (b).m_itemid))
860 #define BUFF_ONREM(b) if (!(player.buffs & (b).m_itemid) && (player.oldbuffs & (b).m_itemid))
862 if(player.buffs != player.oldbuffs)
864 entity buff = buff_FirstFromFlags(player.buffs);
865 float bufftime = buff != BUFF_Null ? buff.m_time(buff) : 0;
866 player.buff_time = (bufftime) ? time + bufftime : 0;
868 BUFF_ONADD(BUFF_AMMO)
870 player.buff_ammo_prev_infitems = (player.items & IT_UNLIMITED_WEAPON_AMMO);
871 player.items |= IT_UNLIMITED_WEAPON_AMMO;
874 player.buff_ammo_prev_clipload = player.clip_load;
875 player.clip_load = player.(weapon_load[PS(player).m_switchweapon.m_id]) = player.clip_size;
878 BUFF_ONREM(BUFF_AMMO)
880 if(player.buff_ammo_prev_infitems)
881 player.items |= IT_UNLIMITED_WEAPON_AMMO;
883 player.items &= ~IT_UNLIMITED_WEAPON_AMMO;
885 if(player.buff_ammo_prev_clipload)
886 player.clip_load = player.buff_ammo_prev_clipload;
889 BUFF_ONADD(BUFF_INVISIBLE)
891 if(time < player.strength_finished && g_instagib)
892 player.alpha = autocvar_g_instagib_invis_alpha;
894 player.alpha = player.buff_invisible_prev_alpha;
895 player.alpha = autocvar_g_buffs_invisible_alpha;
898 BUFF_ONREM(BUFF_INVISIBLE)
899 player.alpha = player.buff_invisible_prev_alpha;
901 player.oldbuffs = player.buffs;
904 if(!player.buff_model)
905 buffs_BuffModel_Spawn(player);
907 player.buff_model.color = buff.m_color;
908 player.buff_model.glowmod = buff_GlowColor(player.buff_model);
909 player.buff_model.skin = buff.m_skin;
911 player.effects |= EF_NOSHADOW;
915 delete(player.buff_model);
916 player.buff_model = NULL;
918 player.effects &= ~(EF_NOSHADOW);
922 if(player.buff_model)
924 player.buff_model.effects = player.effects;
925 player.buff_model.effects |= EF_LOWPRECISION;
926 player.buff_model.effects = player.buff_model.effects & EFMASK_CHEAP; // eat performance
928 player.buff_model.alpha = player.alpha;
935 MUTATOR_HOOKFUNCTION(buffs, SpectateCopy)
937 entity spectatee = M_ARGV(0, entity);
938 entity client = M_ARGV(1, entity);
940 client.buffs = spectatee.buffs;
943 MUTATOR_HOOKFUNCTION(buffs, VehicleEnter)
945 entity player = M_ARGV(0, entity);
946 entity veh = M_ARGV(1, entity);
948 veh.buffs = player.buffs;
950 veh.buff_time = max(0, player.buff_time - time);
951 player.buff_time = 0;
954 MUTATOR_HOOKFUNCTION(buffs, VehicleExit)
956 entity player = M_ARGV(0, entity);
957 entity veh = M_ARGV(1, entity);
959 player.buffs = player.oldbuffs = veh.buffs;
961 player.buff_time = time + veh.buff_time;
965 MUTATOR_HOOKFUNCTION(buffs, PlayerRegen)
967 entity player = M_ARGV(0, entity);
969 if(player.buffs & BUFF_MEDIC.m_itemid)
971 M_ARGV(2, float) = autocvar_g_buffs_medic_rot; // rot_mod
972 M_ARGV(4, float) = M_ARGV(1, float) = autocvar_g_buffs_medic_max; // limit_mod = max_mod
973 M_ARGV(2, float) = autocvar_g_buffs_medic_regen; // regen_mod
976 if(player.buffs & BUFF_SPEED.m_itemid)
977 M_ARGV(2, float) = autocvar_g_buffs_speed_regen; // regen_mod
980 REPLICATE(cvar_cl_buffs_autoreplace, bool, "cl_buffs_autoreplace");
982 MUTATOR_HOOKFUNCTION(buffs, BuildMutatorsString)
984 M_ARGV(0, string) = strcat(M_ARGV(0, string), ":Buffs");
987 MUTATOR_HOOKFUNCTION(buffs, BuildMutatorsPrettyString)
989 M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Buffs");
992 void buffs_DelayedInit(entity this)
994 if(autocvar_g_buffs_spawn_count > 0)
995 if(find(NULL, classname, "item_buff") == NULL)
998 for(i = 0; i < autocvar_g_buffs_spawn_count; ++i)
1001 e.spawnflags |= 64; // always randomize
1002 e.velocity = randomvec() * 250; // this gets reset anyway if random location works