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 RSS Small Server Side Stuff

Two ( more are coming ) server side stuff

Posted by on - Basic Server Side Coding

1. SERVER SIDE RECOIL FUNCTION:

1. Open weapons.h and find the declaration of the CBasePlayerWeapon class.

2. Add

void V_PunchAngles( int x = 0, int y = 0, int z = 0, int minus = 1 );

below

BOOL AddSecondaryAmmo( int iCount, char *szName, int iMaxCarry );

3. Now go to weapons.cpp and paste this code anywhere ( not inside another function obviously )

void CBasePlayerWeapon::V_PunchAngles( int x, int y, int z, int minus )
{
	if ( minus )
	{
		m_pPlayer->pev->punchangle.x -= x;
		m_pPlayer->pev->punchangle.y -= y;
		m_pPlayer->pev->punchangle.z -= z;
	}
	else
	{
		m_pPlayer->pev->punchangle.x = x;
		m_pPlayer->pev->punchangle.y = y;
		m_pPlayer->pev->punchangle.z = z;
	}

}

NOTE: If you set int minus to 1( default ), it means the recoil will add up. For example: if you set int x to 1, it will keep going up until you stop firing or the ammo runs out.

However, if you set int minus to 0, it will go up and stay in a fixed position.

If you dont understand, try it yourself.

4. Now go to mp5.cpp.

5. In the PrimaryAttack function, below m_iClip--, add this

///////////////////////////////
//
//		RECOIL START
//
///////////////////////////////
	switch ( m_iClip )
	{
	case 30:
		V_PunchAngles( 1 );
		break;
	case 29:
		V_PunchAngles( 1 );
		break;
	case 28:
		V_PunchAngles( 1 );
		break;
	case 27:
		V_PunchAngles( 1 );
		break;
	case 26:
		V_PunchAngles( 1 );
		break;
	case 25:
		V_PunchAngles( 0, 2 );
		break;
	case 24:
		V_PunchAngles( 0, 2 );
		break;
	case 23:
		V_PunchAngles( 0, 2 );
		break;
	case 22:
		V_PunchAngles( 0, 2 );
		break;
	case 21:
		V_PunchAngles( 0, -2 );
		break;
	case 20:
		V_PunchAngles( 0, -2 );
		break;
	case 19:
		V_PunchAngles( 0, -2 );
		break;
	case 18:
		V_PunchAngles( 0, -2 );
		break;
	case 17:
		V_PunchAngles( 0, 0 );
		break;
	case 16:
		V_PunchAngles( 1 );
		break;
	case 15:
		V_PunchAngles( 1 );
		break;
	case 14:
		V_PunchAngles( 1 );
		break;
	case 13:
		V_PunchAngles( 1 );
		break;
	case 12:
		V_PunchAngles( 1 );
		break;
	case 11:
		V_PunchAngles( 1 );
		break;
	case 10:
		V_PunchAngles( 0, -2 );
		break;
	case 9:
		V_PunchAngles( 0, -3 );
		break;
	case 8:
		V_PunchAngles( 0, -2 );
		break;
	case 7:
		V_PunchAngles( 0, -3 );
		break;
	case 6:
		V_PunchAngles( 0, 1 );
		break;
	case 5:
		V_PunchAngles( 0, 1 );
		break;
	case 4:
		V_PunchAngles( 0, 1 );
		break;
	case 3:
		V_PunchAngles( 1, 0 );
		break;
	case 2:
		V_PunchAngles( 1 );
		break;
	case 1:
		V_PunchAngles( 1 );
		break;
	case 0:
		V_PunchAngles( 0 );
		break;
	}
///////////////////////////////
//
//		RECOIL END
//
///////////////////////////////

Note : int x is vertical and int y is horizontal. You will also have to change the value of MP5_MAX_CLIP and MP5_DEFAULT_GIVE to 30.

6. When compiling from client side you will get an error. To fix this, go to hl_baseentity.cpp and at the bottom add

void CBasePlayerWeapon::V_PunchAngles( int x, int y, int z, int minus ) {}

It is done! If you have any problems, ask me in the comments.



2. Weapon Knockback

1. Open mp5.cpp and find the PrimaryAttack function.

2. Under m_iClip--, add

	if (m_pPlayer->pev->flags & FL_ONGROUND)
	{
		m_pPlayer->pev->velocity = m_pPlayer->pev->velocity - gpGlobals->v_forward*( 100  );
	}

Note: 100 is the power of the knockback.

Done! Pretty short huh. If you have any problems, ask me in the comments.


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 Profile
Icon
Half-Life
Game
Half-Life
Creator
badsniper365
Contact
Send Message
Release date
Mod watch
Follow
Tutorial
Browse
Tutorials
Views
74 (1 today)
Share
Related Games
Half-Life
Half-Life First Person Shooter