1 #include "clientkill.qh"
3 #include <server/defs.qh>
8 #include <common/vehicles/sv_vehicles.qh>
9 #include <common/notifications/all.qh>
10 #include <common/stats.qh>
12 void ClientKill_Now_TeamChange(entity this)
14 if (this.killindicator_teamchange == -1)
16 TeamBalance_JoinBestTeam(this);
18 else if (this.killindicator_teamchange == -2)
21 Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_SPECTATE_WARNING, autocvar_g_maxplayers_spectator_blocktime);
22 PutObserverInServer(this);
26 Player_SetTeamIndexChecked(this, Team_TeamToIndex(
27 this.killindicator_teamchange));
29 this.killindicator_teamchange = 0;
32 void ClientKill_Now(entity this)
36 vehicles_exit(this.vehicle, VHEF_RELEASE);
37 if (!this.killindicator_teamchange)
39 this.vehicle_health = -1;
40 Damage(this, this, this, 1 , DEATH_KILL.m_id, DMG_NOWEP, this.origin, '0 0 0');
44 if (this.killindicator && !wasfreed(this.killindicator))
45 delete(this.killindicator);
47 this.killindicator = NULL;
49 if (this.killindicator_teamchange)
50 ClientKill_Now_TeamChange(this);
52 if (!IS_SPEC(this) && !IS_OBSERVER(this) && MUTATOR_CALLHOOK(ClientKill_Now, this) == false)
54 Damage(this, this, this, 100000, DEATH_KILL.m_id, DMG_NOWEP, this.origin, '0 0 0');
57 // now I am sure the player IS dead
59 void KillIndicator_Think(entity this)
61 if (game_stopped || (this.owner.alpha < 0 && !this.owner.vehicle))
63 this.owner.killindicator = NULL;
70 ClientKill_Now(this.owner);
74 // count == 1 means that it's silent
78 setmodel(this, MDL_NUM(this.cnt));
79 if (IS_REAL_CLIENT(this.owner))
82 Send_Notification(NOTIF_ONE, this.owner, MSG_ANNCE, Announcer_PickNumber(CNT_KILL, this.cnt));
85 this.nextthink = time + 1;
91 .float clientkill_nexttime;
92 void ClientKill_TeamChange(entity this, float targetteam) // 0 = don't change, -1 = auto, -2 = spec
97 float killtime = autocvar_g_balance_kill_delay;
99 if (MUTATOR_CALLHOOK(ClientKill, this, killtime))
101 killtime = M_ARGV(1, float);
103 this.killindicator_teamchange = targetteam;
105 // this.killindicator.count == 1 means that the kill indicator was spawned by ClientKill_Silent
106 if(killtime <= 0 && this.killindicator && this.killindicator.count == 1)
108 ClientKill_Now(this); // allow instant kill in this case
112 if (!this.killindicator)
116 killtime = max(killtime, this.clientkill_nexttime - time);
117 this.clientkill_nexttime = time + killtime + autocvar_g_balance_kill_antispam;
120 if (killtime <= 0 || !IS_PLAYER(this) || IS_DEAD(this))
122 ClientKill_Now(this);
126 float starttime = max(time, clientkilltime);
128 this.killindicator = spawn();
129 this.killindicator.owner = this;
130 this.killindicator.scale = 0.5;
131 setattachment(this.killindicator, this, "");
132 setorigin(this.killindicator, '0 0 52');
133 setthink(this.killindicator, KillIndicator_Think);
134 this.killindicator.nextthink = starttime + (this.lip) * 0.05;
135 clientkilltime = max(clientkilltime, this.killindicator.nextthink + 0.05);
136 this.killindicator.cnt = ceil(killtime);
137 this.killindicator.count = bound(0, ceil(killtime), 10);
138 //sprint(this, strcat("^1You'll be dead in ", ftos(this.killindicator.cnt), " seconds\n"));
140 IL_EACH(g_clones, it.enemy == this && !(it.effects & CSQCMODEL_EF_RESPAWNGHOST),
142 it.killindicator = spawn();
143 it.killindicator.owner = it;
144 it.killindicator.scale = 0.5;
145 setattachment(it.killindicator, it, "");
146 setorigin(it.killindicator, '0 0 52');
147 setthink(it.killindicator, KillIndicator_Think);
148 it.killindicator.nextthink = starttime + (it.lip) * 0.05;
149 //clientkilltime = max(clientkilltime, it.killindicator.nextthink + 0.05);
150 it.killindicator.cnt = ceil(killtime);
155 if (this.killindicator)
158 if (targetteam == 0) // just die
160 this.killindicator.colormod = '0 0 0';
161 notif = CENTER_TEAMCHANGE_SUICIDE;
163 else if (targetteam == -1) // auto
165 this.killindicator.colormod = '0 1 0';
166 notif = CENTER_TEAMCHANGE_AUTO;
168 else if (targetteam == -2) // spectate
170 this.killindicator.colormod = '0.5 0.5 0.5';
171 notif = CENTER_TEAMCHANGE_SPECTATE;
175 this.killindicator.colormod = Team_ColorRGB(targetteam);
176 notif = APP_TEAM_NUM(targetteam, CENTER_TEAMCHANGE);
178 if (IS_REAL_CLIENT(this) && this.killindicator.cnt > 0)
179 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, notif, this.killindicator.cnt);
184 void ClientKill_Silent(entity this, float _delay)
186 this.killindicator = spawn();
187 this.killindicator.owner = this;
188 setthink(this.killindicator, KillIndicator_Think);
189 this.killindicator.nextthink = time + (this.lip) * 0.05;
190 this.killindicator.cnt = ceil(_delay);
191 this.killindicator.count = 1; // this is used to indicate that it should be silent
195 // Called when a client types 'kill' in the console
196 void ClientKill(entity this)
198 if (game_stopped || this.player_blocked || STAT(FROZEN, this))
201 ClientKill_TeamChange(this, 0);