Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
- fix monsters having no health
- fix text menu pagination (max of 2 items per page in vanilla hl...)
  • Loading branch information
wootguy committed Nov 19, 2024
1 parent d41984c commit b399ced
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
18 changes: 9 additions & 9 deletions dlls/TextMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ void TextMenu::handleMenuselectCmd(CBasePlayer* pPlayer, int selection) {
// exit menu
viewers &= ~playerbit;
}
else if (isPaginated() && selection == 7) {
else if (isPaginated() && selection == BACK_OPTION_IDX) {
Open(lastDuration, lastPage - 1, pPlayer);
}
else if (isPaginated() && selection == 8) {
else if (isPaginated() && selection == MORE_OPTION_IDX) {
Open(lastDuration, lastPage + 1, pPlayer);
}
else if (selection < numOptions && IsValidPlayer(pPlayer->edict())) {
Expand All @@ -144,7 +144,7 @@ void TextMenu::handleMenuselectCmd(CBasePlayer* pPlayer, int selection) {
}

bool TextMenu::isPaginated() {
return numOptions > 9;
return numOptions > MAX_ITEMS_NO_PAGES;
}

void TextMenu::SetTitle(std::string newTitle) {
Expand All @@ -171,9 +171,9 @@ void TextMenu::Open(uint8_t duration, uint8_t page, CBasePlayer* player) {
lastPage = page;
lastDuration = duration;

int limitPerPage = isPaginated() ? ITEMS_PER_PAGE : 9;
int limitPerPage = isPaginated() ? ITEMS_PER_PAGE : MAX_ITEMS_NO_PAGES;
int itemOffset = page * ITEMS_PER_PAGE;
int totalPages = (numOptions+6) / ITEMS_PER_PAGE;
int totalPages = (numOptions+(ITEMS_PER_PAGE-1)) / ITEMS_PER_PAGE;

int addedOptions = 0;
for (int i = itemOffset, k = 0; i < itemOffset+limitPerPage && i < numOptions; i++, k++) {
Expand All @@ -191,15 +191,15 @@ void TextMenu::Open(uint8_t duration, uint8_t page, CBasePlayer* player) {

if (isPaginated()) {
if (page > 0) {
menuText += "8: Back\n";
validSlots |= (1 << 7);
menuText += std::to_string(BACK_OPTION_IDX+1) + ": Back\n";
validSlots |= (1 << (ITEMS_PER_PAGE));
}
else {
menuText += "\n";
}
if (page < totalPages - 1) {
menuText += "9: More\n";
validSlots |= (1 << 8);
menuText += std::to_string(MORE_OPTION_IDX+1) + ": More\n";
validSlots |= (1 << (ITEMS_PER_PAGE + 1));
}
else {
menuText += "\n";
Expand Down
6 changes: 5 additions & 1 deletion dlls/TextMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
#include <string>

#define MAX_MENU_OPTIONS 128
#define ITEMS_PER_PAGE 7
#define MAX_PAGE_OPTIONS 5
#define ITEMS_PER_PAGE (MAX_PAGE_OPTIONS-3) // leave room for next, more, and exit options
#define BACK_OPTION_IDX (ITEMS_PER_PAGE)
#define MORE_OPTION_IDX (ITEMS_PER_PAGE+1)
#define MAX_ITEMS_NO_PAGES (ITEMS_PER_PAGE+2)
#define MAX_PLAYERS 32

class CTriggerVote;
Expand Down
8 changes: 2 additions & 6 deletions dlls/gamerules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,6 @@ void execSkillCfg(const char* fname, bool isMapSkill) {
if (isMapSkill && mp_skill_allow.value >= 1) {
ALERT(at_console, "Map skill cvars changed: %d\n", numChanges);
}

RefreshSkillData(isMapSkill);
}

void execCfgs() {
Expand All @@ -419,15 +417,13 @@ void execCfgs() {

execServerCfg();
execSkillCfg("skill.cfg", false);
RefreshSkillData(false);
execMapCfg();

if (mp_skill_allow.value != 0) {
execSkillCfg(UTIL_VarArgs("maps/%s_skl.cfg", STRING(gpGlobals->mapname)), true);
}
else {
// sync map health values to server values
RefreshSkillData(true);
}
RefreshSkillData(true);

SERVER_COMMAND("cfg_exec_finished\n");

Expand Down

0 comments on commit b399ced

Please sign in to comment.