Dropped Weapons Remover

For scripting examples for learning how to use AMXX.
User avatar
Archive-Poster
Posts: 1307
Gender:
United States of America

Dropped Weapons Remover

Post by Archive-Poster »

I found a new way to remove the dropped weapons and I think it's usefully.

Code: Select all

#include < amxmodx >
#include < fakemeta >
#include < hamsandwich >

public plugin_init( )
{
  RegisterHam( Ham_Think, "weaponbox", "OnThink", 1 );
  RegisterHam( Ham_Think, "weapon_shield", "OnThink", 1 );

  register_forward( FM_SetModel, "OnSetModel", 1 );
}

public OnThink( iEntity )
  engfunc( EngFunc_RemoveEntity, iEntity );

public OnSetModel( iEntity )
{
  if( pev_valid( iEntity ) )
  {
    static szClass[ 32 ];
    pev( iEntity, pev_classname, szClass, 31 );

    if( equal( szClass, "weaponbox" ) || equal( szClass, "weapon_shield" ) )
      set_pev( iEntity, pev_nextthink, get_gametime( ) + 0.1 );
  }
} 
User avatar
Archive-Poster
Posts: 1307
Gender:
United States of America

Re: Dropped Weapons Remover

Post by Archive-Poster »

best way is to patch mem using orpheu
packPlayerItem set think with CWeaponBox::Kill and set nextthink time to gametime + 300.0, you just need to change 300.0 to 0.1, then let ::Kill function remove it soon.
another place is PlayerDrop
User avatar
Archive-Poster
Posts: 1307
Gender:
United States of America

Re: Dropped Weapons Remover

Post by Archive-Poster »

Yes, it would be more efficient though not sure it would be worth and best way because you would need to patch in 3 locations : packPlayerItem(), CBasePlayer::DropPlayerItem() and CBasePlayer::DropShield(). You can't just trying replacing some value through all the library, you would need to base from the start of the functions. But none are virtual functions thus you would need to make signatures (at least for windows) and that vs SetModel (for example), the latter would be recommended because much more simple, signatures are not that reliable and the difference in efficiently is trivial.

EDIT : For the fun, here an example :

Code: Select all

#include <amxmodx>
#include <orpheu>
#include <orpheu_memory>
#include <orpheu_advanced>

enum Function { packPlayerItem, DropPlayerItem, DropShield };

public plugin_init()
{
    register_plugin( "Dropped Weapons Killer", "1.0.0", "Arkshine" );
    
    patch( packPlayerItem, OrpheuGetFunctionAddress( OrpheuGetFunction( "packPlayerItem" ) ) );
    patch( DropPlayerItem, OrpheuGetFunctionAddress( OrpheuGetFunction( "DropPlayerItem", "CBasePlayer" ) ) );
    patch( DropShield    , OrpheuGetFunctionAddress( OrpheuGetFunction( "DropShield"    , "CBasePlayer" ) ) );
}

public plugin_end()
{
    patch( packPlayerItem, .undo = true );
    patch( DropPlayerItem, .undo = true );
    patch( DropShield    , .undo = true );
}

patch( const Function:currentFunction, startAddress = 0, const bool:undo = false )
{
    const Float:originalValue = 300.0;
    const Float:newValue      = 0.1;
    
    static SavedAddress[ Function ];
    
    undo ? OrpheuMemorySetAtAddress( SavedAddress[ currentFunction ], "float", 1, originalValue ) :
           OrpheuMemoryReplaceAtAddress( startAddress, "float", 1, originalValue, newValue, SavedAddress[ currentFunction ] );
}
Attachments
[signatures]dropped_weapons_killer.zip
(3.12 KiB) Downloaded 8 times
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests