Skip to content

Commit

Permalink
Final(TM) fix for #374 - nades no longer consume the next item in the…
Browse files Browse the repository at this point in the history
… inventory while holding down ADS and cooking the last grenade. Also let's you change weapons without firing by sending cg an event to set grenadecooktimer to 0 when the last grenade is gone
  • Loading branch information
DarthFutuza committed Nov 13, 2024
1 parent fd21049 commit 1d2b2a0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
8 changes: 8 additions & 0 deletions codemp/cgame/cg_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2626,6 +2626,14 @@ void CG_EntityEvent( centity_t *cent, vec3_t position ) {

break;
}
// JKG - launched last cooked grenade in the stack
case EV_GRENADE_COOKED:
if (cg.jkg_grenadeCookTimer && cent->currentState.number == cg.clientNum)
{
cg.jkg_grenadeCookTimer = 0;
}

break;

case EV_EXPLOSIVE_ARM:
DEBUGNAME ("EV_EXPLOSIVE_ARM");
Expand Down
3 changes: 3 additions & 0 deletions codemp/game/bg_items.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,9 @@ void BG_RemoveItemStack(gentity_t* ent, int itemStack) {
}
#else
void BG_RemoveItemStack(int itemStack) {
itemInstance_t item = (*cg.playerInventory)[itemStack];

//tell player it was removed?
cg.playerInventory->erase(cg.playerInventory->begin() + itemStack);
}
#endif
Expand Down
12 changes: 8 additions & 4 deletions codemp/game/bg_pmove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4979,13 +4979,17 @@ static void PM_Weapon(void)
{
if ((pm->cmd.weapon != pm->ps->weaponId) && pm->ps->weaponstate != WEAPON_DROPPING)
{
//change weapon if no more grenades in that item stack left
if (jkg_didGrenadeCook[pm->ps->clientNum])
{
#ifdef _GAME
JKG_DoubleCheckWeaponChange(&pm->cmd, pm->ps); //change weapon if no more grenades in that item stack left
#endif
pm->ps->weaponstate = WEAPON_READY;
PM_AddEvent(EV_GRENADE_COOKED); //notify cg that grenade is no longer cooked
#ifdef _GAME
JKG_DoubleCheckWeaponChange(&pm->cmd, pm->ps);
#endif
pm->ps->weaponTime = 0;
PM_BeginWeaponChange(pm->cmd.weapon, weaponData);
}

else
{
PM_BeginWeaponChange(pm->cmd.weapon, weaponData);
Expand Down
1 change: 1 addition & 0 deletions codemp/game/bg_public.h
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,7 @@ typedef enum {
EV_DAMAGEPLUM,
EV_RELOAD,
EV_GRENADE_COOK,
EV_GRENADE_COOKED,
EV_EXPLOSIVE_ARM,
EV_MISSILE_DIE,
} entity_event_t; // There is a maximum of 256 events (8 bits transmission, 2 high bits for uniqueness)
Expand Down

0 comments on commit 1d2b2a0

Please sign in to comment.