Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
swapper.qc
Go to the documentation of this file.
1#include "swapper.qh"
2
3#ifdef SVQC
4MUTATOR_HOOKFUNCTION(buffs, ForbidThrowCurrentWeapon)
5{
7 return;
8
9 entity player = M_ARGV(0, entity);
10 if (!StatusEffects_active(BUFF_SWAPPER, player))
11 return;
12
13 entity head = WarpZone_FindRadius(player.origin, autocvar_g_buffs_swapper_range, false);
14 entity closest = NULL;
15 float head_dist2, best_dist2 = autocvar_g_buffs_swapper_range ** 2;
16 for (; head; head = head.chain)
17 if (IS_PLAYER(head) && DIFF_TEAM(head, player)
18 && !IS_DEAD(head) && !STAT(FROZEN, head) && !head.vehicle)
19 {
20 head_dist2 = vlen2(head.WarpZone_findradius_dist);
21 if (head_dist2 < best_dist2)
22 {
23 best_dist2 = head_dist2;
24 closest = head;
25 }
26 }
27 if (closest == NULL)
28 return;
29
30 vector my_org = player.origin;
31 vector my_center = CENTER_OF_ENT(player);
32 vector my_vel = player.velocity;
33 vector my_ang = player.angles;
34 vector their_org = closest.origin;
35 vector their_center = CENTER_OF_ENT(closest);
36 vector their_vel = closest.velocity;
37 vector their_ang = closest.angles;
38
39 Drop_Special_Items(closest);
40
41 MUTATOR_CALLHOOK(PortalTeleport, player); // initiate flag dropper
42
43 setorigin(player, their_org);
44 setorigin(closest, my_org);
45
46 closest.velocity = my_vel;
47 closest.angles = my_ang;
48 if (IS_BOT_CLIENT(closest))
49 {
50 closest.v_angle = closest.angles;
51 bot_aim_reset(closest);
52 }
53 closest.fixangle = true;
54 closest.oldorigin = my_org;
55 closest.oldvelocity = my_vel;
56 player.velocity = their_vel;
57 player.angles = their_ang;
58 if (IS_BOT_CLIENT(player))
59 {
60 player.v_angle = player.angles;
61 bot_aim_reset(player);
62 }
63 player.fixangle = true;
64 player.oldorigin = their_org;
65 player.oldvelocity = their_vel;
66
67 // set pusher so player gets the kill if they fall into void
68 closest.pusher = player;
69 closest.pushltime = time + autocvar_g_maxpushtime;
70 closest.istypefrag = PHYS_INPUT_BUTTON_CHAT(closest);
71
72 Send_Effect(EFFECT_SWAPPER, their_center, '0 0 0', 1);
73 Send_Effect(EFFECT_SWAPPER, my_center, '0 0 0', 1);
74
75 sound(player, CH_TRIGGER, SND_KA_RESPAWN, VOL_BASE, ATTEN_NORM);
76 sound(closest, CH_TRIGGER, SND_KA_RESPAWN, VOL_BASE, ATTEN_NORM);
77
78 // TODO: add a counter to handle how many times one can teleport, and a delay to prevent spam
80 return true;
81}
82#endif // SVQC
83#ifdef MENUQC
84METHOD(SwapperBuff, describe, string(SwapperBuff this))
85{
86 TC(SwapperBuff, this);
88 PAR(_("The %s buff allows you to press %s to switch places with a nearby enemy once."), COLORED_NAME(this), strcat("^3", _("drop weapon"), "^7"));
89 PAR(_("A common usage of this buff is to jump over the map's void, then swap with an enemy, to cause them to fall into the void."));
90 PAR(_("The range that the buff works over is limited, so sometimes it may do nothing if there are no enemies nearby."));
91 return PAGE_TEXT;
92}
93#endif // MENUQC
void bot_aim_reset(entity this)
Definition aim.qc:134
#define MUTATOR_CALLHOOK(id,...)
Definition base.qh:143
#define MUTATOR_HOOKFUNCTION(...)
Definition base.qh:335
#define MUTATOR_RETURNVALUE
Definition base.qh:328
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
#define COLORED_NAME(this)
Definition color.qh:189
#define M_ARGV(x, type)
Definition events.qh:17
#define IS_DEAD(s)
Definition player.qh:244
#define PHYS_INPUT_BUTTON_CHAT(s)
Definition player.qh:161
#define IS_PLAYER(s)
Definition player.qh:242
float game_stopped
Definition stats.qh:81
#define CENTER_OF_ENT(ent)
Definition util.qh:10
float time
float autocvar_g_maxpushtime
Definition damage.qh:17
void Send_Effect(entity eff, vector eff_loc, vector eff_vel, int eff_cnt)
Definition all.qc:155
#define TC(T, sym)
Definition _all.inc:82
#define STAT(...)
Definition stats.qh:94
entity WarpZone_FindRadius(vector org, float rad, bool needlineofsight)
Definition common.qc:651
@ STATUSEFFECT_REMOVE_NORMAL
Effect is being removed by a function, calls regular removal mechanics.
Definition all.qh:28
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))
#define METHOD(cname, name, prototype)
Definition oo.qh:274
#define NULL
Definition post.qh:14
vector
Definition self.qh:96
void Drop_Special_Items(entity player)
Definition player.qc:42
const int CH_TRIGGER
Definition sound.qh:12
const float VOL_BASE
Definition sound.qh:36
const float ATTEN_NORM
Definition sound.qh:30
#define sound(e, c, s, v, a)
Definition sound.qh:52
bool StatusEffects_active(StatusEffect this, entity actor)
#define PAGE_TEXT
Definition string.qh:651
#define PAR(...)
Adds an individually translatable paragraph to PAGE_TEXT without having to deal with strcat and sprin...
Definition string.qh:657
#define PAGE_TEXT_INIT()
Definition string.qh:650
void buff_RemoveAll(entity actor, int removal_type)
Definition sv_buffs.qc:285
float autocvar_g_buffs_swapper_range
Definition swapper.qh:6
#define DIFF_TEAM(a, b)
Definition teams.qh:242
#define IS_BOT_CLIENT(v)
want: (IS_CLIENT(v) && !IS_REAL_CLIENT(v))
Definition utils.qh:15
#define vlen2(v)
Definition vector.qh:4