Xonotic
sv_campcheck.qc
Go to the documentation of this file.
1 #include "sv_campcheck.qh"
2 
8 
10 
13 
15 
16 MUTATOR_HOOKFUNCTION(campcheck, PlayerDies)
17 {
18  entity frag_target = M_ARGV(2, entity);
19 
20  Kill_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CPID_CAMPCHECK);
21 }
22 
23 MUTATOR_HOOKFUNCTION(campcheck, Damage_Calculate)
24 {
25  entity frag_attacker = M_ARGV(1, entity);
26  entity frag_target = M_ARGV(2, 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 
41  if(!game_stopped && !warmup_stage && time >= game_starttime)
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 
91 MUTATOR_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 
99 MUTATOR_HOOKFUNCTION(campcheck, BuildMutatorsString)
100 {
101  M_ARGV(0, string) = strcat(M_ARGV(0, string), ":CampCheck");
102 }
#define round_handler_IsActive()
#define PHYS_INPUT_BUTTON_CHAT(s)
Definition: player.qh:155
entity() spawn
bool warmup_stage
Definition: main.qh:103
REGISTER_MUTATOR(campcheck, expr_evaluate(autocvar_g_campcheck))
#define round_handler_IsRoundStarted()
void PlayerPreThink(entity this)
Definition: client.qc:2402
#define DMG_NOWEP
Definition: damage.qh:126
string autocvar_g_campcheck
Definition: sv_campcheck.qc:3
#define IS_REAL_CLIENT(v)
Definition: utils.qh:17
float autocvar_g_campcheck_interval
Definition: sv_campcheck.qc:6
RES_HEALTH
Definition: ent_cs.qc:126
float campcheck_traveled_distance
Definition: sv_campcheck.qc:12
bool weaponLocked(entity player)
vector campcheck_prevorigin
Definition: sv_campcheck.qc:14
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
#define NULL
Definition: post.qh:17
void Damage(entity targ, entity inflictor, entity attacker, float damage, int deathtype,.entity weaponentity, vector hitloc, vector force)
Definition: damage.qc:583
#define M_ARGV(x, type)
Definition: events.qh:17
#define IS_DEAD(s)
Definition: utils.qh:26
bool autocvar_g_campcheck_typecheck
Definition: sv_campcheck.qc:7
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:27
vector(float skel, float bonenum) _skel_get_boneabs_hidden
float GetResource(entity e, Resource res_type)
Returns the current amount of resource the given entity has.
Definition: cl_resources.qc:10
#define vec2(...)
Definition: vector.qh:90
float campcheck_nextcheck
Definition: sv_campcheck.qc:11
bool autocvar_g_campaign
Definition: campaign.qh:6
void CopyBody(entity this, float keepvelocity)
Definition: player.qc:64
float autocvar_g_balance_armor_blockpercent
Definition: damage.qh:21
float autocvar_g_campcheck_distance
Definition: sv_campcheck.qc:5
float time
Definition: csprogsdefs.qc:16
MUTATOR_HOOKFUNCTION(campcheck, PlayerDies)
Definition: sv_campcheck.qc:16
float autocvar_g_campcheck_damage
Definition: sv_campcheck.qc:4
#define IS_PLAYER(v)
Definition: utils.qh:9
ERASEABLE bool expr_evaluate(string s)
Evaluate an expression of the form: [+ | -]? [var[op]val | [op]var | val | var] ...
Definition: cvar.qh:48