Skip to content

Commit

Permalink
Add teleport to stage start command (#1207)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
Awesomerly and rtldg committed Apr 27, 2024
1 parent b773e74 commit 2805cd9
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions addons/sourcemod/scripting/shavit-checkpoints.sp
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down
55 changes: 55 additions & 0 deletions addons/sourcemod/scripting/shavit-zones.sp
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down Expand Up @@ -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<float>({0.0, 0.0, 0.0}));
}
else
{
TeleportEntity(client, gV_ZoneCenter[i], NULL_VECTOR, view_as<float>({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)
Expand Down

0 comments on commit 2805cd9

Please sign in to comment.