Skip to content
Open
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
15 changes: 15 additions & 0 deletions addons/sourcemod/scripting/include/umc-core.inc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public __pl_umccore_SetNTVOptional()
MarkNativeAsOptional("UMC_VoteManagerClientVoted");
MarkNativeAsOptional("UMC_FormatDisplayString");
MarkNativeAsOptional("UMC_IsNewVoteAllowed");
MarkNativeAsOptional("UMC_ForceChangeMap");
}

#define INVALID_GROUP ""
Expand Down Expand Up @@ -359,6 +360,15 @@ forward UMC_OnNextmapSet(Handle:kv, const String:map[], const String:group[],
*/
forward UMC_RequestReloadMapcycle();

/**
* Called immediately after UMC ForceChangeMap Native was called
*
* @param time The time before the map change
*
* @noreturn
*/
forward UMC_OnForceMapChange(const Float:time);


/**
* Retrieves the name of the current map group.
Expand Down Expand Up @@ -519,3 +529,8 @@ native UMC_FormatDisplayString(String:display[], maxlen, Handle:mapcycle, const
* @return True if we can start a new vote, false otherwise.
*/
native bool:UMC_IsNewVoteAllowed(const String:id[]="core");

/**
* Changes the map after the specified time period.
*/
native UMC_ForceChangeMap(const String:map[], Float:time, const String:reason[]="");
45 changes: 5 additions & 40 deletions addons/sourcemod/scripting/include/umc_utils.inc
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ enum CustomHudFallbackType {
HudFallback_Chat,
HudFallback_Hint,
HudFallback_Center,
HudFallback_None
HudFallback_None
}

//Color Arrays for colors in warning messages.
Expand Down Expand Up @@ -425,7 +425,7 @@ public Action:Timer_CenterAd(Handle:timer, Handle:pack)

//
// stock TF2_SendCustomHudMessage(client, const String:icon[], team=-1, CustomHudFallbackType:fallback,
// const String:format[], any:...)
// const String:format[], any:...)
// {
// decl String:message[256];
// VFormat(message, sizeof(message), format, 6);
Expand All @@ -442,7 +442,7 @@ public Action:Timer_CenterAd(Handle:timer, Handle:pack)

// //
// stock TF2_SendCustomHudMessageAll(const String:icon[], team=-1, CustomHudFallbackType:fallback,
// const String:format[], any:...)
// const String:format[], any:...)
// {
// decl String:message[256];
// VFormat(message, sizeof(message), format, 5);
Expand All @@ -465,7 +465,7 @@ public Action:Timer_CenterAd(Handle:timer, Handle:pack)

// //
// public MinModeCheckFinished(QueryCookie:cookie, uid, ConVarQueryResult:result, const String:cvarName[],
// const String:cvarValue[], any:pack)
// const String:cvarValue[], any:pack)
// {
// ResetPack(pack);
// new client = GetClientOfUserId(ReadPackCell(pack));
Expand Down Expand Up @@ -634,44 +634,9 @@ stock ForceChangeInFive(const String:map[], const String:reason[]="")
PrintToChatAll("\x03[UMC]\x01 %t", "Map Change in 5");

//Setup the change.
ForceChangeMap(map, 5.0, reason);
UMC_ForceChangeMap(map, 5.0, reason);
}


//Changes the map after the specified time period.
stock ForceChangeMap(const String:map[], Float:time, const String:reason[]="")
{
LogUMCMessage("%s: Changing map to '%s' in %.f seconds.", reason, map, time);

//Setup the timer.
new Handle:pack;
CreateDataTimer(
time,
Handle_MapChangeTimer,
pack,
TIMER_FLAG_NO_MAPCHANGE
);
WritePackString(pack, map);
WritePackString(pack, reason);
}


//Called after the mapchange timer is completed.
public Action:Handle_MapChangeTimer(Handle:timer, Handle:pack)
{
//Get map from the timer's pack.
decl String:map[MAP_LENGTH], String:reason[255];
ResetPack(pack);
ReadPackString(pack, map, sizeof(map));
ReadPackString(pack, reason, sizeof(reason));

DEBUG_MESSAGE("Changing map to %s: %s", map, reason)

//Change the map.
ForceChangeLevel(map, reason);
}


//Determines if the current server time is between the given min and max.
stock bool:IsTimeBetween(min, max)
{
Expand Down
70 changes: 63 additions & 7 deletions addons/sourcemod/scripting/umc-core.sp
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,9 @@ new Handle:cvar_winlimit = INVALID_HANDLE;
new Handle:cvar_nextlevel = INVALID_HANDLE; //GE:S


/* ForceChangeMap System */
new Handle:forceChangeMap_forward = INVALID_HANDLE;

#if RUNTESTS
RunTests()
{
Expand Down Expand Up @@ -652,6 +655,7 @@ public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max)
CreateNative("UMC_VoteManagerClientVoted", Native_UMCVoteManagerVoted);
CreateNative("UMC_FormatDisplayString", Native_UMCFormatDisplay);
CreateNative("UMC_IsNewVoteAllowed", Native_UMCIsNewVoteAllowed);
CreateNative("UMC_ForceChangeMap", Native_UMCForceChangeMap);

RegPluginLibrary("umccore");

Expand Down Expand Up @@ -868,6 +872,10 @@ public OnPluginStart()
Param_String, Param_Cell, Param_Cell, Param_String, Param_String
);

forceChangeMap_forward = CreateGlobalForward(
"UMC_OnForceMapChange", ET_Ignore, Param_Cell
);

vote_managers = CreateTrie();
vote_manager_ids = CreateArray(ByteCountToCells(64));

Expand Down Expand Up @@ -1269,7 +1277,7 @@ public Native_UMCUnregVoteManager(Handle:plugin, numParams)
CloseHandle(hndl);
GetTrieValue(vM, "checkprogress", hndl);
CloseHandle(hndl);

CloseHandle(vM);

Expand Down Expand Up @@ -1892,6 +1900,41 @@ public Native_UMCGetCurrentGroup(Handle:plugin, numParams)
SetNativeString(1, current_cat, GetNativeCell(2), false);
}

//const String:map[], Float:time, const String:reason[]=""
public Native_UMCForceChangeMap(Handle:plugin, numParams)
{
new mapLen;
GetNativeStringLength(1,mapLen);
new String:map[mapLen];
GetNativeString(1, map, mapLen);

new Float:time = Float:GetNativeCell(2);

new reasonLen;
GetNativeStringLength(3,reasonLen);
new String:reason[reasonLen];
GetNativeString(1, reason, reasonLen);

LogUMCMessage("%s: Changing map to '%s' in %.f seconds.", reason, map, time);

// Send an advertisment
Call_StartForward(forceChangeMap_forward);
Call_PushCell(time);
Call_Finish();

//Setup the timer.
new Handle:pack;
CreateDataTimer(
time,
Handle_MapChangeTimer,
pack,
TIMER_FLAG_NO_MAPCHANGE
);
WritePackString(pack, map);
WritePackString(pack, reason);

}


//************************************************************************************************//
// COMMANDS //
Expand Down Expand Up @@ -2029,7 +2072,7 @@ new bool:core_vote_active;

public bool:VM_IsVoteInProgress()
{
return IsVoteInProgress();
return IsVoteInProgress();
}

//
Expand Down Expand Up @@ -2422,7 +2465,7 @@ bool:IsVMVoteInProgress(Handle:voteManager)
new Handle:progressCheck;
GetTrieValue(voteManager, "checkprogress", progressCheck);
new bool:result;
if (GetForwardFunctionCount(progressCheck) == 0)
{
result = IsVoteInProgress();
Expand Down Expand Up @@ -3395,7 +3438,7 @@ public UMC_OnFormatTemplateString(String:template[], maxlen, Handle:kv, const St
DEBUG_MESSAGE("OFTS: '%s' '%s' '%s'", map, group, template)

decl String:resolvedMap[MAP_LENGTH];
if (GetFeatureStatus(FeatureType_Native, "GetMapDisplayName") == FeatureStatus_Available)
{
// SM 1.8
Expand Down Expand Up @@ -4106,8 +4149,8 @@ Handle:BuildRunoffOptions(Handle:vM, Handle:clientArray)

return newMenu;
}


//Called when the runoff timer for an end-of-map vote completes.
public Action:Handle_RunoffVoteTimer(Handle:timer, Handle:datapack)
{
Expand Down Expand Up @@ -5560,4 +5603,17 @@ bool:GetRandomCat(Handle:kv, String:buffer[], size)
return result;
}


//Called after the mapchange timer is completed.
public Action:Handle_MapChangeTimer(Handle:timer, Handle:pack)
{
//Get map from the timer's pack.
decl String:map[MAP_LENGTH], String:reason[255];
ResetPack(pack);
ReadPackString(pack, map, sizeof(map));
ReadPackString(pack, reason, sizeof(reason));

DEBUG_MESSAGE("Changing map to %s: %s", map, reason)

//Change the map.
ForceChangeLevel(map, reason);
}
Loading