Skip to content

Commit

Permalink
add !prevcp, !nextcp, and !deletecp
Browse files Browse the repository at this point in the history
  • Loading branch information
rtldg committed Dec 27, 2021
1 parent f14ae3a commit f898164
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 4 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ Player commands:
!cp, !cpmenu, !checkpoint, !checkpoints - Opens the checkpoints menu.
!save - Saves checkpoint.
!tele - Teleports to checkpoint (default: 1). Usage: !tele [number]
!prevcp - Selects the previous checkpoint.
!nextcp - Selects the next checkpoint.
!deletecp - Deletes the current checkpoint.
!nc, !prac, !practice, !noclipme, +noclip, sm_noclip - Toggles noclip.
```

Expand Down
116 changes: 112 additions & 4 deletions addons/sourcemod/scripting/shavit-checkpoints.sp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ public void OnPluginStart()
RegConsoleCmd("sm_checkpoints", Command_Checkpoints, "Opens the checkpoints menu. Alias for sm_cpmenu.");
RegConsoleCmd("sm_save", Command_Save, "Saves checkpoint.");
RegConsoleCmd("sm_tele", Command_Tele, "Teleports to 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.");
gH_CheckpointsCookie = RegClientCookie("shavit_checkpoints", "Checkpoints settings", CookieAccess_Protected);
gA_PersistentData = new ArrayList(sizeof(persistent_data_t));

Expand Down Expand Up @@ -712,6 +715,21 @@ void ResetCheckpoints(int client)
gI_CurrentCheckpoint[client] = 0;
}

bool ShouldReopenCheckpointMenu(int client)
{
if (gB_InCheckpointMenu[client])
{
return true;
}

if (!gB_ClosedKZCP[client] && Shavit_GetStyleSettingInt(gI_Style[client], "kzcheckpoints"))
{
return true;
}

return false;
}

public Action Command_Checkpoints(int client, int args)
{
if(client == 0)
Expand Down Expand Up @@ -751,9 +769,9 @@ public Action Command_Save(int client, int args)
{
Shavit_PrintToChat(client, "%T", "MiscCheckpointsSaved", client, gI_CurrentCheckpoint[client], gS_ChatStrings.sVariable, gS_ChatStrings.sText);

if (gB_InCheckpointMenu[client])
if (ShouldReopenCheckpointMenu(client))
{
OpenNormalCPMenu(client);
OpenCheckpointsMenu(client);
}
}

Expand Down Expand Up @@ -796,6 +814,90 @@ public Action Command_Tele(int client, int args)
return Plugin_Handled;
}

public Action Command_PrevCheckpoint(int client, int args)
{
if (client == 0)
{
ReplyToCommand(client, "This command may be only performed in-game.");
return Plugin_Handled;
}

if (!gCV_Checkpoints.BoolValue)
{
Shavit_PrintToChat(client, "%T", "FeatureDisabled", client, gS_ChatStrings.sWarning, gS_ChatStrings.sText);
return Plugin_Handled;
}

if (gI_CurrentCheckpoint[client] > 1)
{
gI_CurrentCheckpoint[client]--;

if (ShouldReopenCheckpointMenu(client))
{
OpenCheckpointsMenu(client);
}
}

return Plugin_Handled;
}

public Action Command_NextCheckpoint(int client, int args)
{
if (client == 0)
{
ReplyToCommand(client, "This command may be only performed in-game.");
return Plugin_Handled;
}

if (!gCV_Checkpoints.BoolValue)
{
Shavit_PrintToChat(client, "%T", "FeatureDisabled", client, gS_ChatStrings.sWarning, gS_ChatStrings.sText);
return Plugin_Handled;
}

if (gI_CurrentCheckpoint[client] < gA_Checkpoints[client].Length)
{
gI_CurrentCheckpoint[client]++;

if (ShouldReopenCheckpointMenu(client))
{
OpenCheckpointsMenu(client);
}
}

return Plugin_Handled;
}

public Action Command_DeleteCheckpoint(int client, int args)
{
if (client == 0)
{
ReplyToCommand(client, "This command may be only performed in-game.");
return Plugin_Handled;
}

if (!gCV_Checkpoints.BoolValue)
{
Shavit_PrintToChat(client, "%T", "FeatureDisabled", client, gS_ChatStrings.sWarning, gS_ChatStrings.sText);
return Plugin_Handled;
}

if (DeleteCheckpoint(client, gI_CurrentCheckpoint[client]))
{
if (gI_CurrentCheckpoint[client] > gA_Checkpoints[client].Length)
{
gI_CurrentCheckpoint[client] = gA_Checkpoints[client].Length;
}

if (ShouldReopenCheckpointMenu(client))
{
OpenCheckpointsMenu(client);
}
}

return Plugin_Handled;
}

public Action OpenCheckpointsMenu(int client)
{
if(Shavit_GetStyleSettingInt(gI_Style[client], "kzcheckpoints"))
Expand Down Expand Up @@ -1040,11 +1142,17 @@ public int MenuHandler_Checkpoints(Menu menu, MenuAction action, int param1, int
}
else if(StrEqual(sInfo, "prev"))
{
gI_CurrentCheckpoint[param1]--;
if (gI_CurrentCheckpoint[param1] > 1)
{
gI_CurrentCheckpoint[param1]--;
}
}
else if(StrEqual(sInfo, "next"))
{
gI_CurrentCheckpoint[param1]++;
if (gI_CurrentCheckpoint[param1] < gA_Checkpoints[param1].Length)
{
gI_CurrentCheckpoint[param1]++;
}
}
else if(StrEqual(sInfo, "del"))
{
Expand Down

0 comments on commit f898164

Please sign in to comment.