reworking the patchwork for rtv so it should seem normal. hopefully no more bugs

This commit is contained in:
jenz 2024-09-29 15:03:09 +02:00
parent 04e56aeeaa
commit 27dbbc9294
2 changed files with 22 additions and 22 deletions

View File

@ -143,8 +143,8 @@ bool g_ChangeMapInProgress;
bool g_HasIntermissionStarted = false; bool g_HasIntermissionStarted = false;
bool g_SaveCDOnMapEnd = true; bool g_SaveCDOnMapEnd = true;
bool g_DidNotExtend = false; bool g_DidNotExtend = false;
bool g_DidRoundTerminate = false;
bool g_IniatedLastVote = false; bool g_IniatedLastVote = false;
bool g_bNoLongerRTV = false;
int g_mapFileSerial = -1; int g_mapFileSerial = -1;
int g_iPlayerCount_excludeSpec; int g_iPlayerCount_excludeSpec;
int g_iMapsFromCasualPool; int g_iMapsFromCasualPool;
@ -512,11 +512,11 @@ public Action GetInternalGetCvars(Handle timer)
public void OnMapStart() public void OnMapStart()
{ {
g_bNoLongerRTV = false;
CreateTimer(1.0, GetInternalGetCvars); CreateTimer(1.0, GetInternalGetCvars);
int total_time = (GetConVarInt(g_Cvar_VoteDuration) * 2) + GetConVarInt(g_Cvar_RunOffWarningTime) + 10; int total_time = (GetConVarInt(g_Cvar_VoteDuration) * 2) + GetConVarInt(g_Cvar_RunOffWarningTime) + 10;
ServerCommand("sm_cvar mp_chattime %i", total_time); //prevents map switching supposedly. ServerCommand("sm_cvar mp_chattime %i", total_time); //prevents map switching supposedly.
g_DidRoundTerminate = false;
g_IniatedLastVote = false; g_IniatedLastVote = false;
g_DidNotExtend = false; g_DidNotExtend = false;
ServerCommand("sm_cvar sm_vote_progress_hintbox 1"); //yeah its cheesy but does the job. ServerCommand("sm_cvar sm_vote_progress_hintbox 1"); //yeah its cheesy but does the job.
@ -615,6 +615,7 @@ public void OnConfigsExecuted()
public void OnMapEnd() public void OnMapEnd()
{ {
g_bNoLongerRTV = false;
int total_time = (GetConVarInt(g_Cvar_VoteDuration) * 2) + GetConVarInt(g_Cvar_RunOffWarningTime) + 10; int total_time = (GetConVarInt(g_Cvar_VoteDuration) * 2) + GetConVarInt(g_Cvar_RunOffWarningTime) + 10;
ServerCommand("sm_cvar mp_chattime %i", total_time); ServerCommand("sm_cvar mp_chattime %i", total_time);
@ -623,7 +624,6 @@ public void OnMapEnd()
g_iInterval = 0; g_iInterval = 0;
g_HasVoteStarted = false; g_HasVoteStarted = false;
g_WaitingForVote = false; g_WaitingForVote = false;
g_DidRoundTerminate = false;
g_IniatedLastVote = false; g_IniatedLastVote = false;
g_ChangeMapAtRoundEnd = false; g_ChangeMapAtRoundEnd = false;
g_ChangeMapInProgress = false; g_ChangeMapInProgress = false;
@ -990,18 +990,14 @@ public void Event_WeaponRank(Handle event, const char[] name, bool dontBroadcast
public Action CS_OnTerminateRound(float &delay, CSRoundEndReason &reason) public Action CS_OnTerminateRound(float &delay, CSRoundEndReason &reason)
{ {
char map[PLATFORM_MAX_PATH]; char map[PLATFORM_MAX_PATH];
if (GetNextMap(map, sizeof(map))) //a nextmap is already set, no votes should be done. //why does initiating rtv set a next map dxxxxxxxxxx
if (GetNextMap(map, sizeof(map)) && !g_bNoLongerRTV) //a nextmap is already set, no votes should be done.
{ {
return Plugin_Continue; return Plugin_Continue;
} }
int timeleft; int timeleft;
GetMapTimeLeft(timeleft); GetMapTimeLeft(timeleft);
if (g_WaitingForVote && timeleft <= 0)
{
g_DidRoundTerminate = true;
return Plugin_Handled; //it keeps retriggering this Action.
}
if (g_IniatedLastVote) if (g_IniatedLastVote)
{ {
return Plugin_Handled; //just extra safety check return Plugin_Handled; //just extra safety check
@ -1020,6 +1016,7 @@ public Action CS_OnTerminateRound(float &delay, CSRoundEndReason &reason)
CreateTimer(float(total_time + 10), Timer_fall_back_map_switch, INVALID_HANDLE, TIMER_FLAG_NO_MAPCHANGE); CreateTimer(float(total_time + 10), Timer_fall_back_map_switch, INVALID_HANDLE, TIMER_FLAG_NO_MAPCHANGE);
//sometimes it will simply happen that theres a mapvote where nobody votes anything. //sometimes it will simply happen that theres a mapvote where nobody votes anything.
//have to prevent server from being stuck in those situations with this timer. //have to prevent server from being stuck in those situations with this timer.
InitiateVote(MapChange_Instant); //feature so mapvote happens at actual mapend InitiateVote(MapChange_Instant); //feature so mapvote happens at actual mapend
CreateTimer(1.0, unfreeze_players, INVALID_HANDLE, TIMER_FLAG_NO_MAPCHANGE); CreateTimer(1.0, unfreeze_players, INVALID_HANDLE, TIMER_FLAG_NO_MAPCHANGE);
@ -1028,7 +1025,6 @@ public Action CS_OnTerminateRound(float &delay, CSRoundEndReason &reason)
delay = float(total_time); delay = float(total_time);
return Plugin_Changed; return Plugin_Changed;
} }
g_DidRoundTerminate = false;
return Plugin_Continue; return Plugin_Continue;
} }
@ -1057,13 +1053,12 @@ public void Event_RoundEnd(Handle event, const char[] name, bool dontBroadcast)
int timeleft; int timeleft;
GetMapTimeLeft(timeleft); GetMapTimeLeft(timeleft);
char map[PLATFORM_MAX_PATH]; char map[PLATFORM_MAX_PATH];
if (GetNextMap(map, sizeof(map)) && timeleft <= 0) //a nextmap is already set, if its also the last round we need to change the map. if (GetNextMap(map, sizeof(map)) && timeleft <= 0 && !g_bNoLongerRTV) //a nextmap is already set, if its also the last round we need to change the map.
{ {
g_ChangeMapAtRoundEnd = true; g_ChangeMapAtRoundEnd = true;
} }
g_DidRoundTerminate = false; if (g_ChangeMapAtRoundEnd)
if(g_ChangeMapAtRoundEnd)
{ {
GetNextMap(map, sizeof(map)); GetNextMap(map, sizeof(map));
PrintToChatAll("[MCE] Next Map: %s", map); PrintToChatAll("[MCE] Next Map: %s", map);
@ -1071,10 +1066,10 @@ public void Event_RoundEnd(Handle event, const char[] name, bool dontBroadcast)
PrintToChatAll("[MCE] Next Map: %s", map); PrintToChatAll("[MCE] Next Map: %s", map);
} }
if(g_RoundCounting == RoundCounting_ArmsRace) if (g_RoundCounting == RoundCounting_ArmsRace)
return; return;
if(g_ChangeMapAtRoundEnd && !g_IniatedLastVote) if (g_ChangeMapAtRoundEnd && !g_IniatedLastVote)
{ {
g_ChangeMapAtRoundEnd = false; g_ChangeMapAtRoundEnd = false;
CreateTimer(2.0, Timer_ChangeMap, INVALID_HANDLE, TIMER_FLAG_NO_MAPCHANGE); CreateTimer(2.0, Timer_ChangeMap, INVALID_HANDLE, TIMER_FLAG_NO_MAPCHANGE);
@ -1732,9 +1727,10 @@ public void Handler_VoteFinishedGeneric(char[] map,
} }
else if(strcmp(map, VOTE_DONTCHANGE, false) == 0) else if(strcmp(map, VOTE_DONTCHANGE, false) == 0)
{ {
PrintToChatAll("Current map continues! The Vote has spoken! (Received %i%s of votes)", RoundToFloor((map_votes /num_votes)*100.0), "%"); PrintToChatAll("[MCE] Current map continues! The Vote has spoken! (Received %i%s of votes)", RoundToFloor((map_votes /num_votes)*100.0), "%");
LogAction(-1, -1, "Voting for next map has finished. 'No Change' was the winner"); LogAction(-1, -1, "Voting for next map has finished. 'No Change' was the winner");
g_bNoLongerRTV = true;
g_RunoffCount = 0; g_RunoffCount = 0;
g_HasVoteStarted = false; g_HasVoteStarted = false;
SetupTimeleftTimer(); SetupTimeleftTimer();
@ -1746,8 +1742,7 @@ public void Handler_VoteFinishedGeneric(char[] map,
//SetNextMap(map); //feature edit where MapChange_MapEnd is only used to decide if extend or not extend //SetNextMap(map); //feature edit where MapChange_MapEnd is only used to decide if extend or not extend
g_DidNotExtend = true; //just so warningtimer wont start running again if an admin removes or adds time when players voted to not extend. g_DidNotExtend = true; //just so warningtimer wont start running again if an admin removes or adds time when players voted to not extend.
} }
else if(g_ChangeTime == MapChange_Instant || g_DidRoundTerminate) //g_DidRoundTerminate implies that rtv vote is running while the last round already ended. else if(g_ChangeTime == MapChange_Instant)
//therefore rtv vote has to switch map right now instead of roundend.
{ {
PrintToChatAll("[MCE] Next Map: %s", map); PrintToChatAll("[MCE] Next Map: %s", map);
PrintToChatAll("[MCE] Next Map: %s", map); PrintToChatAll("[MCE] Next Map: %s", map);
@ -1759,6 +1754,7 @@ public void Handler_VoteFinishedGeneric(char[] map,
} }
else // MapChange_RoundEnd else // MapChange_RoundEnd
{ {
g_bNoLongerRTV = false;
SetNextMap(map); SetNextMap(map);
g_ChangeMapAtRoundEnd = true; g_ChangeMapAtRoundEnd = true;
} }
@ -2259,7 +2255,9 @@ void CreateNextVote()
bool CanVoteStart() bool CanVoteStart()
{ {
if(g_WaitingForVote || g_HasVoteStarted) if(g_WaitingForVote || g_HasVoteStarted)
{
return false; return false;
}
return true; return true;
} }
@ -2449,12 +2447,13 @@ public int Native_InitiateVote(Handle plugin, int numParams)
MapChange when = view_as<MapChange>(GetNativeCell(1)); MapChange when = view_as<MapChange>(GetNativeCell(1));
Handle inputarray = view_as<Handle>(GetNativeCell(2)); Handle inputarray = view_as<Handle>(GetNativeCell(2));
LogAction(-1, -1, "Starting map vote because outside request");
int timeleft; int timeleft;
GetMapTimeLeft(timeleft); GetMapTimeLeft(timeleft);
if (timeleft <= 0 && !g_ChangeMapAtRoundEnd) //somehow a random vote might get triggered. this should prevent it int total_time = (GetConVarInt(g_Cvar_VoteDuration) * 2) + GetConVarInt(g_Cvar_RunOffWarningTime) + 10;
if (timeleft <= total_time)
{ {
g_bNoLongerRTV = true; //somehow rtv sets the nextmap so this extra bool is needed
PrintToChatAll("[RTVE] Rock the vote was cancelled due to not enough time left over.");
return 0; return 0;
} }
if (!g_IniatedLastVote) if (!g_IniatedLastVote)
@ -2466,6 +2465,7 @@ public int Native_InitiateVote(Handle plugin, int numParams)
return 0; return 0;
} }
//CanMapChooserStartVote
public int Native_CanVoteStart(Handle plugin, int numParams) public int Native_CanVoteStart(Handle plugin, int numParams)
{ {
return CanVoteStart(); return CanVoteStart();

View File

@ -423,7 +423,6 @@ void StartRTV()
return; return;
} }
PrintToChatAll("Rock The Vote has begun!");
if (EndOfMapVoteEnabled() && HasEndOfMapVoteFinished()) if (EndOfMapVoteEnabled() && HasEndOfMapVoteFinished())
{ {
@ -446,6 +445,7 @@ void StartRTV()
if (CanMapChooserStartVote()) if (CanMapChooserStartVote())
{ {
PrintToChatAll("[RTVE] Rock The Vote has begun!");
MapChange when = view_as<MapChange>(g_Cvar_ChangeTime.IntValue); MapChange when = view_as<MapChange>(g_Cvar_ChangeTime.IntValue);
InitiateMapChooserVote(when); InitiateMapChooserVote(when);