Raised This Month: $32 Target: $400
 8% 

Pickup two hegrenades


Post New Thread Reply   
 
Thread Tools Display Modes
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 11-16-2010 , 19:12   Re: Pickup two hegrenades
Reply With Quote #21

Well actually it would be more or less pointless since all the functions are the same as HLSDK except CWeaponbox::Touch(). In this latter, the difference would be only the support for the bomb, shield and grenades (check and max harcoded too).
__________________
Arkshine is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 11-17-2010 , 01:23   Re: Pickup two hegrenades
Reply With Quote #22

if( m_fHasPrimaryWeapon )

if( pOther->m_fHasPrimaryWeapon )
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 11-17-2010 , 05:40   Re: Pickup two hegrenades
Reply With Quote #23

Fixed.
__________________
Arkshine is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 11-17-2010 , 14:31   Re: Pickup two hegrenades
Reply With Quote #24

Here, the CWeaponBox::Touch() source code :

PHP Code:
void CWeaponBox::TouchCBaseEntity *pOther )
{
    if ( ~
pev->flags FL_ONGROUND || !pOther->IsPlayer() || !pOther->IsAlive() ) )
    {
        return;
    }

    if( 
pOther->m_fIsVIP || pOther->m_iUserPrefs USERPREFS_SHIELD_DRAWN )
    {
        return;
    }

    
pOther->OnTouchingWeaponthis );

    
BOOL bPlayPickupSound;
    
BOOL bUpdateAmmo;

    for( 
int iSlot 0iSlot MAX_ITEM_TYPESiSlot++ )
    {
        
CBasePlayerItem *pItem;

        while( 
m_rgpPlayerItemsiSlot ] )
        {
            
pItem m_rgpPlayerItemsiSlot ];

            if( ( 
pOther->HasShield() && pItem->m_iId == WEAPON_ELITE ) || pOther->IsBot() && TheBots->IsWeaponUseablepItem ) )
            {
                return;
            }

            if( 
FStrEqSTRINGpItem->pev->classname ), "weapon_c4" ) && pOther->m_iTeam == TEAM_TERRORIST && !pOther->pev->deadflags )
            {
                if( 
pOther->m_iUserPrefs USERPREFS_SHIELD_DRAWN && ~m_fHudTextArgsDontResend Bits_HINT_YOU_HAVE_THE_BOMB )
                {
                    
m_fHudTextArgsDontResend |= Bits_HINT_YOU_HAVE_THE_BOMB;
                    
pOther->HintMessage"#Hint_you_have_the_bomb" );
                }
                else
                {
                    
ClientPrintpOther->pevHUD_PRINTCENTER"#Got_bomb" );
                }

                
UTIL_LogPrintf"\"%s<%i><%s><TERRORIST>\" triggered \"Got_The_Bomb\"\n",
                    
STRINGpOther->pev->netname ),
                    
GET_PLAYER_USERIDpOther->edict() ),
                    
GET_PLAYER_AUTHIDpOther->edict() ) );

                
g_pGameRules->m_bBombDropped FALSE;

                
MESSAGE_BEGINMSG_SPECSVC_DIRECTOR );
                
WRITE_BYTE);
                
WRITE_BYTEDRC_CMD_EVENT );
                
WRITE_SHORTENTINDEXpOther->edict() ) );
                
WRITE_SHORTENTINDEXthis->edict() ) );
                
WRITE_ENTITY);
                
MESSAGE_END();

                
pOther->m_fDefusePlant |= CAN_PLANT_BOMB;
                
pOther->SetBombIconFALSE );
                
pOther->pev->body 1;

                
CBaseEntity *pEnt;

                while( ( 
pEnt UTIL_FindEntityByClassnamepEnt"player" ) ) != NULL )
                {
                    
CBasePlayer *pIndex UTIL_PlayerByIndexpEnt );

                    if ( 
pIndex && !FNullEntpIndex->pev ) && pIndex->IsPlayer() && ~pIndex->pev->flags FL_DORMANT )
                    {
                        
CBasePlayer *pPlayer GetClassPtr( ( CBasePlayer * ) pev );

                        if( !
pPlayer->pev->deadflags && pPlayer->m_iTeam == TEAM_TERRORIST && pPlayer != pOther )
                        {
                            
ClientPrintpPlayer->pevHUD_PRINTCENTER"#Game_bomb_pickup" );

                            
MESSAGE_BEGINMSG_ONEgmsgBombPickupNULLpPlayer->edict() );
                            
MESSAGE_END();
                        }
                    }
                }

                
TheBots->SetLooseBombFALSE );
                
TheBots->OnEventEVENT_BOMB_PICKUPpOther->pevNULL );
            }

            if( !( 
<= iSlot <= && pOther->m_rgpPlayerItemsiSlot ] ) )
            {
                if( 
iSlot != )
                {
                    if( ( !
pOther->HasShield() || iSlot != ) && pOther->AddPlayerItempItem ) )
                    {
                        
pItem->AttachToPlayerpOther );

                        
bPlayPickupSound TRUE;
                        
bUpdateAmmo TRUE;
                    }
                }
                else if( 
Item->IsWeapon() )
                {
                    
char *szWeapon;
                    
int iMax;

                    switch( 
pItem->m_iId )
                    {
                        case 
WEAPON_HEGRENADE   :
                        {
                            
szWeapon "weapon_hegrenade";
                            
iMax 1;
                            break;
                        }
                        case 
WEAPON_SMOKEGRNADE :
                        {
                            
szWeapon "weapon_smokegrenade";
                            
iMax 1;
                            break;
                        }
                        case 
WEAPON_FLASHBANG   :
                        {
                            
szWeapon "weapon_flashbang"
                            
iMax 2;
                            break;
                        }
                    }

                    if( 
pOther->m_rgAmmom_iPrimaryAmmoType ] < iMax )
                    {
                        
pOther->GiveNamedItemszWeapon );

                        
bPlayPickupSound TRUE;
                        
bUpdateAmmo TRUE;
                    }
                }
            }

            
m_rgpPlayerItemsiSlot ] = m_rgpPlayerItemsiSlot ]->m_pNext;
        }
    }

    if( 
bUpdateAmmo )
    {
        for( 
0MAX_AMMO_SLOTSi++ )
        {
            if( !
FStringNullm_rgiszAmmo] ) )
            {
                
pPlayer->GiveAmmom_rgAmmo], (char *)STRINGm_rgiszAmmo] ), MaxAmmoCarrym_rgiszAmmo] ) );

                
m_rgiszAmmo] = iStringNull;
                
m_rgAmmo] = 0;
            }
        }

        
SetTouchNULL );
        
UTIL_Removethis );
    }

    if( 
bPlayPickupSound )
    {
        
EMIT_SOUNDpOther->edict(), CHAN_ITEM"items/gunpickup2.wav"1ATTN_NORM );
    }

__________________

Last edited by Arkshine; 11-24-2010 at 03:48.
Arkshine is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-17-2010 , 17:51   Re: Pickup two hegrenades
Reply With Quote #25

In your code it looks like a new grenade is being created and is not giving the player an existing grenade that's linked to the weaponbox. In code from weapons.cpp it looks like the player is given the existing entity.

weapons.cpp
PHP Code:
void CWeaponBox::TouchCBaseEntity *pOther )
...
for ( 
MAX_ITEM_TYPES i++ )
{
    if ( 
m_rgpPlayerItems] )
    {
        
CBasePlayerItem *pItem;

        
// have at least one weapon in this slot
        
while ( m_rgpPlayerItems] )
        {
            
//ALERT ( at_console, "trying to give %s\n", STRING( m_rgpPlayerItems[ i ]->pev->classname ) );

            
pItem m_rgpPlayerItems];
            
m_rgpPlayerItems] = m_rgpPlayerItems]->m_pNext;// unlink this weapon from the box

            
if ( pPlayer->AddPlayerItempItem ) )
            {
                
pItem->AttachToPlayerpPlayer );
            }
        }
    }

CWeaponBox::Touch()
PHP Code:
else if( Item->IsWeapon() )
{
    
char *weapon;
    
int max;
    
    switch( 
pItem->m_iId )
    {
    case 
WEAPON_HEGRENADE   :
    {
        
weapon "weapon_hegrenade";
        
max 1;
        break;
    }
    case 
WEAPON_SMOKEGRNADE :
    {
        
weapon "weapon_smokegrenade";
        
max 1;
        break;
    }
    case 
WEAPON_FLASHBANG   
    {
        
weapon "weapon_flashbang"
        
max 2;
        break;
    }
    }
    
    if( 
pOther->m_rgAmmom_iPrimaryAmmoType ] < max )
    {
    
pOther->GiveNamedItemweapon );
    
    
bPlayPickupSound TRUE;
    
bUpdateAmmo TRUE;
    }
}
 
//... 
weapons.cpp
PHP Code:
void CBasePlayer::GiveNamedItem( const char *pszName )
{
    
edict_t    *pent;

    
int istr MAKE_STRING(pszName);

    
pent CREATE_NAMED_ENTITY(istr);
    if ( 
FNullEntpent ) )
    {
        
ALERT at_console"NULL Ent in GiveNamedItem!\n" );
        return;
    }
    
VARSpent )->origin pev->origin;
    
pent->v.spawnflags |= SF_NORESPAWN;

    
DispatchSpawnpent );
    
DispatchTouchpentENTpev ) );

__________________

Last edited by Bugsy; 11-17-2010 at 18:11.
Bugsy is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 11-17-2010 , 18:15   Re: Pickup two hegrenades
Reply With Quote #26

Interesting question. You know well by default in CS/CZ you can't drop grenades. I've just checked by testing to drop a grenade, I see weapon_hegrenade + weaponbox. Atfer I pickup this grenade, weaponbox has disappeared but I see two weapon_hegrenade. So, yes a new entity is well created. I don't know what happen for CZ when you die and you drop a grenade and you pickup after. [EDIT] It seems a new entity is created for CZ too. Since it's the same code it's quite normal. :p. Don't know why it's designed like that, something to fix for sure.. ^^
__________________

Last edited by Arkshine; 11-17-2010 at 18:33.
Arkshine is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-17-2010 , 19:48   Re: Pickup two hegrenades
Reply With Quote #27

Quote:
Originally Posted by Arkshine View Post
Interesting question. You know well by default in CS/CZ you can't drop grenades. I've just checked by testing to drop a grenade, I see weapon_hegrenade + weaponbox. Atfer I pickup this grenade, weaponbox has disappeared but I see two weapon_hegrenade. So, yes a new entity is well created. I don't know what happen for CZ when you die and you drop a grenade and you pickup after. [EDIT] It seems a new entity is created for CZ too. Since it's the same code it's quite normal. :p. Don't know why it's designed like that, something to fix for sure.. ^^
Interesting. Since CS was coded assuming nades would never be dropped they didn't bother to code the handling of this particular situation, which totally makes sense. I guess it only works because the engine treats it as any other weapon when dropped which allows it to still function, though not perfectly. I was playing around with dropping and picking up of nades and wanted to figure out exactly weaponbox\armoury_entity's operated. Thanks for your info.
__________________

Last edited by Bugsy; 11-17-2010 at 19:51.
Bugsy is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 11-24-2010 , 03:30   Re: Pickup two hegrenades
Reply With Quote #28

@Arkshine
In CWeaponBox::Touch() you have this:
Code:
                    if( ( !pOther->HasShield() || iSlot != 1 ) && pPlayer->AddPlayerItem( pItem ) )
                    {
                        pItem->AttachToPlayer( pPlayer );
                        
                        bPlayPickupSound = TRUE;
                        bUpdateAmmo = TRUE;
                    }
pPlayer is never defined in a scope where it is accessible here.
Did you mean to use pOther?

Also, where could I see the code in AddPlayerItem()?
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 11-24-2010 , 03:47   Re: Pickup two hegrenades
Reply With Quote #29

Yes, pOther, sorry.

You can see the code of this function in the HLSDK. It's the same.
__________________
Arkshine is offline
abdul-rehman
Veteran Member
Join Date: Jan 2010
Location: Khi, Pakistan
Old 11-24-2010 , 04:09   Re: Pickup two hegrenades
Reply With Quote #30

Code:
pOther->HasShield
What is this operator "->" supposed to do ??
I know i am asking a question related to C/C++
__________________

My Plugins For ZP

Inactive due to College and Studies
abdul-rehman is offline
Send a message via Yahoo to abdul-rehman Send a message via Skype™ to abdul-rehman
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 16:34.


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