Creating simple pickup: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(fixed basically everything)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
What:
{{Note|This was made for Orange Box version}}
I will explain how you can add a simple pickup like you have in the singleplayer
Version: Orange Box SDK.
-------
-------
 
First open "hl2mp_player.cpp" and search for "CHL2MP_Player::PickupObject".<br>
First open "hl2mp_player.cpp" and search for "CHL2MP_Player::PickupObject".
Now replace it with the following code:
 
replace the function:
 
<source lang=cpp>
void CHL2MP_Player::PickupObject( CBaseEntity *pObject, bool bLimitMassAndSize )
{
}
</source>
 
with:
<source lang=cpp>
<source lang=cpp>
void CHL2MP_Player::PickupObject( CBaseEntity *pObject, bool bLimitMassAndSize )
void CHL2MP_Player::PickupObject( CBaseEntity *pObject, bool bLimitMassAndSize )
Line 23: Line 10:
return;
return;
if ( bLimitMassAndSize == true )
{
BaseClass::PickupObject(pObject, bLimitMassAndSize);
if ( CBasePlayer::CanPickupObject( pObject, 35, 128 ) == false )
return;
}
 
// Can't be picked up if NPCs are on me
// Can't be picked up if NPCs are on me
if ( pObject->HasNPCsOnIt() )
if ( pObject->HasNPCsOnIt() )
return;
return;
 
HideViewModels();
ClearActiveWeapon();
Weapon_Switch( Weapon_OwnsThisType( "nameofyourweaponentity" ) );
PlayerPickupObject( this, pObject );
PlayerPickupObject( this, pObject );
}
}
</source>
</source>
The code is just taken from the singleplayer.
 
{{Special thanks|SecobMod Team|Updating the code}}


[[Category:Programming]]
[[Category:Programming]]

Latest revision as of 06:05, 11 September 2022

Note.pngNote:This was made for Orange Box version

First open "hl2mp_player.cpp" and search for "CHL2MP_Player::PickupObject".
Now replace it with the following code:

void CHL2MP_Player::PickupObject( CBaseEntity *pObject, bool bLimitMassAndSize )
{
	// can't pick up what you're standing on
	if ( GetGroundEntity() == pObject )
		return;
	
	
	BaseClass::PickupObject(pObject, bLimitMassAndSize);
	
	// Can't be picked up if NPCs are on me
	if ( pObject->HasNPCsOnIt() )
		return;	
	
	HideViewModels();
	ClearActiveWeapon();
	
	Weapon_Switch( Weapon_OwnsThisType( "nameofyourweaponentity" ) );
	
	PlayerPickupObject( this, pObject );
}
Special thanks to SecobMod Team Updating the code