Raised This Month: $ Target: $400
 0% 

Problem with Ham_Item_Deploy and _cl_autowepswitch 1


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Aydeev
Junior Member
Join Date: Oct 2014
Old 11-06-2014 , 10:44   Problem with Ham_Item_Deploy and _cl_autowepswitch 1
Reply With Quote #1

Hello,

I've been using the folowing code to get a player's id when a weapon deploy is registered

PHP Code:
...
RegisterHam(Ham_Item_DeployszWeaponName"Ham_Item_Deploy_hook"0)
...

public 
Ham_Item_Deploy_hook(ent)
{

new 
userid pev(entpev_owner)

// working with the user id
//if (...

When testing with bots i noticed they were causing "index out of bounds" errors on the if statement and after some testing i figured out why:

Apparently it takes some time for pev_owner to update.

If a player using _cl_autowepswitch 1 is picking up a weapon from the ground pev_owner will still be set to the entity id when the function is called. I guess a weapon on the ground is it's own owner and therefore pev_owner = entity id.

So my function will give me invalid user ids.

I've been trying to use set_task(1.0,...) to force a little pause and give it time to update but you can still get index out of bounds if you spam dropping weapons while facing a wall.

Is there any better way to get the player id?
Aydeev is offline
Fr33m@n
Veteran Member
Join Date: May 2008
Location: France Marne
Old 11-06-2014 , 11:17   Re: Problem with Ham_Item_Deploy and _cl_autowepswitch 1
Reply With Quote #2

PHP Code:
//At the start of plugin
const m_pPlayer 41
const XO_WEAPON 4

...
// Unless you need to modify the output of Ham_Item_Deploy_hook aka returning a different value or blocking it's call (HAM_SUPERCEDE) you should use post
RegisterHam(Ham_Item_DeployszWeaponName"Ham_Item_Deploy_hook"1)
...

public 
Ham_Item_Deploy_hook(ent)
{
    new 
userid get_pdata_cbase(entm_pPlayerXO_WEAPON)

    
//...


Last edited by Fr33m@n; 11-06-2014 at 11:29.
Fr33m@n is offline
Aydeev
Junior Member
Join Date: Oct 2014
Old 11-06-2014 , 12:16   Re: Problem with Ham_Item_Deploy and _cl_autowepswitch 1
Reply With Quote #3

I don't understand what's going on there but it works. Thank you
Aydeev is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 11-06-2014 , 15:15   Re: Problem with Ham_Item_Deploy and _cl_autowepswitch 1
Reply With Quote #4

You need to know that pev_owner is filled with the owner id when AttachToPlayer is called, by using the offset it's faster cause it's filled when AddToPlayer get called, which happen earlier than AttachToPlayer
__________________
HamletEagle is offline
Aydeev
Junior Member
Join Date: Oct 2014
Old 11-06-2014 , 20:21   Re: Problem with Ham_Item_Deploy and _cl_autowepswitch 1
Reply With Quote #5

Quote:
Originally Posted by HamletEagle View Post
You need to know that pev_owner is filled with the owner id when AttachToPlayer is called, by using the offset it's faster cause it's filled when AddToPlayer get called, which happen earlier than AttachToPlayer
My mistake was only looking at CBasePlayerWeapon, if I had realized CBasePlayerItem was worth checking out too I might have found m_pPlayer myself

Thanks
Aydeev is offline
Aydeev
Junior Member
Join Date: Oct 2014
Old 11-15-2014 , 12:07   Re: Problem with Ham_Item_Deploy and _cl_autowepswitch 1
Reply With Quote #6

PHP Code:
const m_pPlayer 41
const XO_WEAPON 4

...
//inside the hook function
new userid get_pdata_cbase(entm_pPlayerXO_WEAPON
This works on my local windows test server but not on the main unix server. is there anything wrong with the offset? According to https://wiki.alliedmods.net/CBasePlayerItem_%28CS%29 4 is right

Last edited by Aydeev; 11-15-2014 at 12:08.
Aydeev is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 11-15-2014 , 12:32   Re: Problem with Ham_Item_Deploy and _cl_autowepswitch 1
Reply With Quote #7

Can you show as a full code because the snippet you posted nothing is wrong.
__________________
HamletEagle is offline
Aydeev
Junior Member
Join Date: Oct 2014
Old 11-15-2014 , 12:41   Re: Problem with Ham_Item_Deploy and _cl_autowepswitch 1
Reply With Quote #8

Plugin prevents players from shooting with primary weapons if blockshooting flag is set. Works on windows server, but on unix servers players can still shoot. I currently do not have access to the unix servers' logs so I can't check if it throws any error messages

PHP Code:
const m_pPlayer 41
const XO_WEAPON 4
new blockshooting[33]

public 
plugin_init() 

new 
szWeaponName[32]
    new 
NOSHOT_BITSUM = (1<<CSW_KNIFE) | (1<<CSW_HEGRENADE) | (1<<CSW_FLASHBANG) | (1<<CSW_SMOKEGRENADE) | (1<<CSW_ELITE) | (1<<CSW_FIVESEVEN) | (1<<CSW_USP) | (1<<CSW_GLOCK18) | (1<<CSW_DEAGLE) | (1<<CSW_C4)
    for(new 
iId CSW_SCOUTiId <= CSW_P90iId++)
    {
        if( ~
NOSHOT_BITSUM 1<<iId && get_weaponname(iIdszWeaponNamecharsmax(szWeaponName) ))
        {
            
RegisterHam(Ham_Item_DeployszWeaponName"block_shooting"0)
        }        
    }
}

public 
block_shooting(ent)
{
    new 
userid get_pdata_cbase(entm_pPlayerXO_WEAPON)
    
    if(
blockshooting[userid])
    {    
        
set_pdata_floatent469999.0);
        return 
HAM_HANDLED    
    
}
      
    return 
HAM_HANDLED


Last edited by Aydeev; 11-15-2014 at 12:42.
Aydeev is offline
NiHiLaNTh
Way Past Expiration
Join Date: May 2009
Location: Latvia
Old 11-15-2014 , 16:40   Re: Problem with Ham_Item_Deploy and _cl_autowepswitch 1
Reply With Quote #9

Quote:
set_pdata_float( ent, 46, 9999.0, 5 );

it should be 4 not 5, because 5 is diff for player entities. For weapon ents its +4.
__________________


Last edited by NiHiLaNTh; 11-15-2014 at 16:40.
NiHiLaNTh is offline
Send a message via Skype™ to NiHiLaNTh
Aydeev
Junior Member
Join Date: Oct 2014
Old 11-15-2014 , 20:26   Re: Problem with Ham_Item_Deploy and _cl_autowepswitch 1
Reply With Quote #10

What a stupid mistake to make... I was only looking at the get_pdata_cbase offset and completely forgot the other one

Thanks for your help
Aydeev is offline
Reply


Thread Tools
Display Modes

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 17:44.


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