Skip to content

Commit

Permalink
Resolves #154
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferexx committed May 11, 2022
1 parent 1a590b2 commit 99f4bd4
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 7 deletions.
18 changes: 18 additions & 0 deletions addons/sourcemod/scripting/gokz-hud/options.sp
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,23 @@ static void PrintOptionChangeMessage(int client, HUDOption option, any newValue)
}
}
}
case HUDOption_ShowSpectators:
{
switch (newValue)
{
case ShowSpecs_Disabled:
{
GOKZ_PrintToChat(client, true, "%t", "Option - Show Spectators - Disable");
}
case ShowSpecs_Number:
{
GOKZ_PrintToChat(client, true, "%t", "Option - Show Spectators - Number");
}
case ShowSpecs_Full:
{
GOKZ_PrintToChat(client, true, "%t", "Option - Show Spectators - Full");
}
}
}
}
}
6 changes: 6 additions & 0 deletions addons/sourcemod/scripting/gokz-hud/options_menu.sp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ public void TopMenuHandler_HUD(TopMenu topmenu, TopMenuAction action, TopMenuObj
gC_HUDOptionPhrases[option], param,
gC_ShowControlsPhrases[GOKZ_HUD_GetOption(param, option)], param);
}
case HUDOption_ShowSpectators:
{
FormatEx(buffer, maxlength, "%T - %T",
gC_HUDOptionPhrases[option], param,
gC_ShowSpecsPhrases[GOKZ_HUD_GetOption(param, option)], param);
}
default:FormatToggleableOptionDisplay(param, option, buffer, maxlength);
}
}
Expand Down
76 changes: 74 additions & 2 deletions addons/sourcemod/scripting/gokz-hud/tp_menu.sp
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,25 @@ static void ShowTPMenu(KZPlayer player, HUDInfo info)

static void TPMenuSetTitle(KZPlayer player, Menu menu, HUDInfo info)
{
switch (player.ShowSpectators)
{
case ShowSpecs_Number:
{
menu.SetTitle("%T\n \n", "TP Menu - Spectators - Number", player.ID, GetNumSpectators(player));
}
case ShowSpecs_Full:
{
char display[512];
FormatSpectatorNames(player, display);
menu.SetTitle("%T\n \n", "TP Menu - Spectators - Full", player.ID, GetNumSpectators(player), display);
}
}

if (player.TimerRunning && player.TimerText == TimerText_TPMenu)
{
menu.SetTitle(FormatTimerTextForMenu(player, info));
char display[512];
menu.GetTitle(display, sizeof(display));
menu.SetTitle("%s%s", display, FormatTimerTextForMenu(player,info));
}
}

Expand Down Expand Up @@ -248,4 +264,60 @@ static void TPMenuAddItemStart(KZPlayer player, Menu menu)
FormatEx(display, sizeof(display), "%T", "TP Menu - Start", player.ID);
menu.AddItem(ITEM_INFO_START, display, ITEMDRAW_DEFAULT);
}
}
}

static int GetNumSpectators(KZPlayer player)
{
int count;

for(int i = 1; i <= MaxClients; i++)
{
if (IsValidClient(i) && !IsPlayerAlive(i))
{
int SpecMode = GetEntProp(i, Prop_Send, "m_iObserverMode");
if (SpecMode == 4 || SpecMode == 5)
{
int target = GetEntPropEnt(i, Prop_Send, "m_hObserverTarget");
if (target == player.ID)
{
count++;
}
}
}
}

return count;
}

static void FormatSpectatorNames(KZPlayer player, char display[512])
{
int count;

for(int i = 1; i <= MaxClients; i++)
{
if (IsValidClient(i) && !IsPlayerAlive(i))
{
int SpecMode = GetEntProp(i, Prop_Send, "m_iObserverMode");
if (SpecMode == 4 || SpecMode == 5)
{
int target = GetEntPropEnt(i, Prop_Send, "m_hObserverTarget");
if (target == player.ID)
{
count++;
//strip pound symbol from names
char cleanName[MAX_NAME_LENGTH];
GetClientName(i, cleanName, sizeof(cleanName));
ReplaceString(cleanName, sizeof(cleanName), "#", "", false);
if (count < 6)
{
Format(display, sizeof(display), "%s%s\n", display, cleanName);
}
}
if (count == 6)
{
Format(display, sizeof(display), "%s...", display);
}
}
}
}
}
31 changes: 26 additions & 5 deletions addons/sourcemod/scripting/include/gokz/hud.inc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ enum HUDOption:
HUDOption_SpeedText,
HUDOption_ShowWeapon,
HUDOption_ShowControls,
HUDOption_ShowSpectators,
HUDOPTION_COUNT
};

Expand Down Expand Up @@ -97,6 +98,14 @@ enum
REPLAYCONTROLS_COUNT
};

enum
{
ShowSpecs_Disabled = 0,
ShowSpecs_Number,
ShowSpecs_Full,
SHOWSPECS_COUNT
};



// =====[ STRUCTS ]======
Expand Down Expand Up @@ -140,7 +149,8 @@ stock char gC_HUDOptionNames[HUDOPTION_COUNT][] =
"GOKZ HUD - Show Time Type",
"GOKZ HUD - Speed Text",
"GOKZ HUD - Show Weapon",
"GOKZ HUD - Show Controls"
"GOKZ HUD - Show Controls",
"GOKZ HUD - Show Spectators"
};

stock char gC_HUDOptionDescriptions[HUDOPTION_COUNT][] =
Expand All @@ -153,7 +163,8 @@ stock char gC_HUDOptionDescriptions[HUDOPTION_COUNT][] =
"Timer Type - 0 = Disabled, 1 = Enabled",
"Speed Display - 0 = Disabled, 1 = Centre Panel, 2 = Bottom",
"Weapon Viewmodel - 0 = Disabled, 1 = Enabled",
"Replay Controls Display - 0 = Disbled, 1 = Enabled"
"Replay Controls Display - 0 = Disabled, 1 = Enabled",
"Show Spectators - 0 = Disabled, 1 = Number Only, 2 = Number and Names"
};

stock char gC_HUDOptionPhrases[HUDOPTION_COUNT][] =
Expand All @@ -166,7 +177,8 @@ stock char gC_HUDOptionPhrases[HUDOPTION_COUNT][] =
"Options Menu - Timer Type",
"Options Menu - Speed Text",
"Options Menu - Show Weapon",
"Options Menu - Show Controls"
"Options Menu - Show Controls",
"Options Menu - Show Spectators"
};

stock int gI_HUDOptionCounts[HUDOPTION_COUNT] =
Expand All @@ -179,7 +191,8 @@ stock int gI_HUDOptionCounts[HUDOPTION_COUNT] =
TIMERTYPE_COUNT,
SPEEDTEXT_COUNT,
SHOWWEAPON_COUNT,
REPLAYCONTROLS_COUNT
REPLAYCONTROLS_COUNT,
SHOWSPECS_COUNT
};

stock int gI_HUDOptionDefaults[HUDOPTION_COUNT] =
Expand All @@ -192,7 +205,8 @@ stock int gI_HUDOptionDefaults[HUDOPTION_COUNT] =
TimerType_Enabled,
SpeedText_InfoPanel,
ShowWeapon_Enabled,
ReplayControls_Enabled
ReplayControls_Enabled,
ShowSpecs_Disabled
};

stock char gC_TPMenuPhrases[TPMENU_COUNT][] =
Expand Down Expand Up @@ -237,6 +251,13 @@ stock char gC_ShowControlsPhrases[REPLAYCONTROLS_COUNT][] =
"Options Menu - Enabled"
};

stock char gC_ShowSpecsPhrases[SHOWSPECS_COUNT][] =
{
"Options Menu - Disabled",
"Options Menu - Number",
"Options Menu - Number and Names"
}



// =====[ STOCKS ]=====
Expand Down
18 changes: 18 additions & 0 deletions addons/sourcemod/scripting/include/gokz/kzplayer.inc
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,24 @@ methodmap KZPlayer < MovementAPIPlayer {
}
}

property int ReplayControls {
public get() {
return this.GetHUDOption(HUDOption_ShowControls);
}
public set(int value) {
this.SetHUDOption(HUDOption_ShowControls, value);
}
}

property int ShowSpectators {
public get() {
return this.GetHUDOption(HUDOption_ShowSpectators);
}
public set(int value) {
this.SetHUDOption(HUDOption_ShowSpectators, value);
}
}

#endif
// =====[ END HUD ]=====

Expand Down
34 changes: 34 additions & 0 deletions addons/sourcemod/translations/gokz-hud.phrases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@
{
"en" "{grey}Replay controls are now hidden."
}
"Option - Show Spectators - Disable"
{
"en" "{grey}Spectators are now not shown."
}
"Option - Show Spectators - Number"
{
"en" "{grey}Number of spectators is now shown."
}
"Option - Show Spectators - Full"
{
"en" "{grey}Number and names of spectators are now shown."
}


// =====[ INFO PANEL ]=====
Expand Down Expand Up @@ -107,6 +119,16 @@


// =====[ TELEPORT MENU ]=====
"TP Menu - Spectators - Full"
{
"#format" "{1:d},{2:s}"
"en" "Specs ({1}):\n{2}"
}
"TP Menu - Spectators - Number"
{
"#format" "{1:d}"
"en" "Specs: {1}"
}
"TP Menu - Checkpoint"
{
"en" "Checkpoint"
Expand Down Expand Up @@ -230,6 +252,18 @@
{
"en" "Show replay controls"
}
"Options Menu - Show Spectators"
{
"en" "Show spectators"
}
"Options Menu - Number"
{
"en" "Number"
}
"Options Menu - Number and Names"
{
"en" "Number and Names"
}


// =====[ RACING ]=====
Expand Down

0 comments on commit 99f4bd4

Please sign in to comment.