Skip to content

Commit

Permalink
Fix issue #4
Browse files Browse the repository at this point in the history
Fixed by replacing on_post_weapon_drop() with on_pre_weapon_drop()
 (EntityPostHook => EntityPreHook on 'drop_weapon')

Signed-off-by: BackRaw <backraw@gmx.de>
  • Loading branch information
BackRaw committed Dec 27, 2017
1 parent 4477ae7 commit 7cb1ba0
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions addons/source-python/plugins/udm/udm.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from entities.entity import Entity
from entities.hooks import EntityCondition
from entities.hooks import EntityPreHook
from entities.hooks import EntityPostHook
# Events
from events import Event
from events.hooks import PreEvent
Expand Down Expand Up @@ -304,16 +303,18 @@ def on_pre_bump_weapon(stack_data):
WeaponManager.set_silencer(weapon, inventory_item.silencer_option)


@EntityPostHook(EntityCondition.is_human_player, 'drop_weapon')
@EntityPostHook(EntityCondition.is_bot_player, 'drop_weapon')
def on_post_drop_weapon(stack_data, nothing):
@EntityPreHook(EntityCondition.is_human_player, 'drop_weapon')
@EntityPreHook(EntityCondition.is_bot_player, 'drop_weapon')
def on_pre_drop_weapon(stack_data):
"""Remove the dropped weapon after half the respawn delay."""
# Get a PlayerEntity instance for the player
player = make_object(PlayerEntity, stack_data[0])
# Get the weapon dropped
weapon_ptr = stack_data[1]

# Stop if the weapon pointer is None
if weapon_ptr is not None and weapon_ptr != 0:

# Remove the dropped weapon after the delay if this was a valid drop_weapon() call
if player.classname == 'player':
weapon = make_object(Weapon, stack_data[1])
# Remove the dropped weapon after the delay if this was a valid drop_weapon() call
weapon = make_object(Weapon, weapon_ptr)
delay_manager(
f'drop_{weapon.index}', abs(cvar_respawn_delay.get_float()) / 2,
WeaponManager.remove_weapon, (weapon.index, )
Expand Down

2 comments on commit 7cb1ba0

@Ayuto
Copy link

@Ayuto Ayuto commented on 7cb1ba0 Dec 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of those two ''weapon_ptr'' checks you can just write ''if weapon_ptr''.

@thetredev
Copy link
Owner

@thetredev thetredev commented on 7cb1ba0 Dec 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Will do :D

Edit: Fixed with 44a255b.

Please sign in to comment.