Changing prop models dynamically

From Valve Developer Community
Revision as of 15:50, 8 October 2013 by HenryDorsett (talk | contribs)
Jump to navigation Jump to search

PLACEHOLDER!!

One of the major issues I've seen with the Source engine (and with most engines) is the inability to change the model of a prop on-the-fly. Why is this a problem? Well, presently, the issue, for me, has to do with lights, as most of my issues tend to be. In this case, I have a light fixture that's red at one point, but needs to be changed to white when the light being emitted is also changed.

But wait, why not just make another skin for the model? Because that doesn't cover alternate cases, when I want a completely different model. Moving on.

I was pleasantly surprised to find that this is incredibly easy, as things go. It's just small change to a few places, some copy/paste of Valve's existing code, and BAM!, it's done. So, here's the solution:

Modifying the Source Code

First, open up game/server/props.h. Find class CBaseProp : public CBaseAnimating and replace the entire class declaration with this:

class CBaseProp : public CBaseAnimating
{
public:
	DECLARE_CLASS( CBaseProp, CBaseAnimating );
	DECLARE_DATADESC();

	void Spawn( void );
	void Precache( void );
	void Activate( void );
	bool KeyValue( const char *szKeyName, const char *szValue );
	void CalculateBlockLOS( void );
	int  ParsePropData( void );
	
	void DrawDebugGeometryOverlays( void );

	void InputSetModel( inputdata_t &inputdata );

	// Don't treat as a live target
	virtual bool IsAlive( void ) { return false; }
	virtual bool OverridePropdata() { return true; }
};