Changing default spawn weapons: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
No edit summary
No edit summary
Line 7: Line 7:
Around line 135 at the top of the .cpp youll find '''void CHL2MP_Player::Precache( void )'''
Around line 135 at the top of the .cpp youll find '''void CHL2MP_Player::Precache( void )'''
this is the beginning process of caching the player spawning.
this is the beginning process of caching the player spawning.
{| class="wikitable"
<source lang="cpp">void CHL2MP_Player::Precache( void )
|-
! Code segment to be seen
|-
| void CHL2MP_Player::Precache( void )
{
{
BaseClass::Precache();
BaseClass::Precache();
Line 36: Line 32:
PrecacheScriptSound( "NPC_Citizen.die" );
PrecacheScriptSound( "NPC_Citizen.die" );
}
}
|}
</source>
   
   
below this chunk of code you should see another chunk segment around line 161 '''void CHL2MP_Player::GiveAllItems( void )'''
below this chunk of code you should see another chunk segment around line 161 '''void CHL2MP_Player::GiveAllItems( void )'''
This chunk of code is whats listing ALL of the assets within the engine that can be possibly touched, for us for now this is not to be touched
This chunk of code is whats listing ALL of the assets within the engine that can be possibly touched, for us for now this is not to be touched
{| class="wikitable"
<source lang="cpp"> void CHL2MP_Player::GiveAllItems( void )
|-
! Code segment to be seen
|-
| void CHL2MP_Player::GiveAllItems( void )
{
{
EquipSuit();
EquipSuit();
Line 80: Line 72:
}
}
|}
</source>


but then here below this chunk what we will be tampering with on line 198 '''void CHL2MP_Player::GiveDefaultItems( void )'''
but then here below this chunk what we will be tampering with on line 198 '''void CHL2MP_Player::GiveDefaultItems( void )'''
This chunk of code segment is whats loading into the model at the end of the strings to finally spawn the player. here we will manipulate the listings to give us the results wed actually want.
This chunk of code segment is whats loading into the model at the end of the strings to finally spawn the player. here we will manipulate the listings to give us the results wed actually want.
{| class="wikitable"
<source lang="cpp">void CHL2MP_Player::GiveDefaultItems( void )
|-
| void CHL2MP_Player::GiveDefaultItems( void )
{
{
//EquipSuit();//weapon spawn hack - drN0
//EquipSuit();//weapon spawn hack - drN0
Line 123: Line 113:
}
}
}
}
|}
</source>


Once these codes are altered as so. rebuild your entire solution now under release mode. go to src/game/server and src/game/client and copy and paste both folders client.dll and server.dll into your mods bin/ folder. upon restarting steam entirely your sourcemods sdk 2013 multiplayer mod should now be forcing players to spawn with the weapons youve chosen.
Once these codes are altered as so. rebuild your entire solution now under release mode. go to src/game/server and src/game/client and copy and paste both folders client.dll and server.dll into your mods bin/ folder. upon restarting steam entirely your sourcemods sdk 2013 multiplayer mod should now be forcing players to spawn with the weapons youve chosen.

Revision as of 17:57, 16 July 2024

This is a simple programming tutorial for Source Engine SDKbase 2013 Multiplayer. In this tutorial i will show you how to change the weapons that all players will spawn into a map with by default. This segment will effect both deathmatch and team deathmatch spawning defaults but user referencing is limited to all the precached models at hand in the code meaning a user can be forced to spawn with any of the default listed weapons found in half life 2 deathmatch.

-To start we will open the source engine solution in your main folder setup, mine is in C:\anh\src\game.sln using Visual Studio 2022. -Now with the solution open and running; into the folder of the game.sln go to /game/server/hl2mp/hl2mp_player.cpp and open this in your studio accompanying the game.sln.

Around line 135 at the top of the .cpp youll find void CHL2MP_Player::Precache( void ) this is the beginning process of caching the player spawning.

void CHL2MP_Player::Precache( void )
{
	BaseClass::Precache();

	PrecacheModel ( "sprites/glow01.vmt" );

	//Precache Citizen models
	int nHeads = ARRAYSIZE( g_ppszRandomCitizenModels );
	int i;	

	for ( i = 0; i < nHeads; ++i )
	   	 PrecacheModel( g_ppszRandomCitizenModels[i] );

	//Precache Combine Models
	nHeads = ARRAYSIZE( g_ppszRandomCombineModels );

	for ( i = 0; i < nHeads; ++i )
	   	 PrecacheModel( g_ppszRandomCombineModels[i] );

	PrecacheFootStepSounds();

	PrecacheScriptSound( "NPC_MetroPolice.Die" );
	PrecacheScriptSound( "NPC_CombineS.Die" );
	PrecacheScriptSound( "NPC_Citizen.die" );
}

below this chunk of code you should see another chunk segment around line 161 void CHL2MP_Player::GiveAllItems( void ) This chunk of code is whats listing ALL of the assets within the engine that can be possibly touched, for us for now this is not to be touched

 void CHL2MP_Player::GiveAllItems( void )
{
	EquipSuit();

	CBasePlayer::GiveAmmo( 255,	"Pistol");
	CBasePlayer::GiveAmmo( 255,	"AR2" );
	CBasePlayer::GiveAmmo( 5,	"AR2AltFire" );
	CBasePlayer::GiveAmmo( 255,	"SMG1");
	CBasePlayer::GiveAmmo( 1,	"smg1_grenade");
	CBasePlayer::GiveAmmo( 255,	"Buckshot");
	CBasePlayer::GiveAmmo( 32,	"357" );
	CBasePlayer::GiveAmmo( 3,	"rpg_round");

	CBasePlayer::GiveAmmo( 1,	"grenade" );
	CBasePlayer::GiveAmmo( 2,	"slam" );

	GiveNamedItem( "weapon_crowbar" );
	GiveNamedItem( "weapon_stunstick" );
	GiveNamedItem( "weapon_pistol" );
	GiveNamedItem( "weapon_357" );

	GiveNamedItem( "weapon_smg1" );
	GiveNamedItem( "weapon_ar2" );
	
	GiveNamedItem( "weapon_shotgun" );
	GiveNamedItem( "weapon_frag" );
	
	GiveNamedItem( "weapon_crossbow" );
	
	GiveNamedItem( "weapon_rpg" );

	GiveNamedItem( "weapon_slam" );

	GiveNamedItem( "weapon_physcannon" );
	
}

but then here below this chunk what we will be tampering with on line 198 void CHL2MP_Player::GiveDefaultItems( void ) This chunk of code segment is whats loading into the model at the end of the strings to finally spawn the player. here we will manipulate the listings to give us the results wed actually want.

void CHL2MP_Player::GiveDefaultItems( void )
{
	//EquipSuit();//weapon spawn hack - drN0

	//CBasePlayer::GiveAmmo( 255,	"Pistol");//weapon spawn hack - drN0
	//CBasePlayer::GiveAmmo( 45,	"SMG1");//weapon spawn hack - drN0
	//CBasePlayer::GiveAmmo( 1,	"grenade" );//weapon spawn hack - drN0
	//CBasePlayer::GiveAmmo( 6,	"Buckshot");//weapon spawn hack - drN0
	//CBasePlayer::GiveAmmo( 6,	"357" );//weapon spawn hack - drN0

	if ( GetPlayerModelType() == PLAYER_SOUNDS_METROPOLICE || GetPlayerModelType() == PLAYER_SOUNDS_COMBINESOLDIER )
	{
		GiveNamedItem( "weapon_physcannon" );//weapon STUNSTICK//weapon spawn hack - drN0
	}
	else if ( GetPlayerModelType() == PLAYER_SOUNDS_CITIZEN )
	{
		GiveNamedItem( "weapon_physcannon" );//weapon CROWBAR//weapon spawn hack - drN0
	}
	
	//GiveNamedItem( "weapon_pistol" );//weapon spawn hack - drN0
	//GiveNamedItem( "weapon_smg1" );//weapon spawn hack - drN0
	//GiveNamedItem( "weapon_frag" );//weapon spawn hack - drN0
	GiveNamedItem( "weapon_physcannon" );

	const char *szDefaultWeaponName = engine->GetClientConVarValue( engine->IndexOfEdict( edict() ), "cl_defaultweapon" );

	CBaseCombatWeapon *pDefaultWeapon = Weapon_OwnsThisType( szDefaultWeaponName );

	if ( pDefaultWeapon )
	{
		Weapon_Switch( pDefaultWeapon );
	}
	else
	{
		Weapon_Switch( Weapon_OwnsThisType( "weapon_physcannon" ) );
	}
}

Once these codes are altered as so. rebuild your entire solution now under release mode. go to src/game/server and src/game/client and copy and paste both folders client.dll and server.dll into your mods bin/ folder. upon restarting steam entirely your sourcemods sdk 2013 multiplayer mod should now be forcing players to spawn with the weapons youve chosen.

NOTES: Noticing that cl_defaultweapon is encoded here. You may need to back up this default structure with the config.cfg in your config/ folder of your mods sourcemods/ directory. under binds as cl_defaultweapon "weapon_pistol" or any single weapon thats spawned with other than the physcannon. *this is speculation now because after initially altering codes and adding cl_defaultweapon "weapon_physcannon" to config.cfg and launching the game, after stopping the game and rechecking the config.cfg is seems the cl_defaultweapon "weapon_physcannon" is gone, when originally i had included cl_defaultweapon "weapon_pistol". This means that if as a default every user on either team or non team is spawning with the physcannon then being the physcannon a primary default it has no need for a default weapon. if your default weapon is NOT only a physcannon then you would want to apply the default weapon to your choice either spawn with the weapon 1 or weapon 2. pistol and shotty. crowbar and grenades etc... then you would want to add the cl_defaultweapon "weapon_choice" to your config.cfg as the engine identifies precaching multiple models into a player spawn at some point.

- This was implemented in A Nights Haunting: Source -- feel free to contact me if needed