Skip to content

New CVars: mp_weapondrop and mp_ammodrop and fixes#840

Merged
wopox1337 merged 8 commits intorehlds:masterfrom
dystopm:new-mp-cvars
Jul 10, 2023
Merged

New CVars: mp_weapondrop and mp_ammodrop and fixes#840
wopox1337 merged 8 commits intorehlds:masterfrom
dystopm:new-mp-cvars

Conversation

@dystopm
Copy link
Contributor

@dystopm dystopm commented Jul 2, 2023

  • Added cvar mp_weapondrop which controls behaviour on weapon drop after death. You can choose between (0) do not drop anything after death, (1) drop your heaviest weapon (default behaviour), (2) drop your active weapon or (3) drop all your weapons. It works independently of mp_nadedrops cvar (and it's also an extension of it)
  • Added cvar mp_ammodrop which controls behaviour of ammo packing on weapon boxes drop. You can choose between (0) keep ammo on player always, (1) drop ammo on weaponbox only after death and (2) drop ammo on every weaponbox you drop either death or manual drop.
  • Fix: Ammo resetting inside CreateWeaponBox; ammo was not getting reset if packAmmo = true, no matter if weapon is not considered "exhaustible"
  • Fix: CanDrop used inside PackDeadPlayerItems in case modders want to make a weapon undroppable.
  • Code related: PackPlayerItem now returns the entity created.
  • Changed usage of constants meaning (GR_PLR_DROP_GUN_* inside DeadPlayerWeapons) and added an extra.

Related to/fixes close #520 #620 #758 #821
Tested, work as intended

PS: Cvar's names/description corrections are welcome

@StevenKal
Copy link
Contributor

StevenKal commented Jul 3, 2023

Nice!
But maybe dropping "all weapons" when "GR_PLR_DROP_GUN_ALL" is set could be added (all primary & secondary).
And keep "GR_PLR_DROP_GUN_ACTIVE" for only active weapon on death (if, it is a primary or secondary, however, get & drop best weapon). But a new rule like "GR_PLR_DROP_GUN_BEST" could also be welcomed.
Or, make "GR_PLR_DROP_GUN_ACTIVE" drops best primary/secondary weapon (default behavior), but this does not really match to the rule name...
So, questionable.

@wopox1337 wopox1337 requested review from s1lentq and wopox1337 July 3, 2023 17:03
@wopox1337 wopox1337 assigned wopox1337 and dystopm and unassigned wopox1337 Jul 3, 2023
@wopox1337 wopox1337 added the Type: 🚀 enhancement Improvement or addition of a new feature. label Jul 3, 2023
Copy link
Member

@wopox1337 wopox1337 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code style fixes

@dystopm
Copy link
Contributor Author

dystopm commented Jul 3, 2023

Nice! But maybe dropping "all weapons" when "GR_PLR_DROP_GUN_ALL" is set could be added (all primary & secondary). And keep "GR_PLR_DROP_GUN_ACTIVE" for only active weapon on death (if, it is a primary or secondary, however, get & drop best weapon). But a new rule like "GR_PLR_DROP_GUN_BEST" could also be welcomed. Or, make "GR_PLR_DROP_GUN_ACTIVE" drops best primary/secondary weapon (default behavior), but this does not really match to the rule name... So, questionable.

I've been thinking on a nice way to implement that. Thing is: drop weapons separately guided by player angles (left to right, depending on how many weapons player will drop) or drop weapons in forward, each one further forward than the last (easy implementation, just store them into an array and apply an scalar to their current velocity since all are going forward) - will take a look and then test

@dystopm dystopm requested a review from wopox1337 July 3, 2023 19:11
@dystopm
Copy link
Contributor Author

dystopm commented Jul 4, 2023

Added new behaviour: mp_weapondrop 3 (as @StevenKal requested) will ensure players drop all their weapons (primary and secondary) after death. It basically uses the same pattern but every box created has more velocity than its predecessor. Depending on physics, players can stand still, be on mid air or just running fast, and that will affect weapons drop spreading.

hl_g8EpmJvJFR
hl_PXYqh0CfDC
hl_taBKuYQ8LT

Used sv_cheats 1 and impulse 255 for testing purposes only, because in legit scenarios players can have at least 2 weapons.

Credits to @metita for his help in test scenarios.

@dystopm dystopm requested a review from wopox1337 July 7, 2023 17:48
@wopox1337 wopox1337 changed the title New CVars: mp_weapondrop and mp_ammodrop New CVars: mp_weapondrop and mp_ammodrop and fixes Jul 10, 2023
@@ -1386,78 +1395,130 @@ void PackPlayerNade(CBasePlayer *pPlayer, CBasePlayerItem *pItem, bool packAmmo)
void CBasePlayer::PackDeadPlayerItems()
Copy link
Member

@wopox1337 wopox1337 Jul 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CBasePlayer::PackDeadPlayerItems() function looks terrible (it's not because of your PR). It needs refactoring (later), for the logic is hard to track. 😞

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wopox1337 yeah you're right, I just tried to stick to the original code but indeed it is certainly bad coded

@wopox1337 wopox1337 merged commit 8ddda26 into rehlds:master Jul 10, 2023
@dystopm dystopm mentioned this pull request Jul 10, 2023
@dystopm dystopm deleted the new-mp-cvars branch October 11, 2023 15:10
yohimik pushed a commit to yohimik/ReGameDLL_CS that referenced this pull request Jun 5, 2025
* First implementation

* Update player.cpp

* Apply suggestions from code review

Co-authored-by: Sergey Shorokhov <[email protected]>

* Improve readability

* Improve readability x2

Co-authored-by: Sergey Shorokhov <[email protected]>

* Tabulation tip

* Compile error resolved

* Add mp_weapondrop 3: drop all weapons

---------

Co-authored-by: Sergey Shorokhov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: 🚀 enhancement Improvement or addition of a new feature.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Problem with ammo on dropped weapons

3 participants