Skip to content

Commit

Permalink
fix: give default weapons when not full equip set
Browse files Browse the repository at this point in the history
Co-Authored-By: golukon <[email protected]>
  • Loading branch information
SergeyShorokhov and golukon committed Sep 12, 2023
1 parent 6d2b3b8 commit d95f5cd
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ bool: ModeVote_RoundEnd_Post() {
return true
}

ModeVote_GiveDefaultItems(const player) {
ModeVote_OnSpawnEquip(const player) {
if (!g_voteStarted)
return

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ static redm_keep_weapon_slot = 1
static bool: redm_open_equip_menu = false

EquipManager_Init() {
RegisterHookChain(RG_CBasePlayer_GiveDefaultItems, "CBasePlayer_GiveDefaultItems", .post = false)
RegisterHookChain(RG_CBasePlayer_OnSpawnEquip, "CBasePlayer_OnSpawnEquip", .post = false)
RegisterHookChain(RG_CBasePlayer_OnSpawnEquip, "CBasePlayer_OnSpawnEquip_Post", .post = true)
// RegisterHookChain(RG_CBasePlayer_GiveNamedItem, "CBasePlayer_GiveNamedItem", .post = false)
RegisterHookChain(RG_CBasePlayer_AddPlayerItem, "CBasePlayer_AddPlayerItem", .post = false)

Expand Down Expand Up @@ -293,39 +294,53 @@ public MenuHandler_ChooseEquip(const player, const menu, const item) {
return PLUGIN_HANDLED
}

public CBasePlayer_GiveDefaultItems(const player) {
public CBasePlayer_OnSpawnEquip(const player, bool: addDefault, bool: equipGame) {
if (!IsActive())
return HC_CONTINUE
return

ModeVote_GiveDefaultItems(player)
RoundModes_OnSpawnEquip(player)
ModeVote_OnSpawnEquip(player)

if (is_user_bot(player))
return HC_CONTINUE
set_member(player, m_bNotKilled, false)
rg_set_user_armor(player, 0, ARMOR_NONE)

if (redm_keep_weapon_slot)
RequestFrame("Player_ForceSlotChoose", player)

rg_give_item(player, "weapon_knife")

new bool: fullyEquipped = true
for (new EquipType_e: section; section < EquipType_e; section++) {
if (!HasEquipItems(section))
continue
if (g_playerRandomWeapons[player]) {

if (g_playerRandomWeapons[player])
g_playerWeapons[player][section] = random_num(0, ArraySize(Array: g_equip[section]) - 1)
}

if (g_playerWeapons[player][section] == EQUIP_NOT_CHOOSEN) {
if (redm_open_equip_menu)
Menu_ChooseEquip(player, section)
if (g_playerWeapons[player][section] != EQUIP_NOT_CHOOSEN)
continue

return HC_CONTINUE
}
fullyEquipped = false
}

if (fullyEquipped) {
rg_give_item(player, "weapon_knife")

Player_GiveWeapon(player, section)
SetHookChainArg(2, ATYPE_BOOL, (addDefault = false))
}
}

public CBasePlayer_OnSpawnEquip_Post(const player, bool: addDefault, bool: equipGame) {
for (new EquipType_e: section; section < EquipType_e; section++) {
if (g_playerWeapons[player][section] != EQUIP_NOT_CHOOSEN) {
Player_GiveWeapon(player, section)

continue
}

if (redm_open_equip_menu)
Menu_ChooseEquip(player, section)

return HC_SUPERCEDE
return
}
}

public CBasePlayer_AddPlayerItem(const player, const item) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ RoundModes_Init() {

RegisterHookChain(RG_RoundEnd, "RoundEnd_Post", .post = true)
RegisterHookChain(RG_CSGameRules_RestartRound, "CSGameRules_RestartRound", .post = false)
RegisterHookChain(RG_CBasePlayer_OnSpawnEquip, "CBasePlayer_OnSpawnEquip", .post = false)


bind_pcvar_string(
create_cvar(
Expand Down Expand Up @@ -83,13 +83,7 @@ public CSGameRules_RestartRound() {
}
}

public CBasePlayer_OnSpawnEquip(const player, bool: addDefault, bool: equipGame) {
if (!IsActive())
return

set_member(player, m_bNotKilled, false)
rg_set_user_armor(player, 0, ARMOR_NONE)

RoundModes_OnSpawnEquip(const player) {
if (g_currentRoundModeIdx == -1)
return

Expand Down

0 comments on commit d95f5cd

Please sign in to comment.