Skip to content

Commit

Permalink
Add new CVar mp_default_weapons_random
Browse files Browse the repository at this point in the history
  • Loading branch information
Vaqtincha committed Sep 18, 2024
1 parent 9b626b1 commit d4dd466
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).<br/> `0` disabled<br/>`1` enabled |
| mp_give_player_c4 | 1 | 0 | 1 | Whether this map should spawn a C4 bomb for a player or not.<br/> `0` disabled<br/>`1` enabled |
| mp_weapons_allow_map_placed | 1 | 0 | 1 | When set, map weapons (located on the floor by map) will be shown.<br/> `0` hide all map weapons.<br/>`1` enabled<br/>`NOTE`: Effect will work after round restart. |
| mp_free_armor | 0 | 0 | 2 | Give free armor on player spawn.<br/>`0` disabled <br/>`1` Give Kevlar <br/>`2` Give Kevlar + Helmet |
Expand Down
7 changes: 7 additions & 0 deletions dist/game.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions regamedll/dlls/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions regamedll/dlls/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
37 changes: 35 additions & 2 deletions regamedll/dlls/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
Expand All @@ -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);
}
}
}

Expand Down

0 comments on commit d4dd466

Please sign in to comment.