Skip to content

Commit

Permalink
Add new CVar's for default weapons (#470)
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyShorokhov authored Jun 17, 2020
1 parent 532c132 commit 3878f46
Show file tree
Hide file tree
Showing 7 changed files with 225 additions and 21 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).<br/>`0` disable delay |
| mp_radio_maxinround | 60 | - | - | Maximum Radio messages count for player per round.<br/>`0` disable radio messages |
| mp_buy_anywhere | 0 | 0 | 3 | When set, players can buy anywhere, not only in buyzones.<br/> `0` disabled.<br/>`1` both teams <br/>`2` only Terrorists team <br/>`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.<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_fadetoblack | 0 | 0 | 2 | Observer's screen will fade to black on kill event or permanent.<br/> `0` No fade.<br/>`1` Fade to black and won't be able to watch anybody.<br/>`2` fade to black only on kill moment. |
Expand Down
47 changes: 47 additions & 0 deletions dist/game.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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"
19 changes: 18 additions & 1 deletion regamedll/dlls/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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");

Expand Down
9 changes: 9 additions & 0 deletions regamedll/dlls/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
38 changes: 38 additions & 0 deletions regamedll/dlls/items.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,3 +550,41 @@ ItemID GetItemIdByArmoury(ArmouryItemPack armoury)
default: return ITEM_NONE;
}
}

ItemID GetItemIdByWeaponId(int weaponId)
{
switch (static_cast<WeaponIdType>(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;
}
}
1 change: 1 addition & 0 deletions regamedll/dlls/items.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,4 @@ class CItemThighPack: public CItem

ItemID GetItemIdByName(const char *pszName);
ItemID GetItemIdByArmoury(ArmouryItemPack armoury);
ItemID GetItemIdByWeaponId(int weaponId);
124 changes: 104 additions & 20 deletions regamedll/dlls/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CBasePlayerItem *>(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)
{
Expand All @@ -1518,7 +1603,6 @@ void EXT_FUNC CBasePlayer::__API_HOOK(GiveDefaultItems)()
break;
}
#endif

}

void CBasePlayer::RemoveAllItems(BOOL removeSuit)
Expand Down

0 comments on commit 3878f46

Please sign in to comment.