Commit 63e78b04 authored by Neoony's avatar Neoony
Browse files

v0.2 -Extended default vote duration from 15 to 30 seconds -Extended preferred...

v0.2 -Extended default vote duration from 15 to 30 seconds -Extended preferred server duration from 5 to 10 minutes (to 600 seconds) -Adjusted default minplayers needed for preferred server from 1 to 4 -Added sound before the vote starts -Reduce number of characters in vote menu by only showing max players number -Added Vote Status with HUD message -Few bugfixes
parent ddea3503
Pipeline #10095 passed with stages
in 6 minutes and 28 seconds
......@@ -58,4 +58,13 @@
- Added HUD messages
**v0.1.1**
- Small bugfix
\ No newline at end of file
- Small bugfix
**v0.2**
- Extended default vote duration from 15 to 30 seconds
- Extended preferred server duration from 5 to 10 minutes (to 600 seconds)
- Adjusted default minplayers needed for preferred server from 1 to 4
- Added sound before the vote starts
- Reduce number of characters in vote menu by only showing max players number
- Added Vote Status with HUD message
- Few bugfixes
\ No newline at end of file
......@@ -621,7 +621,7 @@ copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
{Lobby} {Create a vote to join a server on certain player count}
Copyright (C) {2019} {Neoony}
Copyright (C) {2020} {Neoony}
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......
......@@ -3,7 +3,7 @@
#**This plugin is not designed for public use**
##Download latest version: [Download link](https://git.empiresmod.com/sourcemod/Lobby/-/jobs/artifacts/master/download?job=build)
#Download latest version: [Download link](https://git.empiresmod.com/sourcemod/Lobby/-/jobs/artifacts/master/download?job=build)
*Created by* **Neoony**
--
......@@ -42,7 +42,7 @@ https://forums.alliedmods.net/showthread.php?t=152216
**"l_minplayersext"** *"def. 8"*
*"How many players needed on external server / active server. (Players)"*
**"l_votetimer"** *"def.15"*
**"l_votetimer"** *"def.30"*
*"How long to keep the vote for (Seconds)"*
**"l_threshold"** *"def. 50"*
......@@ -51,10 +51,10 @@ https://forums.alliedmods.net/showthread.php?t=152216
**"l_restrictvote"** *"def. 30"*
*"For how long to restrict the vote starting, after a vote happened (Seconds)"*
**"l_preferredservertimer"** *"def. 300"*
**"l_preferredservertimer"** *"def. 600"*
*"For how long should the chosen server from voting be preferred for (Seconds) (It will also become unpreferred if the player number becomes 0)"*
**"l_preferredservermp"** *"def. 1"*
**"l_preferredservermp"** *"def. 4"*
*"Minimum players for chosen by a vote preferred server needed"*
**"l_backupserver"** *"def. 185.165.242.40:17701"*
......
// {Lobby} {Create a vote to join a server on certain player count}
// Copyright (C) {2019} {Neoony}
// Copyright (C) {2020} {Neoony}
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
......@@ -22,7 +22,7 @@
#include <socket>
#include <cURL>
#define PluginVer "v0.1.1"
#define PluginVer "v0.2"
public Plugin myinfo =
{
......@@ -54,6 +54,8 @@ int PlayersNumber;
int votestarted = 0;
int rowCount;
int StartVoteCounterLeft = 5;
Handle PlayerCountCheck;
Handle StartVoteTimer;
Handle ConnectDialogTimer;
......@@ -62,6 +64,7 @@ Handle RestrictVoteHowLong;
int RestrictVoteSecondsLeft;
bool VoteSuccessfulRedirecting = false;
Handle StartVoteTimeleftTimer = INVALID_HANDLE;
Handle StartVoteCountTimer = INVALID_HANDLE;
int StartVoteTimeleft;
Handle VoteHandle = INVALID_HANDLE;
Handle Timer1[MAXPLAYERS+1] = INVALID_HANDLE;
......@@ -92,6 +95,12 @@ char mapx[10][256];
char ServerVoteItem[10][256];
//Votestatus
char VoteStatusText[1024];
int VotesCount[10];
bool ClientVoted[MAXPLAYERS+1] = false;
int ClientVotedOption[MAXPLAYERS+1];
char redirectAddress[128];
char ForceRedirectAddr[256];
......@@ -167,11 +176,11 @@ public void OnPluginStart()
//l_lobbyenabled = CreateConVar("l_lobbyenabled", "1", "Enable(1)/Disable(0) lobby plugin");
l_minplayers = CreateConVar("l_minplayers", "8", "How many players required to start a vote about joining another server. (Players who selected a team)");
l_minplayersext = CreateConVar("l_minplayersext", "8", "How many players needed on external server / active server. (Players)");
l_votetimer = CreateConVar("l_votetimer", "15", "How long to keep the vote for (Seconds)");
l_votetimer = CreateConVar("l_votetimer", "30", "How long to keep the vote for (Seconds)");
l_threshold = CreateConVar("l_threshold", "50", "Percantage needed for successful vote (Percentage, max 100)");
l_restrictvote = CreateConVar("l_restrictvote", "30", "For how long to restrict the vote starting, after a vote happened (Seconds)");
l_preferredservertimer = CreateConVar("l_preferredservertimer", "300", "For how long should the chosen server from voting be preferred for (Seconds) (It will also become unpreferred if the player number becomes 0)");
l_preferredservermp = CreateConVar("l_preferredservermp", "1", "Minimum players for chosen by a vote preferred server needed");
l_preferredservertimer = CreateConVar("l_preferredservertimer", "600", "For how long should the chosen server from voting be preferred for (Seconds) (It will also become unpreferred if the player number becomes 0)");
l_preferredservermp = CreateConVar("l_preferredservermp", "4", "Minimum players for chosen by a vote preferred server needed");
//l_restrictvotestay = CreateConVar("l_restrictvotestay", "300", "For how long to restrict the vote after players choose to stay in the lobby (Seconds)");
l_backupserver = CreateConVar("l_backupserver", "185.165.242.40:17701", "IP of the server to get redirected into, in case of failing to connect to DB, or if no servers are found (IP:PORT)");
......@@ -568,7 +577,7 @@ public void RedirectToPopulatedServerCallback(Handle hDriver, Handle hResult, co
//HUD message
SetHudTextParams(-1.0, 0.03, 15.0, 255, 0, 0, 255, 2, 0.1, 0.03, 0.03);
for(int i = 1;i<MaxClients;i++)
for(int i = 1;i<=MaxClients;i++)
{
if(IsClientInGame(i))
{
......@@ -645,6 +654,9 @@ public OnMapStart()
PrintToServer("[L]Start of the map.");
}
AutoExecConfig(true, "Lobby");
PrecacheSound("vehicles/missile/lock2.wav");
PrecacheSound("vehicles/missile/lock3.wav");
}
public OnMapEnd()
......@@ -699,6 +711,13 @@ public OnMapEnd()
KillTimer(StartVoteTimeleftTimer);
StartVoteTimeleftTimer = INVALID_HANDLE;
}
//Clear timer
if (StartVoteCountTimer != INVALID_HANDLE)
{
KillTimer(StartVoteCountTimer);
StartVoteCountTimer = INVALID_HANDLE;
}
/*
//Clear timer
......@@ -757,16 +776,24 @@ void Event_GameEnd(Handle event, const char[] name, bool dontBroadcast)
}
//Clear timer
if (StartVoteTimer != INVALID_HANDLE)
if (StartVoteCountTimer != INVALID_HANDLE)
{
KillTimer(StartVoteTimer);
StartVoteTimer = INVALID_HANDLE;
KillTimer(StartVoteCountTimer);
StartVoteCountTimer = INVALID_HANDLE;
}
if (StartVoteTimeleftTimer != INVALID_HANDLE)
{
KillTimer(StartVoteTimeleftTimer);
StartVoteTimeleftTimer = INVALID_HANDLE;
}
//Clear timer
if (StartVoteTimer != INVALID_HANDLE)
{
KillTimer(StartVoteTimer);
StartVoteTimer = INVALID_HANDLE;
}
/*
//Clear timer
......@@ -807,6 +834,13 @@ public void OnConfigsExecuted()
RestrictVoteHowLong = INVALID_HANDLE;
}
//Clear timer
if (StartVoteCountTimer != INVALID_HANDLE)
{
KillTimer(StartVoteCountTimer);
StartVoteCountTimer = INVALID_HANDLE;
}
//Clear timer
if (StartVoteTimer != INVALID_HANDLE)
{
......@@ -1141,7 +1175,7 @@ public void PlayersNumberCheck()
{
//HUD message
SetHudTextParams(-1.0, 0.0, 10.0, 121, 93, 20, 255, 2, 0.5, 0.1, 0.1);
for(int i = 1;i<MaxClients;i++)
for(int i = 1;i<=MaxClients;i++)
{
if(IsClientInGame(i))
{
......@@ -1153,7 +1187,7 @@ public void PlayersNumberCheck()
{
//HUD message
SetHudTextParams(-1.0, 0.0, 10.0, 121, 93, 20, 255);
for(int i = 1;i<MaxClients;i++)
for(int i = 1;i<=MaxClients;i++)
{
if(IsClientInGame(i))
{
......@@ -1166,7 +1200,7 @@ public void PlayersNumberCheck()
{
//HUD message
SetHudTextParams(-1.0, 0.0, 10.0, 121, 93, 20, 255, 2, 0.5, 0.1, 0.1);
for(int i = 1;i<MaxClients;i++)
for(int i = 1;i<=MaxClients;i++)
{
if(IsClientInGame(i))
{
......@@ -1178,7 +1212,7 @@ public void PlayersNumberCheck()
{
//HUD message
SetHudTextParams(-1.0, 0.0, 10.0, 121, 93, 20, 255);
for(int i = 1;i<MaxClients;i++)
for(int i = 1;i<=MaxClients;i++)
{
if(IsClientInGame(i))
{
......@@ -1205,12 +1239,25 @@ public void PlayersNumberReached()
PrintToChatAll("\x04[L] \x01Player amount required has been reached");
PrintToChatAll("\x04[L] \x01Creating a vote to join a server in\x073399ff 5\x01 seconds");
StartVoteTimer = CreateTimer(5.0, StartVoteTmr, _, TIMER_REPEAT);
QueryNumberOfServers();
votestarted = 1;
EmitSoundToAll("vehicles/missile/lock2.wav", _, _, 50);
//Clear timer
if (StartVoteCountTimer != INVALID_HANDLE)
{
KillTimer(StartVoteCountTimer);
StartVoteCountTimer = INVALID_HANDLE;
}
StartVoteCounterLeft = 5;
StartVoteCountTimer = CreateTimer(1.0, StartVoteCountTmr, _, TIMER_REPEAT);
//HUD message
SetHudTextParams(-1.0, 0.0, 10.0, 0, 255, 0, 255);
for(int i = 1;i<MaxClients;i++)
for(int i = 1;i<=MaxClients;i++)
{
if(IsClientInGame(i))
{
......@@ -1228,19 +1275,44 @@ public Action StartVoteTmr(Handle timer)
KillTimer(StartVoteTimer);
StartVoteTimer = INVALID_HANDLE;
}
//Clear timer
if (StartVoteCountTimer != INVALID_HANDLE)
{
KillTimer(StartVoteCountTimer);
StartVoteCountTimer = INVALID_HANDLE;
}
StartVote();
StartVoteTimeleftTimer = CreateTimer(1.0, StartVoteTimeleftTmr, _, TIMER_REPEAT);
StartVoteTimeleft = GetConVarInt(l_votetimer);
}
public Action StartVoteCountTmr(Handle timer)
{
//Clear timer
if (StartVoteCountTimer != INVALID_HANDLE)
{
KillTimer(StartVoteCountTimer);
StartVoteCountTimer = INVALID_HANDLE;
}
StartVoteCounterLeft = StartVoteCounterLeft - 1;
if (StartVoteCounterLeft >= 1)
{
PrintToChatAll("\x04[L] \x01Server vote starts in\x073399ff %i\x01 seconds", StartVoteCounterLeft);
EmitSoundToAll("vehicles/missile/lock2.wav", _, _, 50);
StartVoteCountTimer = CreateTimer(1.0, StartVoteCountTmr, _, TIMER_REPEAT);
}
}
public Action StartVoteTimeleftTmr(Handle timer)
{
StartVoteTimeleft = StartVoteTimeleft - 1;
//HUD message
SetHudTextParams(-1.0, 0.0, 999.0, 0, 255, 0, 255);
for(int i = 1;i<MaxClients;i++)
for(int i = 1;i<=MaxClients;i++)
{
if(IsClientInGame(i))
{
......@@ -1251,6 +1323,27 @@ public Action StartVoteTimeleftTmr(Handle timer)
public Action StartVote()
{
//Clear timer
if (StartVoteCountTimer != INVALID_HANDLE)
{
KillTimer(StartVoteCountTimer);
StartVoteCountTimer = INVALID_HANDLE;
}
EmitSoundToAll("vehicles/missile/lock3.wav", _, _, 50);
PrintToChatAll("\x04[L] \x01Server vote \x07008000started");
//Reset Votes Count
for (int i = 0; i <= 9; i++)
{
VotesCount[i] = 0;
}
for (int i = 1; i <= MaxClients; i++)
{
ClientVoted[i] = false;
ClientVotedOption[i] = -1;
}
int[] Players = new int[MaxClients+1];
int PlayersCount;
......@@ -1269,20 +1362,98 @@ public Action StartVote()
SetMenuTitle(VoteHandle, "[Lobby] Which server to join?");
SetMenuPagination(VoteHandle, 6);
for(int ServerCount=1; ServerCount<=rowCount; ServerCount++)
{
int ServerIndex = ServerCount - 1;
Format(ServerVoteItem[ServerIndex], 256, "%s [max %s players] [XP %s] \n %s", namex[ServerIndex], maxplayersx[ServerIndex], XPonstring[ServerIndex], mapx[ServerIndex]);
Format(ServerVoteItem[ServerIndex], 256, "%s [%s] [XP %s] \n %s", namex[ServerIndex], maxplayersx[ServerIndex], XPonstring[ServerIndex], mapx[ServerIndex]);
AddMenuItem(VoteHandle, addrx[ServerIndex], ServerVoteItem[ServerIndex]);
//PrintToServer("IP: %s", addrx[ServerIndex]);
}
//InsertMenuItem(VoteHandle, 0, "Stay", "[Stay in lobby](Extend 5 minutes)");
VoteMenu(VoteHandle, Players, PlayersCount, GetConVarInt(l_votetimer));
ShowVoteStatus();
}
public Action ShowVoteStatus()
{
Format(VoteStatusText, 1024, "");
for(int ServerCount=1; ServerCount<=rowCount; ServerCount++)
{
int ServerIndex = ServerCount - 1;
char NameOfServerFormatted[18];
if (VotesCount[ServerIndex] >= 1)
{
int ReturnSplitCheck;
ReturnSplitCheck = SplitString(namex[ServerIndex], " ", NameOfServerFormatted, sizeof(NameOfServerFormatted));
//int NumberOfStrings
//NumberOfStrings = ExplodeString(namex[ServerIndex], " ", char[][] buffers, int maxStrings, int maxStringLength, bool copyRemainder)
if (ReturnSplitCheck == -1)
{
Format(NameOfServerFormatted, sizeof(NameOfServerFormatted), "%s", namex[ServerIndex]);
}
if (StrContains(namex[ServerIndex], "Empires", false) != -1)
{
Format(NameOfServerFormatted, sizeof(NameOfServerFormatted), "%s", namex[ServerIndex]);
}
if (StrContains(namex[ServerIndex], "Hardcore", false) != -1)
{
if (StrContains(namex[ServerIndex], "Main", false) != -1)
{
Format(NameOfServerFormatted, sizeof(NameOfServerFormatted), "Hardcore Main");
}
if (StrContains(namex[ServerIndex], "Backup", false) != -1)
{
Format(NameOfServerFormatted, sizeof(NameOfServerFormatted), "Hardcore Backup");
}
}
Format(VoteStatusText, sizeof(VoteStatusText), "%s%i: %s [%i]\n", VoteStatusText, ServerCount, NameOfServerFormatted, VotesCount[ServerIndex]);
}
}
//HUD message
SetHudTextParams(-1.0, 0.60, 30.0, 219, 178, 54, 255);
for(int i = 1;i<=MaxClients;i++)
{
if(IsClientInGame(i))
{
ShowHudText(i, 4, "%s", VoteStatusText);
}
}
}
int Handle_VoteMenu(Handle menu, MenuAction action, int param1, int param2)
{
if (action == MenuAction_Select)
{
//PrintToChatAll("Client: %i Item: %i", param1, param2);
if (ClientVoted[param1] == true)
{
VotesCount[ClientVotedOption[param1]]--;
ClientVotedOption[param1] = param2;
VotesCount[param2]++;
//PrintToChatAll("%i", ClientVotedOption[param1]);
}
if (ClientVoted[param1] == false)
{
ClientVoted[param1] = true;
ClientVotedOption[param1] = param2;
VotesCount[param2]++;
//PrintToChatAll("%i", ClientVotedOption[param1]);
}
//PrintToChatAll("Client: %i Item: %i", param1, param2);
ShowVoteStatus();
}
if (action == MenuAction_VoteEnd)
{
int Votes;
......@@ -1319,7 +1490,7 @@ int Handle_VoteMenu(Handle menu, MenuAction action, int param1, int param2)
PrintToChatAll("\x04[L] \x01Server\x04 %s\x01 has received\x04 %d\x01(\x07ff6600%d\x01%%%%%) out of total\x04 %d\x01 votes. Required \x07ff6600%d\x01(\x07ff6600%d\x01%%%%%).\x04 %d\x01 people could vote.", namex[param1], Votes, VotesPercent, TotalVotes, NeededVotes, NeededPercent, VoteInfo[VOTE_INFO_NUMCLIENTS]);
//HUD message
SetHudTextParams(-1.0, 0.0, 999.0, 0, 255, 0, 255);
for(int i = 1;i<MaxClients;i++)
for(int i = 1;i<=MaxClients;i++)
{
if(IsClientInGame(i))
{
......@@ -1339,7 +1510,7 @@ int Handle_VoteMenu(Handle menu, MenuAction action, int param1, int param2)
PrintToChatAll("\x04[L] \x01Server vote\x07b30000 failed");
//HUD message
SetHudTextParams(-1.0, 0.0, 999.0, 255, 0, 0, 255);
for(int i = 1;i<MaxClients;i++)
for(int i = 1;i<=MaxClients;i++)
{
if(IsClientInGame(i))
{
......@@ -1368,7 +1539,7 @@ int Handle_VoteMenu(Handle menu, MenuAction action, int param1, int param2)
PrintToChatAll("\x04[L] \x01Server vote\x07b30000 failed");
//HUD message
SetHudTextParams(-1.0, 0.0, 999.0, 255, 0, 0, 255);
for(int i = 1;i<MaxClients;i++)
for(int i = 1;i<=MaxClients;i++)
{
if(IsClientInGame(i))
{
......@@ -1424,7 +1595,7 @@ public Action VoteSuccessful(int param1)
PrintToChatAll("\x04[L] \x01Server has been\x07008000 chosen\x01, players will be redirected in\x073399ff 5\x01 seconds");
//HUD message
SetHudTextParams(-1.0, 0.03, 15.0, 255, 0, 0, 255, 2, 0.1, 0.03, 0.03);
for(int i = 1;i<MaxClients;i++)
for(int i = 1;i<=MaxClients;i++)
{
if(IsClientInGame(i))
{
......@@ -1488,7 +1659,7 @@ public Action RestrictVtHowLong(Handle timer)
{
//HUD message
SetHudTextParams(-1.0, 0.0, 10.0, 255, 0, 0, 255);
for(int i = 1;i<MaxClients;i++)
for(int i = 1;i<=MaxClients;i++)
{
if(IsClientInGame(i))
{
......@@ -2219,7 +2390,7 @@ public void LobbyHud()
{
//HUD message
SetHudTextParams(-1.0, 0.97, 10.0, 255, 255, 255, 255);
for(int i = 1;i<MaxClients;i++)
for(int i = 1;i<=MaxClients;i++)
{
if(IsClientInGame(i))
{
......
......@@ -4,7 +4,7 @@
{
"Version"
{
"Latest" "v0.1.1"
"Latest" "v0.2"
}
"Notes" "Small bugfix"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment