From: bones_was_here Date: Sun, 18 Jun 2023 22:13:58 +0000 (+1000) Subject: overkill: optimise loot item mutator hooks X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=3e2b2cee6f356f9453be5b02b4640405f19a8bf8;p=xonotic%2Fxonotic-data.pk3dir.git overkill: optimise loot item mutator hooks No need to delete an item then spawn it again, and we can use the itemdef to skip the classname search. --- diff --git a/qcsrc/common/mutators/mutator/overkill/sv_overkill.qc b/qcsrc/common/mutators/mutator/overkill/sv_overkill.qc index 5dd0fdbb2..d4a1f4aeb 100644 --- a/qcsrc/common/mutators/mutator/overkill/sv_overkill.qc +++ b/qcsrc/common/mutators/mutator/overkill/sv_overkill.qc @@ -78,12 +78,13 @@ MUTATOR_HOOKFUNCTION(ok, Damage_Calculate, CBC_ORDER_LAST) } } -void ok_DropItem(entity this, entity targ) +void ok_DropItem(entity this, entity attacker, entity e) { - entity e = spawn(); e.ok_item = true; - Item_InitializeLoot(e, "item_armor_small", this.origin + '0 0 32', - '0 0 200' + normalize(targ.origin - this.origin) * 500, 5); + e.itemdef = ITEM_ArmorSmall; + e.origin = this.origin + '0 0 32'; + e.velocity = '0 0 200' + normalize(attacker.origin - this.origin) * 500; + e.lifetime = 5; } MUTATOR_HOOKFUNCTION(ok, PlayerDies) @@ -91,9 +92,10 @@ MUTATOR_HOOKFUNCTION(ok, PlayerDies) entity frag_attacker = M_ARGV(1, entity); entity frag_target = M_ARGV(2, entity); - entity targ = ((IS_PLAYER(frag_attacker)) ? frag_attacker : frag_target); - - ok_DropItem(frag_target, targ); + entity attacker = ((IS_PLAYER(frag_attacker)) ? frag_attacker : frag_target); + entity item = spawn(); + ok_DropItem(frag_target, attacker, item); + Item_Initialise(item); for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) { @@ -106,14 +108,10 @@ MUTATOR_HOOKFUNCTION(ok, PlayerDies) MUTATOR_HOOKFUNCTION(ok, MonsterDropItem) { entity mon = M_ARGV(0, entity); - entity olditem = M_ARGV(1, entity); + entity item = M_ARGV(1, entity); entity frag_attacker = M_ARGV(2, entity); - delete(olditem); - - M_ARGV(1, entity) = NULL; - - ok_DropItem(mon, frag_attacker); + ok_DropItem(mon, frag_attacker, item); } MUTATOR_HOOKFUNCTION(ok, ForbidThrowCurrentWeapon)