Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prac mode rework #43

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
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
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

[2021-05-26 - Version 3.1.6]
---
- Changed the way savelocs are saved, from a server based system to a player based system
- Added time comparisions when in practice mode
- Added the ability to recreate other players savelocs by using `sm_addsaveloc` / `sm_addloc` followed by the various inputs required to recreate the saveloc
- Added the ability to clear savelocs by using `sm_clearsavelocs` / `sm_clearlocs`
- Added `ck_allow_checkpoint_recreation` to enable server owners control over allowing checkpoint recreation and how they want it to be impelemented
- Changed the way savelocs are created when spectating a player/bot. You will now create the saveloc with the time that the player/bot had at that point. This will allow you to teleport to the saveloc and receive the time the player/bot had instead of the timer just starting at 0
- Changed how practice mode works when leaving start zone. Before it would allow you to start a run in practice mode but now it will kick you out of practice mode and start the run normally
- Changed a few of the HUD colours

[2021-04-13 - Version 3.0.5]
---
- Added `ck_sound_record_type` to enable controll over record sounds by @Kyli3Boi
Expand Down
44 changes: 35 additions & 9 deletions addons/sourcemod/scripting/SurfTimer.sp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#pragma semicolon 1

// Plugin Info
#define VERSION "3.0.5"
#define VERSION "3.1.6"

// Database Definitions
#define MYSQL 0
Expand Down Expand Up @@ -122,7 +122,7 @@
#define EF_NODRAW 32

// New Save Locs
#define MAX_LOCS 1024
#define MAX_LOCS 128

//CSGO HUD Hint Fix
#define MAX_HINT_SIZE 254
Expand Down Expand Up @@ -428,6 +428,7 @@ bool g_bWrcpEndZone[MAXPLAYERS + 1] = false;
int g_CurrentStage[MAXPLAYERS + 1];
float g_fStartWrcpTime[MAXPLAYERS + 1];
float g_fFinalWrcpTime[MAXPLAYERS + 1];
float g_fOldFinalWrcpTime[MAXPLAYERS + 1];

// Total time the run took in 00:00:00 format
char g_szFinalWrcpTime[MAXPLAYERS + 1][32];
Expand All @@ -446,6 +447,16 @@ bool g_bStageSRVRecord[MAXPLAYERS + 1][CPLIMIT];
char g_szStageRecordPlayer[CPLIMIT][MAX_NAME_LENGTH];
// bool g_bFirstStageRecord[CPLIMIT];

// PracMode SRCP
float g_fStartPracSrcpTime[MAXPLAYERS + 1];
float g_fCurrentPracSrcpRunTime[MAXPLAYERS + 1];
bool g_bPracSrcpTimerActivated[MAXPLAYERS + 1] = false;
int g_iPracSrcpStage[MAXPLAYERS + 1];
bool g_bPracSrcpEndZone[MAXPLAYERS + 1] = false;
float g_fFinalPracSrcpTime[MAXPLAYERS + 1];
char g_szFinalPracSrcpTime[MAXPLAYERS + 1][32];
float g_fSrcpPauseTime[MAXPLAYERS + 1];

/*---------- Map Settings Variables ----------*/
float g_fMaxVelocity;
ConVar g_hMaxVelocity;
Expand Down Expand Up @@ -790,6 +801,9 @@ char g_szBonusTimeDifference[MAXPLAYERS + 1];
// Time when run was started
float g_fStartTime[MAXPLAYERS + 1];

// Time when PracMode run was started
float g_fPracModeStartTime[MAXPLAYERS + 1];

// Total time the run took
float g_fFinalTime[MAXPLAYERS + 1];

Expand All @@ -805,6 +819,9 @@ float g_fStartPauseTime[MAXPLAYERS + 1];
// Current runtime
float g_fCurrentRunTime[MAXPLAYERS + 1];

// PracticeMode total time the run took in 00:00:00 format
char g_szPracticeTime[MAXPLAYERS + 1][32];

// Missed personal record time?
bool g_bMissedMapBest[MAXPLAYERS + 1];

Expand Down Expand Up @@ -1240,16 +1257,24 @@ int g_iTotalMeasures[MAXPLAYERS + 1];
float g_fAngleCache[MAXPLAYERS + 1];

// Save locs
int g_iSaveLocCount;
float g_fSaveLocCoords[MAX_LOCS][3]; // [loc id][coords]
float g_fSaveLocAngle[MAX_LOCS][3]; // [loc id][angle]
float g_fSaveLocVel[MAX_LOCS][3]; // [loc id][velocity]
int g_iSaveLocCount[MAXPLAYERS + 1];
float g_fSaveLocCoords[MAXPLAYERS + 1][MAX_LOCS][3]; // [loc id][coords]
float g_fSaveLocAngle[MAXPLAYERS + 1][MAX_LOCS][3]; // [loc id][angle]
float g_fSaveLocVel[MAXPLAYERS + 1][MAX_LOCS][3]; // [loc id][velocity]
char g_szSaveLocTargetname[MAX_LOCS][128]; // [loc id]
char g_szSaveLocClientName[MAX_LOCS][MAX_NAME_LENGTH];
char g_szSaveLocClientName[MAXPLAYERS + 1][MAX_LOCS][MAX_NAME_LENGTH];
int g_iLastSaveLocIdClient[MAXPLAYERS + 1];
float g_fLastCheckpointMade[MAXPLAYERS + 1];
int g_iSaveLocUnix[MAX_LOCS]; // [loc id]
int g_iSaveLocUnix[MAX_LOCS][MAXPLAYERS + 1]; // [loc id]
int g_iMenuPosition[MAXPLAYERS + 1];
int g_iPreviousSaveLocIdClient[MAXPLAYERS + 1]; // The previous saveloc the client used
float g_fPlayerPracTimeSnap[MAXPLAYERS + 1][MAX_LOCS]; // PracticeMode saveloc runtime
int g_iPlayerPracLocationSnap[MAXPLAYERS + 1][MAX_LOCS]; // Stage the player was in when creating saveloc
int g_iPlayerPracLocationSnapIdClient[MAXPLAYERS + 1]; // Stage Index to use when tele to saveloc
bool g_bSaveLocTele[MAXPLAYERS + 1]; // Has the player teleported to saveloc?
int g_iSaveLocInBonus[MAXPLAYERS + 1][MAX_LOCS]; // Bonus number if player created saveloc in bonus
float g_fPlayerPracSrcpTimeSnap[MAXPLAYERS + 1][MAX_LOCS]; // PracticeMode Wrcp saveloc runtime
int g_iAllowCheckpointRecreation; // Int for allowCheckpointRecreation convar

char g_sServerName[256];
ConVar g_hHostName = null;
Expand Down Expand Up @@ -1900,7 +1925,6 @@ public void OnMapStart()

// Save Locs
ResetSaveLocs();

}

public void OnMapEnd()
Expand Down Expand Up @@ -2144,7 +2168,9 @@ public void OnClientDisconnect(int client)
g_fPlayerLastTime[client] = GetGameTime() - g_fStartTime[client] - g_fPauseTime[client];
}
else
{
g_fPlayerLastTime[client] = g_fCurrentRunTime[client];
}
}

SDKUnhook(client, SDKHook_SetTransmit, Hook_SetTransmit);
Expand Down
107 changes: 97 additions & 10 deletions addons/sourcemod/scripting/surftimer/buttonpress.sp
Original file line number Diff line number Diff line change
@@ -1,37 +1,39 @@
// Start Timer
public void CL_OnStartTimerPress(int client)
{
float fGetGameTime = GetGameTime();

if (!IsFakeClient(client))
{
if (IsValidClient(client))
{
if (!g_bServerDataLoaded)
{
if (GetGameTime() - g_fErrorMessage[client] > 1.0)
if (fGetGameTime - g_fErrorMessage[client] > 1.0)
{
CPrintToChat(client, "%t", "BPress1", g_szChatPrefix);
ClientCommand(client, "play buttons\\button10.wav");
g_fErrorMessage[client] = GetGameTime();
g_fErrorMessage[client] = fGetGameTime;
}
return;
}
else if (g_bLoadingSettings[client])
{
if (GetGameTime() - g_fErrorMessage[client] > 1.0)
if (fGetGameTime - g_fErrorMessage[client] > 1.0)
{
CPrintToChat(client, "%t", "BPress2", g_szChatPrefix);
ClientCommand(client, "play buttons\\button10.wav");
g_fErrorMessage[client] = GetGameTime();
g_fErrorMessage[client] = fGetGameTime;
}
return;
}
else if (!g_bSettingsLoaded[client])
{
if (GetGameTime() - g_fErrorMessage[client] > 1.0)
if (fGetGameTime - g_fErrorMessage[client] > 1.0)
{
CPrintToChat(client, "%t", "BPress3", g_szChatPrefix);
ClientCommand(client, "play buttons\\button10.wav");
g_fErrorMessage[client] = GetGameTime();
g_fErrorMessage[client] = fGetGameTime;
}
return;
}
Expand All @@ -40,25 +42,28 @@ public void CL_OnStartTimerPress(int client)
return;
}

if (!g_bSpectate[client] && !g_bNoClip[client] && ((GetGameTime() - g_fLastTimeNoClipUsed[client]) > 2.0))
if (!g_bSpectate[client] && !g_bNoClip[client] && ((fGetGameTime - g_fLastTimeNoClipUsed[client]) > 2.0))
{
if (g_bActivateCheckpointsOnStart[client])
g_bCheckpointsEnabled[client] = true;

// Reset Run Variables
tmpDiff[client] = 9999.0;
g_fPauseTime[client] = 0.0;
g_fSrcpPauseTime[client] = 0.0;
g_fStartPauseTime[client] = 0.0;
g_bPause[client] = false;
SetEntityMoveType(client, MOVETYPE_WALK);
SetEntityRenderMode(client, RENDER_NORMAL);
g_fStartTime[client] = GetGameTime();
g_fStartTime[client] = fGetGameTime;
g_fCurrentRunTime[client] = 0.0;
g_fPracModeStartTime[client] = fGetGameTime;
g_bPositionRestored[client] = false;
g_bMissedMapBest[client] = true;
g_bMissedBonusBest[client] = true;
g_bTimerRunning[client] = true;
g_bTop10Time[client] = false;

// Strafe Sync
g_iGoodGains[client] = 0;
g_iTotalMeasures[client] = 0;
Expand Down Expand Up @@ -195,10 +200,13 @@ public void CL_OnEndTimerPress(int client)

if (g_bPracticeMode[client])
{
// Get CurrentRunTime and format it to a string
FormatTimeFloat(client, g_fCurrentRunTime[client], 3, g_szPracticeTime[client], 32);

if (g_iClientInZone[client][2] > 0)
CPrintToChat(client, "%t", "BPress4", g_szChatPrefix, szName, g_szFinalTime[client]);
CPrintToChat(client, "%t", "BPress4", g_szChatPrefix, szName, g_szPracticeTime[client]);
else
CPrintToChat(client, "%t", "BPress5", g_szChatPrefix, szName, g_szFinalTime[client]);
CPrintToChat(client, "%t", "BPress5", g_szChatPrefix, szName, g_szPracticeTime[client]);

/* Start function call */
Call_StartForward(g_PracticeFinishForward);
Expand All @@ -211,6 +219,9 @@ public void CL_OnEndTimerPress(int client)
/* Finish the call, get the result */
Call_Finish();

// Stop Timer
Client_Stop(client, 1);

return;
}

Expand Down Expand Up @@ -879,6 +890,7 @@ public void CL_OnEndWrcpTimerPress(int client, float time2)
}

db_selectWrcpRecord(client, 0, stage);

g_bWrcpTimeractivated[client] = false;
}
else if (g_bWrcpTimeractivated[client] && g_iCurrentStyle[client] != 0) // styles
Expand All @@ -905,7 +917,82 @@ public void CL_OnEndWrcpTimerPress(int client, float time2)
}

FormatTimeFloat(client, g_fFinalWrcpTime[client], 3, g_szFinalWrcpTime[client], 32);

db_selectWrcpRecord(client, style, stage);

g_bWrcpTimeractivated[client] = false;
}
}

public void CL_OnStartPracSrcpTimerPress(int client)
{
float fGetGameTime = GetGameTime();

if (!g_bSpectate[client] && !g_bNoClip[client] && ((fGetGameTime - g_fLastTimeNoClipUsed[client]) > 2.0))
{
int zGroup = g_iClientInZone[client][2];


if(zGroup != 0)
{
return;
}
if (zGroup == 0)
{
g_bPracSrcpTimerActivated[client] = true;
g_fSrcpPauseTime[client] = 0.0;
g_fStartPracSrcpTime[client] = fGetGameTime;

if (g_bSaveLocTele[client]) // Has the player teleported to saveloc?
{
g_iPracSrcpStage[client] = g_iPlayerPracLocationSnap[client][g_iLastSaveLocIdClient[client]];
}
else
{
g_iPracSrcpStage[client] = g_Stage[g_iClientInZone[client][2]][client];
}
}
}
}

public void CL_OnEndPracSrcpTimerPress(int client, float currentPracSrcpRunTime)
{
if (!IsValidClient(client))
{
return;
}

int stage = g_iPracSrcpStage[client];

if (g_bPracSrcpEndZone[client])
{
stage += 1;
g_bPracSrcpEndZone[client] = false;
}

if (stage > g_TotalStages) // Hack Fix for multiple end zone issue
{
stage = g_TotalStages;
}
else if (stage < 1)
{
stage = 1;
}

if (g_bPracSrcpTimerActivated[client])
{
g_fFinalPracSrcpTime[client] = currentPracSrcpRunTime;
g_bPracSrcpTimerActivated[client] = false;
}

if (g_fFinalPracSrcpTime[client] <= 0.0)
{
CPrintToChat(client, "%t", "ErrorPracWrcpTime", g_szChatPrefix, stage);
return;
}

FormatTimeFloat(client, g_fFinalPracSrcpTime[client], 3, g_szFinalPracSrcpTime[client], 32);

int style = g_iCurrentStyle[client];
db_selectPracWrcpRecord(client, style, stage);
}
Loading