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);
25 SV_ChangeTeam(this, this.killindicator_teamchange - 1);
26 this.killindicator_teamchange = 0;
29 void ClientKill_Now(entity this)
33 vehicles_exit(this.vehicle, VHEF_RELEASE);
34 if (!this.killindicator_teamchange)
36 this.vehicle_health = -1;
37 Damage(this, this, this, 1 , DEATH_KILL.m_id, DMG_NOWEP, this.origin, '0 0 0');
41 if (this.killindicator && !wasfreed(this.killindicator))
42 delete(this.killindicator);
44 this.killindicator = NULL;
46 if (this.killindicator_teamchange)
47 ClientKill_Now_TeamChange(this);
49 if (!IS_SPEC(this) && !IS_OBSERVER(this) && MUTATOR_CALLHOOK(ClientKill_Now, this) == false)
51 Damage(this, this, this, 100000, DEATH_KILL.m_id, DMG_NOWEP, this.origin, '0 0 0');
54 // now I am sure the player IS dead
56 void KillIndicator_Think(entity this)
58 if (game_stopped || (this.owner.alpha < 0 && !this.owner.vehicle))
60 this.owner.killindicator = NULL;
67 ClientKill_Now(this.owner);
71 // count == 1 means that it's silent
75 setmodel(this, MDL_NUM(this.cnt));
76 if (IS_REAL_CLIENT(this.owner))
79 Send_Notification(NOTIF_ONE, this.owner, MSG_ANNCE, Announcer_PickNumber(CNT_KILL, this.cnt));
82 this.nextthink = time + 1;
88 .float clientkill_nexttime;
89 void ClientKill_TeamChange(entity this, float targetteam) // 0 = don't change, -1 = auto, -2 = spec
94 float killtime = autocvar_g_balance_kill_delay;
96 if (MUTATOR_CALLHOOK(ClientKill, this, killtime))
98 killtime = M_ARGV(1, float);
100 this.killindicator_teamchange = targetteam;
102 if (!this.killindicator)
106 killtime = max(killtime, this.clientkill_nexttime - time);
107 this.clientkill_nexttime = time + killtime + autocvar_g_balance_kill_antispam;
110 if (killtime <= 0 || !IS_PLAYER(this) || IS_DEAD(this))
112 ClientKill_Now(this);
116 float starttime = max(time, clientkilltime);
118 this.killindicator = spawn();
119 this.killindicator.owner = this;
120 this.killindicator.scale = 0.5;
121 setattachment(this.killindicator, this, "");
122 setorigin(this.killindicator, '0 0 52');
123 setthink(this.killindicator, KillIndicator_Think);
124 this.killindicator.nextthink = starttime + (this.lip) * 0.05;
125 clientkilltime = max(clientkilltime, this.killindicator.nextthink + 0.05);
126 this.killindicator.cnt = ceil(killtime);
127 this.killindicator.count = bound(0, ceil(killtime), 10);
128 //sprint(this, strcat("^1You'll be dead in ", ftos(this.killindicator.cnt), " seconds\n"));
130 IL_EACH(g_clones, it.enemy == this && !(it.effects & CSQCMODEL_EF_RESPAWNGHOST),
132 it.killindicator = spawn();
133 it.killindicator.owner = it;
134 it.killindicator.scale = 0.5;
135 setattachment(it.killindicator, it, "");
136 setorigin(it.killindicator, '0 0 52');
137 setthink(it.killindicator, KillIndicator_Think);
138 it.killindicator.nextthink = starttime + (it.lip) * 0.05;
139 //clientkilltime = max(clientkilltime, it.killindicator.nextthink + 0.05);
140 it.killindicator.cnt = ceil(killtime);
145 if (this.killindicator)
148 if (targetteam == 0) // just die
150 this.killindicator.colormod = '0 0 0';
151 notif = CENTER_TEAMCHANGE_SUICIDE;
153 else if (targetteam == -1) // auto
155 this.killindicator.colormod = '0 1 0';
156 notif = CENTER_TEAMCHANGE_AUTO;
158 else if (targetteam == -2) // spectate
160 this.killindicator.colormod = '0.5 0.5 0.5';
161 notif = CENTER_TEAMCHANGE_SPECTATE;
165 this.killindicator.colormod = Team_ColorRGB(targetteam);
166 notif = APP_TEAM_NUM(targetteam, CENTER_TEAMCHANGE);
168 if (IS_REAL_CLIENT(this) && this.killindicator.cnt > 0)
169 Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, notif, this.killindicator.cnt);
174 // Called when a client types 'kill' in the console
175 void ClientKill(entity this)
177 // TODO: once .health is removed, will need to check it here for the "already dead" message!
179 if (game_stopped || this.player_blocked || STAT(FROZEN, this))
182 ClientKill_TeamChange(this, 0);