New Gamerules: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m (categorizing)
m (cleanup/no credits)
Line 1: Line 1:
For all of those who need to implement new gamerules in their mod, or have tried and failed (Me for the second time), these two snippets (well... files), will help you along.
For all of those who need to implement new gamerules in their mod, or have tried and failed these two snippets will help you along.


You can find/replace
You can find/replace
Line 5: Line 5:


and then replace with your game rules name.
and then replace with your game rules name.
Full credits go to [http://forums.steampowered.com/forums/member.php?u=369486 StuD-tos]


The header file:
The header file:
<pre>
<pre>
//========= Copyright © 2005-2007, Attitude Corporation, All rights reserved. ============//
//
// Author:  Christopher 'StuD' Loy
// Purpose:
// File:    inherited_gamerules.h
//
//=============================================================================//


#ifndef INHERITED_GAMERULES_H
#ifndef INHERITED_GAMERULES_H
Line 87: Line 78:
The main CPP file:
The main CPP file:


<pre>//========= Copyright © 2005-2007, Attitude Corporation, All rights reserved. ============//
//
// Author:  Christopher 'StuD' Loy
// Purpose:
// File:    inherited_gamerules.cpp
//
//=============================================================================//
#include "cbase.h"
#include "cbase.h"
#include "inherited_gamerules.h"
#include "inherited_gamerules.h"
Line 210: Line 194:
}</pre>
}</pre>


Posted by Marine


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

Revision as of 10:31, 5 September 2008

For all of those who need to implement new gamerules in their mod, or have tried and failed these two snippets will help you along.

You can find/replace

InheritedGameRules

and then replace with your game rules name.

The header file:


#ifndef INHERITED_GAMERULES_H
#define INHERITED_GAMERULES_H
#pragma once

#include "gamerules.h"
#include "teamplay_gamerules.h"
#include "hl2mp_gamerules.h"
#include "gamevars_shared.h"

#ifndef CLIENT_DLL
#include "hl2mp_player.h"
#endif

#ifdef CLIENT_DLL
	#define CInheritedGameRules C_InheritedGameRules
	#define CInheritedGameRulesProxy C_InheritedGameRulesProxy
#endif

class CInheritedGameRulesProxy : public CHL2MPGameRulesProxy
{
public:
	DECLARE_CLASS( CInheritedGameRulesProxy, CHL2MPGameRulesProxy );
	DECLARE_NETWORKCLASS();
};

class CInheritedGameRules : public CHL2MPRules
{
public:
	DECLARE_CLASS( CInheritedGameRules, CHL2MPRules );

#ifdef CLIENT_DLL

	DECLARE_CLIENTCLASS_NOBASE(); // This makes datatables able to access our private vars.

#else

	DECLARE_SERVERCLASS_NOBASE(); // This makes datatables able to access our private vars.
#endif

	// Constructor
	CInheritedGameRules();
	// Destructor
	virtual ~CInheritedGameRules();

	virtual void Precache( void );
	virtual bool ClientCommand( const char *pcmd, CBaseEntity *pEdict );

	virtual void Think( void );

	virtual const char *GetGameDescription( void ){ return "Inherited"; }
	
#ifndef CLIENT_DLL


#endif
	
private:

};

inline CInheritedGameRules* InheritedGameRules()
{
	return static_cast<CInheritedGameRules*>(g_pGameRules);
}

#endif //INHERITED_GAMERULES_H

The main CPP file:

  1. include "cbase.h"
  2. include "inherited_gamerules.h"
  3. include "viewport_panel_names.h"
  4. include "gameeventdefs.h"
  5. include <KeyValues.h>
  6. include "ammodef.h"
  1. ifdef CLIENT_DLL

#include "c_hl2mp_player.h"

  1. else

#include "eventqueue.h" #include "player.h" #include "gamerules.h" #include "game.h" #include "items.h" #include "entitylist.h" #include "mapentities.h" #include "in_buttons.h" #include <ctype.h> #include "voice_gamemgr.h" #include "iscorer.h" #include "hl2mp_player.h" #include "weapon_hl2mpbasehlmpcombatweapon.h" #include "team.h" #include "voice_gamemgr.h" #include "hl2mp_gameinterface.h" #include "hl2mp_cvars.h"

  1. ifdef DEBUG

#include "hl2mp_bot_temp.h"

  1. endif
  1. endif

REGISTER_GAMERULES_CLASS( CInheritedGameRules );

BEGIN_NETWORK_TABLE_NOBASE( CInheritedGameRules, DT_InheritedGameRules )

#ifdef CLIENT_DLL

#else

#endif

END_NETWORK_TABLE()


LINK_ENTITY_TO_CLASS( inherited_gamerules, CInheritedGameRulesProxy ); IMPLEMENT_NETWORKCLASS_ALIASED( InheritedGameRulesProxy, DT_InheritedGameRulesProxy )

  1. ifdef CLIENT_DLL

void RecvProxy_InheritedGameRules( const RecvProp *pProp, void **pOut, void *pData, int objectID ) { CInheritedGameRules *pRules = InheritedGameRules(); Assert( pRules ); *pOut = pRules; }

BEGIN_RECV_TABLE( CInheritedGameRulesProxy, DT_InheritedGameRulesProxy ) RecvPropDataTable( "inherited_gamerules_data", 0, 0, &REFERENCE_RECV_TABLE( DT_InheritedGameRules ), RecvProxy_InheritedGameRules ) END_RECV_TABLE()

  1. else

void* SendProxy_InheritedGameRules( const SendProp *pProp, const void *pStructBase, const void *pData, CSendProxyRecipients *pRecipients, int objectID ) { CInheritedGameRules *pRules = InheritedGameRules(); Assert( pRules ); return pRules; }

BEGIN_SEND_TABLE( CInheritedGameRulesProxy, DT_InheritedGameRulesProxy ) SendPropDataTable( "inherited_gamerules_data", 0, &REFERENCE_SEND_TABLE( DT_InheritedGameRules ), SendProxy_InheritedGameRules ) END_SEND_TABLE()

  1. endif

CInheritedGameRules::CInheritedGameRules() {

  1. ifndef CLIENT_DLL
  1. endif

}

CInheritedGameRules::~CInheritedGameRules( void ) {

  1. ifndef CLIENT_DLL

// Note, don't delete each team since they are in the gEntList and will // automatically be deleted from there, instead. g_Teams.Purge();

  1. endif

}

void CInheritedGameRules::Think( void ) {

  1. ifndef CLIENT_DLL

BaseClass::Think();

  1. endif

}

//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CInheritedGameRules::Precache( void ) { BaseClass::Precache(); }

bool CInheritedGameRules::ClientCommand(const char *pcmd, CBaseEntity *pEdict ) {

return BaseClass::ClientCommand( pcmd, pEdict );

}