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

FrostNades


Post New Thread Reply   
 
Thread Tools Display Modes
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 01-02-2012 , 12:21   Re: FrostNades
Reply With Quote #521

That's the purpose of AddToPlayer, it's called when an item is added to the player's inventory, whatever where it comes.
__________________
Arkshine is offline
Nextra
Veteran Member
Join Date: Apr 2008
Location: Germany
Old 01-03-2012 , 12:06   Re: FrostNades
Reply With Quote #522

When I tried something similar I ended up using Ham_Item_AttachToPlayer. You may want to experiment with both of them, I'm not sure if there was an issue with AddToPlayer that made me use AttachToPlayer.

To detect when something was removed from the players Inventory I used Ham_RemovePlayerItem and Ham_Use for the player_weaponstrip entity.
__________________
In Flames we trust!
Nextra is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 01-03-2012 , 12:23   Re: FrostNades
Reply With Quote #523

AttachToPlayer is just called after but there is no reason AddToPlayer would not work.

When you look at the code, you have generally such code :

PHP Code:
    if (pOther->AddPlayerItemthis ))
    {
        
AttachToPlayerpPlayer );
        
//
    

And AddPlayerItem :

PHP Code:
BOOL CBasePlayer::AddPlayerItemCBasePlayerItem *pItem )
{
    
CBasePlayerItem *pInsert;

    
pInsert m_rgpPlayerItemspItem->iItemSlot() ];

    while( 
pInsert )
    {
        if( 
FClassnameIspInsert->pevSTRINGpItem->pev->classname ) ) )
        {
            if( 
pItem->AddDuplicatepInsert ) )
            {
                
g_pGameRules->PlayerGotWeaponthispItem );
                
pItem->CheckRespawn();

                
// ugly hack to update clip w/o an update clip message
                
pInsert->UpdateItemInfo( );

                if( 
m_pActiveItem )
                    
m_pActiveItem->UpdateItemInfo();

                
pItem->Kill( );
            }
            else if( 
gEvilImpulse101 )
            {
                
// FIXME: remove anyway for deathmatch testing
                
pItem->Kill();
            }
            return 
FALSE;
        }

        
pInsert pInsert->m_pNext;
    }

    if( 
pItem->AddToPlayerthis ) )
    {
        
g_pGameRules->PlayerGotWeaponthispItem );

        if( 
pItem->iItemSlot() == ItemSlot_Primary )
        {
            
m_fHasPrimaryWeapon TRUE;
        }

        
pItem->CheckRespawn();

        
pItem->m_pNext m_rgpPlayerItemspItem->iItemSlot() ];
        
m_rgpPlayerItems [pItem->iItemSlot() ] = pItem;

        if( 
HasShield() )
        {
            
pev->gamestate 0;
        }

        
// should we switch to this item?
        
if( g_pGameRules->FShouldSwitchWeaponthispItem ) && !IsProtectedByShield() )
        {
            
SwitchWeaponpItem );
        }

        return 
TRUE;
    }
    else if( 
gEvilImpulse101 )
    {
        
// FIXME: remove anyway for deathmatch testing
        
pItem->Kill();
    }
    return 
FALSE;

So, hooking AddToPlayer as post, is the same level as PlayerGotWeapon, and it would hard to think there is some issue at this time.
About grenade removed, it's a good point, I thought later ; it's true some plugin could remove silently a grenade and these forwards are appropriate.
__________________

Last edited by Arkshine; 01-03-2012 at 12:23.
Arkshine is offline
Nextra
Veteran Member
Join Date: Apr 2008
Location: Germany
Old 01-03-2012 , 12:36   Re: FrostNades
Reply With Quote #524

Ah yes I see. Maybe I didn't register AddToPlayer as post and ran into issues then, but I dont really know anymore. AttachToPlayer will probably work both as pre and post hook.
__________________
In Flames we trust!
Nextra is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 01-03-2012 , 13:01   Re: FrostNades
Reply With Quote #525

Nice to see this worked on again. Very nice work, Ava.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
XxAvalanchexX
Veteran Member
Join Date: Oct 2004
Location: abort73.com
Old 01-03-2012 , 20:49   Re: FrostNades
Reply With Quote #526

Quote:
Originally Posted by Arkshine View Post
That's the purpose of AddToPlayer, it's called when an item is added to the player's inventory, whatever where it comes.
I agree. I'm thinking AddToPlayer will probably be called whether you pick up a grenade from armoury_entity or you buy one. But that has to do with whether or not I have a frost grenade, as opposed to whether or not I have it selected.

To detect whether or not it's selected, you recommended I use Deploy and Holster. So, the issue is that Deploy isn't called when you switch to a grenade via cl_autowepswitch after picking it up from an armoury_entity (at least, it wasn't in my testing). So, that means a player could switch to a frost grenade without it being detected by Deploy. Does that make sense?

So I'm thinking the workaround would be to also check whether or not the frost grenade is selected in AddToPlayer or AttachToPlayer, assuming that the player's new weapon is updated at that point?
UPDATE: See this post about Deploy and cl_autowepswitch.

Thanks,

Ava
__________________
No longer around. Thanks your support, everyone! As always:
THIS ONES FOR YOU
3000 PTS

Last edited by XxAvalanchexX; 01-03-2012 at 21:56.
XxAvalanchexX is offline
Nextra
Veteran Member
Join Date: Apr 2008
Location: Germany
Old 01-03-2012 , 20:58   Re: FrostNades
Reply With Quote #527

Oh wow, buying a second flashbang really called the AddDuplicate forward? I must have overlooked that forward. When I wrote my plugin I used Ham_Item_UpdateItemInfo to detect when a second flashbang was bought.
__________________
In Flames we trust!
Nextra is offline
XxAvalanchexX
Veteran Member
Join Date: Oct 2004
Location: abort73.com
Old 01-03-2012 , 21:50   Re: FrostNades
Reply With Quote #528

Sorry about what I said earlier--it looks like Deploy actually _is_ called when switching to a new weapon via cl_autowepswitch. However, the pev->owner field is not updated at that point in that case, even as a post hook, so I'm not sure how to detect which player is deploying the weapon (is there some pdata field in the weapon which might be updated?).

Quote:
Originally Posted by Nextra View Post
Oh wow, buying a second flashbang really called the AddDuplicate forward? I must have overlooked that forward. When I wrote my plugin I used Ham_Item_UpdateItemInfo to detect when a second flashbang was bought.
Yes, but it looks like the pev->owner field is not updated at that point, even as a post hook. However, one of the arguments is the entity index of the weapon of that type which the player already owns, so you can check that entity's owner. (UPDATE: It looks like AddDuplicate is also called when picking up a 2nd flashbang via armoury_entity, although the pev->owner field still isn't set.)

I also found that if a player already has a flashbang, giving them another with give_item does not call AddToPlayer, AttachToPlayer, AddDuplicate, UpdateItemInfo, AddWeapon, or GiveAmmo, which is troubling, ha. (Whereas actually buying one seems to call AddDuplicate and UpdateItemInfo.) UPDATE: I may've actually been calling cs_set_user_bpammo instead of give_item in this case, which would explain this.

Ava
__________________
No longer around. Thanks your support, everyone! As always:
THIS ONES FOR YOU
3000 PTS

Last edited by XxAvalanchexX; 03-25-2012 at 01:56.
XxAvalanchexX is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 01-04-2012 , 04:28   Re: FrostNades
Reply With Quote #529

Quote:
Sorry about what I said earlier--it looks like Deploy actually _is_ called when switching to a new weapon via cl_autowepswitch. However, the pev->owner field is not updated at that point in that case, even as a post hook, so I'm not sure how to detect which player is deploying the weapon (is there some pdata field in the weapon which might be updated?).
Yes, pev_owner is not updated yet only in the situation where the weapon is switched to the new weapon. pev_owner is set in AttachToPlayer. You have to use m_pPlayer which is set in AddToPlayer
To understand more easily :

AddPlayerItem -> AddToPlayer (m_pPlayer) -> [ FShouldSwitchWeapon ? -> SwitchWeapon -> Deploy ] -> AttachToPlayer (pev_owner).

When you get a new weapon and you switch to this one, pev_owner will be updated after.
Therefore, simply use the weapon offset m_pPlayer ( 41, get_pdata_cbase( weaponIndex, m_pPlayer, 4 ) ).

EDIT: Wait lol, AddToPlayer, the player's index is already passed in the header, no need to use m_pPayer.

Quote:
I also found that if a player already has a flashbang, giving them another with give_item does not call AddToPlayer, AttachToPlayer, AddDuplicate, UpdateItemInfo, AddWeapon, or GiveAmmo, which is troubling, ha. (Whereas actually buying one seems to call AddDuplicate and UpdateItemInfo.)
Test again ? ; that's not possible that at least one of these are not called. Anyway, you don't need that for your plugin.
__________________

Last edited by Arkshine; 01-06-2012 at 01:07.
Arkshine is offline
kramesa
Veteran Member
Join Date: Feb 2011
Location: Brazil
Old 01-14-2012 , 20:29   Re: FrostNades
Reply With Quote #530

omfg, some updated
__________________
kramesa is offline
Old 01-17-2012, 04:12
reko_o
This message has been deleted by xPaw. Reason: Flooding "thanks" posts
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 11:29.


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