Skip to content

Commit

Permalink
stop that random map change thing
Browse files Browse the repository at this point in the history
  • Loading branch information
rtldg committed Jul 4, 2023
1 parent cf90d11 commit d69bd18
Showing 1 changed file with 31 additions and 32 deletions.
63 changes: 31 additions & 32 deletions addons/sourcemod/scripting/shavit-mapchooser.sp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ char g_cMapName[PLATFORM_MAX_PATH];

MapChange g_ChangeTime;

bool g_bWaitingForChange;
bool g_bMapVoteStarted;
bool g_bMapVoteFinished;
float g_fMapStartTime;
Expand Down Expand Up @@ -330,6 +331,7 @@ public void OnConfigsExecuted()
public void OnMapEnd()
{
gB_ConfigsExecuted = false;
g_bWaitingForChange = false;

if(g_cvMapVoteBlockMapInterval.IntValue > 0)
{
Expand Down Expand Up @@ -391,6 +393,24 @@ float MapChangeDelay()
return 1.0;
}

void StartMapChange(float delay, const char[] map, const char[] reason)
{
if (g_bWaitingForChange)
{
// Could be here if someone !map's during the 1-4s delay before the changelevel... but this simplifies things...
LogError("StartMapChange called but already waiting for map change. Blocking... (%f, %s, %s)", delay, map, reason);
return;
}

g_bWaitingForChange = true;
SetNextMap(map);

DataPack dp;
CreateDataTimer(delay, Timer_ChangeMap, dp);
dp.WriteString(map);
dp.WriteString(reason);
}

int ExplodeCvar(ConVar cvar, char[][] buffers, int maxStrings, int maxStringLength)
{
char cvarstring[2048];
Expand Down Expand Up @@ -952,11 +972,7 @@ void DoMapChangeAfterMapVote(char map[PLATFORM_MAX_PATH], char displayName[PLATF
Call_Finish();
}

DataPack data;
CreateDataTimer(MapChangeDelay(), Timer_ChangeMap, data);
data.WriteString(map);
data.WriteString("RTV Mapvote");
// ClearRTV();
StartMapChange(MapChangeDelay(), map, "RTV Mapvote");
}

g_bMapVoteStarted = false;
Expand Down Expand Up @@ -1397,6 +1413,7 @@ public Action Timer_ChangeMap(Handle timer, DataPack data)
data.ReadString(map, sizeof(map));
data.ReadString(reason, sizeof(reason));

//LogError("Timer_ChangeMap(%s, %s)", map, reason);
ForceChangeLevel(map, reason);
return Plugin_Stop;
}
Expand Down Expand Up @@ -1733,10 +1750,7 @@ public int MapsMenuHandler(Menu menu, MenuAction action, int param1, int param2)
ShowActivity2(param1, g_cPrefix, "%t", "Changing map", map);
LogAction(param1, -1, "\"%L\" changed map to \"%s\"", param1, map);

DataPack dp;
CreateDataTimer(MapChangeDelay(), Timer_ChangeMap, dp);
dp.WriteString(map);
dp.WriteString("sm_map");
StartMapChange(MapChangeDelay(), map, "sm_map (MapsMenuHandler)");
}
else if (action == MenuAction_End)
{
Expand Down Expand Up @@ -1891,6 +1905,9 @@ public Action Command_RockTheVote(int client, int args)

int CheckRTV(int client = 0)
{
if (g_bWaitingForChange)
return 0;

int needed, rtvcount, total;
GetRTVStuff(total, needed, rtvcount);
char name[MAX_NAME_LENGTH];
Expand Down Expand Up @@ -1922,11 +1939,7 @@ int CheckRTV(int client = 0)
PrintToChatAll("%sRTV vote now majority, map changing to %s ...", g_cPrefix, map);
}

SetNextMap(map);
DataPack data;
CreateDataTimer(MapChangeDelay(), Timer_ChangeMap, data);
data.WriteString(map);
data.WriteString("rtv after map vote");
StartMapChange(MapChangeDelay(), map, "rtv after map vote");
}
else
{
Expand Down Expand Up @@ -2063,11 +2076,7 @@ public void FindUnzonedMapCallback(Database db, DBResultSet results, const char[
if (foundMap)
{
Shavit_PrintToChatAll("Loading unzoned map %s", buffer);

DataPack dp;
CreateDataTimer(1.0, Timer_ChangeMap, dp);
dp.WriteString(buffer);
dp.WriteString("sm_loadunzonedmap");
StartMapChange(1.0, buffer, "sm_loadunzonedmap");
}
}

Expand All @@ -2082,11 +2091,7 @@ public Action Command_LoadUnzonedMap(int client, int args)
public Action Command_ReloadMap(int client, int args)
{
PrintToChatAll("%sReloading current map..", g_cPrefix);
DataPack dp;
CreateDataTimer(MapChangeDelay(), Timer_ChangeMap, dp);
dp.WriteString(g_cMapName);
dp.WriteString("sm_reloadmap");

StartMapChange(MapChangeDelay(), g_cMapName, "sm_reloadmap");
return Plugin_Handled;
}

Expand Down Expand Up @@ -2172,10 +2177,7 @@ public Action BaseCommands_Command_Map_Menu(int client, int args)
ShowActivity2(client, g_cPrefix, "%t", "Changing map", map);
LogAction(client, -1, "\"%L\" changed map to \"%s\"", client, map);

DataPack dp;
CreateDataTimer(MapChangeDelay(), Timer_ChangeMap, dp);
dp.WriteString(map);
dp.WriteString("sm_map");
StartMapChange(MapChangeDelay(), map, "sm_map (BaseCommands_Command_Map_Menu)");
}
default:
{
Expand Down Expand Up @@ -2258,10 +2260,7 @@ public Action BaseCommands_Command_Map(int client, int args)
ShowActivity2(client, g_cPrefix, "%t", "Changing map", displayName);
LogAction(client, -1, "\"%L\" changed map to \"%s\"", client, map);

DataPack dp;
CreateDataTimer(MapChangeDelay(), Timer_ChangeMap, dp);
dp.WriteString(map);
dp.WriteString("sm_map");
StartMapChange(MapChangeDelay(), map, "sm_map (BaseCommands_Command_Map)");

return Plugin_Handled;
}
Expand Down

1 comment on commit d69bd18

@azalty
Copy link
Contributor

@azalty azalty commented on d69bd18 Sep 10, 2023

Choose a reason for hiding this comment

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

Good fix, nice that you managed to find the problem

Please sign in to comment.