AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Detecting a Weapon Drop (https://forums.alliedmods.net/showthread.php?t=117274)

wrecked_ 01-30-2010 14:46

Detecting a Weapon Drop
 
As the title stated, I'd like to know how I would detect if a player had dropped a weapon.

Furthermore, when this happens, would I be able to set a Pre-Think to this event, to detect the origin of the entity ( weapon )?

OptimizeR 01-30-2010 14:52

Re: Detecting a Weapon Drop
 
PHP Code:

register_clcmd("drop""cmddrop")

public 
cmddrop(id)
{
      
client_print(idprint_center"You have dropped weapon")


or fw_setmodel

Bugsy 01-30-2010 14:56

Re: Detecting a Weapon Drop
 
You can cache the entity id of each weapon when acquired so it can be used when dropped.

wrecked_ 01-30-2010 14:57

Re: Detecting a Weapon Drop
 
No, that's not even close to what I was looking for.

I want to set up a forward to detect if a player has dropped a weapon. For example, HAM has a forward to detect when a player is killed, takes damage, spawns, etc. I was wondering if there is a forward to detect that with an entity (weapon), and a way to set-up a prethink to find the origin before it is dropped.

wrecked_ 01-30-2010 14:58

Re: Detecting a Weapon Drop
 
Quote:

Originally Posted by Bugsy (Post 1073233)
You can cache the entity id of each weapon when acquired so it can be used when dropped.

Could you provide a quick example, please?

ConnorMcLeod 01-30-2010 17:06

Re: Detecting a Weapon Drop
 
Ham_Item_Drop

You may use Ham_CS_Item_CanDrop inside Ham_Item_Drop callback.


Both have to be registered/used with weapons classnames/indexes
And to retrieve player, use m_pPlayer weapon offset.

wrecked_ 01-30-2010 17:40

Re: Detecting a Weapon Drop
 
Quote:

Originally Posted by ConnorMcLeod (Post 1073400)
Ham_Item_Drop

You may use Ham_CS_Item_CanDrop inside Ham_Item_Drop callback.


Both have to be registered/used with weapons classnames/indexes
And to retrieve player, use m_pPlayer weapon offset.

Thank you.

Bugsy 01-30-2010 20:51

Re: Detecting a Weapon Drop
 
g_Weapons holds the weapons that you want to monitor being dropped. Remove whichever you don't want or you can eliminate the check all together.
PHP Code:

#include <amxmodx>
#include <hamsandwich>
#include <cstrike>

new g_Weapons = ( << CSW_P228 ) | 
        ( 
<< CSW_SCOUT ) | 
        ( 
<< CSW_XM1014 ) | 
        ( 
<< CSW_C4 ) | 
        ( 
<< CSW_MAC10 ) | 
        ( 
<< CSW_AUG ) | 
        ( 
<< CSW_ELITE ) | 
        ( 
<< CSW_FIVESEVEN ) | 
        ( 
<< CSW_UMP45 ) | 
        ( 
<< CSW_SG550 ) | 
        ( 
<< CSW_GALI ) | 
        ( 
<< CSW_GALIL ) | 
        ( 
<< CSW_FAMAS ) | 
        ( 
<< CSW_USP ) | 
        ( 
<< CSW_GLOCK18 ) | 
        ( 
<< CSW_AWP ) | 
        ( 
<< CSW_MP5NAVY ) | 
        ( 
<< CSW_M249 ) | 
        ( 
<< CSW_M3 ) | 
        ( 
<< CSW_M4A1 ) | 
        ( 
<< CSW_TMP ) | 
        ( 
<< CSW_G3SG1 ) | 
        ( 
<< CSW_DEAGLE ) | 
        ( 
<< CSW_SG552 ) | 
        ( 
<< CSW_AK47 ) | 
        ( 
<< CSW_P90 )
  
public 
plugin_init() 
{
    
register_plugin"Item Drop Hook" "0.1" "bugsy" );
        
    
RegisterHamHam_RemovePlayerItem "player" "fw_HamRemovePlayerItem" );
}

public 
fw_HamRemovePlayerItemid iEnt )
{
    if ( !
is_user_aliveid ) )
        return 
HAM_IGNORED;
    
    new 
iWeapon cs_get_weapon_idiEnt );
    
    if ( !( 
g_Weapons & ( << iWeapon ) ) )
        return 
HAM_IGNORED;
        
    
//Your code here
    // id = player id
    // iEnt = entity index
    // iWeapon = weapon index [CSW_*]
    
    
return HAM_IGNORED;



2reason2kill 05-04-2011 05:19

Re: Detecting a Weapon Drop
 
Quote:

Originally Posted by Bugsy (Post 1073627)
g_Weapons holds the weapons that you want to monitor being dropped. Remove whichever you don't want or you can eliminate the check all together.
PHP Code:

#include <amxmodx>
#include <hamsandwich>
#include <cstrike>
 
new g_Weapons = ( << CSW_P228 ) | 
        ( 
<< CSW_SCOUT ) | 
        ( 
<< CSW_XM1014 ) | 
        ( 
<< CSW_C4 ) | 
        ( 
<< CSW_MAC10 ) | 
        ( 
<< CSW_AUG ) | 
        ( 
<< CSW_ELITE ) | 
        ( 
<< CSW_FIVESEVEN ) | 
        ( 
<< CSW_UMP45 ) | 
        ( 
<< CSW_SG550 ) | 
        ( 
<< CSW_GALI ) | 
        ( 
<< CSW_GALIL ) | 
        ( 
<< CSW_FAMAS ) | 
        ( 
<< CSW_USP ) | 
        ( 
<< CSW_GLOCK18 ) | 
        ( 
<< CSW_AWP ) | 
        ( 
<< CSW_MP5NAVY ) | 
        ( 
<< CSW_M249 ) | 
        ( 
<< CSW_M3 ) | 
        ( 
<< CSW_M4A1 ) | 
        ( 
<< CSW_TMP ) | 
        ( 
<< CSW_G3SG1 ) | 
        ( 
<< CSW_DEAGLE ) | 
        ( 
<< CSW_SG552 ) | 
        ( 
<< CSW_AK47 ) | 
        ( 
<< CSW_P90 )
 
public 
plugin_init() 
{
    
register_plugin"Item Drop Hook" "0.1" "bugsy" );
 
    
RegisterHamHam_RemovePlayerItem "player" "fw_HamRemovePlayerItem" );
}
 
public 
fw_HamRemovePlayerItemid iEnt )
{
    if ( !
is_user_aliveid ) )
        return 
HAM_IGNORED;
 
    new 
iWeapon cs_get_weapon_idiEnt );
 
    if ( !( 
g_Weapons & ( << iWeapon ) ) )
        return 
HAM_IGNORED;
 
    
//Your code here
    // id = player id
    // iEnt = entity index
    // iWeapon = weapon index [CSW_*]
 
    
return HAM_IGNORED;



can i do it like when a ct kill a t it says a msg??? plz help

Exolent[jNr] 05-04-2011 21:38

Re: Detecting a Weapon Drop
 
Quote:

Originally Posted by 2reason2kill (Post 1462954)
can i do it like when a ct kill a t it says a msg??? plz help

That code is for dropping weapons, not hooking when player is dead.
You already have a topic for when player is dead so stick to that topic.


All times are GMT -4. The time now is 07:23.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.