diff --git a/README.md b/README.md
index 3d1201bf7..45d2874b3 100644
--- a/README.md
+++ b/README.md
@@ -98,6 +98,7 @@ This means that plugins that do binary code analysis (Orpheu for example) probab
| mp_ct_give_player_knife | 1 | 0 | 1 | Whether Counter-Terrorist player spawn with knife. |
| mp_ct_default_weapons_primary | "" | "" | - | The default primary (rifle) weapon that the CTs will spawn with. |
| mp_ct_default_weapons_secondary | "usp" | "" | - | The default secondary (pistol) weapon that the CTs will spawn with. |
+| mp_default_weapons_random | 0 | 0 | 1 | Randomize default weapons (if there are multiple).
`0` disabled
`1` enabled |
| mp_give_player_c4 | 1 | 0 | 1 | Whether this map should spawn a C4 bomb for a player or not.
`0` disabled
`1` enabled |
| mp_weapons_allow_map_placed | 1 | 0 | 1 | When set, map weapons (located on the floor by map) will be shown.
`0` hide all map weapons.
`1` enabled
`NOTE`: Effect will work after round restart. |
| mp_free_armor | 0 | 0 | 2 | Give free armor on player spawn.
`0` disabled
`1` Give Kevlar
`2` Give Kevlar + Helmet |
diff --git a/dist/game.cfg b/dist/game.cfg
index c5dad01c9..6fd593d09 100644
--- a/dist/game.cfg
+++ b/dist/game.cfg
@@ -466,6 +466,13 @@ mp_ct_default_weapons_primary ""
// Default value: "usp"
mp_ct_default_weapons_secondary "usp"
+// Randomize default weapons (if there are multiple)
+// 0 - disabled (default behaviour)
+// 1 - enabled
+//
+// Default value: "0"
+mp_default_weapons_random "0"
+
// Give the player free armor on player spawn
// 0 - No armor (default behavior)
// 1 - Give Kevlar
diff --git a/regamedll/dlls/game.cpp b/regamedll/dlls/game.cpp
index 789435938..867cc8036 100644
--- a/regamedll/dlls/game.cpp
+++ b/regamedll/dlls/game.cpp
@@ -160,6 +160,7 @@ cvar_t t_default_grenades = { "mp_t_default_grenades", "", 0, 0.0
cvar_t t_give_player_knife = { "mp_t_give_player_knife", "1", 0, 1.0f, nullptr };
cvar_t t_default_weapons_secondary = { "mp_t_default_weapons_secondary", "glock18", 0, 0.0f, nullptr };
cvar_t t_default_weapons_primary = { "mp_t_default_weapons_primary", "", 0, 0.0f, nullptr };
+cvar_t default_weapons_random = { "mp_default_weapons_random", "", 0, 0.0f, nullptr };
cvar_t free_armor = { "mp_free_armor", "0", 0, 0.0f, nullptr };
cvar_t teamflash = { "mp_team_flash", "1", 0, 1.0f, nullptr };
cvar_t allchat = { "sv_allchat", "0", 0, 0.0f, nullptr };
@@ -431,6 +432,7 @@ void EXT_FUNC GameDLLInit()
CVAR_REGISTER(&t_give_player_knife);
CVAR_REGISTER(&t_default_weapons_secondary);
CVAR_REGISTER(&t_default_weapons_primary);
+ CVAR_REGISTER(&default_weapons_random);
CVAR_REGISTER(&free_armor);
CVAR_REGISTER(&teamflash);
CVAR_REGISTER(&allchat);
diff --git a/regamedll/dlls/game.h b/regamedll/dlls/game.h
index 09da5305a..c3078eb43 100644
--- a/regamedll/dlls/game.h
+++ b/regamedll/dlls/game.h
@@ -186,6 +186,7 @@ extern cvar_t t_default_grenades;
extern cvar_t t_give_player_knife;
extern cvar_t t_default_weapons_secondary;
extern cvar_t t_default_weapons_primary;
+extern cvar_t default_weapons_random;
extern cvar_t free_armor;
extern cvar_t teamflash;
extern cvar_t allchat;
diff --git a/regamedll/dlls/player.cpp b/regamedll/dlls/player.cpp
index 9782921c1..d118163b0 100644
--- a/regamedll/dlls/player.cpp
+++ b/regamedll/dlls/player.cpp
@@ -1644,6 +1644,10 @@ void EXT_FUNC CBasePlayer::__API_HOOK(GiveDefaultItems)()
// Give default secondary equipment
{
char *secondaryString = NULL;
+ int secondaryCount = 0;
+ const int MAX_SECONDARY = 13; // x2 + 1
+ WeaponInfoStruct *secondaryWeaponInfoArray[MAX_SECONDARY];
+
if (m_iTeam == CT)
secondaryString = ct_default_weapons_secondary.string;
else if (m_iTeam == TERRORIST)
@@ -1665,18 +1669,34 @@ void EXT_FUNC CBasePlayer::__API_HOOK(GiveDefaultItems)()
if (weaponInfo) {
const auto iItemID = GetItemIdByWeaponId(weaponInfo->id);
if (iItemID != ITEM_NONE && !HasRestrictItem(iItemID, ITEM_TYPE_EQUIPPED) && IsSecondaryWeapon(iItemID)) {
- GiveWeapon(weaponInfo->gunClipSize * iAmountOfBPAmmo, weaponInfo->entityName);
+ if (default_weapons_random.value != 0.0f) {
+ if (secondaryCount < MAX_SECONDARY) {
+ secondaryWeaponInfoArray[secondaryCount++] = weaponInfo;
+ }
+ }
+ else {
+ GiveWeapon(weaponInfo->gunClipSize * iAmountOfBPAmmo, weaponInfo->entityName);
+ }
}
}
secondaryString = SharedParse(secondaryString);
}
+
+ if (default_weapons_random.value != 0.0f) {
+ WeaponInfoStruct *weaponInfo = secondaryWeaponInfoArray[RANDOM_LONG(0, secondaryCount - 1)];
+ if (weaponInfo)
+ GiveWeapon(weaponInfo->gunClipSize * iAmountOfBPAmmo, weaponInfo->entityName);
+ }
}
}
// Give default primary equipment
{
char *primaryString = NULL;
+ int primaryCount = 0;
+ const int MAX_PRIMARY = 39; // x2 + 1
+ WeaponInfoStruct *primaryWeaponInfoArray[MAX_PRIMARY];
if (m_iTeam == CT)
primaryString = ct_default_weapons_primary.string;
@@ -1699,12 +1719,25 @@ void EXT_FUNC CBasePlayer::__API_HOOK(GiveDefaultItems)()
if (weaponInfo) {
const auto iItemID = GetItemIdByWeaponId(weaponInfo->id);
if (iItemID != ITEM_NONE && !HasRestrictItem(iItemID, ITEM_TYPE_EQUIPPED) && IsPrimaryWeapon(iItemID)) {
- GiveWeapon(weaponInfo->gunClipSize * iAmountOfBPAmmo, weaponInfo->entityName);
+ if (default_weapons_random.value != 0.0f) {
+ if (primaryCount < MAX_PRIMARY) {
+ primaryWeaponInfoArray[primaryCount++] = weaponInfo;
+ }
+ }
+ else {
+ GiveWeapon(weaponInfo->gunClipSize * iAmountOfBPAmmo, weaponInfo->entityName);
+ }
}
}
primaryString = SharedParse(primaryString);
}
+
+ if (default_weapons_random.value != 0.0f) {
+ WeaponInfoStruct *weaponInfo = primaryWeaponInfoArray[RANDOM_LONG(0, primaryCount - 1)];
+ if (weaponInfo)
+ GiveWeapon(weaponInfo->gunClipSize * iAmountOfBPAmmo, weaponInfo->entityName);
+ }
}
}