Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified addons/sourcemod/plugins/optional/l4d2_map_transitions.smx
Binary file not shown.
72 changes: 72 additions & 0 deletions addons/sourcemod/scripting/include/l4d2_map_transitions.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
SourcePawn is Copyright (C) 2006-2008 AlliedModders LLC. All rights reserved.
SourceMod is Copyright (C) 2006-2008 AlliedModders LLC. All rights reserved.
Pawn and SMALL are Copyright (C) 1997-2008 ITB CompuPhase.
Source is Copyright (C) Valve Corporation.
All trademarks are property of their respective owners.

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 the
Free Software Foundation, either version 3 of the License, or (at your
option) any later version.

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 <http://www.gnu.org/licenses/>.
*/
#if defined _l4d2_map_transitions_included_
#endinput
#endif
#define _l4d2_map_transitions_included_

/**
* @brief Get the next map name for map transition
*
* @param buffer String to write map name, empty if no map transition set
* @param maxlength Max length of buffer
*
* @noreturn
*/
native void l4d2_map_transitions_GetNextMap(char[] buffer, int maxlength);

/**
* @brief Called when the plugin is about to force change next map
*
* @param sNextMapName the next map name for map transition
*
* @return Plugin_Handled to block map changing, Plugin_Continue otherwise
*/
forward Action l4d2_map_transitions_OnChangeNextMap_Pre(const char[] sNextMapName);

/**
* @brief Called when the plugin is about to force change next map
* @remarks This forward will not trigger if the relative pre-hook forward has been blocked with Plugin_Handled
*
* @param sNextMapName the next map name for map transition
*
* @noreturn
*/
forward void l4d2_map_transitions_OnChangeNextMap_Post(const char[] sNextMapName);


public SharedPlugin __pl_l4d2_map_transitions =
{
name = "l4d2_map_transitions",
file = "l4d2_map_transitions.smx",
#if defined REQUIRE_PLUGIN
required = 1,
#else
required = 0,
#endif
};

#if !defined REQUIRE_PLUGIN
public void __pl_l4d2_map_transitions_SetNTVOptional()
{
MarkNativeAsOptional("l4d2_map_transitions_GetNextMap");
}
#endif
62 changes: 62 additions & 0 deletions addons/sourcemod/scripting/l4d2_map_transitions.sp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@
#include <l4d2util>
#include <colors>

GlobalForward g_hFWD_ChangeNextMapPre;
GlobalForward g_hFWD_ChangeNextMapPost;

public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
CreateNative("l4d2_map_transitions_GetNextMap", Native_GetNextMap);

g_hFWD_ChangeNextMapPre = new GlobalForward("l4d2_map_transitions_OnChangeNextMap_Pre", ET_Event, Param_String);
g_hFWD_ChangeNextMapPost = new GlobalForward("l4d2_map_transitions_OnChangeNextMap_Post", ET_Ignore, Param_String);

RegPluginLibrary("l4d2_map_transitions");

return APLRes_Success;
}

#define DEBUG 0

#define MAP_NAME_MAX_LENGTH 64
Expand Down Expand Up @@ -115,6 +130,24 @@ Action OnRoundEnd_Post(Handle hTimer)
LogMessage("Map transitioned from: %s to: %s", sCurrentMapName, sNextMapName);
#endif

Action aResult = Plugin_Continue;
Call_StartForward(g_hFWD_ChangeNextMapPre);
Call_PushString(sNextMapName);
Call_Finish(aResult);

if( aResult == Plugin_Handled )
{
g_iPointsTeamA = 0;
g_iPointsTeamB = 0;
g_bHasTransitioned = false;

return Plugin_Stop;
}

Call_StartForward(g_hFWD_ChangeNextMapPost);
Call_PushString(sNextMapName);
Call_Finish();

CPrintToChatAll("{olive}[MT]{default} Starting transition from: {blue}%s{default} to: {blue}%s", sCurrentMapName, sNextMapName);
ForceChangeLevel(sNextMapName, "Map Transitions");
}
Expand Down Expand Up @@ -195,3 +228,32 @@ int GetCurrentMapLower(char[] buffer, int maxlength)
if (bytes) String_ToLower(buffer, maxlength);
return bytes;
}


// Native------------

// native void l4d2_map_transitions_GetNextMap(char[] buffer, int maxlength);
int Native_GetNextMap(Handle plugin, int numParams)
{
int maxlength = GetNativeCell(2);
if (maxlength <= 0)
return 0;

char[] buffer = new char[maxlength];

char sCurrentMapName[MAP_NAME_MAX_LENGTH], sNextMapName[MAP_NAME_MAX_LENGTH];
GetCurrentMapLower(sCurrentMapName, sizeof(sCurrentMapName));

//We have a map to transition to
if (g_hMapTransitionPair.GetString(sCurrentMapName, sNextMapName, sizeof(sNextMapName)))
{
FormatEx(buffer, maxlength, "%s", sNextMapName);
SetNativeString(1, buffer, maxlength);
}
else
{
FormatEx(buffer, maxlength, "");
}

return 0;
}
Loading