General SDK Snippets & Fixes: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
No edit summary
Line 153: Line 153:
Place with you Spawn function of the entity:
Place with you Spawn function of the entity:
<pre>
<pre>
       int ModelType = random->RandomInt(1,100);
       int ModelType = random->RandomInt(1,10);
       switch( ModelType )
       switch( ModelType )
{
{

Revision as of 20:11, 15 January 2009


Remove Head Crab

How to Remove HeadCrab from zombie

in hl2_dll\npc_zombie.cpp look for void CZombie::Spawn( void ) then find this line.

m_fIsHeadless = false;

and simply change it to read this

m_fIsHeadless = true;

Now open hl2_dll\npc_BaseZombie.cpp and change this section to look like this.

//-----------------------------------------------------------------------------
// Purpose: A zombie has taken damage. Determine whether he release his headcrab.
// Output : YES, IMMEDIATE, or SCHEDULED (see HeadcrabRelease_t)
//-----------------------------------------------------------------------------
HeadcrabRelease_t CNPC_BaseZombie::ShouldReleaseHeadcrab( const CTakeDamageInfo &info, float flDamageThreshold )
{
	return ( m_iHealth <= 0 && m_fIsTorso && IsChopped( info ) )?RELEASE_RAGDOLL_SLICED_OFF:RELEASE_NO;
}

Working CS:S Muzzle Flashes without Model Editing

In c_baseanimating.cpp, at line 3024 (after the big switch statement), comment out the code so it looks like this

			if ( iAttachment != -1 && m_Attachments.Count() > iAttachment )
			{
				/*
				GetAttachment( iAttachment+1, attachOrigin, attachAngles );
				int entId = render->GetViewEntity();
				ClientEntityHandle_t hEntity = ClientEntityList().EntIndexToHandle( entId );
				tempents->MuzzleFlash( attachOrigin, attachAngles, atoi( options ), hEntity, bFirstPerson );
				*/
			}

and insert the following code after the comment.

 				if ( input->CAM_IsThirdPerson() )
 				{
 					C_BaseCombatWeapon *pWeapon = GetActiveWeapon();
 					pWeapon->GetAttachment( iAttachment+1, attachOrigin, attachAngles );
 				}
 				else
 				{
 					C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer();
 					CBaseViewModel *vm = pPlayer->GetViewModel();
 					vm->GetAttachment( iAttachment+1, attachOrigin, attachAngles );
 					engine->GetViewAngles( attachAngles );
 				}
 				g_pEffects->MuzzleFlash( attachOrigin, attachAngles, 1.0, MUZZLEFLASH_TYPE_DEFAULT );

Go to fx.cpp, under the statement pParticle->m_vecVelocity.Init(); in FX_MuzzleFlash, place the following code.

		C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer();
		Vector velocity = pPlayer->GetLocalVelocity();
		pParticle->m_vecVelocity += velocity;

Crossbow Bolt going through glass (func_breakable)

Open weapon_crossbow.cpp

In CCrossbowBolt::BoltTouch( CBaseEntity *pOther ) After :

if ( pOther->GetCollisionGroup() == COLLISION_GROUP_BREAKABLE_GLASS )
	return;

Insert the following code :

if(FClassnameIs(pOther, "func_breakable"))
{
    CBreakable* pOtherEntity =  static_cast<CBreakable*> (pOther);
    if(pOtherEntity->GetMaterialType() == matGlass)
        return;
}

Ignite Your Ragdolls

In your player's class (CSDKPlayer or CBasePlayer) find the Event_Killed() function. Add this inside of it:

if( info.GetDamageType() & (DMG_BLAST|DMG_BURN) )
{
    if( m_hRagdoll )
    {
        CBaseAnimating *pRagdoll = (CBaseAnimating *)CBaseEntity::Instance(m_hRagdoll);
        if( info.GetDamageType() & (DMG_BURN|DMG_BLAST) )
        {
            pRagdoll->Ignite(45, false, 10 );
        }
    }
}

If you don't have a ragdoll to ignite before that is called, make sure that code is placed after a call to CreateRagdollEntity(). If you're not doing that, add it in right above the if( info.GetDamageType() & (DMG_BLAST|DMG_BURN) ) line.

Control height and width of icon progress bars

This allows you to control the height and width of progress bars drawn with icons instead of the bars being the same dimensions as the textures.
In the file hud.h add the function declaration:

void	DrawIconProgressBarExt( int x, int y, int w, int h, CHudTexture *icon, CHudTexture *icon2, float percentage, Color &clr, int type );

Underneath the old declaration:

void    DrawIconProgressBar( int x, int y, CHudTexture *icon, CHudTexture *icon2, float percentage, Color& clr, int type );

Then in hud_redraw.cpp add the function itself:

void CHud::DrawIconProgressBarExt( int x, int y, int w, int h, CHudTexture *icon, CHudTexture *icon2, float percentage, Color& clr, int type )
{
	if ( icon == NULL )
		return;

	//Clamp our percentage
	percentage = min( 1.0f, percentage );
	percentage = max( 0.0f, percentage );

	int	height = icon->Height();
	int	width  = icon->Width();

	//Draw a vertical progress bar
	if ( type == HUDPB_VERTICAL )
	{
		int	barOfs = height * percentage;

		icon2->DrawSelfCropped( 
			x, y,  // Pos
			0, 0, width, barOfs, // Cropped subrect
			w, (h * percentage), clr );

		icon->DrawSelfCropped( 
			x, y + (h * percentage), 
			0, barOfs, width, height - barOfs, // Cropped subrect
			w, h - (h * percentage), clr );
	}
}

This was tested with vertical bars, horizontal bars haven't been tested.

Enabling func_precipitation rendering whilst in a point_viewcontrol

Currently, in the Orangebox code (ep1 not tested) func_precipitation doesn't get rendered when in a point_viewcontrol. To change this and get the precipitation working, open the viewrender.cpp (clientside) and find and delete this on line 595:

if ( CurrentViewID() == VIEW_MONITOR )
   return;


Randomizing Models

Place with you Spawn function of the entity:

       int ModelType = random->RandomInt(1,10);
       switch( ModelType )
	{
	case 1:
		SetModel( "Model1" );	
		break;

	case 2:
		SetModel( "Model2" );		
		break;

	case 3:
		SetModel( "Model3" );		
		break;
	
	case 4:
		SetModel( "Model4" );		
		break;
			
	case 5:
		SetModel( "Model5" );	
		break;
	
	case 6:
		SetModel( "Model6" );		
		break;

	case 7:
		SetModel( "Model7" );		
		break;

	case 8:
		SetModel( "Model8" );		
		break;
	
	case 9:
		SetModel( "Model9" );	
		break;
			
	case 10:
		SetModel( "Model10" );	
		break;
}
Note.pngNote:You can make it so you randomize skins too.