Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
sv_campcheck.qc
Go to the documentation of this file.
1#include "sv_campcheck.qh"
2
8
10
13
15
16MUTATOR_HOOKFUNCTION(campcheck, PlayerDies)
17{
19
20 Kill_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CPID_CAMPCHECK);
21}
22
23MUTATOR_HOOKFUNCTION(campcheck, Damage_Calculate)
24{
25 entity frag_attacker = M_ARGV(1, entity);
27
28 if(frag_attacker != frag_target && IS_PLAYER(frag_target) && IS_PLAYER(frag_attacker))
29 {
30 frag_target.campcheck_traveled_distance = autocvar_g_campcheck_distance;
31 frag_attacker.campcheck_traveled_distance = autocvar_g_campcheck_distance;
32 }
33}
34
36{
37 entity player = M_ARGV(0, entity);
38 bool checked = false;
39
42 if(IS_PLAYER(player) && !IS_DEAD(player) && !STAT(FROZEN, player))
44 if(IS_REAL_CLIENT(player)) // only apply to real clients (bots may "camp" due to missing waypoints in the map, but that's no reason to constantly kill them, clones can't move)
45 if(!weaponLocked(player))
46 {
47 // calculate player movement (in 2 dimensions only, so jumping on one spot doesn't count as movement)
48 vector dist = vec2(player.campcheck_prevorigin - player.origin);
49 player.campcheck_traveled_distance += fabs(vlen(dist));
50
52 {
53 player.campcheck_nextcheck = time + autocvar_g_campcheck_interval * 2;
54 player.campcheck_traveled_distance = 0;
55 }
56
57 if(time > player.campcheck_nextcheck)
58 {
59 if(player.campcheck_traveled_distance < autocvar_g_campcheck_distance)
60 {
61 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_CAMPCHECK);
62 if(player.vehicle)
63 Damage(player.vehicle, NULL, NULL, autocvar_g_campcheck_damage * 2, DEATH_CAMP.m_id, DMG_NOWEP, player.vehicle.origin, '0 0 0');
64 else
65 {
66 float max_dmg = GetResource(player, RES_HEALTH) + GetResource(player, RES_ARMOR) * autocvar_g_balance_armor_blockpercent + 5;
67 Damage(player, NULL, NULL, bound(0, autocvar_g_campcheck_damage, max_dmg), DEATH_CAMP.m_id, DMG_NOWEP, player.origin, '0 0 0');
68 }
69 }
70 player.campcheck_nextcheck = time + autocvar_g_campcheck_interval;
71 player.campcheck_traveled_distance = 0;
72 }
73
74 checked = true;
75 }
76
77 if(!checked)
78 player.campcheck_nextcheck = time + autocvar_g_campcheck_interval; // one of the above checks failed, so keep the timer up to date
79
80 player.campcheck_prevorigin = player.origin;
81}
82
84{
85 entity player = M_ARGV(0, entity);
86 entity clone = M_ARGV(1, entity);
87
88 clone.campcheck_prevorigin = player.campcheck_prevorigin;
89}
90
91MUTATOR_HOOKFUNCTION(campcheck, PlayerSpawn)
92{
93 entity player = M_ARGV(0, entity);
94
95 player.campcheck_nextcheck = time + autocvar_g_campcheck_interval * 2;
96 player.campcheck_traveled_distance = 0;
97}
98
99MUTATOR_HOOKFUNCTION(campcheck, BuildMutatorsString)
100{
101 M_ARGV(0, string) = strcat(M_ARGV(0, string), ":CampCheck");
102}
#define REGISTER_MUTATOR(...)
Definition base.qh:295
#define MUTATOR_HOOKFUNCTION(...)
Definition base.qh:335
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
float GetResource(entity e, Resource res_type)
Returns the current amount of resource the given entity has.
bool warmup_stage
Definition main.qh:120
#define M_ARGV(x, type)
Definition events.qh:17
#define IS_DEAD(s)
Definition player.qh:245
#define PHYS_INPUT_BUTTON_CHAT(s)
Definition player.qh:159
#define IS_PLAYER(s)
Definition player.qh:243
float game_starttime
Definition stats.qh:82
float game_stopped
Definition stats.qh:81
float time
ERASEABLE bool expr_evaluate(string s)
Evaluate an expression of the form: [+ | -]?
Definition cvar.qh:48
void Damage(entity targ, entity inflictor, entity attacker, float damage, int deathtype,.entity weaponentity, vector hitloc, vector force)
Definition damage.qc:503
float autocvar_g_balance_armor_blockpercent
Definition damage.qh:21
#define DMG_NOWEP
Definition damage.qh:104
RES_ARMOR
Definition ent_cs.qc:130
#define PlayerPreThink
Definition _all.inc:254
#define STAT(...)
Definition stats.qh:82
bool autocvar_g_campaign
Definition menu.qc:747
float bound(float min, float value, float max)
float vlen(vector v)
float fabs(float f)
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))
void Send_Notification(NOTIF broadcast, entity client, MSG net_type, Notification net_name,...count)
Definition all.qc:1573
void Kill_Notification(NOTIF broadcast, entity client, MSG net_type, CPID net_cpid)
Definition all.qc:1537
#define NULL
Definition post.qh:14
#define round_handler_IsActive()
#define round_handler_IsRoundStarted()
vector
Definition self.qh:92
bool campaign_bots_may_start
campaign mode: bots shall spawn but wait for the player to spawn before they do anything in other gam...
Definition campaign.qh:26
void CopyBody(entity this, float keepvelocity)
Definition player.qc:64
bool autocvar_g_campcheck_typecheck
float campcheck_nextcheck
float campcheck_traveled_distance
float autocvar_g_campcheck_damage
float autocvar_g_campcheck_distance
vector campcheck_prevorigin
float autocvar_g_campcheck_interval
string autocvar_g_campcheck
entity frag_target
Definition sv_ctf.qc:2321
#define IS_REAL_CLIENT(v)
Definition utils.qh:17
#define vec2(...)
Definition vector.qh:90
bool weaponLocked(entity player)