Hey!
Im requesting a small plugin which should do following:
If a player equips a weapon from the ground, it should be dropped and instantly removed.
Same shoulda work if a weapon has been dropped from the player on the ground, it should be removed instantly too. (Thinking of you spawn with an usp, and you drop it on the ground)
Thanks
Weapon Cleaner
Re: Weapon Cleaner
Syntax: Select all
from entities.hooks import EntityPreHook
from entities.hooks import EntityCondition
import memory
from entities.entity import Entity
from entities.entity import BaseEntity
@EntityPreHook(EntityCondition.is_player, 'bump_weapon')
def pre_bump_weapon(args):
player = memory.make_object(Entity, args[0])
weapon = memory.make_object(Entity, args[1])
# Player received weapon through GiveNamedItem (e.g. on spawn)
# Maybe there is a better solution for this.
if player.origin == weapon.origin:
return
weapon.remove()
return False
@EntityPreHook(EntityCondition.is_player, 'drop_weapon')
def pre_drop_weapon(args):
weapon_ptr = args[1]
if not weapon_ptr:
return
weapon = memory.make_object(BaseEntity, weapon_ptr)
weapon.remove()
return False
Re: Weapon Cleaner
I've had weird random crashes when removing an entity in a pre-hook without preventing function from further executing. Invincible told me it happened because function may try to continue operating on a removed entity. So I'd in both hooks after removing it.
Syntax: Select all
return False
/id/its_iPlayer
My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam
Hail, Companion. [...] Hands to yourself, sneak thief.
My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam
Hail, Companion. [...] Hands to yourself, sneak thief.
Re: Weapon Cleaner
Yes, that a good point. Thank you!
Re: Weapon Cleaner
After a second thought... DropWeapon function actually does some important stuff. It actually removes weapon inthandle from player's properties. To be certain, from m_hMyWeapons array, that is used, for instance, here. If we prevent this function from execution, I suspect that weapon's inthandle won't be removed and further attempts to iter over player's weapons would raise. Player.weapon_indexes itself will raise.
So my suggestion: replace second hook with a PostHook. I can confirm that weapon pointer will be valid, no need to do workarounds, at least for Windows, CS:S. But! In some cases (read weapon_knife) DropWeapon will remove the weapon on its own. So you'll also have to be ready for NULL pointer. In case of a post-hook on this function the following lines
are indeed needed.
So my suggestion: replace second hook with a PostHook. I can confirm that weapon pointer will be valid, no need to do workarounds, at least for Windows, CS:S. But! In some cases (read weapon_knife) DropWeapon will remove the weapon on its own. So you'll also have to be ready for NULL pointer. In case of a post-hook on this function the following lines
Syntax: Select all
if not weapon_ptr:
return
/id/its_iPlayer
My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam
Hail, Companion. [...] Hands to yourself, sneak thief.
My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam
Hail, Companion. [...] Hands to yourself, sneak thief.
Who is online
Users browsing this forum: No registered users and 21 guests