Skip to content

Commit

Permalink
Practice mode rework (#43)
Browse files Browse the repository at this point in the history
* Latest Prac Work

* Move this

* Fix naming

* Fix time issue and cleanup

* SaveLoc Recreation!

Initial work:

1. Allows recreating savelocs

Working: on stage maps, have not worked with linear maps

TODO: There is a bug when recreating saveloc after you have cleared savelocs which i have not figured out as yet

* Fix Wrcp bug when switching from spectate

* Revert "Fix Wrcp bug when switching from spectate"

This reverts commit 4801b94.

* Update

1. Fix times issues when using pause/spectate.
2. Remove some code (commented out for now) and use easier method to do this (thanks Just-Sad for pointing this out)

* Fix bugs

* Stop making/go to saveloc whilst spectating

* Fix bug, showing another player name in !savelocs

* Add options for allowing checkpoint (saveloc) recreation

* Fix

1. Fix bug where creating saveloc in prac returns wrong srcp time (commands.sp)
2. move float to better location (misc.sp)
3. Rework this a little for better operation as well as fix bug where no wrcp time in stage 1 after restarting map whilst you were in prac (surfzones.sp)

* Update surfzones.sp

Just move this to here so srcptimer doesnt start if timer disabled

* Fix

1. Fix issue where you couldnt start timer if restarting bonus whilst in prac

* Fix

1. Add missing time to saveloc recreation
2. Fix buffersize issue for saveloc recreation
3. Add restrictions to saveloc recreation (no longer can you use command with invalid number of inputs)

* Fix and Change

1. Fix unix times in !loclist
2. Change !loclist (remove player name and add time)
3. TODO add speed into !loclist (this is very tricky, especially when it comes to players using different measures of speed, xy/xyz/z)

* Fix

1. Fix issue where timer could not start after tele to stage then create saveloc then tele to saveloc then sm_rs and try start time
2. Fix issue where "StageNotRecorded" would be displayed after doing above on stage 2

* Changes

1. Added print to console to display when you created saveloc
2. Change save loc recreation to less precise values which saves space and should always allow it to be inserted via chat
3. Add missing variable to recreatePlayerCheckpoint
4. Remove duplicate variable in recreatePlayerCheckpoint
5. Rename translations

* Creating savelocs from spectate

Still to be tested with players but seems to work fine with bots.

1. Allow saveloc to be created from spectate.
2. Stop stage time print to chat happening in bonus when going into end zone (surfzones.sp)
3. Rename translation

* Fix

1. Force GetcurrentRunTime here to fix the bug with creating a saveloc right infront of CP (showing time as 0)

* Small tidy up

* Update Version

* Complete requested changes

* Fix naming

* Oops forgot this one xD

* another oops...

* Update CHANGELOG.md
  • Loading branch information
Kyli3Boi authored May 26, 2021
1 parent 450a550 commit 6948a5d
Show file tree
Hide file tree
Showing 9 changed files with 1,056 additions and 154 deletions.
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

0 comments on commit 6948a5d

Please sign in to comment.