From 2805cd94c631909946f994aadda4bbaedd5dd2ea Mon Sep 17 00:00:00 2001 From: Awesomerly Date: Sat, 27 Apr 2024 15:55:42 -0400 Subject: [PATCH] Add teleport to stage start command (#1207) * Add teleport command * Slight cleanups for sm_teleport * Make stage restart only work if map is surf * Change /teleport to be /stagerestart, etc * Make sm_teleport behave like sm_tele * Unregister /sr command because it's already taken * Update shavit-zones.sp --------- Co-authored-by: rtldg <55846624+rtldg@users.noreply.github.com> --- .../sourcemod/scripting/shavit-checkpoints.sp | 1 + addons/sourcemod/scripting/shavit-zones.sp | 55 +++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/addons/sourcemod/scripting/shavit-checkpoints.sp b/addons/sourcemod/scripting/shavit-checkpoints.sp index 267d39147..9b82e01b5 100644 --- a/addons/sourcemod/scripting/shavit-checkpoints.sp +++ b/addons/sourcemod/scripting/shavit-checkpoints.sp @@ -186,6 +186,7 @@ public void OnPluginStart() RegConsoleCmd("sm_checkpoints", Command_Checkpoints, "Opens the checkpoints menu. Alias for sm_cpmenu."); RegConsoleCmd("sm_save", Command_Save, "Saves a checkpoint."); RegConsoleCmd("sm_tele", Command_Tele, "Teleports to a checkpoint. Usage: sm_tele [number]"); + RegConsoleCmd("sm_teleport", Command_Tele, "Teleports to a checkpoint. Usage: sm_tele [number]"); RegConsoleCmd("sm_prevcp", Command_PrevCheckpoint, "Selects the previous checkpoint."); RegConsoleCmd("sm_nextcp", Command_NextCheckpoint, "Selects the next checkpoint."); RegConsoleCmd("sm_deletecp", Command_DeleteCheckpoint, "Deletes the current checkpoint."); diff --git a/addons/sourcemod/scripting/shavit-zones.sp b/addons/sourcemod/scripting/shavit-zones.sp index a2c23d1de..321a60b53 100644 --- a/addons/sourcemod/scripting/shavit-zones.sp +++ b/addons/sourcemod/scripting/shavit-zones.sp @@ -275,6 +275,10 @@ public void OnPluginStart() RegConsoleCmd("sm_stage", Command_Stages, "Opens the stage menu. Usage: sm_stage [stage #]"); RegConsoleCmd("sm_s", Command_Stages, "Opens the stage menu. Usage: sm_s [stage #]"); + RegConsoleCmd("sm_rs", Command_StageRestart, "Teleports the player to the current stage. Only works on surf maps."); + RegConsoleCmd("sm_stagerestart", Command_StageRestart, "Teleports the player to the current stage. Only works on surf maps."); + RegConsoleCmd("sm_restartstage", Command_StageRestart, "Teleports the player to the current stage. Only works on surf maps."); + RegConsoleCmd("sm_set", Command_SetStart, "Set current position as spawn location in start zone."); RegConsoleCmd("sm_setstart", Command_SetStart, "Set current position as spawn location in start zone."); RegConsoleCmd("sm_ss", Command_SetStart, "Set current position as spawn location in start zone."); @@ -2462,6 +2466,57 @@ public Action Command_Stages(int client, int args) return Plugin_Handled; } +public Action Command_StageRestart(int client, int args) +{ + // This command should only work on surf maps for now + // There are quite a few bhop maps that have checkpoint triggers and this command would ruin those maps + // Ideally there would be a zone-based solution to this problem + if(!IsValidClient(client) || strncmp(gS_Map, "surf_", 5)) + { + return Plugin_Handled; + } + + if(!IsPlayerAlive(client)) + { + Shavit_PrintToChat(client, "%T", "StageCommandAlive", client); + return Plugin_Handled; + } + + int last = gI_LastStage[client]; + int track = Shavit_GetClientTrack(client); + + // crude way to prevent cheesing + if (InsideZone(client, Zone_Stage, track) || InsideZone(client, Zone_Start, -1)) + { + return Plugin_Handled; + } + + if (last <= 0) + { + Shavit_RestartTimer(client, track); + } + else + { + for(int i = 0; i < gI_MapZones; i++) + { + if (gA_ZoneCache[i].iType == Zone_Stage && gA_ZoneCache[i].iData == last && gA_ZoneCache[i].iTrack == track) + { + if (!EmptyVector(gA_ZoneCache[i].fDestination)) + { + TeleportEntity(client, gA_ZoneCache[i].fDestination, NULL_VECTOR, view_as({0.0, 0.0, 0.0})); + } + else + { + TeleportEntity(client, gV_ZoneCenter[i], NULL_VECTOR, view_as({0.0, 0.0, 0.0})); + } + } + } + } + + return Plugin_Handled; +} + + public int MenuHandler_SelectStage(Menu menu, MenuAction action, int param1, int param2) { if(action == MenuAction_Select)