- Added ForceChangeLevel and Map History to nextmap api

- Changed base plugins to use new api
- Added sm_maphistory command to nextmap.sp

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%402413
This commit is contained in:
Matt Woodrow
2008-07-13 05:13:37 +00:00
parent 8126aa6bb8
commit c75d607a00
10 changed files with 329 additions and 11 deletions
+1 -1
View File
@@ -109,7 +109,7 @@ public Action:Timer_ChangeMap(Handle:timer, Handle:dp)
ResetPack(dp);
ReadPackString(dp, map, sizeof(map));
ServerCommand("changelevel \"%s\"", map);
ForceChangeLevel(map, "sm_map Command");
return Plugin_Stop;
}
+3 -3
View File
@@ -54,9 +54,9 @@ new Handle:g_Cvar_WinLimit = INVALID_HANDLE;
new Handle:g_Cvar_FragLimit = INVALID_HANDLE;
new Handle:g_Cvar_MaxRounds = INVALID_HANDLE;
#define TIMELEFT_ALL_ALWAYS 0
#define TIMELEFT_ALL_MAYBE 1
#define TIMELEFT_ONE 2
#define TIMELEFT_ALL_ALWAYS 0 /* Print to all players */
#define TIMELEFT_ALL_MAYBE 1 /* Print to all players if sm_trigger_show allows */
#define TIMELEFT_ONE 2 /* Print to a single player */
public OnPluginStart()
{
+1 -1
View File
@@ -424,7 +424,7 @@ public Action:Timer_ChangeMap(Handle:timer, Handle:dp)
ResetPack(dp);
ReadPackString(dp, mapname, sizeof(mapname));
ServerCommand("changelevel \"%s\"", mapname);
ForceChangeLevel(mapname, "sm_votemap Result");
return Plugin_Stop;
}
+31 -1
View File
@@ -51,4 +51,34 @@ native bool:SetNextMap(const String:map[]);
* @param maxlen Maximum length of the map buffer.
* @return True if a Map was found and copied, false if no nextmap is set (map will be unchanged).
*/
native bool:GetNextMap(String:map[], maxlen);
native bool:GetNextMap(String:map[], maxlen);
/**
* Changes the current map and records the reason for the change with maphistory
*
* @param map Map to change to.
* @param reason Reason for change.
* @noreturn
*/
native ForceChangeLevel(const String:map[], const String:reason[]);
/**
* Gets the current number of maps in the map history
*
* @return Number of maps.
*/
native GetMapHistorySize();
/**
* Retrieves a map from the map history list.
*
* @param item Item number. Must be 0 or greater and less than GetMapHistorySize().
* @param map Buffer to store the map name.
* @param mapLen Length of map buffer.
* @param reason Buffer to store the change reason.
* @param reasonLen Length of the reason buffer.
* @param startTime Time the map started.
* @noreturn
* @error Invalid item number.
*/
native GetMapHistory(item, String:map[], mapLen, String:reason[], reasonLen, &startTime);
+1 -1
View File
@@ -771,7 +771,7 @@ public Action:Timer_ChangeMap(Handle:hTimer, Handle:dp)
ReadPackString(dp, map, sizeof(map));
}
ServerCommand("changelevel \"%s\"", map);
ForceChangeLevel(map, "Map Vote");
return Plugin_Stop;
}
+64
View File
@@ -51,6 +51,8 @@ public Plugin:myinfo =
new g_MapPos = -1;
new Handle:g_MapList = INVALID_HANDLE;
new g_MapListSerial = -1;
new g_CurrentMapStartTime;
public OnPluginStart()
{
@@ -65,6 +67,7 @@ public OnPluginStart()
RegConsoleCmd("nextmap", Command_Nextmap);
RegAdminCmd("sm_setnextmap", Command_SetNextmap, ADMFLAG_CHANGEMAP, "sm_setnextmap <map>");
RegAdminCmd("sm_maphistory", Command_MapHistory, ADMFLAG_CHANGEMAP, "Shows the most recent maps played");
RegConsoleCmd("listmaps", Command_List);
// Set to the current map so OnMapStart() will know what to do
@@ -72,6 +75,11 @@ public OnPluginStart()
GetCurrentMap(currentMap, 64);
SetNextMap(currentMap);
}
public OnMapStart()
{
g_CurrentMapStartTime = GetTime();
}
public OnConfigsExecuted()
{
@@ -228,3 +236,59 @@ FindAndSetNextMap()
GetArrayString(g_MapList, g_MapPos, mapName, sizeof(mapName));
SetNextMap(mapName);
}
public Action:Command_MapHistory(client, args)
{
new mapCount = GetMapHistorySize();
decl String:mapName[32];
decl String:changeReason[100];
decl String:timeString[100];
decl String:playedTime[100];
new startTime;
new lastMapStartTime = g_CurrentMapStartTime;
PrintToConsole(client, "Map History:\n");
PrintToConsole(client, "Map : Started : Played Time : Reason for ending");
GetCurrentMap(mapName, sizeof(mapName));
PrintToConsole(client, "%02i. %s (Current Map)", 0, mapName);
for (new i=0; i<mapCount; i++)
{
GetMapHistory(i, mapName, sizeof(mapName), changeReason, sizeof(changeReason), startTime);
FormatTimeDuration(timeString, sizeof(timeString), GetTime() - startTime);
FormatTimeDuration(playedTime, sizeof(playedTime), lastMapStartTime - startTime);
PrintToConsole(client, "%02i. %s : %s ago : %s : %s", i+1, mapName, timeString, playedTime, changeReason);
lastMapStartTime = startTime;
}
}
FormatTimeDuration(String:buffer[], maxlen, time)
{
new days = time / 86400;
new hours = (time / 3600) % 24;
new minutes = (time / 60) % 60;
new seconds = time % 60;
if (days > 0)
{
Format(buffer, maxlen, "%id %ih %im", days, hours, (seconds >= 30) ? minutes+1 : minutes);
}
else if (hours > 0)
{
Format(buffer, maxlen, "%ih %im", hours, (seconds >= 30) ? minutes+1 : minutes);
}
else if (minutes > 0)
{
Format(buffer, maxlen, "%im", (seconds >= 30) ? minutes+1 : minutes);
}
else
{
Format(buffer, maxlen, "%is", seconds);
}
}
+1 -1
View File
@@ -298,7 +298,7 @@ public Action:Timer_ChangeMap(Handle:hTimer)
new String:map[65];
if (GetNextMap(map, sizeof(map)))
{
ServerCommand("changelevel \"%s\"", map);
ForceChangeLevel(map, "RTV after mapvote");
}
return Plugin_Stop;