Skip to content
Permalink
Browse files

Implement the Desert Eagle weapon

For Half-Life tutorials and editing resources, visit: https://twhl.info
  • Loading branch information
LogicAndTrick committed Jan 30, 2020
1 parent 3f9f0d7 commit a66e558886322c1e2ea922f4bb42fad5eb6ec032
@@ -68,6 +68,7 @@ void EV_EgonStop( struct event_args_s *args );
void EV_HornetGunFire( struct event_args_s *args );
void EV_TripmineFire( struct event_args_s *args );
void EV_SnarkFire( struct event_args_s *args );
void EV_FireDesertEagle(struct event_args_s* args);


void EV_TrainPitchAdjust( struct event_args_s *args );
@@ -797,6 +798,81 @@ void EV_FirePython( event_args_t *args )
// ( .357 )
//======================

//======================
// DESERT EAGLE START
//======================

// Exactly the same enum from deserteagle.cpp, these
// values correspond to sequences in the viewmodel file
enum desert_eagle_e {
DESERT_EAGLE_IDLE1 = 0,
DESERT_EAGLE_IDLE2,
DESERT_EAGLE_IDLE3,
DESERT_EAGLE_IDLE4,
DESERT_EAGLE_IDLE5,
DESERT_EAGLE_SHOOT,
DESERT_EAGLE_SHOOT_EMPTY,
DESERT_EAGLE_RELOAD,
DESERT_EAGLE_RELOAD_NOT_EMPTY,
DESERT_EAGLE_DRAW,
DESERT_EAGLE_HOLSTER,
};

void EV_FireDesertEagle( event_args_t *args )
{
// Just a bunch of variables and boilerplate copy/paste code
int idx;
vec3_t origin;
vec3_t angles;
vec3_t velocity;
int empty;

vec3_t ShellVelocity;
vec3_t ShellOrigin;
int shell;
vec3_t vecSrc, vecAiming;
vec3_t up, right, forward;

idx = args->entindex;
VectorCopy(args->origin, origin);
VectorCopy(args->angles, angles);
VectorCopy(args->velocity, velocity);

empty = args->bparam1;
AngleVectors(angles, forward, right, up);

shell = gEngfuncs.pEventAPI->EV_FindModelIndex("models/shell.mdl");// brass shell

// If the entity firing this event is the player
if (EV_IsLocal(idx))
{
// Render a muzzleflash
EV_MuzzleFlash();

// Show the weapon animation (a different one if this was the last bullet in the clip)
gEngfuncs.pEventAPI->EV_WeaponAnimation(empty ? DESERT_EAGLE_SHOOT_EMPTY : DESERT_EAGLE_SHOOT, 0);

// Apply some recoil to the player's view
V_PunchAxis(0, -4.0);
}

// Eject an empty bullet shell (the numbers here are mostly magic, experiment with them or just use whatever, it's not too important)
EV_GetDefaultShellInfo(args, origin, velocity, ShellVelocity, ShellOrigin, forward, right, up, -9.0, 14.0, 9.0);
EV_EjectBrass(ShellOrigin, ShellVelocity, angles[YAW], shell, TE_BOUNCE_SHELL);

// Play the "shoot" sound
gEngfuncs.pEventAPI->EV_PlaySound(idx, origin, CHAN_WEAPON, "weapons/desert_eagle_fire.wav", gEngfuncs.pfnRandomFloat(0.92, 1), ATTN_NORM, 0, 98 + gEngfuncs.pfnRandomLong(0, 3));

// Fire some bullets (this will do some prediction stuff, show a tracer, play texture sound, and render a decal where the bullet hits)
EV_GetGunPosition(args, vecSrc, origin);
VectorCopy(forward, vecAiming);
EV_HLDM_FireBullets(idx, forward, right, up, 1, vecSrc, vecAiming, 8192, BULLET_PLAYER_357, 0, 0, args->fparam1, args->fparam2);
}

//======================
// DESERT EAGLE END
//======================

//======================
// GAUSS START
//======================
@@ -37,6 +37,7 @@ void EV_EgonStop( struct event_args_s *args );
void EV_HornetGunFire( struct event_args_s *args );
void EV_TripmineFire( struct event_args_s *args );
void EV_SnarkFire( struct event_args_s *args );
void EV_FireDesertEagle( struct event_args_s *args );



@@ -77,4 +78,5 @@ void Game_HookEvents( void )
gEngfuncs.pfnHookEvent( "events/firehornet.sc", EV_HornetGunFire );
gEngfuncs.pfnHookEvent( "events/tripfire.sc", EV_TripmineFire );
gEngfuncs.pfnHookEvent( "events/snarkfire.sc", EV_SnarkFire );
gEngfuncs.pfnHookEvent("events/eagle.sc", EV_FireDesertEagle);
}
@@ -66,6 +66,7 @@ CHandGrenade g_HandGren;
CSatchel g_Satchel;
CTripmine g_Tripmine;
CSqueak g_Snark;
CDesertEagle g_DesertEagle;


/*
@@ -619,6 +620,7 @@ void HUD_InitClientWeapons( void )
HUD_PrepEntity( &g_Satchel , &player );
HUD_PrepEntity( &g_Tripmine , &player );
HUD_PrepEntity( &g_Snark , &player );
HUD_PrepEntity( &g_DesertEagle, &player );
}

/*
@@ -739,6 +741,10 @@ void HUD_WeaponsPostThink( local_state_s *from, local_state_s *to, usercmd_t *cm
case WEAPON_SNARK:
pWeapon = &g_Snark;
break;

case WEAPON_DESERT_EAGLE:
pWeapon = &g_DesertEagle;
break;
}

// Store pointer to our destination entity_state_t so we can get our origin, etc. from it

0 comments on commit a66e558

Please sign in to comment.
You can’t perform that action at this time.