Raised This Month: $51 Target: $400
 12% 

Get the gun owner


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Tripaloski
Member
Join Date: Jul 2017
Old 08-27-2017 , 13:59   Get the gun owner
Reply With Quote #1

Hello guys.
When a player picks up a fallen weapon, is it possible to know who was the player who bought it?
And who dropped it?
Tripaloski is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 08-27-2017 , 14:07   Re: Get the gun owner
Reply With Quote #2

Ham_Touch (weaponbox) or Ham_Item_AddToPlayer (dropped weapons) and Ham_Item_Drop (when weapon is dropped).
__________________









Last edited by CrazY.; 08-27-2017 at 14:08.
CrazY. is offline
Tripaloski
Member
Join Date: Jul 2017
Old 08-27-2017 , 14:18   Re: Get the gun owner
Reply With Quote #3

What I wanted was this.
When a player picks up a fallen weapon, a message will appear saying, "You got the gun from the 'Name of person who bought it' ".

Last edited by Tripaloski; 08-27-2017 at 14:18.
Tripaloski is offline
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 08-27-2017 , 14:50   Re: Get the gun owner
Reply With Quote #4

You can get only the last owner of the weapon (weaponbox owner).
__________________
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
KiLLeR.
Senior Member
Join Date: Jul 2014
Location: Bulgaria
Old 08-27-2017 , 15:27   Re: Get the gun owner
Reply With Quote #5

Or maybe he can manually keep the owners for every weapon entity?!?
KiLLeR. is offline
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 08-27-2017 , 17:23   Re: Get the gun owner
Reply With Quote #6

RegisterHam(Ham_CS_Item_CanDrop, "weapon_name", "Ham_Item_Can_Drop", 0)

new owner = fm_get_weapon_owner(ent) //player who dropped the weapon
set_pev(entity, pev_iuser2, owner)

Pev iuser 2 is not used by weapons and you save owners ID there.

Then use ham item deploy with the same way but instead you get owner ID from pev.

public ham_deploy(entity)

new owner = pev(entity, pev_iuser2)

//next do what you need with owner


If you want to save the very first owner who bought the weapon then before saving pev iuser, check if pev user2 is null so that you don't overwrite the original owner with the player who picks up and then drops that weapon.

Like :
if(pev(entity, pev_iuser2) == 0)
set_pev(entity, pev_iuser2, owner)
This way you check if dropped weapon didn't have owner before which means that current owner bought this weapon.


If you have difficulties with that, I will give u the code tomorrow (on phone creepy to write )

Last edited by siriusmd99; 08-27-2017 at 17:29.
siriusmd99 is offline
Tripaloski
Member
Join Date: Jul 2017
Old 08-27-2017 , 19:45   Re: Get the gun owner
Reply With Quote #7

Thank you for your help!
I'll try tomorrow.
Tripaloski is offline
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 08-28-2017 , 14:24   Re: Get the gun owner
Reply With Quote #8

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <hamsandwich>

#define PLUGIN "Weapon's Owner Displayer"
#define VERSION "1.0"
#define AUTHOR "siriusmd99"

new const WEAPONENTNAMES[][] = 
{   
"""weapon_p228""""weapon_scout""weapon_hegrenade""weapon_xm1014""weapon_c4""weapon_mac10",
    
"weapon_aug""weapon_smokegrenade""weapon_elite""weapon_fiveseven""weapon_ump45""weapon_sg550",
    
"weapon_galil""weapon_famas""weapon_usp""weapon_glock18""weapon_awp""weapon_mp5navy""weapon_m249",
    
"weapon_m3""weapon_m4a1""weapon_tmp""weapon_g3sg1""weapon_flashbang""weapon_deagle""weapon_sg552",
    
"weapon_ak47""weapon_knife""weapon_p90" 
}

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    for (new 
1sizeof WEAPONENTNAMESi++)
    {
        if (
WEAPONENTNAMES[i][0]) 
        {
          
RegisterHam(Ham_Item_DeployWEAPONENTNAMES[i], "OnItemDeployPost"1);
          
RegisterHam(Ham_CS_Item_CanDropWEAPONENTNAMES[i], "OnItemDropPre"0)
        }
    }
}


public 
OnItemDropPre(ent)
{
    static 
ownerowner fm_cs_get_weapon_ent_owner(ent);
    
    if(
owner && !pev(entpev_iuser2) )
        
set_pev(entpev_iuser2get_user_userid(owner))  
}

public 
OnItemDeployPost(ent)
{
    
    static 
holderholder fm_cs_get_weapon_ent_owner(ent);
    
    if(
holder
    {
        new 
owner pev(entpev_iuser2);
        
        if(
owner)
        {
            new 
owner_id find_player("k"owner)
        
            if(
owner_id)
            {
              new 
szName[32]
              
get_user_name(owner_idszNamecharsmax(szName))
           
              
client_print(holderprint_center"[AMXX] You got the gun from %s !"szName)
            }
            else
          {
            
set_pev(entpev_iuser20)
          } 
        } 
    }
}    

fm_cs_get_weapon_ent_owner(ent)
{
    return (
pev_valid(ent) != 2) ? get_pdata_cbase(ent414);


Last edited by siriusmd99; 08-28-2017 at 18:12.
siriusmd99 is offline
KiLLeR.
Senior Member
Join Date: Jul 2014
Location: Bulgaria
Old 08-28-2017 , 14:57   Re: Get the gun owner
Reply With Quote #9

Quote:
Originally Posted by siriusmd99 View Post
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <hamsandwich>

#define PLUGIN "Weapon's Owner Displayer"
#define VERSION "1.0"
#define AUTHOR "siriusmd99"

new const WEAPONENTNAMES[][] = 
{   
"""weapon_p228""""weapon_scout""weapon_hegrenade""weapon_xm1014""weapon_c4""weapon_mac10",
    
"weapon_aug""weapon_smokegrenade""weapon_elite""weapon_fiveseven""weapon_ump45""weapon_sg550",
    
"weapon_galil""weapon_famas""weapon_usp""weapon_glock18""weapon_awp""weapon_mp5navy""weapon_m249",
    
"weapon_m3""weapon_m4a1""weapon_tmp""weapon_g3sg1""weapon_flashbang""weapon_deagle""weapon_sg552",
    
"weapon_ak47""weapon_knife""weapon_p90" 
}

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    for (new 
1sizeof WEAPONENTNAMESi++)
    {
        if (
WEAPONENTNAMES[i][0]) 
        {
          
RegisterHam(Ham_Item_DeployWEAPONENTNAMES[i], "OnItemDeployPost"1);
          
RegisterHam(Ham_CS_Item_CanDropWEAPONENTNAMES[i], "OnItemDropPre"0)
        }
    }
}


public 
OnItemDropPre(ent)
{
    static 
ownerowner fm_cs_get_weapon_ent_owner(ent);
    
    if(
owner && !pev(entpev_iuser2) )
        
set_pev(entpev_iuser2get_user_userid(owner))  
}

public 
OnItemDeployPost(ent)
{
    
    static 
holderholder fm_cs_get_weapon_ent_owner(ent);
    
    if(
holder
    {
        new 
owner pev(entpev_iuser2);
        
        if(
owner)
        {
            new 
owner_id find_player("k"owner)
        
            if(
owner_id)
            {
              new 
szName[32]
              
get_user_name(owner_idszNamecharsmax(szName))
           
              
client_print(holderprint_center"[AMXX] You got the gun from %s !"szName)
            }
            
            
set_pev(entpev_iuser20)
        } 
    }
}    

fm_cs_get_weapon_ent_owner(ent)
{
    return (
pev_valid(ent) != 2) ? get_pdata_cbase(ent414);

Why did not keep the id instead of userid? Also why you setting iuser2 to 0 when someone pick up the weapon? If weapon is droped again and someone another pick it up, the real buyer is lost.

Last edited by KiLLeR.; 08-28-2017 at 14:58.
KiLLeR. is offline
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 08-28-2017 , 15:48   Re: Get the gun owner
Reply With Quote #10

Quote:
Originally Posted by KiLLeR. View Post
Why did not keep the id instead of userid?
Because player can disconnect and another connecting player can get his slot.
__________________
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 14:21.


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