Post tutorial RSS Easy Pickable Weapon System Tutorial By Morais PGSI

This is a really easy tutorial on how to make the E key in half life 2 ep 2 pick up weapons.

Posted by on - Basic Client Side Coding

This is a tutorial that i wanted to share with peaple who dont know how to do a easy pickable weapon system.

Just open your solution and search for basecombatweapon_shared.cpp in Client episodic - Source Files.

In the file you will find this class function :
void CBaseCombatWeapon::DefaultTouch( CBaseEntity *pOther )

All you need to do is comment everything inside this function: /* Everything inside */

Heres how it should look like:

void CBaseCombatWeapon::DefaultTouch( CBaseEntity *pOther )
{

/*
#if !defined( CLIENT_DLL )
	// Can't pick up dissolving weapons
	if ( IsDissolving() )
		return;

	// if it's not a player, ignore
	CBasePlayer *pPlayer = ToBasePlayer(pOther);
	if ( !pPlayer )
		return;

	if( UTIL_ItemCanBeTouchedByPlayer(this, pPlayer) )
	{
		// This makes sure the player could potentially take the object
		// before firing the cache interaction output. That doesn't mean
		// the player WILL end up taking the object, but cache interactions
		// are fired as soon as you prove you have found the object, not
		// when you finally acquire it.
		m_OnCacheInteraction.FireOutput( pOther, this );
	}

	if( HasSpawnFlags(SF_WEAPON_NO_PLAYER_PICKUP) )
		return;

	if (pPlayer->BumpWeapon(this))
	{
		OnPickedUp( pPlayer );
	}
#endif 
	
*/
}


If you want a simple hint hud just add the following code:

#if !defined( CLIENT_DLL )
	CBasePlayer *pPlayer = ToBasePlayer(pOther);
	if ( !pPlayer )
		return;


	UTIL_HudHintText( pPlayer, "Valve_Hint_PicKUp" );
	

#endif

Now it should look like:

void CBaseCombatWeapon::DefaultTouch( CBaseEntity *pOther )
{

//SIMPLE HUD IMPLEMENTATION
#if !defined( CLIENT_DLL )
	CBasePlayer *pPlayer = ToBasePlayer(pOther);
	if ( !pPlayer )
		return;


	UTIL_HudHintText( pPlayer, "Valve_Hint_PicKUp" );
	
#endif
	
	


/*

#if !defined( CLIENT_DLL )
	// Can't pick up dissolving weapons
	if ( IsDissolving() )
		return;

	// if it's not a player, ignore
	CBasePlayer *pPlayer = ToBasePlayer(pOther);
	if ( !pPlayer )
		return;

	if( UTIL_ItemCanBeTouchedByPlayer(this, pPlayer) )
	{
		// This makes sure the player could potentially take the object
		// before firing the cache interaction output. That doesn't mean
		// the player WILL end up taking the object, but cache interactions
		// are fired as soon as you prove you have found the object, not
		// when you finally acquire it.
		m_OnCacheInteraction.FireOutput( pOther, this );
	}

	if( HasSpawnFlags(SF_WEAPON_NO_PLAYER_PICKUP) )
		return;

	if (pPlayer->BumpWeapon(this))
	{
		OnPickedUp( pPlayer );
	}
#endif 
	
*/
}

And if you wanna add a custom hint hud use the following code:

void CBaseCombatWeapon::DefaultTouch( CBaseEntity *pOther )
{


#if !defined( CLIENT_DLL )
	CBasePlayer *pPlayer = ToBasePlayer(pOther);
	if ( !pPlayer )
		return;


	UTIL_HudHintText( pPlayer, "Valve_Hint_PicKUpWeapon" );//Valve_Hint_PickUpWeapon does not exists yet

#endif
	
/*

#if !defined( CLIENT_DLL )
	// Can't pick up dissolving weapons
	if ( IsDissolving() )
		return;

	// if it's not a player, ignore
	CBasePlayer *pPlayer = ToBasePlayer(pOther);
	if ( !pPlayer )
		return;

	if( UTIL_ItemCanBeTouchedByPlayer(this, pPlayer) )
	{
		// This makes sure the player could potentially take the object
		// before firing the cache interaction output. That doesn't mean
		// the player WILL end up taking the object, but cache interactions
		// are fired as soon as you prove you have found the object, not
		// when you finally acquire it.
		m_OnCacheInteraction.FireOutput( pOther, this );
	}

	if( HasSpawnFlags(SF_WEAPON_NO_PLAYER_PICKUP) )
		return;

	if (pPlayer->BumpWeapon(this))
	{
		OnPickedUp( pPlayer );
	}
#endif 
	
*/
}

After doing that go to modfoldier\resource\modname_english.txt. If you dont have it use the following(it is already finished):

"lang" 
{ 
"Language" "English" 
"Tokens" 
{ 
"Valve_Listen_MapName"			"Map"
"Valve_Movement_Title"			"MOVEMENT"
"Valve_Move_Forward"			"Move forward"
"Valve_Move_Back"			"Move back"
"Valve_Turn_Left"			"Turn left"
"Valve_Turn_Right"			"Turn right"
"Valve_Move_Left"			"Move left (strafe)"
"Valve_Move_Right"			"Move right (strafe)"
"Valve_Jump"				"Jump"
"Valve_Duck"				"Duck"
"Valve_Swim_Up"				"Swim up"
"Valve_Swim_Down"			"Swim down"
"Valve_Look_Up"				"Look up"
"Valve_Look_Down"			"Look down"
"Valve_Look_Straight_Ahead"		"Look straight ahead"
"Valve_Strafe_Modifier"			"Strafe modifier"
"Valve_Mouse_Look_Modifier"		"Mouse look modifier"
"Valve_Keyboard_Look_Modifier"		"Keyboard look modifier"
"Valve_Use_Items"			"Use item (buttons, machines, ...)"
"Valve_Communication_Title"		"COMMUNICATION"
"Valve_Use_Voice_Communication"		"Use voice communication"
"Valve_Chat_Message"			"Chat message"
"Valve_Team_Message"			"Team message"
"Valve_Combat_Title"			"COMBAT"
"Valve_Primary_Attack"			"Primary attack"
"Valve_Secondary_Attack"		"Secondary attack"
"Valve_Reload_Weapon"			"Reload weapon"
"Valve_Walk"				"Walk (Move Slowly)"
"Valve_Flashlight"			"Flashlight"
"Valve_Spray_Logo"			"Spray logo"
"Valve_Weapon_Category_1"		"Weapon category 1"
"Valve_Weapon_Category_2"		"Weapon category 2"
"Valve_Weapon_Category_3"		"Weapon category 3"
"Valve_Weapon_Category_4"		"Weapon category 4"
"Valve_Weapon_Category_5"		"Weapon category 5"
"Valve_Weapon_Category_6"		"Weapon category 6"
"Valve_Weapon_Category_7"		"Weapon category 7"
"Valve_Weapon_Category_8"		"Weapon category 8"
"Valve_Weapon_Category_9"		"Weapon category 9"
"Valve_Weapon_Category_0"		"Weapon category 0"
"Valve_Previous_Weapon"			"Previous weapon"
"Valve_Next_Weapon"			"Next weapon"
"Valve_Last_Weapon_Used"		"Last weapon used"
"Valve_Miscellaneous_Title"		"MISCELLANEOUS"
"Valve_Display_Scores"			"Display multiplayer scores"
"Valve_Take_Screen_Shot"		"Take screen shot"
"Valve_Quick_Save"			"Quick save"
"Valve_Quick_Load"			"Quick load"
"Valve_Pause_Game"			"Pause game"
"Valve_Quit_Game"			"Quit game"
"Valve_Accept_Redirect"			"Accept redirect to another server"
"Valve_ServerOfferingToConnect"		"The server is offering to connect you to:"
"Valve_PressKeyToAccept"		"Press %s1 to accept."
"Valve_BindKeyToAccept"			"Please configure a key to accept."
"Valve_Cheer"				"Cheer"
"Valve_Activate_In_Game_GUI"		"Activate in-game GUI"
"Valve_Change_Team"			"Change team"
"Valve_Change_Class"			"Change class"
"Valve_Use_Special_Skill"		"Use special skill"
"Valve_Multiplayer_Decal_Limit"		"Multiplayer decal limit"
"Valve_Valid_Teams"			"Valid teams, leave blank for all"
"Valve_Frag_Limit"			"Frag Limit"
"Valve_Time_Limit"			"Time Limit (Min.)"
"Valve_Falling_Damage"			"Falling Damage"
"Valve_Normal"				"Normal"
"Valve_Realistic"			"Realistic"
"Valve_Teamplay"			"Teamplay"
"Valve_Friendly_Fire"			"Friendly Fire"
"Valve_Weapons_Stay"			"Weapons Stay"
"Valve_Force_Respawn"			"Force Respawn"
"Valve_Footsteps"			"Footsteps"
"Valve_Autocrosshair"			"Autocrosshair"
"Valve_Center_Player_Names"		"Center player names"
"Valve_Switch_Weapons_Immediately"	"Switch weapons immediately"
"Valve_Automatic_Screenshots"		"Automatically take end-game screenshots"
"Valve_Observer_Crosshair"		"Observer crosshair"

"Spec_Slow_Motion" "Slow Motion"
"Spec_No_PIP" "
Picture-In-Picture is not available
in First-Person mode while playing.
"

"Spec_Replay" "Instant Replay"
"Spec_Auto" "Auto"
"Spec_Time" "Time"
"Spec_Map" "Map: %s1"
"Spectators" "Spectators"
"Spec_PlayerItem_Health" "%s1 (%s2)"
"Spec_PlayerItem" "%s1"
"Spec_PlayerItem_Team" "%s1 (%s2)"
"Spec_Duck"	"Press DUCK for Spectator Menu"
"Spec_Help_Title" "Spectator Mode"
"Spec_Help_Text"  "
Use the following keys to change view styles:

 FIRE1 - Chase next player
 FIRE2 - Chase previous player
 JUMP - Change view modes
 USE - Change inset window mode
 
 DUCK  - Enable spectator menu
  
In Overview Map Mode move around with:

 MOVELEFT - move left
 MOVERIGHT - move right
 FORWARD - zoom in
 BACK - zoom out
 MOUSE - rotate around map/target
"

"Spec_Modes" 	"Camera Options"
"Spec_Mode0" 	"Camera Disabled"
"Spec_Mode1" 	"Death Camera"
"Spec_Mode2" 	"Fixed View"
"Spec_Mode3" 	"First Person"
"Spec_Mode4" 	"Chase Camera"
"Spec_Mode5" 	"Free Look"
"Spec_Mode6" "Chase Map Overview"
"Spec_NoTarget" "No valid targets. Cannot switch Camera Mode."
"Spec_Options"	"Options"
"OBS_NONE" "Camera Options"
"OBS_CHASE_LOCKED" "Locked Chase Camera"
"OBS_CHASE_FREE" "Free Chase Camera"
"OBS_ROAMING" "Free Look"
"OBS_IN_EYE" "First Person"
"OBS_MAP_FREE" "Free Map Overview"
"OBS_MAP_CHASE" "Chase Map Overview"
"SPECT_OPTIONS" "Options"
"CAM_OPTIONS" "Camera Options"

"PlayerName"	"Name"
"PlayerScore"	"Score"
"PlayerDeath"	"Deaths"
"PlayerPing"	"Latency"
"PlayerVoice"	"Voice"
"PlayerTracker"	"Friend"

"T0A0TITLE"	"HAZARD COURSE"
"C0A0TITLE"	"BLACK MESA INBOUND"
"C0A1TITLE"	"ANOMALOUS MATERIALS"
"C1A1TITLE"	"UNFORESEEN CONSEQUENCES"
"C1A2TITLE"	"OFFICE COMPLEX"
"C1A3TITLE"	"WE'VE GOT HOSTILES"
"C1A4TITLE"	"BLAST PIT"
"C2A1TITLE"	"POWER UP"
"C2A2TITLE"	"ON A RAIL"
"C2A3TITLE"	"APPREHENSION"
"C2A4TITLE1"	"RESIDUE PROCESSING"
"C2A4TITLE2"	"QUESTIONABLE ETHICS"
"C2A5TITLE"	"SURFACE TENSION"
"C3A1TITLE"	"FORGET ABOUT FREEMAN!"
"C3A2TITLE"	"LAMBDA CORE"
"C4A1TITLE"	"XEN"
"C4A1ATITLE"	"INTERLOPER"
"C4A2TITLE"	"GONARCH'S LAIR"
"C4A3TITLE"	"NIHILANTH"
"C5TITLE"	"ENDGAME"

"Valve_Hostname"	"Hostname"
"Valve_Max_Players"	"Max. players"
"Valve_Server_Password"	"Server password"

"Valve_Close"		"Close"
"Valve_Help"		"Help"
"Valve_Settings"	"Settings"
"Valve_Chat_Messages"	"Chat Messages"
"Valve_Show_Status"	"Show Status"
"Valve_View_Cone"	"View Cone"
"Valve_Player_Names"	"Player Names"
"Valve_PIP"		"Picture-In-Picture"
"Valve_Overview"	"Overview"
"Valve_Overview_Off"	"No Map"
"Valve_Overview_Small"	"Small Map"
"Valve_Overview_Large"	"Large Map"
"Valve_Overview_ZoomIn"	"Zoom In"
"Valve_Overview_Zoomout" "Zoom Out"
"Valve_Overview_Locked"	"No Rotation"
"Valve_Overview_Names" 	"Show Names"
"Valve_Overview_Health" "Show Health"
"Valve_Overview_Tracks" "Show Tracks"
"Valve_Auto_Director"	"Auto Director"
"Valve_Show_Scores"	"Show Scores"
"Valve_Game_Saved"	"Game Saved"

"Valve_Orange"		"Orange"
"Valve_Yellow"		"Yellow"
"Valve_Blue"		"Blue"
"Valve_Ltblue"		"Ltblue"
"Valve_Green"		"Green"
"Valve_Red"		"Red"
"Valve_Brown"		"Brown"
"Valve_Ltgray"		"Ltgray"
"Valve_Dkgray"		"Dkgray"

"Valve_Playing"		"Playing"
"Valve_Stopped"		"Stopped"
"Valve_Paused"		"Paused"

"Valve_x_1_4"		"x1/4"
"Valve_x_1_2"		"x1/2"
"Valve_x_1"		"x1"
"Valve_x_2"		"x2"
"Valve_x_4"		"x4"

"Valve_ViewDemoStatus"	"%s1  %s2  %s3"

"Valve_Hint_Zoom"	"%+zoom% ZOOM VIEW"
"Valve_Hint_machinegun"	"%+USE% TO USE MOUNTED GUN"
"Valve_Hint_Flashlight" "%impulse 100% FLASHLIGHT"
"Valve_Hint_PhysSwap" "%phys_swap% TO SWAP GRAVITY GUN\n WITH PREVIOUS GUN"
"Valve_Hint_Command_send"  "%impulse 50% SEND YOUR SQUAD TO A LOCATION"
"Valve_Hint_Command_recall"  "%impulse 50% TWICE TO RECALL YOUR SQUAD"
"Valve_Hint_CraneKeys"	"%+forward% EXTEND ARM %+back% RETRACT ARM %+moveleft% TURN LEFT %+moveright% TURN RIGHT %+attack% PICKUP OR DROP OBJECT"
"Valve_Hint_BoatKeys"	"%+forward% SPEED UP %+back% SLOW DOWN %+moveleft% TURN LEFT %+moveright% TURN RIGHT\nUSE MOUSE TO LOOK"
"Valve_Hint_JeepKeys"	"%+speed% TURBO %+jump% HANDBRAKE"
"Valve_Hint_JeepTurbo"	"%+speed% TURBO"
"Valve_Hint_HEVcharger" "%+use% HOLD DOWN TO CHARGE SUIT"
"Valve_Hint_AirboatGun" "%+attack% FIRE AIRBOAT GUN"
"Valve_Hint_AmmoCrate" "%+use% GET AMMO FROM CRATE"
"Valve_Hint_USEPickup"  "%+use% PICKUP OBJECT"
"Valve_Hint_ThrowHeld"  "%+attack% THROW HELD OBJECT"
"Valve_Hint_MomentaryButton"	"%+use% HOLD DOWN TO TURN WHEEL"
"Valve_Hint_ThrowBait"	"%+attack% THROW BUGBAIT"
"Valve_Hint_SqueezeBait"  "%+attack2% CALL ANTLIONS"
"Valve_Hint_PicKUpWeapon" "%+use% TO PICK UP WEAPON"

"Valve_Miscellaneous_Keyboard_Keys_Title"  "MISCELLANEOUS MOVEMENT"
"Valve_Chapter"		"Chapter"

"Valve_HudPoisonDamage"	"NEUROTOXIN DETECTED\nADMINISTERING ANTIDOTE"

"Valve_CreatingCache"	"Creating sound caches..."
"Valve_CreatingSpecificSoundCache"	"Processing:  %s1"

"Valve_UpdatingSteamResources" "Updating Steam resources..."

"Valve_Sprint"		"Sprint (Move Quickly)"
"Valve_Suit_Zoom"	"Suit Zoom"
"Valve_Commander_Mode"	"Send/Recall Squad"
"Valve_Gravity_Gun"	"Gravity Gun"
"Valve_CC_Toggle"	"Toggle close caption sound effects"

"Valve_Hud_HEALTH"		"HEALTH"
"Valve_Hud_AMMO"		"AMMO"
"Valve_Hud_SUIT"		"SUIT"
"Valve_Hud_AUX_POWER"		"AUX POWER"
"Valve_Hud_OXYGEN"		"OXYGEN"
"Valve_Hud_FLASHLIGHT"		"FLASHLIGHT"
"Valve_Hud_SPRINT"		"SPRINT"

"Valve_Hud_SQUAD_FOLLOWING"	"SQUAD FOLLOWING"
"Valve_Hud_SQUAD_STATIONED"	"SQUAD STATIONED"

"Valve_HDRDEMO_LeftTitle"	"Fixed Aperture"
"Valve_HDRDEMO_RightTitle"	"High-Dynamic Range"

"Valve_Hud_CamFOV"		"FOV"
"Valve_Hud_CamHeight"	"Cam Height"
"Valve_CamArmLength"	"Arm Length"

"Valve_FilmDemo_FilmGrain_LeftTitle"	"No Film Grain"
"Valve_FilmDemo_FilmGrain_RightTitle"	"Film Grain"

"Valve_FilmDemo_ColorCorrection_LeftTitle"	"No Color Correction"
"Valve_FilmDemo_ColorCorrection_RightTitle"	"Color Correction"

} 
}

If you have it search for "Valve_Hint_SqueezeBait" "%+attack2% CALL ANTLIONS" and add bellow that:
"Valve_Hint_PicKUpWeapon" "%+use% TO PICK UP WEAPON"

And your done. If you want to edit the hint text consider that the "%+use%" have to be in one of the sides for exemple:
"%+use% TO DO SOMETHING"
or
"DO SOMETHING: %+use%"


Hope you guys like it.

Use E key to pick them up and have fun :)

-This only Apply for weapons not for items.

Comments
Jokerme
Jokerme

Use point_message entity or env_message entity. If you don'T know how to use them go to Valve Developer Community.

Reply Good karma Bad karma+1 vote
MoraisPGSI Author
MoraisPGSI

Ok now you have all you need :)

Reply Good karma+1 vote
Graves.Party.Army
Graves.Party.Army

Hey Ive been trying to get this for EVER but i cant get it to work :(. I keep geting errors on compile.If you can fix this or shed light on my problem it would be much apriciated! Thx XD

Reply Good karma Bad karma-2 votes
Post a comment
Sign in or join with:

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.