1 const float CBC_ORDER_EXCLUSIVE = 3;
2 const float CBC_ORDER_FIRST = 1;
3 const float CBC_ORDER_LAST = 2;
4 const float CBC_ORDER_ANY = 4;
6 float CallbackChain_ReturnValue; // read-only field of the current return value
8 entity CallbackChain_New(string name);
9 float CallbackChain_Add(entity cb, float() func, float order);
10 float CallbackChain_Remove(entity cb, float() func);
11 // a callback function is like this:
12 // float mycallback(entity me)
17 float CallbackChain_Call(entity cb);
19 const float MUTATOR_REMOVING = 0;
20 const float MUTATOR_ADDING = 1;
21 const float MUTATOR_ROLLING_BACK = 2;
22 typedef float(float) mutatorfunc_t;
23 float Mutator_Add(mutatorfunc_t func, string name);
24 void Mutator_Remove(mutatorfunc_t func, string name); // calls error() on fail
26 #define MUTATOR_ADD(name) Mutator_Add(MUTATOR_##name, #name)
27 #define MUTATOR_REMOVE(name) Mutator_Remove(MUTATOR_##name, #name)
28 #define MUTATOR_DEFINITION(name) float MUTATOR_##name(float mode)
29 #define MUTATOR_DECLARATION(name) float MUTATOR_##name(float mode)
30 #define MUTATOR_HOOKFUNCTION(name) float HOOKFUNCTION_##name()
31 #define MUTATOR_HOOK(cb,func,order) do { if(mode == MUTATOR_ADDING) { if(!HOOK_##cb) HOOK_##cb = CallbackChain_New(#cb); if(!CallbackChain_Add(HOOK_##cb,HOOKFUNCTION_##func,order)) { print("HOOK FAILED: ", #func, "\n"); return 1; } } else if(mode == MUTATOR_REMOVING || mode == MUTATOR_ROLLING_BACK) { if(HOOK_##cb) CallbackChain_Remove(HOOK_##cb,HOOKFUNCTION_##func); } } while(0)
32 #define MUTATOR_ONADD if(mode == MUTATOR_ADDING)
33 #define MUTATOR_ONREMOVE if(mode == MUTATOR_REMOVING)
34 #define MUTATOR_ONROLLBACK_OR_REMOVE if(mode == MUTATOR_REMOVING || mode == MUTATOR_ROLLING_BACK)
36 #define MUTATOR_HOOKABLE(cb) entity HOOK_##cb
37 #define MUTATOR_CALLHOOK(cb) CallbackChain_Call(HOOK_##cb)
39 #define MUTATOR_RETURNVALUE CallbackChain_ReturnValue
44 // register all possible hooks here
45 // some parameters are commented to avoid duplicate declarations
47 MUTATOR_HOOKABLE(MakePlayerObserver);
48 // called when a player becomes observer, after shared setup
50 MUTATOR_HOOKABLE(PutClientInServer);
51 // entity self; // client wanting to spawn
53 MUTATOR_HOOKABLE(PlayerSpawn);
54 entity spawn_spot; // spot that was used, or world
55 // called when a player spawns as player, after shared setup, before his weapon is chosen (so items may be changed in here)
57 MUTATOR_HOOKABLE(reset_map_global);
58 // called in reset_map
60 MUTATOR_HOOKABLE(reset_map_players);
61 // called in reset_map
63 MUTATOR_HOOKABLE(ForbidPlayerScore_Clear);
64 // returns 1 if clearing player score shall not be allowed
66 MUTATOR_HOOKABLE(ClientDisconnect);
67 // called when a player disconnects
69 MUTATOR_HOOKABLE(PlayerDies);
70 // called when a player dies to e.g. remove stuff he was carrying.
72 entity frag_inflictor;
74 entity frag_target; // same as self
77 MUTATOR_HOOKABLE(PlayerJump);
78 // called when a player presses the jump key
80 float player_multijump;
81 float player_jumpheight;
83 MUTATOR_HOOKABLE(GiveFragsForKill);
84 // called when someone was fragged by "self", and is expected to change frag_score to adjust scoring for the kill
86 // entity frag_attacker; // same as self
87 // entity frag_target;
91 MUTATOR_HOOKABLE(MatchEnd);
92 // called when the match ends
94 MUTATOR_HOOKABLE(GetTeamCount);
95 // should adjust ret_float to contain the team count
99 MUTATOR_HOOKABLE(SpectateCopy);
100 // copies variables for spectating "other" to "self"
104 MUTATOR_HOOKABLE(ForbidThrowCurrentWeapon);
105 // returns 1 if throwing the current weapon shall not be allowed
107 MUTATOR_HOOKABLE(WeaponRateFactor);
108 // allows changing attack rate
112 MUTATOR_HOOKABLE(SetStartItems);
113 // adjusts {warmup_}start_{items,weapons,ammo_{cells,plasma,rockets,nails,shells,fuel}}
115 MUTATOR_HOOKABLE(BuildMutatorsString);
116 // appends ":mutatorname" to ret_string for logging
120 MUTATOR_HOOKABLE(BuildMutatorsPrettyString);
121 // appends ", Mutator name" to ret_string for display
123 // string ret_string;
125 MUTATOR_HOOKABLE(CustomizeWaypoint);
126 // called every frame
127 // customizes the waypoint for spectators
128 // INPUT: self = waypoint, other = player, other.enemy = spectator
130 MUTATOR_HOOKABLE(FilterItem);
131 // 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)
132 // return error to request removal
134 MUTATOR_HOOKABLE(TurretSpawn);
135 // return error to request removal
136 // INPUT: self - turret
138 MUTATOR_HOOKABLE(OnEntityPreSpawn);
139 // return error to prevent entity spawn, or modify the entity
141 MUTATOR_HOOKABLE(PlayerPreThink);
142 // runs in the event loop for players; is called for ALL player entities, also bots, also the dead, or spectators
144 MUTATOR_HOOKABLE(GetPressedKeys);
145 // TODO change this into a general PlayerPostThink hook?
147 MUTATOR_HOOKABLE(PlayerPhysics);
148 // called before any player physics, may adjust variables for movement,
149 // is run AFTER bot code and idle checking
151 MUTATOR_HOOKABLE(GetCvars);
152 // is meant to call GetCvars_handle*(get_cvars_s, get_cvars_f, cvarfield, "cvarname") for cvars this mutator needs from the client
157 MUTATOR_HOOKABLE(EditProjectile);
158 // can edit any "just fired" projectile
163 MUTATOR_HOOKABLE(MonsterSpawn);
164 // called when a monster spawns
166 MUTATOR_HOOKABLE(MonsterDies);
167 // called when a monster dies
169 // entity frag_attacker;
171 MUTATOR_HOOKABLE(MonsterRespawn);
172 // called when a monster wants to respawn
176 MUTATOR_HOOKABLE(MonsterDropItem);
177 // called when a monster is dropping loot
179 .void() monster_loot;
182 MUTATOR_HOOKABLE(MonsterMove);
183 // called when a monster moves
184 // returning true makes the monster stop
186 float monster_speed_run;
187 float monster_speed_walk;
188 entity monster_target;
190 MUTATOR_HOOKABLE(MonsterFindTarget);
191 // called when a monster looks for another target
193 MUTATOR_HOOKABLE(MonsterCheckBossFlag);
194 // called to change a random monster to a miniboss
196 MUTATOR_HOOKABLE(AllowMobSpawning);
197 // called when a player tries to spawn a monster
198 // return 1 to prevent spawning
200 MUTATOR_HOOKABLE(PlayerDamage_SplitHealthArmor);
201 // called when a player gets damaged to e.g. remove stuff he was carrying.
203 // entity frag_inflictor;
204 // entity frag_attacker;
205 // entity frag_target; // same as self
206 vector damage_force; // NOTE: this force already HAS been applied
211 MUTATOR_HOOKABLE(PlayerDamage_Calculate);
212 // called to adjust damage and force values which are applied to the player, used for e.g. strength damage/force multiplier
213 // i'm not sure if I should change this around slightly (Naming of the entities, and also how they're done in g_damage).
215 // entity frag_attacker;
216 // entity frag_target;
217 // float frag_deathtype;
220 float frag_mirrordamage;
223 MUTATOR_HOOKABLE(PlayerPowerups);
224 // called at the end of player_powerups() in cl_client.qc, used for manipulating the values which are set by powerup items.
227 float olditems; // also technically output, but since it is at the end of the function it's useless for that :P
229 MUTATOR_HOOKABLE(PlayerRegen);
230 // called every player think frame
231 // return 1 to disable regen
234 float regen_mod_regen;
236 float regen_mod_limit;
238 MUTATOR_HOOKABLE(PlayerUseKey);
239 // called when the use key is pressed
240 // if MUTATOR_RETURNVALUE is 1, don't do anything
241 // return 1 if the use key actually did something
243 MUTATOR_HOOKABLE(SV_ParseClientCommand);
244 // called when a client command is parsed
245 // NOTE: hooks MUST start with if(MUTATOR_RETURNVALUE) return 0;
246 // NOTE: return 1 if you handled the command, return 0 to continue handling
247 // NOTE: THESE HOOKS MUST NEVER EVER CALL tokenize()
249 string cmd_name; // command name
250 float cmd_argc; // also, argv() can be used
251 string cmd_string; // whole command, use only if you really have to
254 MUTATOR_HOOKFUNCTION(foo_SV_ParseClientCommand)
256 if(MUTATOR_RETURNVALUE) // command was already handled?
258 if(cmd_name == "echocvar" && cmd_argc >= 2)
260 print(cvar_string(argv(1)), "\n");
263 if(cmd_name == "echostring" && cmd_argc >= 2)
265 print(substring(cmd_string, argv_start_index(1), argv_end_index(-1) - argv_start_index(1)), "\n");
272 MUTATOR_HOOKABLE(Spawn_Score);
273 // called when a spawnpoint is being evaluated
274 // return 1 to make the spawnpoint unusable
276 // entity self; // player wanting to spawn
277 // entity spawn_spot; // spot to be evaluated
279 vector spawn_score; // _x is priority, _y is "distance"
281 MUTATOR_HOOKABLE(SV_StartFrame);
282 // runs globally each server frame
284 MUTATOR_HOOKABLE(SetModname);
286 // string modname; // name of the mutator/mod if it warrants showing as such in the server browser
288 MUTATOR_HOOKABLE(Item_Spawn);
289 // called for each item being spawned on a map, including dropped weapons
290 // return 1 to remove an item
292 // entity self; // the item
294 MUTATOR_HOOKABLE(SetWeaponreplace);
296 // entity self; // map entity
297 // entity other; // weapon info
299 // string ret_string;
301 MUTATOR_HOOKABLE(Item_RespawnCountdown);
302 // called when an item is about to respawn
307 MUTATOR_HOOKABLE(BotShouldAttack);
308 // called when a bot checks a target to attack
312 MUTATOR_HOOKABLE(PortalTeleport);
313 // called whenever a player goes through a portal gun teleport
314 // allows you to strip a player of an item if they go through the teleporter to help prevent cheating
318 MUTATOR_HOOKABLE(HelpMePing);
319 // called whenever a player uses impulse 33 (help me) in cl_impulse.qc
320 // normally help me ping uses self.waypointsprite_attachedforcarrier,
321 // but if your mutator uses something different then you can handle it
322 // in a special manner using this hook
324 // entity self; // the player who pressed impulse 33
326 MUTATOR_HOOKABLE(VehicleSpawn);
327 // called when a vehicle initializes
328 // return true to remove the vehicle
330 MUTATOR_HOOKABLE(VehicleEnter);
331 // called when a player enters a vehicle
332 // allows mutators to set special settings in this event
334 entity vh_player; // player
335 entity vh_vehicle; // vehicle
337 MUTATOR_HOOKABLE(VehicleTouch);
338 // called when a player touches a vehicle
339 // return true to stop player from entering the vehicle
341 // entity self; // vehicle
342 // entity other; // player
344 MUTATOR_HOOKABLE(VehicleExit);
345 // called when a player exits a vehicle
346 // allows mutators to set special settings in this event
348 // entity vh_player; // player
349 // entity vh_vehicle; // vehicle
351 MUTATOR_HOOKABLE(AbortSpeedrun);
352 // called when a speedrun is aborted and the player is teleported back to start position
354 // entity self; // player
356 MUTATOR_HOOKABLE(ItemTouch);
357 // called at when a item is touched. Called early, can edit item properties.
358 // entity self; // item
359 // entity other; // player
360 const float MUT_ITEMTOUCH_CONTINUE = 0; // return this flag to make the function continue as normal
361 const float MUT_ITEMTOUCH_RETURN = 1; // return this flag to make the function return (handled entirely by mutator)
362 const float MUT_ITEMTOUCH_PICKUP = 2; // return this flag to have the item "picked up" and taken even after mutator handled it
364 MUTATOR_HOOKABLE(ClientConnect);
365 // called at when a player connect
366 // entity self; // player
368 MUTATOR_HOOKABLE(HavocBot_ChooseRole);
371 MUTATOR_HOOKABLE(AccuracyTargetValid);
372 // called when a target is checked for accuracy
373 // entity frag_attacker; // attacker
374 // entity frag_target; // target
375 const float MUT_ACCADD_VALID = 0; // return this flag to make the function continue if target is a client
376 const float MUT_ACCADD_INVALID = 1; // return this flag to make the function always continue
377 const float MUT_ACCADD_INDIFFERENT = 2; // return this flag to make the function always return