From 3878f46678049201fb35f00168c9f9e1f493a8b9 Mon Sep 17 00:00:00 2001 From: Shorohov Sergey Date: Wed, 17 Jun 2020 19:42:40 +0300 Subject: [PATCH] Add new CVar's for default weapons (#470) --- README.md | 8 +++ dist/game.cfg | 47 +++++++++++++++ regamedll/dlls/game.cpp | 19 +++++- regamedll/dlls/game.h | 9 +++ regamedll/dlls/items.cpp | 38 ++++++++++++ regamedll/dlls/items.h | 1 + regamedll/dlls/player.cpp | 124 ++++++++++++++++++++++++++++++++------ 7 files changed, 225 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index a4341e818..754ac3879 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,14 @@ Archive's bin directory contains 2 subdirectories, 'bugfixed' and 'pure' | mp_radio_timeout | 1.5 | 0.0 | - | Delay between player Radio messages. (in seconds).
`0` disable delay | | mp_radio_maxinround | 60 | - | - | Maximum Radio messages count for player per round.
`0` disable radio messages | | mp_buy_anywhere | 0 | 0 | 3 | When set, players can buy anywhere, not only in buyzones.
`0` disabled.
`1` both teams
`2` only Terrorists team
`3` only CT team | +| mp_t_default_grenades | "" | "" | - | The default grenades that the Ts will spawn with. | +| mp_t_give_player_knife | 1 | 0 | 1 | Whether Terrorist player spawn with knife. | +| mp_t_default_weapons_primary | "" | "" | - | The default primary (rifle) weapon that the Ts will spawn with. | +| mp_t_default_weapons_secondary | "glock18" | "" | - | The default secondary (pistol) weapon that the Ts will spawn with. | +| mp_ct_default_grenades | "" | "" | - | The default grenades that the CTs will spawn with. | +| 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_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_fadetoblack | 0 | 0 | 2 | Observer's screen will fade to black on kill event or permanent.
`0` No fade.
`1` Fade to black and won't be able to watch anybody.
`2` fade to black only on kill moment. | diff --git a/dist/game.cfg b/dist/game.cfg index d6890b9dd..e05adc427 100644 --- a/dist/game.cfg +++ b/dist/game.cfg @@ -394,3 +394,50 @@ mp_fadetoblack 0 // Default value: "1" mp_falldamage 1 +// The default grenades that the Ts will spawn with. +// Usage: "hegrenade flash sgren" +// +// Default value: "" +mp_t_default_grenades "" + +// Whether Terrorist player spawn with knife. +// 0 - disabled +// 1 - enabled (default behaviour) +// +// Default value: "1" +mp_t_give_player_knife 1 + +// The default primary (rifle) weapon that the Ts will spawn with. +// Usage: "awp m4a1 mp5navy" +// +// Default value: "" +mp_t_default_weapons_primary "" + +// The default secondary (pistol) weapon that the Ts will spawn with. +// +// Default value: "glock18" +mp_t_default_weapons_secondary "glock18" + +// The default grenades that the CTs will spawn with. +// Usage: "hegrenade flash sgren" +// +// Default value: "" +mp_ct_default_grenades "" + +// Whether Counter-Terrorist player spawn with knife. +// 0 - disabled +// 1 - enabled (default behaviour) +// +// Default value: "1" +mp_ct_give_player_knife 1 + +// The default primary (rifle) weapon that the CTs will spawn with. +// Usage: "awp m4a1 mp5navy" +// +// Default value: "" +mp_ct_default_weapons_primary "" + +// The default secondary (pistol) weapon that the CTs will spawn with. +// +// Default value: "usp" +mp_ct_default_weapons_secondary "usp" diff --git a/regamedll/dlls/game.cpp b/regamedll/dlls/game.cpp index f9d62d6b8..d0f43e625 100644 --- a/regamedll/dlls/game.cpp +++ b/regamedll/dlls/game.cpp @@ -149,6 +149,14 @@ cvar_t radio_timeout = { "mp_radio_timeout", "1.5", FCVAR_SERVER, 1.5f cvar_t radio_maxinround = { "mp_radio_maxinround", "60", FCVAR_SERVER, 60.0f, nullptr }; cvar_t falldamage = { "mp_falldamage", "1", FCVAR_SERVER, 1.0f, nullptr }; +cvar_t ct_default_grenades = { "mp_ct_default_grenades", "", 0, 0.0f, nullptr }; +cvar_t ct_give_player_knife = { "mp_ct_give_player_knife", "1", 0, 1.0f, nullptr }; +cvar_t ct_default_weapons_secondary = { "mp_ct_default_weapons_secondary", "usp", 0, 0.0f, nullptr }; +cvar_t ct_default_weapons_primary = { "mp_ct_default_weapons_primary", "", 0, 0.0f, nullptr }; +cvar_t t_default_grenades = { "mp_t_default_grenades", "", 0, 0.0f, nullptr }; +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 }; void GameDLL_Version_f() { @@ -362,7 +370,16 @@ void EXT_FUNC GameDLLInit() CVAR_REGISTER(&radio_timeout); CVAR_REGISTER(&radio_maxinround); CVAR_REGISTER(&falldamage); - + + CVAR_REGISTER(&ct_default_grenades); + CVAR_REGISTER(&ct_give_player_knife); + CVAR_REGISTER(&ct_default_weapons_secondary); + CVAR_REGISTER(&ct_default_weapons_primary); + CVAR_REGISTER(&t_default_grenades); + CVAR_REGISTER(&t_give_player_knife); + CVAR_REGISTER(&t_default_weapons_secondary); + CVAR_REGISTER(&t_default_weapons_primary); + // print version CONSOLE_ECHO("ReGameDLL version: " APP_VERSION "\n"); diff --git a/regamedll/dlls/game.h b/regamedll/dlls/game.h index 6884a41c4..f99f66184 100644 --- a/regamedll/dlls/game.h +++ b/regamedll/dlls/game.h @@ -175,6 +175,15 @@ extern cvar_t radio_timeout; extern cvar_t radio_maxinround; extern cvar_t falldamage; +extern cvar_t ct_default_grenades; +extern cvar_t ct_give_player_knife; +extern cvar_t ct_default_weapons_secondary; +extern cvar_t ct_default_weapons_primary; +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; + #endif extern cvar_t scoreboard_showmoney; diff --git a/regamedll/dlls/items.cpp b/regamedll/dlls/items.cpp index 38f226ab6..0968d7b0b 100644 --- a/regamedll/dlls/items.cpp +++ b/regamedll/dlls/items.cpp @@ -550,3 +550,41 @@ ItemID GetItemIdByArmoury(ArmouryItemPack armoury) default: return ITEM_NONE; } } + +ItemID GetItemIdByWeaponId(int weaponId) +{ + switch (static_cast(weaponId)) + { + case WEAPON_KNIFE: return ITEM_KNIFE; + case WEAPON_MP5N: return ITEM_MP5N; + case WEAPON_TMP: return ITEM_TMP; + case WEAPON_P90: return ITEM_P90; + case WEAPON_MAC10: return ITEM_MAC10; + case WEAPON_AK47: return ITEM_AK47; + case WEAPON_SG552: return ITEM_SG552; + case WEAPON_M4A1: return ITEM_M4A1; + case WEAPON_AUG: return ITEM_AUG; + case WEAPON_SCOUT: return ITEM_SCOUT; + case WEAPON_G3SG1: return ITEM_G3SG1; + case WEAPON_AWP: return ITEM_AWP; + case WEAPON_M3: return ITEM_M3; + case WEAPON_XM1014: return ITEM_XM1014; + case WEAPON_C4: return ITEM_C4; + case WEAPON_M249: return ITEM_M249; + case WEAPON_FLASHBANG: return ITEM_FLASHBANG; + case WEAPON_HEGRENADE: return ITEM_HEGRENADE; + case WEAPON_SMOKEGRENADE: return ITEM_SMOKEGRENADE; + case WEAPON_SHIELDGUN: return ITEM_SHIELDGUN; + case WEAPON_GLOCK18: return ITEM_GLOCK18; + case WEAPON_USP: return ITEM_USP; + case WEAPON_ELITE: return ITEM_ELITE; + case WEAPON_FIVESEVEN: return ITEM_FIVESEVEN; + case WEAPON_P228: return ITEM_P228; + case WEAPON_DEAGLE: return ITEM_DEAGLE; + case WEAPON_FAMAS: return ITEM_FAMAS; + case WEAPON_SG550: return ITEM_SG550; + case WEAPON_GALIL: return ITEM_GALIL; + case WEAPON_UMP45: return ITEM_UMP45; + default: return ITEM_NONE; + } +} diff --git a/regamedll/dlls/items.h b/regamedll/dlls/items.h index 4d21e3f20..fd8f3e717 100644 --- a/regamedll/dlls/items.h +++ b/regamedll/dlls/items.h @@ -175,3 +175,4 @@ class CItemThighPack: public CItem ItemID GetItemIdByName(const char *pszName); ItemID GetItemIdByArmoury(ArmouryItemPack armoury); +ItemID GetItemIdByWeaponId(int weaponId); diff --git a/regamedll/dlls/player.cpp b/regamedll/dlls/player.cpp index fd7f5e3db..2cd0d62c2 100644 --- a/regamedll/dlls/player.cpp +++ b/regamedll/dlls/player.cpp @@ -1471,38 +1471,123 @@ void EXT_FUNC CBasePlayer::__API_HOOK(GiveDefaultItems)() #endif #ifdef REGAMEDLL_ADD - auto GiveWeapon = [&](int ammo, char *pszWeaponName) { + auto GiveWeapon = [&](int ammo, const char *pszWeaponName) { auto pItem = static_cast(GiveNamedItemEx(pszWeaponName)); if (pItem) { GiveAmmo(refill_bpammo_weapons.value != 0.0f ? pItem->iMaxAmmo1() : ammo, pItem->pszAmmo1(), pItem->iMaxAmmo1()); } }; - switch (m_iTeam) - { - case CT: - { - if (!HasRestrictItem(ITEM_KNIFE, ITEM_TYPE_EQUIPPED)) { - GiveNamedItem("weapon_knife"); - } - if (!HasRestrictItem(ITEM_USP, ITEM_TYPE_EQUIPPED)) { - GiveWeapon(m_bIsVIP ? 12 : 24, "weapon_usp"); - } + bool bGiveKnife = false; + if (m_iTeam == CT) + bGiveKnife = ct_give_player_knife.value != 0; + else if (m_iTeam == TERRORIST) + bGiveKnife = t_give_player_knife.value != 0; - break; + if (bGiveKnife && !HasRestrictItem(ITEM_KNIFE, ITEM_TYPE_EQUIPPED)) { + GiveNamedItemEx("weapon_knife"); } - case TERRORIST: + + const int iAmountOfBPAmmo = m_bIsVIP ? 1 : 2; // Give regular the player backpack ammo twice more than to VIP the player + + // Give default secondary equipment { - if (!HasRestrictItem(ITEM_KNIFE, ITEM_TYPE_EQUIPPED)) { - GiveNamedItem("weapon_knife"); - } - if (!HasRestrictItem(ITEM_GLOCK18, ITEM_TYPE_EQUIPPED)) { - GiveWeapon(40, "weapon_glock18"); + char *secondaryString = NULL; + if (m_iTeam == CT) + secondaryString = ct_default_weapons_secondary.string; + else if (m_iTeam == TERRORIST) + secondaryString = t_default_weapons_secondary.string; + + if (secondaryString && secondaryString[0] != '\0') + { + secondaryString = SharedParse(secondaryString); + + while (secondaryString) + { + WeaponInfoStruct *weaponInfo; + WeaponIdType weaponId = AliasToWeaponID(SharedGetToken()); + if (weaponId != WEAPON_NONE) + weaponInfo = GetWeaponInfo(weaponId); + else + weaponInfo = GetWeaponInfo(SharedGetToken()); + + 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); + } + } + + secondaryString = SharedParse(secondaryString); + } } + } - break; + // Give default primary equipment + { + char *primaryString = NULL; + + if (m_iTeam == CT) + primaryString = ct_default_weapons_primary.string; + else if (m_iTeam == TERRORIST) + primaryString = t_default_weapons_primary.string; + + if (primaryString && primaryString[0] != '\0') + { + primaryString = SharedParse(primaryString); + + while (primaryString) + { + WeaponInfoStruct *weaponInfo; + WeaponIdType weaponId = AliasToWeaponID(SharedGetToken()); + if (weaponId != WEAPON_NONE) + weaponInfo = GetWeaponInfo(weaponId); + else + weaponInfo = GetWeaponInfo(SharedGetToken()); + + 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); + } + } + + primaryString = SharedParse(primaryString); + } + } } + + // Give the player grenades if he needs them + char *grenadeString = NULL; + if (m_iTeam == CT) + grenadeString = ct_default_grenades.string; + else if (m_iTeam == TERRORIST) + grenadeString = t_default_grenades.string; + + if (grenadeString && grenadeString[0] != '\0') + { + grenadeString = SharedParse(grenadeString); + + while (grenadeString) + { + WeaponInfoStruct *weaponInfo; + WeaponIdType weaponId = AliasToWeaponID(SharedGetToken()); + if (weaponId != WEAPON_NONE) + weaponInfo = GetWeaponInfo(weaponId); + else + weaponInfo = GetWeaponInfo(SharedGetToken()); + + if (weaponInfo) { + const auto iItemID = GetItemIdByWeaponId(weaponInfo->id); + if (iItemID != ITEM_NONE && !HasRestrictItem(iItemID, ITEM_TYPE_EQUIPPED) && IsGrenadeWeapon(iItemID)) { + GiveNamedItemEx(weaponInfo->entityName); + } + } + + grenadeString = SharedParse(grenadeString); + } } + #else switch (m_iTeam) { @@ -1518,7 +1603,6 @@ void EXT_FUNC CBasePlayer::__API_HOOK(GiveDefaultItems)() break; } #endif - } void CBasePlayer::RemoveAllItems(BOOL removeSuit)