Weapon Cleaner

A place for requesting new Source.Python plugins to be made for your server.

Please request only one plugin per thread.
decompile
Senior Member
Posts: 416
Joined: Sat Oct 10, 2015 10:37 am
Location: Germany
Contact:

Weapon Cleaner

Postby decompile » Sun Nov 06, 2016 1:32 am

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
User avatar
Ayuto
Project Leader
Posts: 2193
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: Weapon Cleaner

Postby Ayuto » Sun Nov 06, 2016 9:15 am

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
User avatar
iPlayer
Developer
Posts: 590
Joined: Sat Nov 14, 2015 8:37 am
Location: Moscow
Contact:

Re: Weapon Cleaner

Postby iPlayer » Sun Nov 06, 2016 9:20 am

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

Syntax: Select all

return False
in both hooks after removing it.
Image /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. Image
User avatar
Ayuto
Project Leader
Posts: 2193
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: Weapon Cleaner

Postby Ayuto » Sun Nov 06, 2016 9:54 am

Yes, that a good point. Thank you!
User avatar
iPlayer
Developer
Posts: 590
Joined: Sat Nov 14, 2015 8:37 am
Location: Moscow
Contact:

Re: Weapon Cleaner

Postby iPlayer » Sun Nov 06, 2016 2:35 pm

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

Syntax: Select all

if not weapon_ptr:
return
are indeed needed.
Image /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. Image

Return to “Plugin Requests”

Who is online

Users browsing this forum: No registered users and 15 guests