From 6d8e693d6afb7c143b59515046f28da613df0029 Mon Sep 17 00:00:00 2001 From: Samual Lenks Date: Tue, 14 May 2013 21:00:19 -0400 Subject: [PATCH] Fix ItemTouch mutator hook usage (fixes #1572) --- qcsrc/server/mutators/base.qh | 3 +++ qcsrc/server/mutators/gamemode_freezetag.qc | 4 ++-- qcsrc/server/mutators/gamemode_lms.qc | 2 +- qcsrc/server/mutators/mutator_minstagib.qc | 5 ++++- qcsrc/server/mutators/mutator_superspec.qc | 4 ++-- qcsrc/server/t_items.qc | 15 ++++++++------- 6 files changed, 20 insertions(+), 13 deletions(-) diff --git a/qcsrc/server/mutators/base.qh b/qcsrc/server/mutators/base.qh index b2f9b29fd..a6c6f3a7e 100644 --- a/qcsrc/server/mutators/base.qh +++ b/qcsrc/server/mutators/base.qh @@ -292,6 +292,9 @@ MUTATOR_HOOKABLE(ItemTouch); // called at when a item is touched. Called early, can edit item properties. entity self; // item entity other; // player + #define MUT_ITEMTOUCH_CONTINUE 0 // return this flag to make the function continue as normal + #define MUT_ITEMTOUCH_RETURN 1 // return this flag to make the function return (handled entirely by mutator) + #define MUT_ITEMTOUCH_PICKUP 2 // return this flag to have the item "picked up" and taken even after mutator handled it MUTATOR_HOOKABLE(ClientConnect); // called at when a player connect diff --git a/qcsrc/server/mutators/gamemode_freezetag.qc b/qcsrc/server/mutators/gamemode_freezetag.qc index 79ce5e2e1..d1f123a89 100644 --- a/qcsrc/server/mutators/gamemode_freezetag.qc +++ b/qcsrc/server/mutators/gamemode_freezetag.qc @@ -549,8 +549,8 @@ MUTATOR_HOOKFUNCTION(freezetag_ForbidThrowCurrentWeapon) MUTATOR_HOOKFUNCTION(freezetag_ItemTouch) { if (other.freezetag_frozen) - return 1; - return 0; + return MUT_ITEMTOUCH_RETURN; + return MUT_ITEMTOUCH_CONTINUE; } MUTATOR_HOOKFUNCTION(freezetag_BotRoles) diff --git a/qcsrc/server/mutators/gamemode_lms.qc b/qcsrc/server/mutators/gamemode_lms.qc index 82258ac77..193b5378e 100644 --- a/qcsrc/server/mutators/gamemode_lms.qc +++ b/qcsrc/server/mutators/gamemode_lms.qc @@ -212,7 +212,7 @@ MUTATOR_HOOKFUNCTION(lms_ItemTouch) PlayerScore_Add(other, SP_LMS_LIVES, autocvar_g_lms_extra_lives); } - return FALSE; + return MUT_ITEMTOUCH_CONTINUE; } // scoreboard stuff diff --git a/qcsrc/server/mutators/mutator_minstagib.qc b/qcsrc/server/mutators/mutator_minstagib.qc index 05354a2b1..28e8623d6 100644 --- a/qcsrc/server/mutators/mutator_minstagib.qc +++ b/qcsrc/server/mutators/mutator_minstagib.qc @@ -350,15 +350,18 @@ MUTATOR_HOOKFUNCTION(minstagib_ItemTouch) if(other.health < 100) other.health = 100; + + return MUT_ITEMTOUCH_CONTINUE; } if(self.max_health) { other.armorvalue = bound(other.armorvalue, 999, other.armorvalue + autocvar_g_minstagib_extralives); Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_EXTRALIVES); + return MUT_ITEMTOUCH_PICKUP; } - return FALSE; + return MUT_ITEMTOUCH_RETURN; } MUTATOR_HOOKFUNCTION(minstagib_OnEntityPreSpawn) diff --git a/qcsrc/server/mutators/mutator_superspec.qc b/qcsrc/server/mutators/mutator_superspec.qc index b11ee77eb..a8e442abd 100644 --- a/qcsrc/server/mutators/mutator_superspec.qc +++ b/qcsrc/server/mutators/mutator_superspec.qc @@ -117,7 +117,7 @@ MUTATOR_HOOKFUNCTION(superspec_ItemTouch) _spectate(other); self = _oldself; - return FALSE; + return MUT_ITEMTOUCH_CONTINUE; } } @@ -149,7 +149,7 @@ MUTATOR_HOOKFUNCTION(superspec_ItemTouch) self = _oldself; - return FALSE; + return MUT_ITEMTOUCH_CONTINUE; } MUTATOR_HOOKFUNCTION(superspec_SV_ParseClientCommand) diff --git a/qcsrc/server/t_items.qc b/qcsrc/server/t_items.qc index cb6700a2c..926a4ab9d 100644 --- a/qcsrc/server/t_items.qc +++ b/qcsrc/server/t_items.qc @@ -651,11 +651,6 @@ float Item_GiveTo(entity item, entity player) pickedup = TRUE; player.superweapons_finished = max(player.superweapons_finished, time) + item.superweapons_finished; } - if (item.max_health) - { - pickedup = TRUE; - // extra life powerup handled by mutators - } :skip @@ -695,8 +690,12 @@ void Item_Touch (void) return; if (self.owner == other) return; - if(MUTATOR_CALLHOOK(ItemTouch)) - return; + + switch(MUTATOR_CALLHOOK(ItemTouch)) + { + case MUT_ITEMTOUCH_RETURN: { return; } + case MUT_ITEMTOUCH_PICKUP: { goto pickup; } + } if (self.classname == "droppedweapon") { @@ -717,6 +716,8 @@ void Item_Touch (void) return; } + :pickup + other.last_pickup = time; pointparticles(particleeffectnum("item_pickup"), self.origin, '0 0 0', 1); -- 2.39.2