From 46839b9752901abb6238d4c1c9452ec2468ea2ba Mon Sep 17 00:00:00 2001 From: Ross Bemrose Date: Tue, 16 Dec 2014 13:38:43 -0500 Subject: [PATCH 01/12] Update MapChooser to use 1.7 syntax... except there's a bug you run into with Advanced Vote Callbacks. --- plugins/mapchooser.sp | 381 +++++++++++++++++++++--------------------- 1 file changed, 192 insertions(+), 189 deletions(-) diff --git a/plugins/mapchooser.sp b/plugins/mapchooser.sp index 6de66496..fd8b48f2 100644 --- a/plugins/mapchooser.sp +++ b/plugins/mapchooser.sp @@ -37,7 +37,9 @@ #include #include -public Plugin:myinfo = +#pragma newdecls required + +public Plugin myinfo = { name = "MapChooser", author = "AlliedModders LLC", @@ -69,49 +71,49 @@ ConVar g_Cvar_VoteDuration; ConVar g_Cvar_RunOff; ConVar g_Cvar_RunOffPercent; -new Handle:g_VoteTimer = INVALID_HANDLE; -new Handle:g_RetryTimer = INVALID_HANDLE; +Handle g_VoteTimer = null; +Handle g_RetryTimer = null; /* Data Handles */ -new Handle:g_MapList = null; -new Handle:g_NominateList = null; -new Handle:g_NominateOwners = null; -new Handle:g_OldMapList = null; -new Handle:g_NextMapList = null; +ArrayList g_MapList; +ArrayList g_NominateList; +ArrayList g_NominateOwners; +ArrayList g_OldMapList; +ArrayList g_NextMapList; Menu g_VoteMenu; -new g_Extends; -new g_TotalRounds; -new bool:g_HasVoteStarted; -new bool:g_WaitingForVote; -new bool:g_MapVoteCompleted; -new bool:g_ChangeMapAtRoundEnd; -new bool:g_ChangeMapInProgress; -new g_mapFileSerial = -1; +int g_Extends; +int g_TotalRounds; +bool g_HasVoteStarted; +bool g_WaitingForVote; +bool g_MapVoteCompleted; +bool g_ChangeMapAtRoundEnd; +bool g_ChangeMapInProgress; +int g_mapFileSerial = -1; -new MapChange:g_ChangeTime; +MapChange g_ChangeTime; -new Handle:g_NominationsResetForward = null; -new Handle:g_MapVoteStartedForward = null; +Handle g_NominationsResetForward = null; +Handle g_MapVoteStartedForward = null; /* Upper bound of how many team there could be */ #define MAXTEAMS 10 -new g_winCount[MAXTEAMS]; +int g_winCount[MAXTEAMS]; #define VOTE_EXTEND "##extend##" #define VOTE_DONTCHANGE "##dontchange##" -public OnPluginStart() +public void OnPluginStart() { LoadTranslations("mapchooser.phrases"); LoadTranslations("common.phrases"); - new arraySize = ByteCountToCells(PLATFORM_MAX_PATH); - g_MapList = CreateArray(arraySize); - g_NominateList = CreateArray(arraySize); - g_NominateOwners = CreateArray(1); - g_OldMapList = CreateArray(arraySize); - g_NextMapList = CreateArray(arraySize); + int arraySize = ByteCountToCells(PLATFORM_MAX_PATH); + g_MapList = new ArrayList(arraySize); + g_NominateList = new ArrayList(arraySize); + g_NominateOwners = new ArrayList(); + g_OldMapList = new ArrayList(arraySize); + g_NextMapList = new ArrayList(arraySize); g_Cvar_EndOfMapVote = CreateConVar("sm_mapvote_endvote", "1", "Specifies if MapChooser should run an end of map vote", _, true, 0.0, true, 1.0); @@ -177,7 +179,7 @@ public OnPluginStart() g_MapVoteStartedForward = CreateGlobalForward("OnMapVoteStarted", ET_Ignore); } -public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max) +public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max) { RegPluginLibrary("mapchooser"); @@ -194,7 +196,7 @@ public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max) return APLRes_Success; } -public OnConfigsExecuted() +public void OnConfigsExecuted() { if (ReadMapList(g_MapList, g_mapFileSerial, @@ -218,10 +220,10 @@ public OnConfigsExecuted() g_MapVoteCompleted = false; - ClearArray(g_NominateList); - ClearArray(g_NominateOwners); + g_NominateList.ClearArray(); + g_NominateOwners.ClearArray(); - for (new i=0; i g_Cvar_ExcludeMaps.IntValue) + if (g_OldMapList.Length > g_Cvar_ExcludeMaps.IntValue) { - RemoveFromArray(g_OldMapList, 0); + g_OldMapList.Erase(0); } } -public OnClientDisconnect(client) +public void OnClientDisconnect(int client) { - new index = FindValueInArray(g_NominateOwners, client); + int index = g_NominateOwners.FindValue(client); if (index == -1) { return; } - new String:oldmap[PLATFORM_MAX_PATH]; - GetArrayString(g_NominateList, index, oldmap, sizeof(oldmap)); + char oldmap[PLATFORM_MAX_PATH]; + g_NominateList.GetString(index, oldmap, sizeof(oldmap)); Call_StartForward(g_NominationsResetForward); Call_PushString(oldmap); Call_PushCell(GetArrayCell(g_NominateOwners, index)); Call_Finish(); - RemoveFromArray(g_NominateOwners, index); - RemoveFromArray(g_NominateList, index); + g_NominateOwners.Erase(index); + g_NominateList.Erase(index); } -public Action:Command_SetNextmap(client, args) +public Action Command_SetNextmap(int client, int args) { if (args < 1) { @@ -285,7 +287,7 @@ public Action:Command_SetNextmap(client, args) return Plugin_Handled; } - decl String:map[PLATFORM_MAX_PATH]; + char map[PLATFORM_MAX_PATH]; GetCmdArg(1, map, sizeof(map)); if (!IsMapValid(map)) @@ -303,20 +305,20 @@ public Action:Command_SetNextmap(client, args) return Plugin_Handled; } -public OnMapTimeLeftChanged() +public void OnMapTimeLeftChanged() { - if (GetArraySize(g_MapList)) + if (g_MapList.Length) { SetupTimeleftTimer(); } } -SetupTimeleftTimer() +void SetupTimeleftTimer() { - new time; + int time; if (GetMapTimeLeft(time) && time > 0) { - new startTime = g_Cvar_StartTime.IntValue * 60; + int startTime = g_Cvar_StartTime.IntValue * 60; if (time - startTime < 0 && g_Cvar_EndOfMapVote.BoolValue && !g_MapVoteCompleted && !g_HasVoteStarted) { InitiateVote(MapChange_MapEnd, null); @@ -330,16 +332,16 @@ SetupTimeleftTimer() } //g_VoteTimer = CreateTimer(float(time - startTime), Timer_StartMapVote, _, TIMER_FLAG_NO_MAPCHANGE); - new Handle:data; + DataPack data; g_VoteTimer = CreateDataTimer(float(time - startTime), Timer_StartMapVote, data, TIMER_FLAG_NO_MAPCHANGE); - WritePackCell(data, _:MapChange_MapEnd); - WritePackCell(data, _:INVALID_HANDLE); - ResetPack(data); + data.WriteCell(MapChange_MapEnd); + data.WriteCell(view_as(null)); + data.Reset(); } } } -public Action:Timer_StartMapVote(Handle:timer, Handle:data) +public Action Timer_StartMapVote(Handle timer, DataPack data) { if (timer == g_RetryTimer) { @@ -351,26 +353,26 @@ public Action:Timer_StartMapVote(Handle:timer, Handle:data) g_VoteTimer = null; } - if (!GetArraySize(g_MapList) || !g_Cvar_EndOfMapVote.BoolValue || g_MapVoteCompleted || g_HasVoteStarted) + if (!g_MapList.Length || !g_Cvar_EndOfMapVote.BoolValue || g_MapVoteCompleted || g_HasVoteStarted) { return Plugin_Stop; } - new MapChange:mapChange = MapChange:ReadPackCell(data); - new Handle:hndl = Handle:ReadPackCell(data); + MapChange mapChange = view_as(data.ReadCell()); + ArrayList hndl = view_as(data.ReadCell()); InitiateVote(mapChange, hndl); return Plugin_Stop; } -public Event_TFRestartRound(Handle:event, const String:name[], bool:dontBroadcast) +public void Event_TFRestartRound(Event event, const char[] name, bool dontBroadcast) { /* Game got restarted - reset our round count tracking */ g_TotalRounds = 0; } -public Event_TeamPlayWinPanel(Event event, const String:name[], bool:dontBroadcast) +public void Event_TeamPlayWinPanel(Event event, const char[] name, bool dontBroadcast) { if (g_ChangeMapAtRoundEnd) { @@ -379,14 +381,14 @@ public Event_TeamPlayWinPanel(Event event, const String:name[], bool:dontBroadca g_ChangeMapInProgress = true; } - new bluescore = event.GetInt("blue_score"); - new redscore = event.GetInt("red_score"); + int bluescore = event.GetInt("blue_score"); + int redscore = event.GetInt("red_score"); if (event.GetInt("round_complete") == 1 || StrEqual(name, "arena_win_panel")) { g_TotalRounds++; - if (!GetArraySize(g_MapList) || g_HasVoteStarted || g_MapVoteCompleted || !g_Cvar_EndOfMapVote.BoolValue) + if (!g_MapList.Length || g_HasVoteStarted || g_MapVoteCompleted || !g_Cvar_EndOfMapVote.BoolValue) { return; } @@ -412,7 +414,7 @@ public Event_TeamPlayWinPanel(Event event, const String:name[], bool:dontBroadca } } /* You ask, why don't you just use team_score event? And I answer... Because CSS doesn't. */ -public Event_RoundEnd(Event event, const String:name[], bool:dontBroadcast) +public void Event_RoundEnd(Event event, const char[] name, bool dontBroadcast) { if (g_ChangeMapAtRoundEnd) { @@ -421,7 +423,7 @@ public Event_RoundEnd(Event event, const String:name[], bool:dontBroadcast) g_ChangeMapInProgress = true; } - new winner; + int winner; if (strcmp(name, "round_win") == 0) { // Nuclear Dawn @@ -446,7 +448,7 @@ public Event_RoundEnd(Event event, const String:name[], bool:dontBroadcast) g_winCount[winner]++; - if (!GetArraySize(g_MapList) || g_HasVoteStarted || g_MapVoteCompleted) + if (!g_MapList.Length || g_HasVoteStarted || g_MapVoteCompleted) { return; } @@ -455,7 +457,7 @@ public Event_RoundEnd(Event event, const String:name[], bool:dontBroadcast) CheckMaxRounds(g_TotalRounds); } -public CheckWinLimit(winner_score) +public void CheckWinLimit(int winner_score) { if (g_Cvar_Winlimit) { @@ -470,7 +472,7 @@ public CheckWinLimit(winner_score) } } -public CheckMaxRounds(roundcount) +public void CheckMaxRounds(int roundcount) { if (g_Cvar_Maxrounds) { @@ -485,9 +487,9 @@ public CheckMaxRounds(roundcount) } } -public Event_PlayerDeath(Event event, const String:name[], bool:dontBroadcast) +public void Event_PlayerDeath(Event event, const char[] name, bool dontBroadcast) { - if (!GetArraySize(g_MapList) || !g_Cvar_Fraglimit || g_HasVoteStarted) + if (!g_MapList.Length || !g_Cvar_Fraglimit || g_HasVoteStarted) { return; } @@ -502,7 +504,7 @@ public Event_PlayerDeath(Event event, const String:name[], bool:dontBroadcast) return; } - new fragger = GetClientOfUserId(event.GetInt("attacker")); + int fragger = GetClientOfUserId(event.GetInt("attacker")); if (!fragger) { @@ -515,7 +517,7 @@ public Event_PlayerDeath(Event event, const String:name[], bool:dontBroadcast) } } -public Action:Command_Mapvote(client, args) +public Action Command_Mapvote(int client, int args) { InitiateVote(MapChange_MapEnd, null); @@ -529,7 +531,7 @@ public Action:Command_Mapvote(client, args) * @param inputlist Optional list of maps to use for the vote, otherwise an internal list of nominations + random maps will be used. * @param noSpecials Block special vote options like extend/nochange (upgrade this to bitflags instead?) */ -InitiateVote(MapChange:when, Handle:inputlist=null) +void InitiateVote(MapChange when, ArrayList inputlist=null) { g_WaitingForVote = true; @@ -538,11 +540,11 @@ InitiateVote(MapChange:when, Handle:inputlist=null) // Can't start a vote, try again in 5 seconds. //g_RetryTimer = CreateTimer(5.0, Timer_StartMapVote, _, TIMER_FLAG_NO_MAPCHANGE); - new Handle:data; + DataPack data; g_RetryTimer = CreateDataTimer(5.0, Timer_StartMapVote, data, TIMER_FLAG_NO_MAPCHANGE); - WritePackCell(data, _:when); - WritePackCell(data, _:inputlist); - ResetPack(data); + data.WriteCell(when); + data.WriteCell(inputlist); + data.Reset(); return; } @@ -557,7 +559,7 @@ InitiateVote(MapChange:when, Handle:inputlist=null) g_WaitingForVote = false; g_HasVoteStarted = true; - g_VoteMenu = new Menu(Handler_MapVoteMenu, MenuAction:MENU_ACTIONS_ALL); + g_VoteMenu = new Menu(Handler_MapVoteMenu, MENU_ACTIONS_ALL); g_VoteMenu.SetTitle("Vote Nextmap"); g_VoteMenu.VoteResultCallback = Handler_MapVoteFinished; @@ -577,44 +579,44 @@ InitiateVote(MapChange:when, Handle:inputlist=null) /* No input given - User our internal nominations and maplist */ if (inputlist == null) { - int nominateCount = GetArraySize(g_NominateList); + int nominateCount = g_NominateList.Length; int voteSize = g_Cvar_IncludeMaps.IntValue; /* Smaller of the two - It should be impossible for nominations to exceed the size though (cvar changed mid-map?) */ int nominationsToAdd = nominateCount >= voteSize ? voteSize : nominateCount; - for (new i=0; i 1) { @@ -789,7 +791,7 @@ public Handler_MapVoteFinished(Menu menu, if (winningvotes < required) { /* Insufficient Winning margin - Lets do a runoff */ - g_VoteMenu = CreateMenu(Handler_MapVoteMenu, MenuAction:MENU_ACTIONS_ALL); + g_VoteMenu = CreateMenu(Handler_MapVoteMenu, MENU_ACTIONS_ALL); g_VoteMenu.SetTitle("Runoff Vote Nextmap"); SetVoteResultCallback(g_VoteMenu, Handler_VoteFinishedGeneric); @@ -821,7 +823,7 @@ public Handler_MapVoteFinished(Menu menu, Handler_VoteFinishedGeneric(menu, num_votes, num_clients, client_info, num_items, item_info); } -public Handler_MapVoteMenu(Menu menu, MenuAction action, int param1, int param2) +public int Handler_MapVoteMenu(Menu menu, MenuAction action, int param1, int param2) { switch (action) { @@ -833,10 +835,10 @@ public Handler_MapVoteMenu(Menu menu, MenuAction action, int param1, int param2) case MenuAction_Display: { - decl String:buffer[255]; + char buffer[255]; Format(buffer, sizeof(buffer), "%T", "Vote Nextmap", param1); - Panel panel = Panel:param2; + Panel panel = view_as(param2); panel.SetTitle(buffer); } @@ -864,8 +866,8 @@ public Handler_MapVoteMenu(Menu menu, MenuAction action, int param1, int param2) // If we receive 0 votes, pick at random. if (param1 == VoteCancel_NoVotes && g_Cvar_NoVoteMode.BoolValue) { - new count = menu.ItemCount; - decl String:map[PLATFORM_MAX_PATH]; + int count = menu.ItemCount; + char map[PLATFORM_MAX_PATH]; menu.GetItem(0, map, sizeof(map)); // Make sure the first map in the menu isn't one of the special items. @@ -873,7 +875,7 @@ public Handler_MapVoteMenu(Menu menu, MenuAction action, int param1, int param2) if (strcmp(map, VOTE_EXTEND, false) != 0 && strcmp(map, VOTE_DONTCHANGE, false) != 0) { // Get a random map from the list. - new item = GetRandomInt(0, count - 1); + int item = GetRandomInt(0, count - 1); menu.GetItem(item, map, sizeof(map)); // Make sure it's not one of the special items. @@ -899,11 +901,11 @@ public Handler_MapVoteMenu(Menu menu, MenuAction action, int param1, int param2) return 0; } -public Action:Timer_ChangeMap(Handle:hTimer, Handle:dp) +public Action Timer_ChangeMap(Handle hTimer, DataPack dp) { g_ChangeMapInProgress = false; - new String:map[PLATFORM_MAX_PATH]; + char map[PLATFORM_MAX_PATH]; if (dp == null) { @@ -915,8 +917,8 @@ public Action:Timer_ChangeMap(Handle:hTimer, Handle:dp) } else { - ResetPack(dp); - ReadPackString(dp, map, sizeof(map)); + dp.Reset(); + dp.ReadString(map, sizeof(map)); } ForceChangeLevel(map, "Map Vote"); @@ -924,50 +926,51 @@ public Action:Timer_ChangeMap(Handle:hTimer, Handle:dp) return Plugin_Stop; } -bool:RemoveStringFromArray(Handle:array, String:str[]) +bool RemoveStringFromArray(ArrayList array, char[] str) { - new index = FindStringInArray(array, str); + int index = array.FindString(str); if (index != -1) { - RemoveFromArray(array, index); + array.Erase(index); return true; } return false; } -CreateNextVote() +void CreateNextVote() { ClearArray(g_NextMapList); char map[PLATFORM_MAX_PATH]; - new Handle:tempMaps = CloneArray(g_MapList); + ArrayList tempMaps = g_MapList.Clone(); GetCurrentMap(map, sizeof(map)); RemoveStringFromArray(tempMaps, map); - if (g_Cvar_ExcludeMaps.IntValue && GetArraySize(tempMaps) > g_Cvar_ExcludeMaps.IntValue) + if (g_Cvar_ExcludeMaps.IntValue && tempMaps.Length > g_Cvar_ExcludeMaps.IntValue) { - for (new i = 0; i < GetArraySize(g_OldMapList); i++) + for (int i = 0; i < g_OldMapList.Length; i++) { - GetArrayString(g_OldMapList, i, map, sizeof(map)); + g_OldMapList.GetString(i, map, sizeof(map)); RemoveStringFromArray(tempMaps, map); } } - int limit = (g_Cvar_IncludeMaps.IntValue < GetArraySize(tempMaps) ? g_Cvar_IncludeMaps.IntValue : GetArraySize(tempMaps)); + int limit = (g_Cvar_IncludeMaps.IntValue < tempMaps.Length ? g_Cvar_IncludeMaps.IntValue : tempMaps.Length); for (int i = 0; i < limit; i++) { int b = GetRandomInt(0, GetArraySize(tempMaps) - 1); - GetArrayString(tempMaps, b, map, sizeof(map)); - PushArrayString(g_NextMapList, map); - RemoveFromArray(tempMaps, b); + tempMaps.GetString(b, map, sizeof(map)); + g_NextMapList.PushString(map); + tempMaps.Erase(b); } + // TODO: Wait, why are we deleting the array we were just manipulating? Check this! delete tempMaps; } -bool:CanVoteStart() +bool CanVoteStart() { if (g_WaitingForVote || g_HasVoteStarted) { @@ -977,7 +980,7 @@ bool:CanVoteStart() return true; } -NominateResult:InternalNominateMap(String:map[], bool:force, owner) +NominateResult InternalNominateMap(char[] map, bool force, int owner) { if (!IsMapValid(map)) { @@ -985,47 +988,47 @@ NominateResult:InternalNominateMap(String:map[], bool:force, owner) } /* Map already in the vote */ - if (FindStringInArray(g_NominateList, map) != -1) + if (g_NominateList.FindString(map) != -1) { return Nominate_AlreadyInVote; } - new index; + int index; /* Look to replace an existing nomination by this client - Nominations made with owner = 0 aren't replaced */ - if (owner && ((index = FindValueInArray(g_NominateOwners, owner)) != -1)) + if (owner && ((index = g_NominateOwners.FindValue(owner)) != -1)) { - new String:oldmap[PLATFORM_MAX_PATH]; - GetArrayString(g_NominateList, index, oldmap, sizeof(oldmap)); + char oldmap[PLATFORM_MAX_PATH]; + g_NominateList.GetString(index, oldmap, sizeof(oldmap)); Call_StartForward(g_NominationsResetForward); Call_PushString(oldmap); Call_PushCell(owner); Call_Finish(); - SetArrayString(g_NominateList, index, map); + g_NominateList.SetString(index, map); return Nominate_Replaced; } /* Too many nominated maps. */ - if (GetArraySize(g_NominateList) >= g_Cvar_IncludeMaps.IntValue && !force) + if (g_NominateList.Length >= g_Cvar_IncludeMaps.IntValue && !force) { return Nominate_VoteFull; } - PushArrayString(g_NominateList, map); - PushArrayCell(g_NominateOwners, owner); + g_NominateList.PushString(map); + g_NominateOwners.Push(owner); - while (GetArraySize(g_NominateList) > g_Cvar_IncludeMaps.IntValue) + while (g_NominateList.Length > g_Cvar_IncludeMaps.IntValue) { char oldmap[PLATFORM_MAX_PATH]; - GetArrayString(g_NominateList, 0, oldmap, sizeof(oldmap)); + g_NominateList.GetString(0, oldmap, sizeof(oldmap)); Call_StartForward(g_NominationsResetForward); Call_PushString(oldmap); Call_PushCell(GetArrayCell(g_NominateOwners, 0)); Call_Finish(); - RemoveFromArray(g_NominateList, 0); - RemoveFromArray(g_NominateOwners, 0); + g_NominateList.Erase(0); + g_NominateOwners.Erase(0); } return Nominate_Added; @@ -1034,9 +1037,9 @@ NominateResult:InternalNominateMap(String:map[], bool:force, owner) /* Add natives to allow nominate and initiate vote to be call */ /* native bool:NominateMap(const String:map[], bool:force, &NominateError:error); */ -public Native_NominateMap(Handle:plugin, numParams) +public int Native_NominateMap(Handle plugin, int numParams) { - new len; + int len; GetNativeStringLength(1, len); if (len <= 0) @@ -1044,18 +1047,18 @@ public Native_NominateMap(Handle:plugin, numParams) return false; } - new String:map[len+1]; + char[] map = new char[len+1]; GetNativeString(1, map, len+1); - return _:InternalNominateMap(map, GetNativeCell(2), GetNativeCell(3)); + return view_as(InternalNominateMap(map, GetNativeCell(2), GetNativeCell(3))); } -bool:InternalRemoveNominationByMap(String:map[]) +bool InternalRemoveNominationByMap(char[] map) { - for (new i = 0; i < GetArraySize(g_NominateList); i++) + for (int i = 0; i < GetArraySize(g_NominateList); i++) { - new String:oldmap[PLATFORM_MAX_PATH]; - GetArrayString(g_NominateList, i, oldmap, sizeof(oldmap)); + char oldmap[PLATFORM_MAX_PATH]; + g_NominateList.GetString(i, oldmap, sizeof(oldmap)); if(strcmp(map, oldmap, false) == 0) { @@ -1064,8 +1067,8 @@ bool:InternalRemoveNominationByMap(String:map[]) Call_PushCell(GetArrayCell(g_NominateOwners, i)); Call_Finish(); - RemoveFromArray(g_NominateList, i); - RemoveFromArray(g_NominateOwners, i); + g_NominateList.Erase(i); + g_NominateOwners.Erase(i); return true; } @@ -1075,9 +1078,9 @@ bool:InternalRemoveNominationByMap(String:map[]) } /* native bool:RemoveNominationByMap(const String:map[]); */ -public Native_RemoveNominationByMap(Handle:plugin, numParams) +public int Native_RemoveNominationByMap(Handle plugin, int numParams) { - new len; + int len; GetNativeStringLength(1, len); if (len <= 0) @@ -1085,28 +1088,28 @@ public Native_RemoveNominationByMap(Handle:plugin, numParams) return false; } - new String:map[len+1]; + char[] map = new char[len+1]; GetNativeString(1, map, len+1); - return _:InternalRemoveNominationByMap(map); + return view_as(InternalRemoveNominationByMap(map)); } -bool:InternalRemoveNominationByOwner(owner) +bool InternalRemoveNominationByOwner(int owner) { - new index; + int index; - if (owner && ((index = FindValueInArray(g_NominateOwners, owner)) != -1)) + if (owner && ((index = g_NominateOwners.FindValue(owner)) != -1)) { - new String:oldmap[PLATFORM_MAX_PATH]; - GetArrayString(g_NominateList, index, oldmap, sizeof(oldmap)); + char oldmap[PLATFORM_MAX_PATH]; + g_NominateList.GetString(index, oldmap, sizeof(oldmap)); Call_StartForward(g_NominationsResetForward); Call_PushString(oldmap); Call_PushCell(owner); Call_Finish(); - RemoveFromArray(g_NominateList, index); - RemoveFromArray(g_NominateOwners, index); + g_NominateList.Erase(index); + g_NominateOwners.Erase(index); return true; } @@ -1115,76 +1118,76 @@ bool:InternalRemoveNominationByOwner(owner) } /* native bool:RemoveNominationByOwner(owner); */ -public Native_RemoveNominationByOwner(Handle:plugin, numParams) +public int Native_RemoveNominationByOwner(Handle plugin, int numParams) { - return _:InternalRemoveNominationByOwner(GetNativeCell(1)); + return view_as(InternalRemoveNominationByOwner(GetNativeCell(1))); } /* native InitiateMapChooserVote(); */ -public Native_InitiateVote(Handle:plugin, numParams) +public int Native_InitiateVote(Handle plugin, int numParams) { - new MapChange:when = MapChange:GetNativeCell(1); - new Handle:inputarray = Handle:GetNativeCell(2); + MapChange when = view_as(GetNativeCell(1)); + ArrayList inputarray = view_as(GetNativeCell(2)); LogAction(-1, -1, "Starting map vote because outside request"); InitiateVote(when, inputarray); } -public Native_CanVoteStart(Handle:plugin, numParams) +public int Native_CanVoteStart(Handle plugin, int numParams) { return CanVoteStart(); } -public Native_CheckVoteDone(Handle:plugin, numParams) +public int Native_CheckVoteDone(Handle plugin, int numParams) { return g_MapVoteCompleted; } -public Native_EndOfMapVoteEnabled(Handle:plugin, numParams) +public int Native_EndOfMapVoteEnabled(Handle plugin, int numParams) { return g_Cvar_EndOfMapVote.BoolValue; } -public Native_GetExcludeMapList(Handle:plugin, numParams) +public int Native_GetExcludeMapList(Handle plugin, int numParams) { - new Handle:array = Handle:GetNativeCell(1); + ArrayList array = view_as(GetNativeCell(1)); if (array == null) { return; } - new size = GetArraySize(g_OldMapList); - decl String:map[PLATFORM_MAX_PATH]; + int size = g_OldMapList.Length; + char map[PLATFORM_MAX_PATH]; - for (new i=0; i(GetNativeCell(1)); + ArrayList ownerarray = view_as(GetNativeCell(2)); if (maparray == null) return; - decl String:map[PLATFORM_MAX_PATH]; + char map[PLATFORM_MAX_PATH]; - for (new i = 0; i < GetArraySize(g_NominateList); i++) + for (int i = 0; i < g_NominateList.Length; i++) { - GetArrayString(g_NominateList, i, map, sizeof(map)); - PushArrayString(maparray, map); + g_NominateList.GetString(i, map, sizeof(map)); + maparray.PushString(map); // If the optional parameter for an owner list was passed, then we need to fill that out as well if(ownerarray != null) { - new index = GetArrayCell(g_NominateOwners, i); - PushArrayCell(ownerarray, index); + int index = g_NominateOwners.Get(i); + ownerarray.Push(index); } } From bc4d6b710452b6a0eaea04e0a248e363501227d7 Mon Sep 17 00:00:00 2001 From: Ross Bemrose Date: Tue, 16 Dec 2014 13:53:54 -0500 Subject: [PATCH 02/12] Eliminate extraneous view_as calls and also update mapchooser.inc. --- plugins/include/mapchooser.inc | 19 +++++++++---------- plugins/mapchooser.sp | 17 +++++++++++------ 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/plugins/include/mapchooser.inc b/plugins/include/mapchooser.inc index 1b89fdeb..360fd81b 100644 --- a/plugins/include/mapchooser.inc +++ b/plugins/include/mapchooser.inc @@ -27,7 +27,7 @@ enum MapChange * @param owner Client index of the nominater. If the client disconnects the nomination will be removed. Use 0 for constant nominations * @return Nominate Result of the outcome */ -native NominateResult:NominateMap(const String:map[], bool:force, owner); +native NominateResult NominateMap(const char[] map, bool force, int owner); /** * Attempt to remove a map from the mapchooser map list. @@ -35,7 +35,7 @@ native NominateResult:NominateMap(const String:map[], bool:force, owner); * @param map Map to remove. * @return True if the nomination was found and removed, or false if the nomination was not found. */ -native bool:RemoveNominationByMap(const String:map[]); +native bool RemoveNominationByMap(const char[] map); /** * Attempt to remove a map from the mapchooser map list. @@ -43,7 +43,7 @@ native bool:RemoveNominationByMap(const String:map[]); * @param owner Client index of the nominater. * @return True if the nomination was found and removed, or false if the nomination was not found. */ -native bool:RemoveNominationByOwner(owner); +native bool RemoveNominationByOwner(int owner); /** * Gets the current list of excluded maps. @@ -51,7 +51,7 @@ native bool:RemoveNominationByOwner(owner); * @param array An ADT array handle to add the map strings to. * @noreturn */ -native GetExcludeMapList(Handle:array); +native GetExcludeMapList(ArrayList array); /** * Gets the current list of nominated maps. @@ -60,14 +60,14 @@ native GetExcludeMapList(Handle:array); * @param ownerarray An optional ADT array handle to add the nominator client indexes to. * @noreturn */ -native GetNominatedMapList(Handle:maparray, Handle:ownerarray = INVALID_HANDLE); +native GetNominatedMapList(ArrayList maparray, ArrayList ownerarray = null); /** * Checks if MapChooser will allow a vote * * @return True if a vote can be held, or false if mapchooser is already holding a vote. */ -native bool:CanMapChooserStartVote(); +native bool CanMapChooserStartVote(); /** * Initiates a MapChooser map vote @@ -78,21 +78,21 @@ native bool:CanMapChooserStartVote(); * @param when MapChange consant of when the resulting mapchange should occur. * @param inputarray ADT array list of maps to add to the vote. */ -native InitiateMapChooserVote(MapChange:when, Handle:inputarray=INVALID_HANDLE); +native InitiateMapChooserVote(MapChange when, ArrayList inputarray=null); /** * Checks if MapChooser's end of map vote has completed. * * @return True if complete, false otherwise. */ -native bool:HasEndOfMapVoteFinished(); +native bool HasEndOfMapVoteFinished(); /** * Checks if MapChooser is set to run an end of map vote. * * @return True if enabled, false otherwise. */ -native bool:EndOfMapVoteEnabled(); +native bool EndOfMapVoteEnabled(); /** * Called when mapchooser removes a nomination from its list. @@ -105,7 +105,6 @@ forward void OnNominationRemoved(const char[] map, int owner); */ forward void OnMapVoteStarted(); - public SharedPlugin:__pl_mapchooser = { name = "mapchooser", diff --git a/plugins/mapchooser.sp b/plugins/mapchooser.sp index fd8b48f2..7ff9e983 100644 --- a/plugins/mapchooser.sp +++ b/plugins/mapchooser.sp @@ -1036,7 +1036,7 @@ NominateResult InternalNominateMap(char[] map, bool force, int owner) /* Add natives to allow nominate and initiate vote to be call */ -/* native bool:NominateMap(const String:map[], bool:force, &NominateError:error); */ +/* native NominateResult NominateMap(const char[] map, bool force, int owner); */ public int Native_NominateMap(Handle plugin, int numParams) { int len; @@ -1077,7 +1077,7 @@ bool InternalRemoveNominationByMap(char[] map) return false; } -/* native bool:RemoveNominationByMap(const String:map[]); */ +/* native bool RemoveNominationByMap(const char[] map); */ public int Native_RemoveNominationByMap(Handle plugin, int numParams) { int len; @@ -1091,7 +1091,7 @@ public int Native_RemoveNominationByMap(Handle plugin, int numParams) char[] map = new char[len+1]; GetNativeString(1, map, len+1); - return view_as(InternalRemoveNominationByMap(map)); + return InternalRemoveNominationByMap(map); } bool InternalRemoveNominationByOwner(int owner) @@ -1117,13 +1117,13 @@ bool InternalRemoveNominationByOwner(int owner) return false; } -/* native bool:RemoveNominationByOwner(owner); */ +/* native bool RemoveNominationByOwner(int owner); */ public int Native_RemoveNominationByOwner(Handle plugin, int numParams) { - return view_as(InternalRemoveNominationByOwner(GetNativeCell(1))); + return InternalRemoveNominationByOwner(GetNativeCell(1)); } -/* native InitiateMapChooserVote(); */ +/* native InitiateMapChooserVote(MapChange when, ArrayList inputarray=null); */ public int Native_InitiateVote(Handle plugin, int numParams) { MapChange when = view_as(GetNativeCell(1)); @@ -1133,21 +1133,25 @@ public int Native_InitiateVote(Handle plugin, int numParams) InitiateVote(when, inputarray); } +/* native bool CanMapChooserStartVote(); */ public int Native_CanVoteStart(Handle plugin, int numParams) { return CanVoteStart(); } +/* native bool HasEndOfMapVoteFinished(); */ public int Native_CheckVoteDone(Handle plugin, int numParams) { return g_MapVoteCompleted; } +/* native bool EndOfMapVoteEnabled(); */ public int Native_EndOfMapVoteEnabled(Handle plugin, int numParams) { return g_Cvar_EndOfMapVote.BoolValue; } +/* native GetExcludeMapList(ArrayList array); */ public int Native_GetExcludeMapList(Handle plugin, int numParams) { ArrayList array = view_as(GetNativeCell(1)); @@ -1168,6 +1172,7 @@ public int Native_GetExcludeMapList(Handle plugin, int numParams) return; } +/* native GetNominatedMapList(ArrayList maparray, ArrayList ownerarray = null); */ public int Native_GetNominatedMapList(Handle plugin, int numParams) { ArrayList maparray = view_as(GetNativeCell(1)); From 1b79252947c381b53bddffe64406280abb3d8d12 Mon Sep 17 00:00:00 2001 From: Ross Bemrose Date: Tue, 16 Dec 2014 14:16:06 -0500 Subject: [PATCH 03/12] Update NextMap, Nominations, RandomCycle, and RockTheVote with newer MethodMap stuff --- plugins/nextmap.sp | 33 ++++++++++++------------ plugins/nominations.sp | 34 ++++++++++++------------- plugins/randomcycle.sp | 44 ++++++++++++++++---------------- plugins/rockthevote.sp | 57 +++++++++++++++++++++--------------------- 4 files changed, 86 insertions(+), 82 deletions(-) diff --git a/plugins/nextmap.sp b/plugins/nextmap.sp index 8dd6624a..6e59c83f 100644 --- a/plugins/nextmap.sp +++ b/plugins/nextmap.sp @@ -47,7 +47,7 @@ public Plugin myinfo = }; int g_MapPos = -1; -Handle g_MapList = null; +ArrayList g_MapList = null; int g_MapListSerial = -1; int g_CurrentMapStartTime; @@ -78,14 +78,15 @@ public void OnPluginStart() LoadTranslations("common.phrases"); LoadTranslations("nextmap.phrases"); - g_MapList = CreateArray(32); + int size = ByteCountToCells(PLATFORM_MAX_PATH); + g_MapList = new ArrayList(size); 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 - char currentMap[64]; - GetCurrentMap(currentMap, 64); + char currentMap[PLATFORM_MAX_PATH]; + GetCurrentMap(currentMap, sizeof(currentMap)); SetNextMap(currentMap); } @@ -96,9 +97,9 @@ public void OnMapStart() public void OnConfigsExecuted() { - char lastMap[64], currentMap[64]; + char lastMap[PLATFORM_MAX_PATH], currentMap[PLATFORM_MAX_PATH]; GetNextMap(lastMap, sizeof(lastMap)); - GetCurrentMap(currentMap, 64); + GetCurrentMap(currentMap, sizeof(currentMap)); // Why am I doing this? If we switched to a new map, but it wasn't what we expected (Due to sm_map, sm_votemap, or // some other plugin/command), we don't want to scramble the map cycle. Or for example, admin switches to a custom map @@ -113,11 +114,11 @@ public Action Command_List(int client, int args) { PrintToConsole(client, "Map Cycle:"); - int mapCount = GetArraySize(g_MapList); - char mapName[32]; + int mapCount = g_MapList.Length; + char mapName[PLATFORM_MAX_PATH]; for (int i = 0; i < mapCount; i++) { - GetArrayString(g_MapList, i, mapName, sizeof(mapName)); + g_MapList.GetString(i, mapName, sizeof(mapName)); PrintToConsole(client, "%s", mapName); } @@ -139,17 +140,17 @@ void FindAndSetNextMap() } } - int mapCount = GetArraySize(g_MapList); - char mapName[32]; + int mapCount = g_MapList.Length; + char mapName[PLATFORM_MAX_PATH]; if (g_MapPos == -1) { - char current[64]; - GetCurrentMap(current, 64); + char current[PLATFORM_MAX_PATH]; + GetCurrentMap(current, sizeof(current)); for (int i = 0; i < mapCount; i++) { - GetArrayString(g_MapList, i, mapName, sizeof(mapName)); + g_MapList.GetString(i, mapName, sizeof(mapName)); if (strcmp(current, mapName, false) == 0) { g_MapPos = i; @@ -165,7 +166,7 @@ void FindAndSetNextMap() if (g_MapPos >= mapCount) g_MapPos = 0; - GetArrayString(g_MapList, g_MapPos, mapName, sizeof(mapName)); + g_MapList.GetString(g_MapPos, mapName, sizeof(mapName)); SetNextMap(mapName); } @@ -173,7 +174,7 @@ public Action Command_MapHistory(int client, int args) { int mapCount = GetMapHistorySize(); - char mapName[32]; + char mapName[PLATFORM_MAX_PATH]; char changeReason[100]; char timeString[100]; char playedTime[100]; diff --git a/plugins/nominations.sp b/plugins/nominations.sp index b142fc18..5028e6a1 100644 --- a/plugins/nominations.sp +++ b/plugins/nominations.sp @@ -50,7 +50,7 @@ ConVar g_Cvar_ExcludeOld; ConVar g_Cvar_ExcludeCurrent; Menu g_MapMenu = null; -Handle g_MapList = null; +ArrayList g_MapList = null; int g_mapFileSerial = -1; #define MAPSTATUS_ENABLED (1<<0) @@ -66,8 +66,8 @@ public void OnPluginStart() LoadTranslations("common.phrases"); LoadTranslations("nominations.phrases"); - int arraySize = ByteCountToCells(33); - g_MapList = CreateArray(arraySize); + int arraySize = ByteCountToCells(PLATFORM_MAX_PATH); + g_MapList = new ArrayList(arraySize); g_Cvar_ExcludeOld = CreateConVar("sm_nominate_excludeold", "1", "Specifies if the current map should be excluded from the Nominations list", 0, true, 0.00, true, 1.0); g_Cvar_ExcludeCurrent = CreateConVar("sm_nominate_excludecurrent", "1", "Specifies if the MapChooser excluded maps should also be excluded from Nominations", 0, true, 0.00, true, 1.0); @@ -123,7 +123,7 @@ public Action Command_Addmap(int client, int args) return Plugin_Handled; } - char mapname[64]; + char mapname[PLATFORM_MAX_PATH]; GetCmdArg(1, mapname, sizeof(mapname)); @@ -184,7 +184,7 @@ public Action Command_Nominate(int client, int args) return Plugin_Handled; } - char mapname[64]; + char mapname[PLATFORM_MAX_PATH]; GetCmdArg(1, mapname, sizeof(mapname)); int status; @@ -234,7 +234,7 @@ public Action Command_Nominate(int client, int args) g_mapTrie.SetValue(mapname, MAPSTATUS_DISABLED|MAPSTATUS_EXCLUDE_NOMINATED); - char name[64]; + char name[MAX_NAME_LENGTH+1]; GetClientName(client, name, sizeof(name)); PrintToChatAll("[SM] %t", "Map Nominated", name, mapname); @@ -257,14 +257,14 @@ void BuildMapMenu() g_MapMenu = new Menu(Handler_MapSelectMenu, MENU_ACTIONS_DEFAULT|MenuAction_DrawItem|MenuAction_DisplayItem); - char map[64]; + char map[PLATFORM_MAX_PATH]; ArrayList excludeMaps; - char currentMap[32]; + char currentMap[PLATFORM_MAX_PATH]; if (g_Cvar_ExcludeOld.BoolValue) { - excludeMaps = new ArrayList(ByteCountToCells(33)); + excludeMaps = new ArrayList(ByteCountToCells(PLATFORM_MAX_PATH)); GetExcludeMapList(excludeMaps); } @@ -274,11 +274,11 @@ void BuildMapMenu() } - for (int i = 0; i < GetArraySize(g_MapList); i++) + for (int i = 0; i < g_MapList.Length; i++) { int status = MAPSTATUS_ENABLED; - GetArrayString(g_MapList, i, map, sizeof(map)); + g_MapList.GetString(i, map, sizeof(map)); if (g_Cvar_ExcludeCurrent.BoolValue) { @@ -312,10 +312,10 @@ public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int p { case MenuAction_Select: { - char map[64], name[64]; - menu.GetItem(param2, map, sizeof(map)); + char map[PLATFORM_MAX_PATH], name[MAX_NAME_LENGTH+1]; + menu.GetItem(param2, map, sizeof(map)); - GetClientName(param1, name, 64); + GetClientName(param1, name, sizeof(name)); NominateResult result = NominateMap(map, false, param1); @@ -344,7 +344,7 @@ public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int p case MenuAction_DrawItem: { - char map[64]; + char map[PLATFORM_MAX_PATH]; menu.GetItem(param2, map, sizeof(map)); int status; @@ -366,7 +366,7 @@ public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int p case MenuAction_DisplayItem: { - char map[64]; + char map[PLATFORM_MAX_PATH]; menu.GetItem(param2, map, sizeof(map)); int status; @@ -377,7 +377,7 @@ public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int p return 0; } - char display[100]; + char display[PLATFORM_MAX_PATH + 64]; if ((status & MAPSTATUS_DISABLED) == MAPSTATUS_DISABLED) { diff --git a/plugins/randomcycle.sp b/plugins/randomcycle.sp index 46dab7f9..38fb4d7d 100644 --- a/plugins/randomcycle.sp +++ b/plugins/randomcycle.sp @@ -34,7 +34,9 @@ #pragma semicolon 1 #include -public Plugin:myinfo = +#pragma newdecls required + +public Plugin myinfo = { name = "RandomCycle", author = "AlliedModders LLC", @@ -45,22 +47,22 @@ public Plugin:myinfo = ConVar g_Cvar_ExcludeMaps; -new Handle:g_MapList = null; -new Handle:g_OldMapList = null; -new g_mapListSerial = -1; +ArrayList g_MapList = null; +ArrayList g_OldMapList = null; +int g_mapListSerial = -1; -public OnPluginStart() +public void OnPluginStart() { - new arraySize = ByteCountToCells(33); - g_MapList = CreateArray(arraySize); - g_OldMapList = CreateArray(arraySize); + int arraySize = ByteCountToCells(PLATFORM_MAX_PATH); + g_MapList = new ArrayList(arraySize); + g_OldMapList = new ArrayList(arraySize); g_Cvar_ExcludeMaps = CreateConVar("sm_randomcycle_exclude", "5", "Specifies how many past maps to exclude from the vote.", _, true, 0.0); AutoExecConfig(true, "randomcycle"); } -public OnConfigsExecuted() +public void OnConfigsExecuted() { if (ReadMapList(g_MapList, g_mapListSerial, @@ -77,31 +79,31 @@ public OnConfigsExecuted() CreateTimer(5.0, Timer_RandomizeNextmap); // Small delay to give Nextmap time to complete OnMapStart() } -public Action:Timer_RandomizeNextmap(Handle:timer) +public Action Timer_RandomizeNextmap(Handle timer) { - decl String:map[32]; + char map[PLATFORM_MAX_PATH]; - new bool:oldMaps = false; - if (g_Cvar_ExcludeMaps.IntValue && GetArraySize(g_MapList) > g_Cvar_ExcludeMaps.IntValue) + bool oldMaps = false; + if (g_Cvar_ExcludeMaps.IntValue && g_MapList.Length > g_Cvar_ExcludeMaps.IntValue) { oldMaps = true; } - new b = GetRandomInt(0, GetArraySize(g_MapList) - 1); - GetArrayString(g_MapList, b, map, sizeof(map)); + int b = GetRandomInt(0, g_MapList.Length - 1); + g_MapList.GetString(b, map, sizeof(map)); - while (oldMaps && FindStringInArray(g_OldMapList, map) != -1) + while (oldMaps && g_OldMapList.FindString(map) != -1) { - b = GetRandomInt(0, GetArraySize(g_MapList) - 1); - GetArrayString(g_MapList, b, map, sizeof(map)); + b = GetRandomInt(0, g_MapList.Length - 1); + g_MapList.GetString(b, map, sizeof(map)); } - PushArrayString(g_OldMapList, map); + g_OldMapList.PushString(map); SetNextMap(map); - if (GetArraySize(g_OldMapList) > g_Cvar_ExcludeMaps.IntValue) + if (g_OldMapList.Length > g_Cvar_ExcludeMaps.IntValue) { - RemoveFromArray(g_OldMapList, 0); + g_OldMapList.Erase(0); } LogAction(-1, -1, "RandomCycle has chosen %s for the nextmap.", map); diff --git a/plugins/rockthevote.sp b/plugins/rockthevote.sp index cb1528ac..ab178e3b 100644 --- a/plugins/rockthevote.sp +++ b/plugins/rockthevote.sp @@ -36,8 +36,9 @@ #include #pragma semicolon 1 +#pragma newdecls required -public Plugin:myinfo = +public Plugin myinfo = { name = "Rock The Vote", author = "AlliedModders LLC", @@ -53,16 +54,16 @@ ConVar g_Cvar_Interval; ConVar g_Cvar_ChangeTime; ConVar g_Cvar_RTVPostVoteAction; -new bool:g_CanRTV = false; // True if RTV loaded maps and is active. -new bool:g_RTVAllowed = false; // True if RTV is available to players. Used to delay rtv votes. -new g_Voters = 0; // Total voters connected. Doesn't include fake clients. -new g_Votes = 0; // Total number of "say rtv" votes -new g_VotesNeeded = 0; // Necessary votes before map vote begins. (voters * percent_needed) -new bool:g_Voted[MAXPLAYERS+1] = {false, ...}; +bool g_CanRTV = false; // True if RTV loaded maps and is active. +bool g_RTVAllowed = false; // True if RTV is available to players. Used to delay rtv votes. +int g_Voters = 0; // Total voters connected. Doesn't include fake clients. +int g_Votes = 0; // Total number of "say rtv" votes +int g_VotesNeeded = 0; // Necessary votes before map vote begins. (voters * percent_needed) +bool g_Voted[MAXPLAYERS+1] = {false, ...}; -new bool:g_InChange = false; +bool g_InChange = false; -public OnPluginStart() +public void OnPluginStart() { LoadTranslations("common.phrases"); LoadTranslations("rockthevote.phrases"); @@ -79,7 +80,7 @@ public OnPluginStart() AutoExecConfig(true, "rtv"); } -public OnMapStart() +public void OnMapStart() { g_Voters = 0; g_Votes = 0; @@ -87,7 +88,7 @@ public OnMapStart() g_InChange = false; /* Handle late load */ - for (new i=1; i<=MaxClients; i++) + for (int i=1; i<=MaxClients; i++) { if (IsClientConnected(i)) { @@ -96,20 +97,20 @@ public OnMapStart() } } -public OnMapEnd() +public void OnMapEnd() { g_CanRTV = false; g_RTVAllowed = false; } -public OnConfigsExecuted() +public void OnConfigsExecuted() { g_CanRTV = true; g_RTVAllowed = false; CreateTimer(g_Cvar_InitialDelay.FloatValue, Timer_DelayRTV, _, TIMER_FLAG_NO_MAPCHANGE); } -public OnClientConnected(client) +public void OnClientConnected(int client) { if(IsFakeClient(client)) return; @@ -122,7 +123,7 @@ public OnClientConnected(client) return; } -public OnClientDisconnect(client) +public void OnClientDisconnect(int client) { if(IsFakeClient(client)) return; @@ -155,7 +156,7 @@ public OnClientDisconnect(client) } } -public OnClientSayCommand_Post(client, const String:command[], const String:sArgs[]) +public void OnClientSayCommand_Post(int client, const char[] command, const char[] sArgs) { if (!g_CanRTV || !client) { @@ -164,7 +165,7 @@ public OnClientSayCommand_Post(client, const String:command[], const String:sArg if (strcmp(sArgs, "rtv", false) == 0 || strcmp(sArgs, "rockthevote", false) == 0) { - new ReplySource:old = SetCmdReplySource(SM_REPLY_TO_CHAT); + ReplySource old = SetCmdReplySource(SM_REPLY_TO_CHAT); AttemptRTV(client); @@ -172,7 +173,7 @@ public OnClientSayCommand_Post(client, const String:command[], const String:sArg } } -public Action:Command_RTV(client, args) +public Action Command_RTV(int client, int args) { if (!g_CanRTV || !client) { @@ -184,7 +185,7 @@ public Action:Command_RTV(client, args) return Plugin_Handled; } -AttemptRTV(client) +void AttemptRTV(int client) { if (!g_RTVAllowed || (g_Cvar_RTVPostVoteAction.IntValue == 1 && HasEndOfMapVoteFinished())) { @@ -210,7 +211,7 @@ AttemptRTV(client) return; } - new String:name[64]; + char name[MAX_NAME_LENGTH+1]; GetClientName(client, name, sizeof(name)); g_Votes++; @@ -224,12 +225,12 @@ AttemptRTV(client) } } -public Action:Timer_DelayRTV(Handle:timer) +public Action Timer_DelayRTV(Handle timer) { g_RTVAllowed = true; } -StartRTV() +void StartRTV() { if (g_InChange) { @@ -239,7 +240,7 @@ StartRTV() if (EndOfMapVoteEnabled() && HasEndOfMapVoteFinished()) { /* Change right now then */ - new String:map[65]; + char map[PLATFORM_MAX_PATH]; if (GetNextMap(map, sizeof(map))) { PrintToChatAll("[SM] %t", "Changing Maps", map); @@ -255,7 +256,7 @@ StartRTV() if (CanMapChooserStartVote()) { - new MapChange:when = MapChange:g_Cvar_ChangeTime.IntValue; + MapChange when = view_as(g_Cvar_ChangeTime.IntValue); InitiateMapChooserVote(when); ResetRTV(); @@ -265,23 +266,23 @@ StartRTV() } } -ResetRTV() +void ResetRTV() { g_Votes = 0; - for (new i=1; i<=MAXPLAYERS; i++) + for (int i=1; i<=MAXPLAYERS; i++) { g_Voted[i] = false; } } -public Action:Timer_ChangeMap(Handle:hTimer) +public Action Timer_ChangeMap(Handle hTimer) { g_InChange = false; LogMessage("RTV changing map manually"); - new String:map[65]; + char map[PLATFORM_MAX_PATH]; if (GetNextMap(map, sizeof(map))) { ForceChangeLevel(map, "RTV after mapvote"); From 8272151d78843179e5a020fe8ffdebde436e5b60 Mon Sep 17 00:00:00 2001 From: Ross Bemrose Date: Tue, 16 Dec 2014 16:20:03 -0500 Subject: [PATCH 04/12] Convert the MapChooser VoteHandlers over to the new style. --- plugins/mapchooser.sp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/mapchooser.sp b/plugins/mapchooser.sp index 7ff9e983..4a1ea323 100644 --- a/plugins/mapchooser.sp +++ b/plugins/mapchooser.sp @@ -682,11 +682,11 @@ void InitiateVote(MapChange when, ArrayList inputlist=null) } public void Handler_VoteFinishedGeneric(Menu menu, - int num_votes, + int num_votes, int num_clients, - const int client_info[][2], + const int[][] client_info, int num_items, - const int item_info[][2]) + const int[][] item_info) { char map[PLATFORM_MAX_PATH]; menu.GetItem(item_info[0][VOTEINFO_ITEM_INDEX], map, sizeof(map)); @@ -777,11 +777,11 @@ public void Handler_VoteFinishedGeneric(Menu menu, } public void Handler_MapVoteFinished(Menu menu, - int num_votes, + int num_votes, int num_clients, - const int client_info[][2], + const int[][] client_info, int num_items, - const int item_info[][2]) + const int[][] item_info) { if (g_Cvar_RunOff.BoolValue && num_items > 1) { From 2d5b71c83264f8054ed97ccdd8aa761e4c445838 Mon Sep 17 00:00:00 2001 From: Ross Bemrose Date: Tue, 16 Dec 2014 16:57:49 -0500 Subject: [PATCH 05/12] Deleted comment... checked into it and its working as intended. --- plugins/mapchooser.sp | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/mapchooser.sp b/plugins/mapchooser.sp index 4a1ea323..b70cfbde 100644 --- a/plugins/mapchooser.sp +++ b/plugins/mapchooser.sp @@ -966,7 +966,6 @@ void CreateNextVote() tempMaps.Erase(b); } - // TODO: Wait, why are we deleting the array we were just manipulating? Check this! delete tempMaps; } From 032dde7be94765c70f57dd14f1d6bcb8f0145679 Mon Sep 17 00:00:00 2001 From: Ross Bemrose Date: Tue, 16 Dec 2014 17:00:00 -0500 Subject: [PATCH 06/12] Missed a few GetArrayCell and GetArraySizes in MapChooser. --- plugins/mapchooser.sp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/mapchooser.sp b/plugins/mapchooser.sp index b70cfbde..d484aa68 100644 --- a/plugins/mapchooser.sp +++ b/plugins/mapchooser.sp @@ -272,7 +272,7 @@ public void OnClientDisconnect(int client) g_NominateList.GetString(index, oldmap, sizeof(oldmap)); Call_StartForward(g_NominationsResetForward); Call_PushString(oldmap); - Call_PushCell(GetArrayCell(g_NominateOwners, index)); + Call_PushCell(g_NominateOwners.Get(index)); Call_Finish(); g_NominateOwners.Erase(index); @@ -960,7 +960,7 @@ void CreateNextVote() int limit = (g_Cvar_IncludeMaps.IntValue < tempMaps.Length ? g_Cvar_IncludeMaps.IntValue : tempMaps.Length); for (int i = 0; i < limit; i++) { - int b = GetRandomInt(0, GetArraySize(tempMaps) - 1); + int b = GetRandomInt(0, tempMaps.Length - 1); tempMaps.GetString(b, map, sizeof(map)); g_NextMapList.PushString(map); tempMaps.Erase(b); @@ -1023,7 +1023,7 @@ NominateResult InternalNominateMap(char[] map, bool force, int owner) g_NominateList.GetString(0, oldmap, sizeof(oldmap)); Call_StartForward(g_NominationsResetForward); Call_PushString(oldmap); - Call_PushCell(GetArrayCell(g_NominateOwners, 0)); + Call_PushCell(g_NominateOwners.Get(0)); Call_Finish(); g_NominateList.Erase(0); @@ -1054,7 +1054,7 @@ public int Native_NominateMap(Handle plugin, int numParams) bool InternalRemoveNominationByMap(char[] map) { - for (int i = 0; i < GetArraySize(g_NominateList); i++) + for (int i = 0; i < g_NominateList.Length; i++) { char oldmap[PLATFORM_MAX_PATH]; g_NominateList.GetString(i, oldmap, sizeof(oldmap)); @@ -1063,7 +1063,7 @@ bool InternalRemoveNominationByMap(char[] map) { Call_StartForward(g_NominationsResetForward); Call_PushString(oldmap); - Call_PushCell(GetArrayCell(g_NominateOwners, i)); + Call_PushCell(g_NominateOwners.Get(i)); Call_Finish(); g_NominateList.Erase(i); From ccf5aa6b54ca99a08f72402ce4d501d580c50312 Mon Sep 17 00:00:00 2001 From: Ross Bemrose Date: Wed, 17 Dec 2014 11:07:51 -0500 Subject: [PATCH 07/12] Change all view_as<>(null) back to INVALID_HANDLE for now. --- plugins/mapchooser.sp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/mapchooser.sp b/plugins/mapchooser.sp index d484aa68..4e01be19 100644 --- a/plugins/mapchooser.sp +++ b/plugins/mapchooser.sp @@ -335,7 +335,7 @@ void SetupTimeleftTimer() DataPack data; g_VoteTimer = CreateDataTimer(float(time - startTime), Timer_StartMapVote, data, TIMER_FLAG_NO_MAPCHANGE); data.WriteCell(MapChange_MapEnd); - data.WriteCell(view_as(null)); + data.WriteCell(INVALID_HANDLE); data.Reset(); } } From f40bfbf7628957e3493bd7698cd1e6c62d3f93ef Mon Sep 17 00:00:00 2001 From: Ross Bemrose Date: Wed, 17 Dec 2014 11:53:02 -0500 Subject: [PATCH 08/12] Updated nextmap.inc. Also fixed copyright years and added missing copyright header to mapchooser.inc (all .inc files use the same copyright header, so...) --- plugins/include/mapchooser.inc | 31 +++++++++++++++++++++++++++++++ plugins/include/nextmap.inc | 12 ++++++------ plugins/mapchooser.sp | 2 +- plugins/nextmap.sp | 2 +- plugins/nominations.sp | 2 +- plugins/randomcycle.sp | 2 +- 6 files changed, 41 insertions(+), 10 deletions(-) diff --git a/plugins/include/mapchooser.inc b/plugins/include/mapchooser.inc index 360fd81b..6c4bb4ec 100644 --- a/plugins/include/mapchooser.inc +++ b/plugins/include/mapchooser.inc @@ -1,3 +1,34 @@ +/** + * vim: set ts=4 : + * ============================================================================= + * SourceMod (C)2004-2014 AlliedModders LLC. All rights reserved. + * ============================================================================= + * + * This file is part of the SourceMod/SourcePawn SDK. + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License, version 3.0, as published by the + * Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + * + * As a special exception, AlliedModders LLC gives you permission to link the + * code of this program (as well as its derivative works) to "Half-Life 2," the + * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software + * by the Valve Corporation. You must obey the GNU General Public License in + * all respects for all other code used. Additionally, AlliedModders LLC grants + * this exception to all derivative works. AlliedModders LLC defines further + * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), + * or . + * + * Version: $Id$ + */ #if defined _mapchooser_included_ #endinput #endif diff --git a/plugins/include/nextmap.inc b/plugins/include/nextmap.inc index ec085824..a1632679 100644 --- a/plugins/include/nextmap.inc +++ b/plugins/include/nextmap.inc @@ -1,7 +1,7 @@ /** * vim: set ts=4 : * ============================================================================= - * SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved. + * SourceMod (C)2004-2014 AlliedModders LLC. All rights reserved. * ============================================================================= * * This file is part of the SourceMod/SourcePawn SDK. @@ -42,7 +42,7 @@ * @param map Next map to set. * @return True if the nextmap was set, false if map was invalid. */ -native bool:SetNextMap(const String:map[]); +native bool SetNextMap(const char[] map); /** * Returns SourceMod's internal nextmap. @@ -51,7 +51,7 @@ 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(char[] map, int maxlen); /** * Changes the current map and records the reason for the change with maphistory @@ -60,14 +60,14 @@ native bool:GetNextMap(String:map[], maxlen); * @param reason Reason for change. * @noreturn */ -native ForceChangeLevel(const String:map[], const String:reason[]); +native void ForceChangeLevel(const char[] map, const char[] reason); /** * Gets the current number of maps in the map history * * @return Number of maps. */ -native GetMapHistorySize(); +native int GetMapHistorySize(); /** * Retrieves a map from the map history list. @@ -81,4 +81,4 @@ native GetMapHistorySize(); * @noreturn * @error Invalid item number. */ -native GetMapHistory(item, String:map[], mapLen, String:reason[], reasonLen, &startTime); \ No newline at end of file +native void GetMapHistory(int item, char[] map, int mapLen, char[] reason, int reasonLen, int &startTime); \ No newline at end of file diff --git a/plugins/mapchooser.sp b/plugins/mapchooser.sp index 4e01be19..f9e5dcd0 100644 --- a/plugins/mapchooser.sp +++ b/plugins/mapchooser.sp @@ -5,7 +5,7 @@ * Creates a map vote at appropriate times, setting sm_nextmap to the winning * vote * - * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved. + * SourceMod (C)2004-2014 AlliedModders LLC. All rights reserved. * ============================================================================= * * This program is free software; you can redistribute it and/or modify it under diff --git a/plugins/nextmap.sp b/plugins/nextmap.sp index 6e59c83f..a0740f04 100644 --- a/plugins/nextmap.sp +++ b/plugins/nextmap.sp @@ -4,7 +4,7 @@ * SourceMod Nextmap Plugin * Adds sm_nextmap cvar for changing map and nextmap chat trigger. * - * SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved. + * SourceMod (C)2004-2014 AlliedModders LLC. All rights reserved. * ============================================================================= * * This program is free software; you can redistribute it and/or modify it under diff --git a/plugins/nominations.sp b/plugins/nominations.sp index 5028e6a1..5b0c3226 100644 --- a/plugins/nominations.sp +++ b/plugins/nominations.sp @@ -4,7 +4,7 @@ * SourceMod Rock The Vote Plugin * Creates a map vote when the required number of players have requested one. * - * SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved. + * SourceMod (C)2004-2014 AlliedModders LLC. All rights reserved. * ============================================================================= * * This program is free software; you can redistribute it and/or modify it under diff --git a/plugins/randomcycle.sp b/plugins/randomcycle.sp index 38fb4d7d..a2e3ee14 100644 --- a/plugins/randomcycle.sp +++ b/plugins/randomcycle.sp @@ -4,7 +4,7 @@ * SourceMod Random Map Cycle Plugin * Randomly picks a map from the mapcycle. * - * SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved. + * SourceMod (C)2004-2014 AlliedModders LLC. All rights reserved. * ============================================================================= * * This program is free software; you can redistribute it and/or modify it under From 01f4b204c95bd6d1369e50a93a51dd30840dfe32 Mon Sep 17 00:00:00 2001 From: Ross Bemrose Date: Wed, 17 Dec 2014 16:05:14 -0500 Subject: [PATCH 09/12] Added two items missed in the original conversion with the Runoff vote. --- plugins/mapchooser.sp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/mapchooser.sp b/plugins/mapchooser.sp index f9e5dcd0..3d38b2e8 100644 --- a/plugins/mapchooser.sp +++ b/plugins/mapchooser.sp @@ -791,9 +791,9 @@ public void Handler_MapVoteFinished(Menu menu, if (winningvotes < required) { /* Insufficient Winning margin - Lets do a runoff */ - g_VoteMenu = CreateMenu(Handler_MapVoteMenu, MENU_ACTIONS_ALL); + g_VoteMenu = new Menu(Handler_MapVoteMenu, MENU_ACTIONS_ALL); g_VoteMenu.SetTitle("Runoff Vote Nextmap"); - SetVoteResultCallback(g_VoteMenu, Handler_VoteFinishedGeneric); + g_VoteMenu.VoteResultCallback = Handler_VoteFinishedGeneric; char map[PLATFORM_MAX_PATH]; char info1[PLATFORM_MAX_PATH]; From f69f4eb85fdf99f1b1c5b0e9a1a41715128f9b59 Mon Sep 17 00:00:00 2001 From: Ross Bemrose Date: Fri, 26 Dec 2014 12:36:12 -0500 Subject: [PATCH 10/12] Fixes to make mapchooser.inc transitional compliant. Also updated comments in mapchooser.sp to match the new mapchooser.inc signature. --- plugins/include/mapchooser.inc | 10 +++++----- plugins/mapchooser.sp | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/plugins/include/mapchooser.inc b/plugins/include/mapchooser.inc index 6c4bb4ec..8fef0d9b 100644 --- a/plugins/include/mapchooser.inc +++ b/plugins/include/mapchooser.inc @@ -82,7 +82,7 @@ native bool RemoveNominationByOwner(int owner); * @param array An ADT array handle to add the map strings to. * @noreturn */ -native GetExcludeMapList(ArrayList array); +native void GetExcludeMapList(ArrayList array); /** * Gets the current list of nominated maps. @@ -91,7 +91,7 @@ native GetExcludeMapList(ArrayList array); * @param ownerarray An optional ADT array handle to add the nominator client indexes to. * @noreturn */ -native GetNominatedMapList(ArrayList maparray, ArrayList ownerarray = null); +native void GetNominatedMapList(ArrayList maparray, ArrayList ownerarray = null); /** * Checks if MapChooser will allow a vote @@ -109,7 +109,7 @@ native bool CanMapChooserStartVote(); * @param when MapChange consant of when the resulting mapchange should occur. * @param inputarray ADT array list of maps to add to the vote. */ -native InitiateMapChooserVote(MapChange when, ArrayList inputarray=null); +native void InitiateMapChooserVote(MapChange when, ArrayList inputarray=null); /** * Checks if MapChooser's end of map vote has completed. @@ -136,7 +136,7 @@ forward void OnNominationRemoved(const char[] map, int owner); */ forward void OnMapVoteStarted(); -public SharedPlugin:__pl_mapchooser = +public SharedPlugin __pl_mapchooser = { name = "mapchooser", file = "mapchooser.smx", @@ -147,7 +147,7 @@ public SharedPlugin:__pl_mapchooser = #endif }; -public __pl_mapchooser_SetNTVOptional() +public void __pl_mapchooser_SetNTVOptional() { MarkNativeAsOptional("NominateMap"); MarkNativeAsOptional("RemoveNominationByMap"); diff --git a/plugins/mapchooser.sp b/plugins/mapchooser.sp index 3d38b2e8..3934f9e3 100644 --- a/plugins/mapchooser.sp +++ b/plugins/mapchooser.sp @@ -1122,7 +1122,7 @@ public int Native_RemoveNominationByOwner(Handle plugin, int numParams) return InternalRemoveNominationByOwner(GetNativeCell(1)); } -/* native InitiateMapChooserVote(MapChange when, ArrayList inputarray=null); */ +/* native void InitiateMapChooserVote(MapChange when, ArrayList inputarray=null); */ public int Native_InitiateVote(Handle plugin, int numParams) { MapChange when = view_as(GetNativeCell(1)); @@ -1150,7 +1150,7 @@ public int Native_EndOfMapVoteEnabled(Handle plugin, int numParams) return g_Cvar_EndOfMapVote.BoolValue; } -/* native GetExcludeMapList(ArrayList array); */ +/* native void GetExcludeMapList(ArrayList array); */ public int Native_GetExcludeMapList(Handle plugin, int numParams) { ArrayList array = view_as(GetNativeCell(1)); @@ -1171,7 +1171,7 @@ public int Native_GetExcludeMapList(Handle plugin, int numParams) return; } -/* native GetNominatedMapList(ArrayList maparray, ArrayList ownerarray = null); */ +/* native void GetNominatedMapList(ArrayList maparray, ArrayList ownerarray = null); */ public int Native_GetNominatedMapList(Handle plugin, int numParams) { ArrayList maparray = view_as(GetNativeCell(1)); From 8567246772ccb32e6a141bcfcc4bebbe60d8c6ef Mon Sep 17 00:00:00 2001 From: Ross Bemrose Date: Tue, 6 Jan 2015 10:07:15 -0500 Subject: [PATCH 11/12] ClearArray was changed to Clear in recent SourceMod builds. --- plugins/mapchooser.sp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/mapchooser.sp b/plugins/mapchooser.sp index 3934f9e3..223fb024 100644 --- a/plugins/mapchooser.sp +++ b/plugins/mapchooser.sp @@ -220,8 +220,8 @@ public void OnConfigsExecuted() g_MapVoteCompleted = false; - g_NominateList.ClearArray(); - g_NominateOwners.ClearArray(); + g_NominateList.Clear(); + g_NominateOwners.Clear(); for (int i=0; i Date: Thu, 4 Jun 2015 21:42:25 -0400 Subject: [PATCH 12/12] One minor issue left from the merge --- plugins/rockthevote.sp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/rockthevote.sp b/plugins/rockthevote.sp index fbc167ae..9474e386 100644 --- a/plugins/rockthevote.sp +++ b/plugins/rockthevote.sp @@ -211,7 +211,7 @@ void AttemptRTV(int client) return; } - new String:name[MAX_NAME_LENGTH]; + char name[MAX_NAME_LENGTH]; GetClientName(client, name, sizeof(name)); g_Votes++;