]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/mutators/events.qh
Merge branch 'Mario/format_message' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / mutators / events.qh
1 #ifndef SERVER_MUTATORS_EVENTS_H
2 #define SERVER_MUTATORS_EVENTS_H
3
4 #include "../../common/mutators/base.qh"
5
6 // register all possible hooks here
7
8 /** called when a player becomes observer, after shared setup */
9 #define EV_MakePlayerObserver(i, o) \
10     /**/
11 MUTATOR_HOOKABLE(MakePlayerObserver, EV_MakePlayerObserver)
12
13 /** */
14 #define EV_PutClientInServer(i, o) \
15     /** client wanting to spawn */ i(entity, self) \
16     /**/
17 MUTATOR_HOOKABLE(PutClientInServer, EV_PutClientInServer);
18
19 /** called when a player spawns as player, after shared setup, before his weapon is chosen (so items may be changed in here) */
20 #define EV_PlayerSpawn(i, o) \
21     /** spot that was used, or world */ i(entity, spawn_spot) \
22     /**/
23 entity spawn_spot;
24 MUTATOR_HOOKABLE(PlayerSpawn, EV_PlayerSpawn);
25
26 /** called in reset_map */
27 #define EV_reset_map_global(i, o) \
28     /**/
29 MUTATOR_HOOKABLE(reset_map_global, EV_reset_map_global);
30
31 /** called in reset_map */
32 #define EV_reset_map_players(i, o) \
33     /**/
34 MUTATOR_HOOKABLE(reset_map_players, EV_reset_map_players);
35
36 /** returns 1 if clearing player score shall not be allowed */
37 #define EV_ForbidPlayerScore_Clear(i, o) \
38     /**/
39 MUTATOR_HOOKABLE(ForbidPlayerScore_Clear, EV_ForbidPlayerScore_Clear);
40
41 /** called when a player disconnects */
42 #define EV_ClientDisconnect(i, o) \
43     /**/
44 MUTATOR_HOOKABLE(ClientDisconnect, EV_ClientDisconnect);
45
46 /** called when a player dies to e.g. remove stuff he was carrying. */
47 #define EV_PlayerDies(i, o) \
48     /**/ i(entity, frag_inflictor) \
49     /**/ i(entity, frag_attacker) \
50     /** same as self */ i(entity, frag_target) \
51     /**/ i(int, frag_deathtype) \
52     /**/
53 entity frag_inflictor;
54 entity frag_attacker;
55 entity frag_target;
56 int frag_deathtype;
57 MUTATOR_HOOKABLE(PlayerDies, EV_PlayerDies);
58
59 /** called when a player dies to e.g. remove stuff he was carrying. */
60 #define EV_PlayHitsound(i, o) \
61     /**/ i(entity, frag_victim) \
62     /**/
63 entity frag_victim;
64 MUTATOR_HOOKABLE(PlayHitsound, EV_PlayHitsound);
65
66 /** called when a player presses the jump key */
67 #define EV_PlayerJump(i, o) \
68     /**/ i(float, player_multijump) \
69     /**/ i(float, player_jumpheight) \
70     /**/ o(float, player_multijump) \
71     /**/ o(float, player_jumpheight) \
72     /**/
73 float player_multijump;
74 float player_jumpheight;
75 MUTATOR_HOOKABLE(PlayerJump, EV_PlayerJump);
76
77 /** called when someone was fragged by "self", and is expected to change frag_score to adjust scoring for the kill */
78 #define EV_GiveFragsForKill(i, o) \
79     /** same as self */ i(entity, frag_attacker) \
80     /**/ i(entity, frag_target) \
81     /**/ i(float, frag_score) \
82     /**/ o(float, frag_score) \
83     /**/
84 float frag_score;
85 MUTATOR_HOOKABLE(GiveFragsForKill, EV_GiveFragsForKill);
86
87 /** called when the match ends */
88 MUTATOR_HOOKABLE(MatchEnd, EV_NO_ARGS);
89
90 /** should adjust ret_float to contain the team count */
91 #define EV_GetTeamCount(i, o) \
92     /**/ i(float, ret_float) \
93     /**/ o(float, ret_float) \
94     /**/
95 float ret_float;
96 MUTATOR_HOOKABLE(GetTeamCount, EV_GetTeamCount);
97
98 /** copies variables for spectating "other" to "self" */
99 #define EV_SpectateCopy(i, o) \
100     /**/ i(entity, other) \
101     /**/ i(entity, self) \
102     /**/
103 MUTATOR_HOOKABLE(SpectateCopy, EV_SpectateCopy);
104
105 /** called when formatting a chat message to replace fancy functions */
106 #define EV_FormatMessage(i, o) \
107     /**/ i(string, format_escape) \
108     /**/ i(string, format_replacement) \
109     /**/ o(string, format_replacement) \
110     /**/
111 string format_escape;
112 string format_replacement;
113 MUTATOR_HOOKABLE(FormatMessage, EV_FormatMessage);
114
115 /** returns 1 if throwing the current weapon shall not be allowed */
116 MUTATOR_HOOKABLE(ForbidThrowCurrentWeapon, EV_NO_ARGS);
117
118 /** allows changing attack rate */
119 #define EV_WeaponRateFactor(i, o) \
120     /**/ i(float, weapon_rate) \
121     /**/ o(float, weapon_rate) \
122     /**/
123 float weapon_rate;
124 MUTATOR_HOOKABLE(WeaponRateFactor, EV_WeaponRateFactor);
125
126 /** allows changing weapon speed (projectiles mostly) */
127 #define EV_WeaponSpeedFactor(i, o) \
128     /**/ i(float, ret_float) \
129     /**/ o(float, ret_float) \
130     /**/
131 MUTATOR_HOOKABLE(WeaponSpeedFactor, EV_WeaponSpeedFactor);
132
133 /** adjusts {warmup_}start_{items,weapons,ammo_{cells,plasma,rockets,nails,shells,fuel}} */
134 MUTATOR_HOOKABLE(SetStartItems, EV_NO_ARGS);
135
136 /** called every frame. customizes the waypoint for spectators */
137 #define EV_CustomizeWaypoint(i, o) \
138     /** waypoint */ i(entity, self) \
139     /** player; other.enemy = spectator */ i(entity, other) \
140     /**/
141 MUTATOR_HOOKABLE(CustomizeWaypoint, EV_CustomizeWaypoint);
142
143 /**
144  * checks if the current item may be spawned (self.items and self.weapons may be read and written to, as well as the ammo_ fields)
145  * return error to request removal
146  */
147 MUTATOR_HOOKABLE(FilterItem, EV_NO_ARGS);
148
149 /** return error to request removal */
150 #define EV_TurretSpawn(i, o) \
151     /** turret */ i(entity, self) \
152     /**/
153 MUTATOR_HOOKABLE(TurretSpawn, EV_TurretSpawn);
154
155 /** return error to prevent entity spawn, or modify the entity */
156 MUTATOR_HOOKABLE(OnEntityPreSpawn, EV_NO_ARGS);
157
158 /** runs in the event loop for players; is called for ALL player entities, also bots, also the dead, or spectators */
159 MUTATOR_HOOKABLE(PlayerPreThink, EV_NO_ARGS);
160
161 /** TODO change this into a general PlayerPostThink hook? */
162 MUTATOR_HOOKABLE(GetPressedKeys, EV_NO_ARGS);
163
164 /**
165  * called before any player physics, may adjust variables for movement,
166  * is run AFTER bot code and idle checking
167  */
168 MUTATOR_HOOKABLE(PlayerPhysics, EV_NO_ARGS);
169
170 /** is meant to call GetCvars_handle*(get_cvars_s, get_cvars_f, cvarfield, "cvarname") for cvars this mutator needs from the client */
171 #define EV_GetCvars(i, o) \
172     /**/ i(float, get_cvars_f) \
173     /**/ i(string, get_cvars_s) \
174     /**/
175 float get_cvars_f;
176 string get_cvars_s;
177 MUTATOR_HOOKABLE(GetCvars, EV_NO_ARGS); // NOTE: Can't use EV_GetCvars because of `SZ_GetSpace: overflow`
178
179 /** can edit any "just fired" projectile */
180 #define EV_EditProjectile(i, o) \
181     /**/ i(entity, self) \
182     /**/ i(entity, other) \
183     /**/
184 MUTATOR_HOOKABLE(EditProjectile, EV_EditProjectile);
185
186 /** called when a monster spawns */
187 MUTATOR_HOOKABLE(MonsterSpawn, EV_NO_ARGS);
188
189 /** called when a monster dies */
190 #define EV_MonsterDies(i, o) \
191     /**/ i(entity, frag_attacker) \
192     /**/
193 MUTATOR_HOOKABLE(MonsterDies, EV_MonsterDies);
194
195 /** called when a monster wants to respawn */
196 #define EV_MonsterRespawn(i, o) \
197     /**/ i(entity, other) \
198     /**/
199 MUTATOR_HOOKABLE(MonsterRespawn, EV_MonsterRespawn);
200
201 /** called when a monster is dropping loot */
202 #define EV_MonsterDropItem(i, o) \
203     /**/ i(entity, other) \
204     /**/ o(entity, other) \
205     /**/
206 .void() monster_loot;
207 MUTATOR_HOOKABLE(MonsterDropItem, EV_MonsterDropItem);
208
209 /**
210  * called when a monster moves
211  * returning true makes the monster stop
212  */
213 #define EV_MonsterMove(i, o) \
214     /**/ i(float, monster_speed_run) \
215     /**/ o(float, monster_speed_run) \
216     /**/ i(float, monster_speed_walk) \
217     /**/ o(float, monster_speed_walk) \
218     /**/ i(entity, monster_target) \
219     /**/
220 float monster_speed_run;
221 float monster_speed_walk;
222 entity monster_target;
223 MUTATOR_HOOKABLE(MonsterMove, EV_MonsterMove);
224
225 /** called when a monster looks for another target */
226 MUTATOR_HOOKABLE(MonsterFindTarget, EV_NO_ARGS);
227
228 /** called to change a random monster to a miniboss */
229 MUTATOR_HOOKABLE(MonsterCheckBossFlag, EV_NO_ARGS);
230
231 /**
232  * called when a player tries to spawn a monster
233  * return 1 to prevent spawning
234  */
235 MUTATOR_HOOKABLE(AllowMobSpawning, EV_NO_ARGS);
236
237 /** called when a player gets damaged to e.g. remove stuff he was carrying. */
238 #define EV_PlayerDamage_SplitHealthArmor(i, o) \
239     /**/ i(entity, frag_inflictor) \
240     /**/ i(entity, frag_attacker) \
241     /** same as self */ i(entity, frag_target) \
242     /** NOTE: this force already HAS been applied */ i(vector, damage_force) \
243     /**/ i(float, damage_take) \
244     /**/ o(float, damage_take) \
245         /**/ i(float, damage_save) \
246     /**/ o(float, damage_save) \
247     /**/
248 vector damage_force;
249 float damage_take;
250 float damage_save;
251 MUTATOR_HOOKABLE(PlayerDamage_SplitHealthArmor, EV_PlayerDamage_SplitHealthArmor);
252
253 /**
254  * called to adjust damage and force values which are applied to the player, used for e.g. strength damage/force multiplier
255  * i'm not sure if I should change this around slightly (Naming of the entities, and also how they're done in g_damage).
256  */
257 #define EV_PlayerDamage_Calculate(i, o) \
258     /**/ i(entity, frag_attacker) \
259     /**/ i(entity, frag_target) \
260     /**/ i(float, frag_deathtype) \
261         /**/ i(float, frag_damage) \
262     /**/ o(float, frag_damage) \
263         /**/ i(float, frag_mirrordamage) \
264     /**/ o(float, frag_mirrordamage) \
265     /**/ i(vector, frag_force) \
266     /**/ o(vector, frag_force) \
267     /**/
268 float frag_damage;
269 float frag_mirrordamage;
270 vector frag_force;
271 MUTATOR_HOOKABLE(PlayerDamage_Calculate, EV_PlayerDamage_Calculate);
272
273 /**
274  * Called when a player is damaged
275  */
276 #define EV_PlayerDamaged(i, o) \
277     /** attacker */ i(entity, mutator_argv_entity_0) \
278     /** target */ i(entity, mutator_argv_entity_1) \
279     /** health */ i(int, mutator_argv_int_0) \
280     /** armor */ i(int, mutator_argv_int_1) \
281     /** location */ i(vector, mutator_argv_vector_0) \
282     /**/
283 MUTATOR_HOOKABLE(PlayerDamaged, EV_PlayerDamaged);
284
285 /** called at the end of player_powerups() in cl_client.qc, used for manipulating the values which are set by powerup items. */
286 #define EV_PlayerPowerups(i, o) \
287     /**/ i(entity, self) \
288     /**/ i(int, olditems) \
289     /**/
290 int olditems;
291 MUTATOR_HOOKABLE(PlayerPowerups, EV_PlayerPowerups);
292
293 /**
294  * called every player think frame
295  * return 1 to disable regen
296  */
297 #define EV_PlayerRegen(i, o) \
298     /**/ i(float, regen_mod_max) \
299     /**/ o(float, regen_mod_max) \
300     /**/ i(float, regen_mod_regen) \
301     /**/ o(float, regen_mod_regen) \
302     /**/ i(float, regen_mod_rot) \
303     /**/ o(float, regen_mod_rot) \
304     /**/ i(float, regen_mod_limit) \
305     /**/ o(float, regen_mod_limit) \
306     /**/
307 float regen_mod_max;
308 float regen_mod_regen;
309 float regen_mod_rot;
310 float regen_mod_limit;
311 MUTATOR_HOOKABLE(PlayerRegen, EV_PlayerRegen);
312
313 /**
314  * called when the use key is pressed
315  * if MUTATOR_RETURNVALUE is 1, don't do anything
316  * return 1 if the use key actually did something
317  */
318 MUTATOR_HOOKABLE(PlayerUseKey, EV_NO_ARGS);
319
320 /**
321  * called when a client command is parsed
322  * NOTE: hooks MUST start with if (MUTATOR_RETURNVALUE) return false;
323  * NOTE: return true if you handled the command, return false to continue handling
324  * NOTE: THESE HOOKS MUST NEVER EVER CALL tokenize()
325  * // example:
326  * MUTATOR_HOOKFUNCTION(foo_SV_ParseClientCommand)
327  * {
328  *     if (MUTATOR_RETURNVALUE) // command was already handled?
329  *         return false;
330  *     if (cmd_name == "echocvar" && cmd_argc >= 2)
331  *     {
332  *         print(cvar_string(argv(1)), "\n");
333  *         return true;
334  *     }
335  *     if (cmd_name == "echostring" && cmd_argc >= 2)
336  *     {
337  *         print(substring(cmd_string, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)), "\n");
338  *         return true;
339  *     }
340  *     return false;
341  * }
342  */
343 #define EV_SV_ParseClientCommand(i, o) \
344     /** command name */ i(string, cmd_name) \
345     /** also, argv() can be used */ i(int, cmd_argc) \
346     /** whole command, use only if you really have to */ i(string, cmd_string) \
347     /**/
348 string cmd_name;
349 int cmd_argc;
350 string cmd_string;
351 MUTATOR_HOOKABLE(SV_ParseClientCommand, EV_SV_ParseClientCommand);
352
353 /**
354  * called when a spawnpoint is being evaluated
355  * return 1 to make the spawnpoint unusable
356  */
357 #define EV_Spawn_Score(i, o) \
358     /** player wanting to spawn */ i(entity, self) \
359     /** spot to be evaluated */ i(entity, spawn_spot) \
360     /** _x is priority, _y is "distance" */ i(vector, spawn_score) \
361     /**/ o(vector, spawn_score) \
362     /**/
363 vector spawn_score;
364 MUTATOR_HOOKABLE(Spawn_Score, EV_Spawn_Score);
365
366 /** runs globally each server frame */
367 MUTATOR_HOOKABLE(SV_StartFrame, EV_NO_ARGS);
368
369 #define EV_SetModname(i, o) \
370     /** name of the mutator/mod if it warrants showing as such in the server browser */ \
371     o(string, modname) \
372     /**/
373 MUTATOR_HOOKABLE(SetModname, EV_SetModname);
374
375 /**
376  * called for each item being spawned on a map, including dropped weapons
377  * return 1 to remove an item
378  */
379 #define EV_Item_Spawn(i, o) \
380     /** the item */ i(entity, self) \
381     /**/
382 MUTATOR_HOOKABLE(Item_Spawn, EV_Item_Spawn);
383
384 #define EV_SetWeaponreplace(i, o) \
385     /** map entity */ i(entity, self) \
386     /** weapon info */ i(entity, other) \
387     /**/ i(string, ret_string) \
388     /**/ o(string, ret_string) \
389     /**/
390 MUTATOR_HOOKABLE(SetWeaponreplace, EV_SetWeaponreplace);
391
392 /** called when an item is about to respawn */
393 #define EV_Item_RespawnCountdown(i, o) \
394     /**/ i(string, item_name) \
395     /**/ o(string, item_name) \
396     /**/ i(vector, item_color) \
397     /**/ o(vector, item_color) \
398     /**/
399 string item_name;
400 vector item_color;
401 MUTATOR_HOOKABLE(Item_RespawnCountdown, EV_Item_RespawnCountdown);
402
403 /** called when a bot checks a target to attack */
404 #define EV_BotShouldAttack(i, o) \
405     /**/ i(entity, checkentity) \
406     /**/
407 entity checkentity;
408 MUTATOR_HOOKABLE(BotShouldAttack, EV_BotShouldAttack);
409
410 /**
411  * called whenever a player goes through a portal gun teleport
412  * allows you to strip a player of an item if they go through the teleporter to help prevent cheating
413  */
414 #define EV_PortalTeleport(i, o) \
415     /**/ i(entity, self) \
416     /**/
417 MUTATOR_HOOKABLE(PortalTeleport, EV_PortalTeleport);
418
419 /**
420  * called whenever a player uses impulse 33 (help me) in cl_impulse.qc
421  * normally help me ping uses self.waypointsprite_attachedforcarrier,
422  * but if your mutator uses something different then you can handle it
423  * in a special manner using this hook
424  */
425 #define EV_HelpMePing(i, o) \
426     /** the player who pressed impulse 33 */ i(entity, self) \
427     /**/
428 MUTATOR_HOOKABLE(HelpMePing, EV_HelpMePing);
429
430 /**
431  * called when a vehicle initializes
432  * return true to remove the vehicle
433  */
434 MUTATOR_HOOKABLE(VehicleSpawn, EV_NO_ARGS);
435
436 /**
437  * called when a player enters a vehicle
438  * allows mutators to set special settings in this event
439  */
440 #define EV_VehicleEnter(i, o) \
441     /** player */ i(entity, vh_player) \
442     /** vehicle */ i(entity, vh_vehicle) \
443     /**/
444 entity vh_player;
445 entity vh_vehicle;
446 MUTATOR_HOOKABLE(VehicleEnter, EV_VehicleEnter);
447
448 /**
449  * called when a player touches a vehicle
450  * return true to stop player from entering the vehicle
451  */
452 #define EV_VehicleTouch(i, o) \
453     /** vehicle */ i(entity, self) \
454     /** player */ i(entity, other) \
455     /**/
456 MUTATOR_HOOKABLE(VehicleTouch, EV_VehicleTouch);
457
458 /**
459  * called when a player exits a vehicle
460  * allows mutators to set special settings in this event
461  */
462 #define EV_VehicleExit(i, o) \
463     /** player */ i(entity, vh_player) \
464     /** vehicle */ i(entity, vh_vehicle) \
465     /**/
466 MUTATOR_HOOKABLE(VehicleExit, EV_VehicleExit);
467
468 /** called when a speedrun is aborted and the player is teleported back to start position */
469 #define EV_AbortSpeedrun(i, o) \
470     /** player */ i(entity, self) \
471     /**/
472 MUTATOR_HOOKABLE(AbortSpeedrun, EV_AbortSpeedrun);
473
474 /** called at when a item is touched. Called early, can edit item properties. */
475 #define EV_ItemTouch(i, o) \
476     /** item */ i(entity, self) \
477     /** player */ i(entity, other) \
478     /**/
479 MUTATOR_HOOKABLE(ItemTouch, EV_ItemTouch);
480
481 enum {
482         MUT_ITEMTOUCH_CONTINUE, // return this flag to make the function continue as normal
483         MUT_ITEMTOUCH_RETURN, // return this flag to make the function return (handled entirely by mutator)
484         MUT_ITEMTOUCH_PICKUP // return this flag to have the item "picked up" and taken even after mutator handled it
485 };
486
487 /** called at when a player connect */
488 #define EV_ClientConnect(i, o) \
489     /** player */ i(entity, self) \
490     /**/
491 MUTATOR_HOOKABLE(ClientConnect, EV_ClientConnect);
492
493 #define EV_HavocBot_ChooseRole(i, o) \
494     /**/ i(entity, self) \
495     /**/
496 MUTATOR_HOOKABLE(HavocBot_ChooseRole, EV_HavocBot_ChooseRole);
497
498 /** called when a target is checked for accuracy */
499 #define EV_AccuracyTargetValid(i, o) \
500     /** attacker */ i(entity, frag_attacker) \
501     /** target */ i(entity, frag_target) \
502     /**/
503 MUTATOR_HOOKABLE(AccuracyTargetValid, EV_AccuracyTargetValid);
504 enum {
505         MUT_ACCADD_VALID, // return this flag to make the function continue if target is a client
506         MUT_ACCADD_INVALID, // return this flag to make the function always continue
507         MUT_ACCADD_INDIFFERENT // return this flag to make the function always return
508 };
509 #endif