Need to start some were in modding right? Why not try the Half-Life modding Kit. This Kit is designed to have all the tools you need to start your own Half-Life mod, simple mods can be made or advance ones like Base Defense with this small set of tools. If you want to start modding Half-Life you should try this.

Post tutorial Report RSS CS Style USP : Server Side ( Repost )

Accidentaly deleted the previous tutorial. I have reposted it with a few tweaks

Posted by on - Intermediate Server Side Coding

FYI: Im the guy who created the iron sight tutorial. Just using a different account
Visual Studio 2006
Alright create a new file called usp.cpp (or whatever you want) and paste this inside:











/***
*
*	Copyright (c) 1996-2001, Valve LLC. All rights reserved.
*	
*	This product contains software technology licensed from Id 
*	Software, Inc. ("Id Technology").  Id Technology (c) 1996 Id Software, Inc. 
*	All Rights Reserved.
*
*   Use, distribution, and modification of this source code and/or resulting
*   object code is restricted to non-commercial enhancements to products from
*   Valve LLC.  All other use, distribution, or modification is prohibited
*   without written permission from Valve LLC.
*
****/

// USP Code By BlueNightHawk

#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "monsters.h"
#include "weapons.h"
#include "nodes.h"
#include "player.h"

enum usp_e {
	USP_IDLE1 = 0,
	USP_SHOOT1,
	USP_SHOOT2,
	USP_SHOOT3,
	USP_SHOOT_EMPTY,
	USP_RELOAD,
	USP_DRAW,
	USP_ADD_SILENCER,
	USP_IDLE1_U,
	USP_SHOOT1_U,
	USP_SHOOT2_U,
	USP_SHOOT3_U,
	USP_SHOOT_EMPTY_U,
	USP_RELOAD_U,
	USP_DRAW_U,
	USP_DETACH_SILENCER
};

LINK_ENTITY_TO_CLASS( weapon_usp, CUSP );

void CUSP::Spawn( )
{
	pev->classname = MAKE_STRING("weapon_usp"); // hack to allow for old names
	Precache( );
	m_iId = WEAPON_USP;
	SET_MODEL(ENT(pev), "models/w_usp.mdl");

	silencer = 1;

	m_iDefaultAmmo = 12;

	FallInit();// get ready to fall down.
}


void CUSP::Precache( void )
{
	PRECACHE_MODEL("models/v_usp.mdl");
	PRECACHE_MODEL("models/w_usp.mdl");
	PRECACHE_MODEL("models/p_usp.mdl");

	m_iShell = PRECACHE_MODEL ("models/shell.mdl");// brass shell

	PRECACHE_SOUND("items/9mmclip1.wav");
	PRECACHE_SOUND("items/9mmclip2.wav");

	PRECACHE_SOUND ("weapons/usp1.wav");//silenced handgun
	PRECACHE_SOUND ("weapons/usp2.wav");//silenced handgun
	PRECACHE_SOUND ("weapons/usp_unsil-1.wav");//handgun
	PRECACHE_SOUND ("weapons/usp_silencer_off.wav");
	PRECACHE_SOUND ("weapons/usp_silencer_on.wav");


	m_usFireUSP1 = PRECACHE_EVENT( 1, "events/usp1.sc" );
	m_usFireUSP2 = PRECACHE_EVENT( 1, "events/usp2.sc" );
}

int CUSP::GetItemInfo(ItemInfo *p)
{
	p->pszName = STRING(pev->classname);
	p->pszAmmo1 = "9mm";
	p->iMaxAmmo1 = 240;
	p->pszAmmo2 = NULL;
	p->iMaxAmmo2 = -1;
	p->iMaxClip = 12;
	p->iSlot = 1;
	p->iPosition = 2;
	p->iFlags = 0;
	p->iId = m_iId = WEAPON_USP;
	p->iWeight = GLOCK_WEIGHT;

	return 1;
}

BOOL CUSP::Deploy( )
{
	if ( silencer  )
	{
		return DefaultDeploy( "models/v_usp.mdl", "models/p_usp.mdl", USP_DRAW, "onehanded", /*UseDecrement() ? 1 : 0*/ 0 );
	}
	else
	{
		return DefaultDeploy( "models/v_usp.mdl", "models/p_usp.mdl", USP_DRAW_U, "onehanded", /*UseDecrement() ? 1 : 0*/ 0 );
	}

}

void CUSP::SecondaryAttack( void )
{
	if ( silencer == 1 )
	{
		SendWeaponAnim( USP_DETACH_SILENCER );
		silencer = 0;
		bCanHolster = FALSE;
		SetThink ( CanHolster );
		pev->nextthink = UTIL_WeaponTimeBase() + 3.8;
	}
	else
	{
		SendWeaponAnim( USP_ADD_SILENCER );
		silencer = 1;
		bCanHolster = FALSE;
		SetThink ( SetCanHolster );
		pev->nextthink = UTIL_WeaponTimeBase() + 3.8;
	}
	m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 3.8;
	m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 3.8;
	m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 3.8;// idle pretty soon after shooting.
}

BOOL CUSP::CanHolster( void )
{
	return bCanHolster;
}

void CUSP::SetCanHolster( void )
{
	bCanHolster = TRUE;
}

void CUSP::PrimaryAttack( void )
{
	GlockFire( 0.01, 0.5, TRUE );
}

void CUSP::GlockFire( float flSpread , float flCycleTime, BOOL fUseAutoAim )
{
	if (m_iClip <= 0)
	{
		if (m_fFireOnEmpty)
		{
			PlayEmptySound();
			m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 0.2;
		}

		return;
	}

	m_iClip--;

	m_pPlayer->pev->effects = (int)(m_pPlayer->pev->effects) | EF_MUZZLEFLASH;

	int flags;

#if defined( CLIENT_WEAPONS )
	flags = FEV_NOTHOST;
#else
	flags = 0;
#endif

	// player "shoot" animation
	m_pPlayer->SetAnimation( PLAYER_ATTACK1 );

	// silenced
	if (silencer == 1)
	{
		m_pPlayer->m_iWeaponVolume = QUIET_GUN_VOLUME;
		m_pPlayer->m_iWeaponFlash = DIM_GUN_FLASH;
	}
	else
	{
		// non-silenced
		m_pPlayer->m_iWeaponVolume = NORMAL_GUN_VOLUME;
		m_pPlayer->m_iWeaponFlash = NORMAL_GUN_FLASH;
	}

	Vector vecSrc	 = m_pPlayer->GetGunPosition( );
	Vector vecAiming;
	
	if ( fUseAutoAim )
	{
		vecAiming = m_pPlayer->GetAutoaimVector( AUTOAIM_10DEGREES );
	}
	else
	{
		vecAiming = gpGlobals->v_forward;
	}

	Vector vecDir;
	if ( silencer == 1 )
	{
		vecDir = m_pPlayer->FireBulletsPlayer( 1, vecSrc, vecAiming, VECTOR_CONE_2DEGREES, 8192, BULLET_PLAYER_9MM, 0, 0, m_pPlayer->pev, m_pPlayer->random_seed );
	}
	else
	{
		vecDir = m_pPlayer->FireBulletsPlayer( 1, vecSrc, vecAiming, VECTOR_CONE_4DEGREES, 8192, BULLET_PLAYER_9MM, 0, 0, m_pPlayer->pev, m_pPlayer->random_seed );
	}
	
	if ( silencer == 1 )
	{
		PLAYBACK_EVENT_FULL( flags, m_pPlayer->edict(), fUseAutoAim ? m_usFireUSP1 : m_usFireUSP1, 0.0, (float *)&g_vecZero, (float *)&g_vecZero, vecDir.x, vecDir.y, 0, 0, ( m_iClip == 0 ) ? 1 : 0, 0 );
	}
	else
	{
		PLAYBACK_EVENT_FULL( flags, m_pPlayer->edict(), fUseAutoAim ? m_usFireUSP2 : m_usFireUSP2, 0.0, (float *)&g_vecZero, (float *)&g_vecZero, vecDir.x, vecDir.y, 0, 0, ( m_iClip == 0 ) ? 1 : 0, 0 );
	}
	m_flNextPrimaryAttack = m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + flCycleTime;

	if (!m_iClip && m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0)
		// HEV suit - indicate out of ammo condition
		m_pPlayer->SetSuitUpdate("!HEV_AMO0", FALSE, 0);

	m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + UTIL_SharedRandomFloat( m_pPlayer->random_seed, 10, 15 );
}


void CUSP::Reload( void )
{
	if ( m_pPlayer->ammo_9mm <= 0 )
		return;
	
	if (silencer )
	{
		DefaultReload( 12, USP_RELOAD, 1.5 );
	}
	else
	{
		DefaultReload( 12, USP_RELOAD_U, 1.5 );
	}
}


void CUSP::WeaponIdle( void )
{
	ResetEmptySound( );

	m_pPlayer->GetAutoaimVector( AUTOAIM_10DEGREES );

	if ( m_flTimeWeaponIdle > UTIL_WeaponTimeBase() )
		return;

	// only idle if the slid isn't back
	if (m_iClip != 0)
	{
		int iAnim;
		float flRand = UTIL_SharedRandomFloat( m_pPlayer->random_seed, 0.0, 1.0 );

		if (silencer)
		{
			iAnim = USP_IDLE1;
			m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 49.0 / 16;
		}
		else
		{
			iAnim = USP_IDLE1_U;
			m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 40.0 / 16.0;
		}
		SendWeaponAnim( iAnim, 1 );
	}
}

BOOL CGlock::CanHolster()
{






class CUSPAmmo : public CBasePlayerAmmo
{
	void Spawn( void )
	{ 
		Precache( );
		SET_MODEL(ENT(pev), "models/w_9mmclip.mdl");
		CBasePlayerAmmo::Spawn( );
	}
	void Precache( void )
	{
		PRECACHE_MODEL ("models/w_9mmclip.mdl");
		PRECACHE_SOUND("items/9mmclip1.wav");
	}
	BOOL AddAmmo( CBaseEntity *pOther ) 
	{ 
		if (pOther->GiveAmmo( 12, "9mm", 240 ) != -1)
		{
			EMIT_SOUND(ENT(pev), CHAN_ITEM, "items/9mmclip1.wav", 1, ATTN_NORM);
			return TRUE;
		}
		return FALSE;
	}
};
LINK_ENTITY_TO_CLASS( ammo_uspclip, CUSPAmmo );




Note: Im using 9mm instead of 45 so if u want to change it you will have to do it by yourself
Now go to weapons.h and add this:




class CUSP : public CBasePlayerWeapon
{
public:
	void Spawn( void );
	void Precache( void );
	int iItemSlot( void ) { return 2; }
	int GetItemInfo(ItemInfo *p);

	void PrimaryAttack( void );
	void SecondaryAttack( void );
	void GlockFire( float flSpread, float flCycleTime, BOOL fUseAutoAim );
	BOOL Deploy( void );
	void Reload( void );
	void WeaponIdle( void );
	int silencer;
        void SetCanHolster ( void);
        BOOL bCanHolster;
        BOOL CanHolster( void );


	virtual BOOL UseDecrement( void )
	{ 
#if defined( CLIENT_WEAPONS )
		return TRUE;
#else
		return FALSE;
#endif
	}

private:
	int m_iShell;
	

	unsigned short m_usFireUSP1;
	unsigned short m_usFireUSP2;
};
Now the rest just follow badsniper365 weapon tutorial.
If you have any questions, ask me in the comment section.
Post a comment
Sign in or join with:

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.

Follow Report Profile
Icon
Half-Life
Game
Half-Life
Creator
badsniper365
Contact
Send Message
Release date
Mod watch
Follow
Tutorial
Browse
Tutorials
Report
Report
Views
60 (1 today)
Share
Related Games
Half-Life
Half-Life First Person Shooter