#define CBC_ORDER_LAST 2
#define CBC_ORDER_ANY 4
+float CallbackChain_ReturnValue; // read-only field of the current return value
+
entity CallbackChain_New(string name);
float CallbackChain_Add(entity cb, float() func, float order)
float CallbackChain_Remove(entity cb, float() func);
#define MUTATOR_HOOKABLE(cb) entity HOOK_##cb
#define MUTATOR_CALLHOOK(cb) CallbackChain_Call(HOOK_##cb)
+#define MUTATOR_RETURNVALUE CallbackChain_ReturnValue
// INPUT
entity self;
float olditems; // also technically output, but since it is at the end of the function it's useless for that :P
+
+MUTATOR_HOOKABLE(PlayerUseKey);
+ // called when the use key is pressed
+ // if MUTATOR_RETURNVALUE is 1, don't do anything
+ // return 1 if the use key actually did something
if(self.ballcarried)
self.items |= IT_KEY1;
- // drop the ball if the player presses the use button
- if(self.BUTTON_USE)
- if(self.ballcarried) { ka_DropEvent(self); }
+ return 0;
+}
+MUTATOR_HOOKFUNCTION(ka_PlayerUseKey)
+{
+ if(MUTATOR_RETURNVALUE == 0)
+ if(self.ballcarried)
+ {
+ ka_DropEvent(self);
+ return 1;
+ }
return 0;
}
MUTATOR_HOOK(PlayerPreThink, ka_PlayerPreThink, CBC_ORDER_ANY);
MUTATOR_HOOK(PlayerDamage_Calculate, ka_PlayerDamage, CBC_ORDER_ANY);
MUTATOR_HOOK(PlayerPowerups, ka_PlayerPowerups, CBC_ORDER_ANY);
+ MUTATOR_HOOK(PlayerUseKey, ka_PlayerUseKey, CBC_ORDER_ANY);
MUTATOR_ONADD
{
makevectors('0 1 0' * (self.cnt + mod(time, 360) * KH_KEY_XYSPEED));
setorigin(self, v_forward * KH_KEY_XYDIST + '0 0 1' * self.origin_z);
#endif
-
- if(self.owner.BUTTON_USE)
- if(time >= self.owner.kh_droptime + autocvar_g_balance_keyhunt_delay_drop)
- {
- self.owner.kh_droptime = time;
- self.kh_droptime = time; // prevent collecting this one for some time
- self.enemy = self.owner;
- self.pusher = world;
- kh_Scores_Event(self.owner, self, "dropkey", 0, 0);
- bprint(self.owner.netname, "^7 dropped the ", self.netname, "\n");
- sound(self.owner, CHAN_AUTO, kh_sound_drop, VOL_BASE, ATTN_NORM);
- makevectors(self.owner.v_angle);
- self.velocity = W_CalculateProjectileVelocity(self.owner.velocity, autocvar_g_balance_keyhunt_throwvelocity * v_forward, FALSE);
- kh_Key_AssignTo(self, world);
- self.pushltime = time + autocvar_g_balance_keyhunt_protecttime;
- self.kh_dropperteam = self.team;
- }
}
// if in nodrop or time over, end the round
return teem;
}
+void kh_Key_DropOne(entity key)
+{
+ // prevent collecting this one for some time
+ entity player;
+ player = key.owner;
+
+ key.kh_droptime = time;
+ key.enemy = player;
+
+ kh_Scores_Event(player, key, "dropkey", 0, 0);
+ PlayerScore_Add(player, SP_KH_LOSSES, 1);
+ bprint(player.netname, "^7 dropped the ", key.netname, "\n");
+ kh_Key_AssignTo(key, world);
+ makevectors(player.v_angle);
+ key.velocity = W_CalculateProjectileVelocity(player.velocity, autocvar_g_balance_keyhunt_throwvelocity * v_forward, FALSE);
+ key.pusher = world;
+ key.pushltime = time + autocvar_g_balance_keyhunt_protecttime;
+ key.kh_dropperteam = key.team;
+
+ sound(player, CHAN_AUTO, kh_sound_drop, VOL_BASE, ATTN_NORM);
+}
+
void kh_Key_DropAll(entity player, float suicide) // runs whenever a player dies
{
entity key;
return 0;
}
+MUTATOR_HOOKFUNCTION(kh_PlayerUseKey)
+{
+ if(MUTATOR_RETURNVALUE == 0)
+ {
+ entity k;
+ k = self.kh_next;
+ if(k)
+ {
+ kh_Key_DropOne(self, k);
+ return 1;
+ }
+ }
+ return 0;
+}
+
MUTATOR_DEFINITION(gamemode_keyhunt)
{
MUTATOR_HOOK(MakePlayerObserver, kh_Key_DropAll, CBC_ORDER_ANY);
MUTATOR_HOOK(MatchEnd, kh_finalize, CBC_ORDER_ANY);
MUTATOR_HOOK(GetTeamCount, kh_GetTeamCount, CBC_ORDER_EXCLUSIVE);
MUTATOR_HOOK(SpectateCopy, kh_SpectateCopy, CBC_ORDER_ANY);
+ MUTATOR_HOOK(PlayerUseKey, kh_PlayerUseKey, CBC_ORDER_ANY);
MUTATOR_ONADD
{