Skip to content

Commit

Permalink
Implement the Desert Eagle weapon
Browse files Browse the repository at this point in the history
For Half-Life tutorials and editing resources, visit: https://twhl.info
  • Loading branch information
LogicAndTrick committed Jul 10, 2023
1 parent 67dc68c commit d137df7
Show file tree
Hide file tree
Showing 16 changed files with 524 additions and 0 deletions.
76 changes: 76 additions & 0 deletions cl_dll/ev_hldm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1571,6 +1571,82 @@ void EV_SnarkFire(event_args_t* args)
// SQUEAK END
//======================

//======================
// 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;
Vector origin;
Vector angles;
Vector velocity;
bool empty;

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

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

empty = 0 != 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
//======================

void EV_TrainPitchAdjust(event_args_t* args)
{
int idx;
Expand Down
1 change: 1 addition & 0 deletions cl_dll/ev_hldm.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ void EV_EgonStop(event_args_t* args);
void EV_HornetGunFire(event_args_t* args);
void EV_TripmineFire(event_args_t* args);
void EV_SnarkFire(event_args_t* args);
void EV_FireDesertEagle(event_args_t* args);



Expand Down
1 change: 1 addition & 0 deletions cl_dll/hl/hl_events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,5 @@ void Game_HookEvents()
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);
}
6 changes: 6 additions & 0 deletions cl_dll/hl/hl_weapons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ CHandGrenade g_HandGren;
CSatchel g_Satchel;
CTripmine g_Tripmine;
CSqueak g_Snark;
CDesertEagle g_DesertEagle;


/*
Expand Down Expand Up @@ -464,6 +465,7 @@ void HUD_InitClientWeapons()
HUD_PrepEntity(&g_Satchel, &player);
HUD_PrepEntity(&g_Tripmine, &player);
HUD_PrepEntity(&g_Snark, &player);
HUD_PrepEntity(&g_DesertEagle, &player);
}

/*
Expand Down Expand Up @@ -586,6 +588,10 @@ void HUD_WeaponsPostThink(local_state_s* from, local_state_s* to, usercmd_t* cmd
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
Expand Down
1 change: 1 addition & 0 deletions dlls/cdll_dll.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ enum WeaponId
WEAPON_TRIPMINE,
WEAPON_SATCHEL,
WEAPON_SNARK,
WEAPON_DESERT_EAGLE,

WEAPON_SUIT = 31
};
Expand Down
Loading

0 comments on commit d137df7

Please sign in to comment.