Skip to content

Commit

Permalink
feat: setnextmap foward, nomination native ,speed improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
Rushaway authored May 2, 2024
1 parent dc45159 commit cf486df
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 16 deletions.
15 changes: 14 additions & 1 deletion addons/sourcemod/scripting/include/mapchooser_extended.inc
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,19 @@ forward void OnMapVoteEnd(const char[] map);
*/
forward void OnNominationDisconnect(char[] oldmap, int owner);

/**
* Called when the nextmap is set
*/
forward void OnSetNextMap(const char[] map);

/**
* Is nomination was made by a client?
*
* @param owner Client index
* @param map buffer to store map name (PLATFORM_MAX_PATH)
* @return true if nomination was made by client (and map is stored in buffer)
*/
native bool GetNominationByOwner(int owner, char[] map);

/**
* Is a map on the current game's official list?
Expand Down Expand Up @@ -171,4 +184,4 @@ public SharedPlugin __pl_mapchooser_extended =
#else
required = 0,
#endif
};
};
67 changes: 52 additions & 15 deletions addons/sourcemod/scripting/mapchooser_extended.sp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
#tryinclude <zleader>
#define REQUIRE_PLUGIN

#define MCE_VERSION "1.11.2"
#define MCE_VERSION "1.11.3"

#define NV "nativevotes"
#define ZLEADER "zleader"
Expand Down Expand Up @@ -161,6 +161,7 @@ MapChange g_ChangeTime;
Handle g_NominationsResetForward = INVALID_HANDLE;
Handle g_NominationDisconnect = INVALID_HANDLE;
Handle g_MapVoteStartedForward = INVALID_HANDLE;
Handle g_SetNextMapForward = INVALID_HANDLE;

/* Mapchooser Extended Plugin ConVars */

Expand Down Expand Up @@ -407,6 +408,7 @@ public void OnPluginStart()
g_NominationsResetForward = CreateGlobalForward("OnNominationRemoved", ET_Ignore, Param_String, Param_Cell);
g_NominationDisconnect= CreateGlobalForward("OnNominationDisconnect", ET_Ignore, Param_String, Param_Cell);
g_MapVoteStartedForward = CreateGlobalForward("OnMapVoteStarted", ET_Ignore);
g_SetNextMapForward = CreateGlobalForward("OnSetNextMap", ET_Ignore, Param_String);

//MapChooser Extended Forwards
g_MapVoteStartForward = CreateGlobalForward("OnMapVoteStart", ET_Ignore); // Deprecated
Expand Down Expand Up @@ -441,6 +443,7 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max
CreateNative("EndOfMapVoteEnabled", Native_EndOfMapVoteEnabled);

// MapChooser Extended natives
CreateNative("GetNominationByOwner", Native_GetNominationByOwner);
CreateNative("IsMapOfficial", Native_IsMapOfficial);
CreateNative("CanNominate", Native_CanNominate);
CreateNative("ExcludeMap", Native_ExcludeMap);
Expand Down Expand Up @@ -481,27 +484,27 @@ public void OnAllPluginsLoaded()

public void OnLibraryAdded(const char[] name)
{
if (StrEqual(name, NV))
if (strcmp(name, NV) == 0)
{
#if defined _nativevotes_included
g_NativeVotes = NativeVotes_IsVoteTypeSupported(NativeVotesType_NextLevelMult);
#else
g_NativeVotes = true;
#endif
}
if (StrEqual(name, ZLEADER))
if (strcmp(name, ZLEADER) == 0)
g_ZLeader = true;
if (StrEqual(name, DYNCHANNELS))
if (strcmp(name, DYNCHANNELS) == 0)
g_DynamicChannels = true;
}

public void OnLibraryRemoved(const char[] name)
{
if (StrEqual(name, NV))
if (strcmp(name, NV) == 0)
g_NativeVotes = false;
if (StrEqual(name, ZLEADER))
if (strcmp(name, ZLEADER) == 0)
g_ZLeader = false;
if (StrEqual(name, DYNCHANNELS))
if (strcmp(name, DYNCHANNELS) == 0)
g_DynamicChannels = false;
}

Expand Down Expand Up @@ -698,6 +701,7 @@ public Action Command_SetNextmap(int client, int args)
LogAction(client, -1, "[MCE] \"%L\" changed nextmap to \"%s\"", client, map);

SetNextMap(map);
Forward_OnSetNextMap(map);
g_MapVoteCompleted = true;

return Plugin_Handled;
Expand Down Expand Up @@ -857,7 +861,7 @@ public void Event_TeamPlayWinPanel(Handle event, const char[] name, bool dontBro
int bluescore = GetEventInt(event, "blue_score");
int redscore = GetEventInt(event, "red_score");

if(GetEventInt(event, "round_complete") == 1 || StrEqual(name, "arena_win_panel"))
if(GetEventInt(event, "round_complete") == 1 || strcmp(name, "arena_win_panel") == 0)
{
g_TotalRounds++;

Expand Down Expand Up @@ -1392,7 +1396,7 @@ void InitiateVote(MapChange when, Handle inputlist=INVALID_HANDLE)
AddMapItem(map);
}
// New in Mapchooser Extended
else if(StrEqual(map, VOTE_DONTCHANGE))
else if(strcmp(map, VOTE_DONTCHANGE) == 0)
{
if (g_NativeVotes)
{
Expand All @@ -1405,7 +1409,7 @@ void InitiateVote(MapChange when, Handle inputlist=INVALID_HANDLE)
AddMenuItem(g_VoteMenu, VOTE_DONTCHANGE, "Don't Change");
}
}
else if(StrEqual(map, VOTE_EXTEND))
else if(strcmp(map, VOTE_EXTEND) == 0)
{
if (GetConVarInt(g_Cvar_Extend) - g_Extends > 0)
FormatEx(allMapsBuffer, allMapsSize, "%s\n- %s", allMapsBuffer, "Extend");
Expand Down Expand Up @@ -1573,6 +1577,7 @@ public void Handler_VoteFinishedGeneric(Handle menu,
if(g_ChangeTime == MapChange_MapEnd)
{
SetNextMap(map);
Forward_OnSetNextMap(map);
if (g_NativeVotes)
{
#if defined _nativevotes_included
Expand All @@ -1596,6 +1601,7 @@ public void Handler_VoteFinishedGeneric(Handle menu,
else // MapChange_RoundEnd
{
SetNextMap(map);
Forward_OnSetNextMap(map);
g_ChangeMapAtRoundEnd = true;

if (g_NativeVotes)
Expand Down Expand Up @@ -1753,25 +1759,25 @@ public int Handler_MapVoteMenu(Handle menu, MenuAction action, int param1, int p
GetMenuItem(menu, param2, map, PLATFORM_MAX_PATH, _, _, _, param1);
}

if(StrEqual(map, VOTE_EXTEND, false))
if(strcmp(map, VOTE_EXTEND, false) == 0)
{
Format(buffer, sizeof(buffer), "%T", "Extend Map", param1);
}
else if(StrEqual(map, VOTE_DONTCHANGE, false))
else if(strcmp(map, VOTE_DONTCHANGE, false) == 0)
{
Format(buffer, sizeof(buffer), "%T", "Dont Change", param1);
}
// Mapchooser Extended
else if(StrEqual(map, LINE_ONE, false))
else if(strcmp(map, LINE_ONE, false) == 0)
{
Format(buffer, sizeof(buffer),"%T", "Line One", param1);
}
else if(StrEqual(map, LINE_TWO, false))
else if(strcmp(map, LINE_TWO, false) == 0)
{
Format(buffer, sizeof(buffer),"%T", "Line Two", param1);
}
// Note that the first part is to discard the spacer line
else if(!StrEqual(map, LINE_SPACER, false))
else if(strcmp(map, LINE_SPACER, false) != 0)
{
if(mark == 1 && !InternalIsMapOfficial(map))
{
Expand Down Expand Up @@ -1857,6 +1863,7 @@ public int Handler_MapVoteMenu(Handle menu, MenuAction action, int param1, int p
while(strcmp(map, VOTE_EXTEND, false) == 0);

SetNextMap(map);
Forward_OnSetNextMap(map);
LogAction(-1, -1, "[MCE] No votes has been receive. Pickup a random map. Nextmap is : %s", map);
g_MapVoteCompleted = true;
if (g_NativeVotes)
Expand Down Expand Up @@ -2147,6 +2154,29 @@ public int Native_NominateMap(Handle plugin, int numParams)
return view_as<int>(InternalNominateMap(map, GetNativeCell(2), GetNativeCell(3)));
}

void InternalGetNominationByOwner(int owner, char[] buffer)
{
int index;
if(owner && ((index = FindValueInArray(g_NominateOwners, owner)) != -1))
{
GetArrayString(g_NominateList, index, buffer, PLATFORM_MAX_PATH);
}
}

/* native bool GetNominationByOwner(owner, const char[] buffer); */
public int Native_GetNominationByOwner(Handle plugin, int numParams)
{
int client = GetNativeCell(1);
char map[PLATFORM_MAX_PATH];
InternalGetNominationByOwner(client, map);

if (!map[0])
return 0;

SetNativeString(2, map, PLATFORM_MAX_PATH);
return 1;
}

bool InternalRemoveNominationByMap(char[] map)
{
for(int i = 0; i < GetArraySize(g_NominateList); i++)
Expand Down Expand Up @@ -3404,3 +3434,10 @@ stock void Forward_OnNominationDisconnect(char[] oldmap, int owner)
Call_PushCell(owner);
Call_Finish();
}

stock void Forward_OnSetNextMap(char[] map)
{
Call_StartForward(g_SetNextMapForward);
Call_PushString(map);
Call_Finish();
}

0 comments on commit cf486df

Please sign in to comment.