[ News | About | Media | Downloads | Tutorials | Contact ]

Tutorials

Back to Tutorials

Controllable Manhacks

Thanks to Bluefire for testing this tutorial.

This tutorial shows you how to get controllable Manhacks to work in your mod. First thing you need to is to download all the files from here. It containts the C++ files, the model src files (.smd and .qc files), and all the mod files.

Small overview of the entities: The controllable Manhacks are made of three different entities: npc_manhack, weapon_manhack, and vehicle_manhack. The NPC is mostly just the regular HL2 Manhack entity with few modifications to allow controlling it. The weapon entity is used by the player to spawn more manhacks and to take control of the vehicle manhack. The vehicle manhack is the entity handling player flying the manhack. The Metrocop model that the player is able to see in the map while controlling the Manhack is the stationary vehicle. It's made invisible and unsolid when the player stops controlling the vehicle.

Note: The code was made for an earlier version of the SP mod code. Also note that I programmed the manhacks a long time ago. If was to do the code again, I would do a lot of things a lot simpler and easier.

Code

First copy the c++ files to server and client sides and add them to the project. There's a bunch of changes you need to do to Source code:

[ movevars_shared ]

First go to movevars_shared.h in the bottom add:
// Manhack convars
extern ConVar r_ManhackViewDampenFreq;
extern ConVar r_ManhackViewDampenDamp;
extern ConVar r_ManhackViewZHeight;
In movevars_shared.cpp in the bottom add:
// Manhack

ConVar r_ManhackViewDampenFreq( "r_ManhackViewDampenFreq", "7.0", FCVAR_CHEAT | FCVAR_NOTIFY | FCVAR_REPLICATED );
ConVar r_ManhackViewDampenDamp( "r_ManhackViewDampenDamp", "1.0", FCVAR_CHEAT | FCVAR_NOTIFY | FCVAR_REPLICATED);
ConVar r_ManhackViewZHeight( "r_ManhackViewZHeight", "10.0", FCVAR_CHEAT | FCVAR_NOTIFY | FCVAR_REPLICATED );

[ viewrender ]

This part is to draw the vgui screen on the manhack weapon viewmodel. It's using the tutorial on the SDK documents.

In viewrender.cpp add:
//TERO: added by me
#include "human_error/c_manhack_screen.h"
#include "c_vguiscreen.h" 
Inside RenderView( ... ) after DrawMonitors( view ); add
DrawManhackScreen( view );
Then somewhere in viewrender.cpp add:
//TERO: remember to edit this shit
void CViewRender::DrawManhackScreen( const CViewSetup &viewSet )
{
	C_BasePlayer *localPlayer = C_BasePlayer::GetLocalPlayer();

	if(!localPlayer)
		return;

	C_BaseCombatWeapon *pWeapon = localPlayer->GetActiveWeapon();

	if( !pWeapon )
		return;

	//if (!pWeapon->IsWeaponManhack()) 
	//If you want to add IsWeaponManhack( void ) { return false; } to 
	//C_BaseCombatWeapon you wont have to use FClassnameIs
	if (!FClassnameIs( pWeapon, "weapon_manhack"))
		return;

	if( !pWeapon->GetViewModel() )
		return;

	CManhackScreen *pScreen = GetManhackScreen();

	if (!pScreen)
	{
		return;
	}

	//Get our camera render target.
	ITexture *pRenderTarget = GetManhackScreenTexture();

	if( pRenderTarget == NULL )
		return;

	if( !pRenderTarget->IsRenderTarget() )
		return;

	CViewSetup ManhackView = viewSet;

	ManhackView.width			= pRenderTarget->GetActualWidth(); 
	ManhackView.height			=  pRenderTarget->GetActualHeight();
	ManhackView.x				= 0;
	ManhackView.y				= 0;

	render->Push2DView( ManhackView, 0, pRenderTarget, GetFrustum() );

	pScreen->SetVisible( true );
	pScreen->SetSize(ManhackView.width , ManhackView.height );
	vgui::ipanel()->SetPos( pScreen->GetVPanel(), 0, 0);
	vgui::ipanel()->SetSize( pScreen->GetVPanel(), ManhackView.width, ManhackView.height);
	vgui::ipanel()->PaintTraverse( pScreen->GetVPanel(), true );
	
	render->PopView( m_Frustum );

	pScreen->SetVisible( false );
}
In viewrender.h after the declaration of DrawMonitors add
void			DrawManhackScreen( const CViewSetup &viewSet );

[ rendertexture ]

In rendertexture.cpp after the GetCameraTexture function add
//=============================================================================
// Manhack Screen Texture
//=============================================================================

#define MANHACK_SCREEN_MATERIAL "vgui/screens/manhack_screen"

static CTextureReference s_pManhackScreenTexture;
ITexture *GetManhackScreenTexture( void )
{ 
	if ( !s_pManhackScreenTexture )
	{
		s_pManhackScreenTexture.Init( materials->FindTexture( MANHACK_SCREEN_MATERIAL, 
						TEXTURE_GROUP_RENDER_TARGET ) );
		Assert( !IsErrorTexture( s_pManhackScreenTexture ) );
		AddReleaseFunc();
	}
	return s_pManhackScreenTexture;
}
In ReleaseRenderTargets( void ) add
s_pManhackScreenTexture.Shutdown();
In rendertexture.h after the declaration of GetCameraTexture add
ITexture *GetManhackScreenTexture( void ); //TERO: for weapon_manhack
In hl2_gamerules.cpp inside GetAmmoDef add
		//TERO: Define the manhack ammo
		def.AddAmmoType("Manhack",		DMG_CLUB, TRACER_NONE, NULL, NULL, 3, 0, 0);
		def.AddAmmoType("ManhacksOnline",	DMG_CLUB, TRACER_NONE, NULL, NULL, 3, 0, 0 );

[ Notes ]

Notes: I added CNPC_Manhack::IRelationType to make sure the Manhacks wont attack the player who created the manhack, but if you want to make sure the Manhacks don't attack players at all you will have to change the relationships in hl2_gamerules.cpp

Scripts

Manhack HUD

While other scripts are just drag and drop from the Manhacks.zip file, you will need to add the hud textures for the Manhack hud into scripts\hud_textures.txt. In the bottom add:
		"manhack_upper"
		{
				"file"		"sprites/metrocop_hud/manhack_upper"
				"x"			"0"
				"y"			"0"
				"width"		"64"
				"height"	"128"
		}
		"manhack_lower"
		{
				"file"		"sprites/metrocop_hud/manhack_lower"
				"x"			"0"
				"y"			"0"
				"width"		"64"
				"height"	"128"
		}

VGUI Screen

You will need to add the manhack_screen to vgui_screen.txt.
	"manhack_screen"
	{
		// TERO: Screen for the Combine Console
		// type defined in c_combine_console_screen.cpp
		"type"				"manhack_screen" // //vgui_screen_panel

		// These describe the dimensions of the screen *in pixels*

		"pixelswide" 	128
		"pixelshigh"	64

		// This is the name of the .res file to load up and apply to the vgui panel
		"resfile"			"scripts/Human_Error_screens/ManhackViewModel.res"
	
	}

Testing

To test the manhacks, you can start pretty much any map and write "give weapon_manhack" on console. Make sure you will have all the materials, models and script files in place.

Back to Tutorials

[ News | About | Media | Downloads | Tutorials | Contact ]



Valve, the Valve logo, Half-Life, the Half-Life logo, the Lambda logo, Steam, the Steam logo, Source, and the Source logo are trademarks and/or registered trademarks of Valve Software. All information is copyright their respective authors. Website designed by some guy I know.