Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mappool #415

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cfg/sourcemod/pugsetup/all.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// add all maps on the server here
1 change: 1 addition & 0 deletions cfg/sourcemod/pugsetup/competitive.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// add competitive maps here
1 change: 1 addition & 0 deletions cfg/sourcemod/pugsetup/fun.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// add fun maps for casual games here
16 changes: 12 additions & 4 deletions scripting/pugsetup.sp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <SteamWorks>

#undef REQUIRE_PLUGIN
#include "include/updater.inc"
#include <updater>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change will break the automated compilation test since this file won't be available: https://github.com/splewis/csgo-pug-setup/blob/master/.travis.yml

I would revert this, unless there's a reliable location to get the include from (i.e., undo ca76885)

#define UPDATE_URL "http://dl.whiffcity.com/plugins/pugsetup/pugsetup.txt"

#define ALIAS_LENGTH 64
Expand Down Expand Up @@ -269,7 +269,7 @@ public void OnPluginStart() {
"sm_pugsetup_force_defaults", "0",
"Whether the default setup options are forced as the setup options (note that admins can override them still).");
g_InstantRunoffVotingCvar = CreateConVar(
"sm_pugsetup_instant_runoff_voting", "1",
"sm_pugsetup_instant_runoff_voting", "0",
"If set, map votes will run instant-runoff style where each client selects their top 3 maps in preference order.");
g_KnifeConfigCvar = CreateConVar(
"sm_pugsetup_knife_cfg", "sourcemod/pugsetup/knife.cfg",
Expand Down Expand Up @@ -1196,6 +1196,7 @@ public int MatchEndHandler(Menu menu, MenuAction action, int param1, int param2)
} else if (action == MenuAction_End) {
CloseHandle(menu);
}
return 1;
}

public Action Command_ForceEnd(int client, int args) {
Expand Down Expand Up @@ -1603,10 +1604,12 @@ public Action Event_MatchOver(Event event, const char[] name, bool dontBroadcast
/** Helper timer to delay starting warmup period after match is over by a little bit **/
public Action Timer_EndMatch(Handle timer) {
EndMatch(false, false);
return Plugin_Continue;
}

public Action Event_RoundStart(Event event, const char[] name, bool dontBroadcast) {
CheckAutoSetup();
return Plugin_Continue;
}

public Action Event_RoundEnd(Event event, const char[] name, bool dontBroadcast) {
Expand All @@ -1633,23 +1636,26 @@ public Action Event_RoundEnd(Event event, const char[] name, bool dontBroadcast)
PugSetup_MessageToAll("%t", "KnifeRoundWinner", teamString, stayCmd, swapCmd);
}
}
return Plugin_Continue;
}

public Action Event_PlayerSpawn(Event event, const char[] name, bool dontBroadcast) {
if (g_GameState != GameState_Warmup)
return;
return Plugin_Continue;

int client = GetClientOfUserId(event.GetInt("userid"));
if (IsPlayer(client) && OnActiveTeam(client) && g_WarmupMoneyOnSpawnCvar.IntValue != 0) {
SetEntProp(client, Prop_Send, "m_iAccount", GetCvarIntSafe("mp_maxmoney"));
}
return Plugin_Continue;
}

public Action Event_PlayerConnect(Event event, const char[] name, bool dontBroadcast) {
int userid = event.GetInt("userid");
int client = GetClientOfUserId(userid);
g_Teams[client] = CS_TEAM_NONE;
g_PlayerAtStart[client] = false;
return Plugin_Continue;
}

public Action Event_PlayerDisconnect(Event event, const char[] name, bool dontBroadcast) {
Expand All @@ -1661,6 +1667,7 @@ public Action Event_PlayerDisconnect(Event event, const char[] name, bool dontBr
g_capt1 = -1;
if (g_capt2 == client)
g_capt2 = -1;
return Plugin_Continue;
}

/**
Expand Down Expand Up @@ -1874,6 +1881,7 @@ public Action Timer_BeginMatch(Handle timer) {
ChangeState(GameState_GoingLive);
CreateTimer(3.0, BeginLO3, _, TIMER_FLAG_NO_MAPCHANGE);
}
return Plugin_Continue;
}

public void ScrambleTeams() {
Expand Down Expand Up @@ -2236,4 +2244,4 @@ stock bool PermissionFromString(const char[] permissionString, Permission& p,
}

return true;
}
}
5 changes: 4 additions & 1 deletion scripting/pugsetup/captainpickmenus.sp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public int InitialChoiceHandler(Menu menu, MenuAction action, int param1, int pa
} else if (action == MenuAction_End) {
delete menu;
}
return 1;
}

public void SideMenu(int client) {
Expand Down Expand Up @@ -88,6 +89,7 @@ public int SideMenuHandler(Menu menu, MenuAction action, int param1, int param2)
} else if (action == MenuAction_End) {
delete menu;
}
return 1;
}

/**
Expand Down Expand Up @@ -123,7 +125,7 @@ public Action GivePlayerSelectionMenu(Handle timer, int serial) {

public int PlayerMenuHandler(Menu menu, MenuAction action, int param1, int param2) {
if (g_GameState != GameState_PickingPlayers)
return;
return 0;

if (action == MenuAction_Select) {
int client = param1;
Expand Down Expand Up @@ -155,6 +157,7 @@ public int PlayerMenuHandler(Menu menu, MenuAction action, int param1, int param
} else if (action == MenuAction_End) {
delete menu;
}
return 1;
}

static void MoreMenuPicks(int client) {
Expand Down
1 change: 1 addition & 0 deletions scripting/pugsetup/instantrunoffvote.sp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ static int CountMapsAlive(int& winner) {

public Action Timer_CollectIRVResults(Handle timer) {
CollectIRVResults();
return Plugin_Continue;
}

public void CollectIRVResults() {
Expand Down
1 change: 1 addition & 0 deletions scripting/pugsetup/kniferounds.sp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public Action Timer_AnnounceKnife(Handle timer) {

public Action Timer_HandleKnifeDecisionVote(Handle timer) {
HandleKnifeDecisionVote(true);
return Plugin_Continue;
}

static void HandleKnifeDecisionVote(bool timeExpired = false) {
Expand Down
3 changes: 3 additions & 0 deletions scripting/pugsetup/leadermenus.sp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public int Captain1MenuHandler(Menu menu, MenuAction action, int param1, int par
} else if (action == MenuAction_End) {
CloseHandle(menu);
}
return 1;
}

public void Captain2Menu(int client) {
Expand Down Expand Up @@ -62,6 +63,7 @@ public int Captain2MenuHandler(Menu menu, MenuAction action, int param1, int par
} else if (action == MenuAction_End) {
CloseHandle(menu);
}
return 1;
}

static int CountPotentialCaptains(int otherCaptain) {
Expand Down Expand Up @@ -110,6 +112,7 @@ public int LeaderMenuHandler(Menu menu, MenuAction action, int param1, int param
} else if (action == MenuAction_End) {
CloseHandle(menu);
}
return 1;
}

static int AddAllPlayers(Menu menu) {
Expand Down
2 changes: 2 additions & 0 deletions scripting/pugsetup/mapveto.sp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public int VetoHandler(Menu menu, MenuAction action, int param1, int param2) {
} else if (action == MenuAction_End) {
CloseHandle(menu);
}
return 1;
}

static void VetoStatusDisplay(int client) {
Expand All @@ -89,4 +90,5 @@ public int VetoStatusHandler(Menu menu, MenuAction action, int param1, int param
if (action == MenuAction_End) {
CloseHandle(menu);
}
return 1;
}
47 changes: 47 additions & 0 deletions scripting/pugsetup/mapvote.sp
Original file line number Diff line number Diff line change
@@ -1,9 +1,53 @@
#define RANDOM_MAP_VOTE "-1" // must be in invalid index for array indexing

char mapGroups[][] = {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned previously, I disagree with placing these in a different directory.

I also disagree with breaking backwards compatibility for existing users populating a different map config file.

"competitive.txt", "fun.txt", "all.txt"
};

/**
* Map voting functions
*/
public void CreateMapVote() {
StartMapVote2();
}
static void StartMapVote2() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a poor name for this function. Can you use a more descriptive name?

Menu menu = new Menu(MapVoteHandler2);
menu.SetTitle("%T", "VoteMenuTitle", LANG_SERVER);
menu.ExitButton = false;
for (int i = 0; i < sizeof(mapGroups); i++) {
char text[64], id[4];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this use the AddMenuInt helper function used elsewhere in the plugin?

Format(text, 64, mapGroups[i]);
Format(id, 4, "%i", i);
ReplaceString(text, 64, ".txt", "", false);
AddMenuItem(menu, id, text);
}
VoteMenuToAll(menu, g_MapVoteTimeCvar.IntValue);
}
public int MapVoteHandler2(Menu menu, MenuAction action, int param1, int param2) {
if (action == MenuAction_VoteEnd) {
int winner = GetMenuInt(menu, param1);

ServerCommand("sm_pugsetup_maplist %s", mapGroups[winner]);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't make sense to override the value here. It doesn't make sense to even have the cvar if the plugin will just override it before it gets used.


char text[64];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using PLATFORM_MAX_PATH instead of 64 seems more appropriate here.

Format(text, 64, mapGroups[winner]);
ReplaceString(text, 64, ".txt", "", false);

PrintCenterTextAll("Winner is %s", text);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This text should use a translation string.


CreateTimer(0.5, Timer_Continue, _, TIMER_FLAG_NO_MAPCHANGE);

} else if (action == MenuAction_End) {
CloseHandle(menu);
}
return 0;
}
public Action Timer_Continue(Handle timer)
{
CreateMapVote2();
return Plugin_Handled;
}
public void CreateMapVote2() {
if (g_ExcludedMaps.IntValue > 0 && g_MapList.Length > g_PastMaps.Length) {
SetupMapVotePool(true);
} else {
Expand All @@ -22,6 +66,7 @@ public void CreateMapVote() {
}

static void StartMapVote() {
FillMapList(g_MapListCvar, g_MapVotePool);
Menu menu = new Menu(MapVoteHandler);
menu.SetTitle("%T", "VoteMenuTitle", LANG_SERVER);
menu.ExitButton = false;
Expand All @@ -39,6 +84,8 @@ static void StartMapVote() {
}

for (int i = 0; i < g_MapVotePool.Length; i++) {
char mapName[64];
g_MapVotePool.GetString(i, mapName, sizeof(mapName));
AddMapIndexToMenu(menu, g_MapVotePool, i);
}

Expand Down
28 changes: 26 additions & 2 deletions scripting/pugsetup/natives.sp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public int Native_SetupGame(Handle plugin, int numParams) {
}

SetupFinished();
return 1;
}

public int Native_GetSetupOptions(Handle plugin, int numParams) {
Expand All @@ -88,6 +89,7 @@ public int Native_GetSetupOptions(Handle plugin, int numParams) {
SetNativeCellRef(4, g_RecordGameOption);
SetNativeCellRef(5, g_DoKnifeRound);
SetNativeCellRef(6, g_AutoLive);
return 1;
}

public int Native_SetSetupOptions(Handle plugin, int numParams) {
Expand All @@ -97,6 +99,7 @@ public int Native_SetSetupOptions(Handle plugin, int numParams) {
g_RecordGameOption = GetNativeCell(4);
g_DoKnifeRound = GetNativeCell(5);
g_AutoLive = GetNativeCell(6);
return 1;
}

public int Native_ReadyPlayer(Handle plugin, int numParams) {
Expand Down Expand Up @@ -218,6 +221,7 @@ public int Native_SetLeader(Handle plugin, int numParams) {
PugSetup_MessageToAll("%t", "NewLeader", client);
g_Leader = client;
}
return 1;
}

public int Native_GetLeader(Handle plugin, int numParams) {
Expand Down Expand Up @@ -277,6 +281,7 @@ public int Native_SetCaptain(Handle plugin, int numParams) {
PugSetup_MessageToAll("%t", "CaptMessage", captainNumber, buffer);
}
}
return 1;
}

public int Native_GetCaptain(Handle plugin, int numParams) {
Expand All @@ -294,7 +299,7 @@ public int Native_GetCaptain(Handle plugin, int numParams) {
public int Native_Message(Handle plugin, int numParams) {
int client = GetNativeCell(1);
if (client != 0 && (!IsClientConnected(client) || !IsClientInGame(client)))
return;
return 0;

char buffer[1024];
int bytesWritten = 0;
Expand All @@ -317,6 +322,7 @@ public int Native_Message(Handle plugin, int numParams) {
Colorize(finalMsg, sizeof(finalMsg));
PrintToChat(client, finalMsg);
}
return 1;
}

public int Native_MessageToAll(Handle plugin, int numParams) {
Expand Down Expand Up @@ -346,6 +352,7 @@ public int Native_MessageToAll(Handle plugin, int numParams) {
PrintToConsole(i, finalMsg);
}
}
return 1;
}

public int Native_GetPugMaxPlayers(Handle plugin, int numParams) {
Expand Down Expand Up @@ -397,7 +404,7 @@ public int Native_HasPermissions(Handle plugin, int numParams) {
return isAdmin;
else if (p == Permission_Leader)
return isLeader || isAdmin;
else if (p == Permission_Captains)
else if (p == Permission_Captains && UsingCaptains())
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change seems potentially problematic. If a permission has Permission_Captains using this native will throw an error now.

return isCapt || isLeader || isAdmin;
else if (p == Permission_All)
return true;
Expand Down Expand Up @@ -426,6 +433,8 @@ public int Native_SetRandomCaptains(Handle plugin, int numParams) {

if (IsPlayer(c2))
PugSetup_SetCaptain(2, c2, true);

return 1;
}

public int Native_AddChatAlias(Handle plugin, int numParams) {
Expand All @@ -445,6 +454,7 @@ public int Native_AddChatAlias(Handle plugin, int numParams) {
g_ChatAliasesCommands.PushString(command);
g_ChatAliasesModes.Push(mode);
}
return 1;
}

public int Native_GiveSetupMenu(Handle plugin, int numParams) {
Expand All @@ -459,12 +469,14 @@ public int Native_GiveSetupMenu(Handle plugin, int numParams) {
}

SetupMenu(client, displayOnly, menuPosition);
return 1;
}

public int Native_GiveMapChangeMenu(Handle plugin, int numParams) {
int client = GetNativeCell(1);
CHECK_CLIENT(client);
ChangeMapMenu(client);
return 1;
}

public int Native_IsValidCommand(Handle plugin, int numParams) {
Expand Down Expand Up @@ -501,7 +513,19 @@ public int Native_SetTeamBalancer(Handle plugin, int numParams) {
bool override = GetNativeCell(2);
if (!PugSetup_IsTeamBalancerAvaliable() || override) {
g_BalancerFunctionPlugin = plugin;
//ArrayList players = new ArrayList();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be removed.

g_BalancerFunction = view_as<TeamBalancerFunction>(GetNativeFunction(1));
for (int i = 1; i <= MaxClients; i++) {
if (IsPlayer(i)) {
if (PugSetup_IsReady(i))
players.Push(i);
}
}
Call_StartFunction(g_BalancerFunctionPlugin, g_BalancerFunction);
Call_PushCell(players);
Call_Finish();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this changing? It seems incorrect to invoke this function since the native could be called far before the match is ready.

delete players;

return true;
}
return false;
Expand Down
Loading