From 0b0d7858852536f5dc4912ffe3b7c7f2f7a2b153 Mon Sep 17 00:00:00 2001 From: shipyy Date: Mon, 29 Aug 2022 00:46:50 +0100 Subject: [PATCH 1/5] --multiple zones --- addons/sourcemod/scripting/surftimer/api.sp | 2 +- .../scripting/surftimer/buttonpress.sp | 6 +- .../sourcemod/scripting/surftimer/commands.sp | 2 +- addons/sourcemod/scripting/surftimer/misc.sp | 24 ++++---- addons/sourcemod/scripting/surftimer/sql.sp | 60 +++++++++++++++---- .../scripting/surftimer/surfzones.sp | 6 +- 6 files changed, 69 insertions(+), 31 deletions(-) diff --git a/addons/sourcemod/scripting/surftimer/api.sp b/addons/sourcemod/scripting/surftimer/api.sp index 02f47f72..c9fc788c 100644 --- a/addons/sourcemod/scripting/surftimer/api.sp +++ b/addons/sourcemod/scripting/surftimer/api.sp @@ -219,7 +219,7 @@ public int Native_GetMapStages(Handle plugin, int numParams) { int stages = 0; if (g_bhasStages) - stages = g_mapZonesTypeCount[0][3] + 1; + stages = g_TotalStages; return stages; } diff --git a/addons/sourcemod/scripting/surftimer/buttonpress.sp b/addons/sourcemod/scripting/surftimer/buttonpress.sp index b22bb230..fe7b3e88 100644 --- a/addons/sourcemod/scripting/surftimer/buttonpress.sp +++ b/addons/sourcemod/scripting/surftimer/buttonpress.sp @@ -306,11 +306,13 @@ public void CL_OnEndTimerPress(int client) if (style == 0) { //ADD LAST TIME TO CP DATA - g_fCheckpointTimesNew[zGroup][client][g_TotalStages-1] = g_fFinalTime[client]; + if (g_bhasStages) + g_fCheckpointTimesNew[zGroup][client][g_TotalStages-1] = g_fFinalTime[client]; + else + g_fCheckpointTimesNew[zGroup][client][g_iTotalCheckpoints] = g_fFinalTime[client]; g_fPBDifference[client][0] = g_fFinalTime[client] - g_fPersonalRecord[client]; g_fWRDifference[client][0] = g_fFinalTime[client] - g_fRecordMapTime; - PrintToServer("FINISEF - %f | %f", g_fWRDifference[client][0], g_fRecordMapTime); // Make a new record bot? if (GetConVarBool(g_hReplaceReplayTime) && (g_fFinalTime[client] < g_fReplayTimes[0][0] || g_fReplayTimes[0][0] == 0.0)) diff --git a/addons/sourcemod/scripting/surftimer/commands.sp b/addons/sourcemod/scripting/surftimer/commands.sp index 920cd1e3..d1285dd2 100644 --- a/addons/sourcemod/scripting/surftimer/commands.sp +++ b/addons/sourcemod/scripting/surftimer/commands.sp @@ -1410,7 +1410,7 @@ public Action Command_Restart(int client, int args) g_bClientRestarting[client] = false; // Check that the client has a timer running, the zonegroup he is in has stages and that this is the first click - if (IsValidClient(client) && g_bTimerRunning[client] && g_mapZonesTypeCount[g_iClientInZone[client][2]][3] > 0 && !g_bClientRestarting[client] && g_Stage[g_iClientInZone[client][2]][client] > 1) + if (IsValidClient(client) && g_bTimerRunning[client] && g_TotalStages > 0 && !g_bClientRestarting[client] && g_Stage[g_iClientInZone[client][2]][client] > 1) { g_fClientRestarting[client] = GetGameTime(); g_bClientRestarting[client] = true; diff --git a/addons/sourcemod/scripting/surftimer/misc.sp b/addons/sourcemod/scripting/surftimer/misc.sp index 3fd67c39..a2db11f8 100644 --- a/addons/sourcemod/scripting/surftimer/misc.sp +++ b/addons/sourcemod/scripting/surftimer/misc.sp @@ -2982,7 +2982,7 @@ public void SpecListMenuDead(int client) // What Spectators see Format(szProBest, 32, "None"); if (g_bhasStages) // There are stages - Format(szStage, 32, "Stage: %i / %i", g_Stage[g_iClientInZone[ObservedUser][2]][ObservedUser], (g_mapZonesTypeCount[g_iClientInZone[ObservedUser][2]][3] + 1)); + Format(szStage, 32, "Stage: %i / %i", g_Stage[g_iClientInZone[ObservedUser][2]][ObservedUser], g_TotalStages); else Format(szStage, 32, "Linear map"); @@ -3614,16 +3614,16 @@ public void CenterHudAlive(int client) { if (g_bSaveLocTele[client]) // Has the player teleported to saveloc? { - Format(module[i], 128, "Stage: %i/%i", g_iPlayerPracLocationSnap[client][g_iPlayerPracLocationSnapIdClient[client]], (g_mapZonesTypeCount[g_iClientInZone[client][2]][3] + 1)); + Format(module[i], 128, "Stage: %i/%i", g_iPlayerPracLocationSnap[client][g_iPlayerPracLocationSnapIdClient[client]], g_TotalStages); } else { - Format(module[i], 128, "Stage: %i/%i", g_Stage[g_iClientInZone[client][2]][client], (g_mapZonesTypeCount[g_iClientInZone[client][2]][3] + 1)); + Format(module[i], 128, "Stage: %i/%i", g_Stage[g_iClientInZone[client][2]][client], g_TotalStages); } } else { - Format(module[i], 128, "Stage: %i/%i", g_Stage[g_iClientInZone[client][2]][client], (g_mapZonesTypeCount[g_iClientInZone[client][2]][3] + 1)); // less \t's to make lines align + Format(module[i], 128, "Stage: %i/%i", g_Stage[g_iClientInZone[client][2]][client], g_TotalStages); // less \t's to make lines align } } } @@ -3816,7 +3816,7 @@ public void SideHudAlive(int client) // Format(szStage, 64, "Linear Map"); char szCP[64]; char szCurrentCP[64]; - if (g_iCurrentCheckpoint[client] == g_mapZonesTypeCount[g_iClientInZone[client][2]][4]) + if (g_iCurrentCheckpoint[client] == g_iTotalCheckpoints) { FormatTimeFloat(0, g_fRecordMapTime, 3, szCP, 64); Format(szCurrentCP, 64, "End Zone"); @@ -3853,16 +3853,16 @@ public void SideHudAlive(int client) { if (g_bSaveLocTele[client]) // Has the player teleported to saveloc? { - Format(szStage, 64, "Stage: %i / %i", g_iPlayerPracLocationSnap[client][g_iLastSaveLocIdClient[client]], (g_mapZonesTypeCount[g_iClientInZone[client][2]][3] + 1)); + Format(szStage, 64, "Stage: %i / %i", g_iPlayerPracLocationSnap[client][g_iLastSaveLocIdClient[client]], g_TotalStages); } else { - Format(szStage, 64, "Stage: %i / %i", g_Stage[g_iClientInZone[client][2]][client], (g_mapZonesTypeCount[g_iClientInZone[client][2]][3] + 1)); + Format(szStage, 64, "Stage: %i / %i", g_Stage[g_iClientInZone[client][2]][client], g_TotalStages); } } else { - Format(szStage, 64, "Stage: %i / %i", g_Stage[g_iClientInZone[client][2]][client], (g_mapZonesTypeCount[g_iClientInZone[client][2]][3] + 1)); + Format(szStage, 64, "Stage: %i / %i", g_Stage[g_iClientInZone[client][2]][client], g_TotalStages); } char szWrcpTime[64]; @@ -3936,6 +3936,8 @@ public void Checkpoint(int client, int zone, int zonegroup, float time) if (!IsValidClient(client) || g_bPositionRestored[client] || IsFakeClient(client) || zone >= CPLIMIT) return; + PrintToServer("===CHECKPOINT %d===", zone); + g_iCPStartFrame_CurrentRun[0][zone][client] = g_iRecordedTicks[client]; float percent = -1.0; @@ -3944,10 +3946,10 @@ public void Checkpoint(int client, int zone, int zonegroup, float time) char szSpecMessage[512]; if (g_bhasStages) // If staged map - totalPoints = g_mapZonesTypeCount[zonegroup][3]; + totalPoints = g_TotalStages; else - if (g_mapZonesTypeCount[zonegroup][4] > 0) // If Linear Map and checkpoints - totalPoints = g_mapZonesTypeCount[zonegroup][4]; + if (g_iTotalCheckpoints > 0) // If Linear Map and checkpoints + totalPoints = g_iTotalCheckpoints; // Count percent of completion percent = (float(zone + 1) / float(totalPoints + 1)); diff --git a/addons/sourcemod/scripting/surftimer/sql.sp b/addons/sourcemod/scripting/surftimer/sql.sp index 8063c05c..fc561477 100644 --- a/addons/sourcemod/scripting/surftimer/sql.sp +++ b/addons/sourcemod/scripting/surftimer/sql.sp @@ -3608,7 +3608,7 @@ public void db_InsertOrUpdateCheckpoints(int client, char szSteamID[32], int zGr if(g_bhasStages) Format(szQuery, sizeof(szQuery), sql_InsertOrUpdateCheckpoints, szSteamID, g_szMapName, i+1, g_fCheckpointTimesNew[zGroup][client][i], g_fStageTimesNew[client][i], g_iStageAttemptsNew[client][i], zGroup, g_fCheckpointTimesNew[zGroup][client][i], g_fStageTimesNew[client][i], g_iStageAttemptsNew[client][i]); else - Format(szQuery, sizeof(szQuery), sql_InsertOrUpdateCheckpoints, szSteamID, g_szMapName, i+1, -1.0, -1.0, g_iStageAttemptsNew[client][i], zGroup, g_fCheckpointTimesNew[zGroup][client][i], g_fStageTimesNew[client][i], g_iStageAttemptsNew[client][i]); + Format(szQuery, sizeof(szQuery), sql_InsertOrUpdateCheckpoints, szSteamID, g_szMapName, i+1, g_fCheckpointTimesNew[zGroup][client][i], -1.0, -1, zGroup, g_fCheckpointTimesNew[zGroup][client][i], -1.0, -1); tAction.AddQuery(szQuery); } @@ -4145,7 +4145,7 @@ public void SQL_selectMapTierCallback(Handle owner, Handle hndl, const char[] er default:Format(g_sTierString, 512, "%s%cTier %i %c- ", g_sTierString, GRAY, tier, WHITE); } if (g_bhasStages) - Format(g_sTierString, 512, "%s%c%i Stages", g_sTierString, LIGHTGREEN, (g_mapZonesTypeCount[0][3] + 1)); + Format(g_sTierString, 512, "%s%c%i Stages", g_sTierString, LIGHTGREEN, g_TotalStages); else Format(g_sTierString, 512, "%s%cLinear", g_sTierString, LIMEGREEN); @@ -5117,6 +5117,9 @@ public void SQL_selectMapZonesCallback(Handle owner, Handle hndl, const char[] e g_bhasBonus = false; g_mapZoneGroupCount = 0; // 1 = No Bonus, 2 = Bonus, >2 = Multiple bonuses g_iTotalCheckpoints = 0; + g_TotalStages = 0; + int g_iTotalCheckpoints_Same = 0; + int g_iTotalStages_Same = 0; for (int i = 0; i < MAXZONES; i++) { @@ -5140,11 +5143,13 @@ public void SQL_selectMapZonesCallback(Handle owner, Handle hndl, const char[] e { g_mapZoneCountinGroup[x] = 0; for (int k = 0; k < ZONEAMOUNT; k++) - g_mapZonesTypeCount[x][k] = 0; + g_mapZonesTypeCount[x][k] = 1; } int zoneIdChecker[MAXZONES], zoneTypeIdChecker[MAXZONEGROUPS][ZONEAMOUNT][MAXZONES], zoneTypeIdCheckerCount[MAXZONEGROUPS][ZONEAMOUNT], zoneGroupChecker[MAXZONEGROUPS]; + ArrayList temp_zonetypeID = new ArrayList(); + // Types: Start(1), End(2), Stage(3), Checkpoint(4), Speed(5), TeleToStart(6), Validator(7), Chekcer(8), Stop(0) while (SQL_FetchRow(hndl)) { @@ -5161,13 +5166,32 @@ public void SQL_selectMapZonesCallback(Handle owner, Handle hndl, const char[] e g_mapZones[g_mapZonesCount].Team = SQL_FetchInt(hndl, 10); g_mapZones[g_mapZonesCount].ZoneGroup = SQL_FetchInt(hndl, 11); - // Total amount of checkpoints + //COUNT CHECKPOINTS AND STAGES if (g_mapZones[g_mapZonesCount].ZoneGroup == 0) { - if (g_mapZones[g_mapZonesCount].ZoneType == 4) + PrintToServer("===ID FOUND : %d===", g_mapZones[g_mapZonesCount].ZoneId) + PrintToServer("===IS CHECKPOINT : %s===", g_mapZones[g_mapZonesCount].ZoneType == 4 ? "true" : "false"); + if (g_mapZones[g_mapZonesCount].ZoneType == 4 && temp_zonetypeID.FindValue(g_mapZones[g_mapZonesCount].ZoneTypeId) == -1) { + PrintToServer("===INCREMENTING g_iTotalCheckpoints==="); + temp_zonetypeID.Push(g_mapZones[g_mapZonesCount].ZoneTypeId); g_iTotalCheckpoints++; } + else if (g_mapZones[g_mapZonesCount].ZoneType == 4 && temp_zonetypeID.FindValue(g_mapZones[g_mapZonesCount].ZoneTypeId) != -1) + { + g_iTotalCheckpoints_Same++; + } + + if (g_mapZones[g_mapZonesCount].ZoneType == 3 && temp_zonetypeID.FindValue(g_mapZones[g_mapZonesCount].ZoneTypeId) == -1) + { + PrintToServer("===INCREMENTING g_TotalStages==="); + temp_zonetypeID.Push(g_mapZones[g_mapZonesCount].ZoneTypeId); + g_TotalStages++; + } + else if (g_mapZones[g_mapZonesCount].ZoneType == 3 && temp_zonetypeID.FindValue(g_mapZones[g_mapZonesCount].ZoneTypeId) != -1) + { + g_iTotalStages_Same++; + } } /** @@ -5290,10 +5314,20 @@ public void SQL_selectMapZonesCallback(Handle owner, Handle hndl, const char[] e g_fZoneCorners[g_mapZonesCount][7][i] = g_mapZones[g_mapZonesCount].PointB[i]; } - // Zone counts: + g_mapZonesTypeCount[g_mapZones[g_mapZonesCount].ZoneGroup][g_mapZones[g_mapZonesCount].ZoneType]++; g_mapZonesCount++; } + + g_TotalStages++; + delete temp_zonetypeID; + + PrintToServer("===TOTAL CHECKPOINTS %d===", g_iTotalCheckpoints); + PrintToServer("===TOTAL STAGES %d===", g_TotalStages); + PrintToServer("===TOTAL ZONES %d===", g_mapZonesCount); + PrintToServer("===TOTAL ZONEGROUPS %d===", g_mapZoneGroupCount); + PrintToServer("===TOTAL CHECKPOINTS REPEATED %d===", g_iTotalCheckpoints_Same); + // Count zone corners // https://forums.alliedmods.net/showpost.php?p=2006539&postcount=8 for (int x = 0; x < g_mapZonesCount; x++) @@ -5334,7 +5368,7 @@ public void SQL_selectMapZonesCallback(Handle owner, Handle hndl, const char[] e } // 3rd ZoneTypeId - for (int i = 0; i < g_mapZoneGroupCount; i++) + /*for (int i = 0; i < g_mapZoneGroupCount; i++) for (int k = 0; k < ZONEAMOUNT; k++) for (int x = 0; x < zoneTypeIdCheckerCount[i][k]; x++) if (zoneTypeIdChecker[i][k][x] != 1 && (k == 3) || (k == 4)) @@ -5352,7 +5386,7 @@ public void SQL_selectMapZonesCallback(Handle owner, Handle hndl, const char[] e Format(szerror, 258, "[SurfTimer] Duplicate Stage Zone ID's on %s [ZoneGroup: %i, ZoneType: 3, ZoneTypeId: %i]", g_szMapName, k, x); LogError(szerror); } - } + }*/ RefreshZones(); @@ -7314,13 +7348,13 @@ public void db_GetTotalStagesCallback(Handle owner, Handle hndl, const char[] er if (SQL_HasResultSet(hndl) && SQL_FetchRow(hndl)) { - g_TotalStages = SQL_FetchInt(hndl, 0) + 1; + //g_TotalStages = SQL_FetchInt(hndl, 0) + 1; - for(int i = 1;i <= g_TotalStages;i++) - { - g_fStageRecord[i] = 0.0; + //for(int i = 1;i <= g_TotalStages;i++) + //{ + // g_fStageRecord[i] = 0.0; // fluffys comeback yo - } + //} } if (!g_bServerDataLoaded) diff --git a/addons/sourcemod/scripting/surftimer/surfzones.sp b/addons/sourcemod/scripting/surftimer/surfzones.sp index ad8aaac4..b336c84b 100644 --- a/addons/sourcemod/scripting/surftimer/surfzones.sp +++ b/addons/sourcemod/scripting/surftimer/surfzones.sp @@ -1666,16 +1666,16 @@ public void SelectNormalZoneType(int client) SelectNormalZoneMenu.SetTitle("Select Zone Type"); SelectNormalZoneMenu.AddItem("1", "Start"); SelectNormalZoneMenu.AddItem("2", "End"); - if (g_mapZonesTypeCount[g_CurrentSelectedZoneGroup[client]][3] == 0 && g_mapZonesTypeCount[g_CurrentSelectedZoneGroup[client]][4] == 0) + if (g_TotalStages == 0 && g_iTotalCheckpoints == 0) { SelectNormalZoneMenu.AddItem("3", "Stage"); SelectNormalZoneMenu.AddItem("4", "Checkpoint"); } - else if (g_mapZonesTypeCount[g_CurrentSelectedZoneGroup[client]][3] > 0 && g_mapZonesTypeCount[g_CurrentSelectedZoneGroup[client]][4] == 0) + else if (g_TotalStages > 0 && g_iTotalCheckpoints == 0) { SelectNormalZoneMenu.AddItem("3", "Stage"); } - else if (g_mapZonesTypeCount[g_CurrentSelectedZoneGroup[client]][3] == 0 && g_mapZonesTypeCount[g_CurrentSelectedZoneGroup[client]][4] > 0) + else if (g_TotalStages == 0 && g_iTotalCheckpoints > 0) SelectNormalZoneMenu.AddItem("4", "Checkpoint"); SelectNormalZoneMenu.AddItem("hook", "Hook Zone"); From e8b688c9a7dd3e1d03af099c14f4a73d440512d3 Mon Sep 17 00:00:00 2001 From: shipyy Date: Mon, 29 Aug 2022 01:14:00 +0100 Subject: [PATCH 2/5] --remove prints --- addons/sourcemod/scripting/surftimer/sql.sp | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/addons/sourcemod/scripting/surftimer/sql.sp b/addons/sourcemod/scripting/surftimer/sql.sp index fc561477..cbaea738 100644 --- a/addons/sourcemod/scripting/surftimer/sql.sp +++ b/addons/sourcemod/scripting/surftimer/sql.sp @@ -5169,11 +5169,8 @@ public void SQL_selectMapZonesCallback(Handle owner, Handle hndl, const char[] e //COUNT CHECKPOINTS AND STAGES if (g_mapZones[g_mapZonesCount].ZoneGroup == 0) { - PrintToServer("===ID FOUND : %d===", g_mapZones[g_mapZonesCount].ZoneId) - PrintToServer("===IS CHECKPOINT : %s===", g_mapZones[g_mapZonesCount].ZoneType == 4 ? "true" : "false"); if (g_mapZones[g_mapZonesCount].ZoneType == 4 && temp_zonetypeID.FindValue(g_mapZones[g_mapZonesCount].ZoneTypeId) == -1) { - PrintToServer("===INCREMENTING g_iTotalCheckpoints==="); temp_zonetypeID.Push(g_mapZones[g_mapZonesCount].ZoneTypeId); g_iTotalCheckpoints++; } @@ -5184,7 +5181,6 @@ public void SQL_selectMapZonesCallback(Handle owner, Handle hndl, const char[] e if (g_mapZones[g_mapZonesCount].ZoneType == 3 && temp_zonetypeID.FindValue(g_mapZones[g_mapZonesCount].ZoneTypeId) == -1) { - PrintToServer("===INCREMENTING g_TotalStages==="); temp_zonetypeID.Push(g_mapZones[g_mapZonesCount].ZoneTypeId); g_TotalStages++; } @@ -5322,12 +5318,6 @@ public void SQL_selectMapZonesCallback(Handle owner, Handle hndl, const char[] e g_TotalStages++; delete temp_zonetypeID; - PrintToServer("===TOTAL CHECKPOINTS %d===", g_iTotalCheckpoints); - PrintToServer("===TOTAL STAGES %d===", g_TotalStages); - PrintToServer("===TOTAL ZONES %d===", g_mapZonesCount); - PrintToServer("===TOTAL ZONEGROUPS %d===", g_mapZoneGroupCount); - PrintToServer("===TOTAL CHECKPOINTS REPEATED %d===", g_iTotalCheckpoints_Same); - // Count zone corners // https://forums.alliedmods.net/showpost.php?p=2006539&postcount=8 for (int x = 0; x < g_mapZonesCount; x++) From 3284312fd6c98946f196451c2693562c02e9545d Mon Sep 17 00:00:00 2001 From: shipyy Date: Mon, 29 Aug 2022 23:51:34 +0100 Subject: [PATCH 3/5] --remove restrictions when setting a zonetypeid via menu `sm_zones` --removed unused query --- .../scripting/surftimer/db/queries.sp | 1 - addons/sourcemod/scripting/surftimer/sql.sp | 85 +++++++------------ 2 files changed, 30 insertions(+), 56 deletions(-) diff --git a/addons/sourcemod/scripting/surftimer/db/queries.sp b/addons/sourcemod/scripting/surftimer/db/queries.sp index 1d9648d5..780c6fdc 100644 --- a/addons/sourcemod/scripting/surftimer/db/queries.sp +++ b/addons/sourcemod/scripting/surftimer/db/queries.sp @@ -104,7 +104,6 @@ char sql_createWrcps[] = "CREATE TABLE IF NOT EXISTS `ck_wrcps` (`steamid` varch char sql_createZones[] = "CREATE TABLE `ck_zones` (`mapname` varchar(54) NOT NULL, `zoneid` int(12) NOT NULL DEFAULT '-1', `zonetype` int(12) DEFAULT '-1', `zonetypeid` int(12) DEFAULT '-1', `pointa_x` float DEFAULT '-1', `pointa_y` float DEFAULT '-1', `pointa_z` float DEFAULT '-1', `pointb_x` float DEFAULT '-1', `pointb_y` float DEFAULT '-1', `pointb_z` float DEFAULT '-1', `vis` int(12) DEFAULT '0', `team` int(12) DEFAULT '0', `zonegroup` int(11) NOT NULL DEFAULT '0', `zonename` varchar(128) DEFAULT NULL, `hookname` varchar(128) DEFAULT 'None', `targetname` varchar(128) DEFAULT 'player', `onejumplimit` int(12) NOT NULL DEFAULT '1', `prespeed` int(64) NOT NULL DEFAULT '%.1f', PRIMARY KEY (`mapname`,`zoneid`)) DEFAULT CHARSET=utf8mb4;"; char sql_insertZones[] = "INSERT INTO ck_zones (mapname, zoneid, zonetype, zonetypeid, pointa_x, pointa_y, pointa_z, pointb_x, pointb_y, pointb_z, vis, team, zonegroup, zonename, hookname, targetname, onejumplimit, prespeed) VALUES ('%s', '%i', '%i', '%i', '%f', '%f', '%f', '%f', '%f', '%f', '%i', '%i', '%i','%s','%s','%s',%i,%f)"; char sql_updateZone[] = "UPDATE ck_zones SET zonetype = '%i', zonetypeid = '%i', pointa_x = '%f', pointa_y ='%f', pointa_z = '%f', pointb_x = '%f', pointb_y = '%f', pointb_z = '%f', vis = '%i', team = '%i', onejumplimit = '%i', prespeed = '%f', hookname = '%s', targetname = '%s', zonegroup = '%i' WHERE zoneid = '%i' AND mapname = '%s'"; -char sql_selectzoneTypeIds[] = "SELECT zonetypeid FROM ck_zones WHERE mapname='%s' AND zonetype='%i' AND zonegroup = '%i';"; char sql_selectMapZones[] = "SELECT zoneid, zonetype, zonetypeid, pointa_x, pointa_y, pointa_z, pointb_x, pointb_y, pointb_z, vis, team, zonegroup, zonename, hookname, targetname, onejumplimit, prespeed FROM ck_zones WHERE mapname = '%s' ORDER BY zonetypeid ASC"; char sql_selectTotalBonusCount[] = "SELECT mapname, zoneid, zonetype, zonetypeid, pointa_x, pointa_y, pointa_z, pointb_x, pointb_y, pointb_z, vis, team, zonegroup, zonename FROM ck_zones WHERE zonetype = 3 GROUP BY mapname, zonegroup;"; char sql_selectZoneIds[] = "SELECT mapname, zoneid, zonetype, zonetypeid, pointa_x, pointa_y, pointa_z, pointb_x, pointb_y, pointb_z, vis, team, zonegroup, zonename, hookname, targetname, onejumplimit, prespeed FROM ck_zones WHERE mapname = '%s' ORDER BY zoneid ASC"; diff --git a/addons/sourcemod/scripting/surftimer/sql.sp b/addons/sourcemod/scripting/surftimer/sql.sp index cbaea738..0c6a0049 100644 --- a/addons/sourcemod/scripting/surftimer/sql.sp +++ b/addons/sourcemod/scripting/surftimer/sql.sp @@ -4908,64 +4908,39 @@ public void SQLTxn_ZoneGroupRemovalFailed(Handle db, any client, int numQueries, public void db_selectzoneTypeIds(int zonetype, int client, int zonegrp) { - char szQuery[258]; - Format(szQuery, 258, sql_selectzoneTypeIds, g_szMapName, zonetype, zonegrp); - SQL_TQuery(g_hDb, SQL_selectzoneTypeIdsCallback, szQuery, client, DBPrio_Low); -} - -public void SQL_selectzoneTypeIdsCallback(Handle owner, Handle hndl, const char[] error, any data) -{ - if (hndl == null) - { - LogError("[SurfTimer] SQL Error (SQL_selectzoneTypeIdsCallback): %s", error); - return; + Menu TypeMenu = new Menu(Handle_EditZoneTypeId); + char MenuNum[24], MenuInfo[6], MenuItemName[24]; + int x = 0; + + // Types: Start(1), End(2), Stage(3), Checkpoint(4), Speed(5), TeleToStart(6), Validator(7), Chekcer(8), Stop(0) //fluffys AntiJump(9), AntiDuck(10) + switch (g_CurrentZoneType[client]) { + case 0:Format(MenuItemName, 24, "Stop"); + case 1:Format(MenuItemName, 24, "Start"); + case 2:Format(MenuItemName, 24, "End"); + case 3: { + Format(MenuItemName, 24, "Stage"); + x = 2; + } + case 4:Format(MenuItemName, 24, "Checkpoint"); + case 5:Format(MenuItemName, 24, "Speed"); + case 6:Format(MenuItemName, 24, "TeleToStart"); + case 7:Format(MenuItemName, 24, "Validator"); + case 8:Format(MenuItemName, 24, "Checker"); + // fluffys + case 9:Format(MenuItemName, 24, "AntiJump"); + case 10:Format(MenuItemName, 24, "AntiDuck"); + case 11:Format(MenuItemName, 24, "MaxSpeed"); + default:Format(MenuItemName, 24, "Unknown"); } - if (SQL_HasResultSet(hndl)) - { - int availableids[MAXZONES] = { 0, ... }, i; - while (SQL_FetchRow(hndl)) - { - i = SQL_FetchInt(hndl, 0); - if (i < MAXZONES) - availableids[i] = 1; - } - Menu TypeMenu = new Menu(Handle_EditZoneTypeId); - char MenuNum[24], MenuInfo[6], MenuItemName[24]; - int x = 0; - // Types: Start(1), End(2), Stage(3), Checkpoint(4), Speed(5), TeleToStart(6), Validator(7), Chekcer(8), Stop(0) //fluffys AntiJump(9), AntiDuck(10) - switch (g_CurrentZoneType[data]) { - case 0:Format(MenuItemName, 24, "Stop"); - case 1:Format(MenuItemName, 24, "Start"); - case 2:Format(MenuItemName, 24, "End"); - case 3: { - Format(MenuItemName, 24, "Stage"); - x = 2; - } - case 4:Format(MenuItemName, 24, "Checkpoint"); - case 5:Format(MenuItemName, 24, "Speed"); - case 6:Format(MenuItemName, 24, "TeleToStart"); - case 7:Format(MenuItemName, 24, "Validator"); - case 8:Format(MenuItemName, 24, "Checker"); - // fluffys - case 9:Format(MenuItemName, 24, "AntiJump"); - case 10:Format(MenuItemName, 24, "AntiDuck"); - case 11:Format(MenuItemName, 24, "MaxSpeed"); - default:Format(MenuItemName, 24, "Unknown"); - } - - for (int k = 0; k < 35; k++) - { - if (availableids[k] == 0) - { - Format(MenuNum, sizeof(MenuNum), "%s-%i", MenuItemName, (k + x)); - Format(MenuInfo, sizeof(MenuInfo), "%i", k); - TypeMenu.AddItem(MenuInfo, MenuNum); - } - } - TypeMenu.ExitButton = true; - TypeMenu.Display(data, MENU_TIME_FOREVER); + for (int k = 0; k < 35; k++) { + Format(MenuNum, sizeof(MenuNum), "%s-%i", MenuItemName, (k + x)); + Format(MenuInfo, sizeof(MenuInfo), "%i", k); + TypeMenu.AddItem(MenuInfo, MenuNum); } + + TypeMenu.ExitButton = true; + TypeMenu.Display(client, MENU_TIME_FOREVER); } /* public checkZoneTypeIds() From 7a1e7c83c6deef22ee53c86d70937a5a5f23e979 Mon Sep 17 00:00:00 2001 From: shipyy Date: Mon, 29 Aug 2022 23:53:21 +0100 Subject: [PATCH 4/5] --removed old commented code regarding zonetypeId --remove leftover print --- addons/sourcemod/scripting/surftimer/misc.sp | 2 - addons/sourcemod/scripting/surftimer/sql.sp | 123 +------------------ 2 files changed, 1 insertion(+), 124 deletions(-) diff --git a/addons/sourcemod/scripting/surftimer/misc.sp b/addons/sourcemod/scripting/surftimer/misc.sp index a2db11f8..ba3a7712 100644 --- a/addons/sourcemod/scripting/surftimer/misc.sp +++ b/addons/sourcemod/scripting/surftimer/misc.sp @@ -3935,8 +3935,6 @@ public void Checkpoint(int client, int zone, int zonegroup, float time) { if (!IsValidClient(client) || g_bPositionRestored[client] || IsFakeClient(client) || zone >= CPLIMIT) return; - - PrintToServer("===CHECKPOINT %d===", zone); g_iCPStartFrame_CurrentRun[0][zone][client] = g_iRecordedTicks[client]; diff --git a/addons/sourcemod/scripting/surftimer/sql.sp b/addons/sourcemod/scripting/surftimer/sql.sp index 0c6a0049..1cbf7f58 100644 --- a/addons/sourcemod/scripting/surftimer/sql.sp +++ b/addons/sourcemod/scripting/surftimer/sql.sp @@ -4938,131 +4938,10 @@ public void db_selectzoneTypeIds(int zonetype, int client, int zonegrp) Format(MenuInfo, sizeof(MenuInfo), "%i", k); TypeMenu.AddItem(MenuInfo, MenuNum); } - + TypeMenu.ExitButton = true; TypeMenu.Display(client, MENU_TIME_FOREVER); } -/* -public checkZoneTypeIds() -{ -InitZoneVariables(); - -char szQuery[258]; -Format(szQuery, 258, "SELECT `zonegroup` ,`zonetype`, `zonetypeid` FROM `ck_zones` WHERE `mapname` = '%s';", g_szMapName); -SQL_TQuery(g_hDb, checkZoneTypeIdsCallback, szQuery, 1, DBPrio_High); -} - -public checkZoneTypeIdsCallback(Handle owner, Handle hndl, const char[] error, any:data) -{ -if (hndl == null) -{ -LogError("[SurfTimer] SQL Error (checkZoneTypeIds): %s", error); -return; -} -if (SQL_HasResultSet(hndl)) -{ -int idChecker[MAXZONEGROUPS][ZONEAMOUNT][MAXZONES], idCount[MAXZONEGROUPS][ZONEAMOUNT]; -char szQuery[258]; -// Fill array with id's -// idChecker = map zones in -while (SQL_FetchRow(hndl)) -{ -idChecker[SQL_FetchInt(hndl, 0)][SQL_FetchInt(hndl, 1)][SQL_FetchInt(hndl, 2)] = 1; -idCount[SQL_FetchInt(hndl, 0)][SQL_FetchInt(hndl, 1)]++; -} -for (int i = 0; i < MAXZONEGROUPS; i++) -{ -for (int j = 0; j < ZONEAMOUNT; j++) -{ -for (int k = 0; k < idCount[i][j]; k++) -{ -if (idChecker[i][j][k] == 1) -continue; -else -{ -PrintToServer("[SurfTimer] Error on zonetype: %i, zonetypeid: %i", i, idChecker[i][k]); -Format(szQuery, 258, "UPDATE `ck_zones` SET zonetypeid = zonetypeid-1 WHERE mapname = '%s' AND zonetype = %i AND zonetypeid > %i AND zonegroup = %i;", g_szMapName, j, k, i); -SQL_LockDatabase(g_hDb); -SQL_FastQuery(g_hDb, szQuery); -SQL_UnlockDatabase(g_hDb); -} -} -} -} - -Format(szQuery, 258, "SELECT `zoneid` FROM `ck_zones` WHERE mapname = '%s' ORDER BY zoneid ASC;", g_szMapName); -SQL_TQuery(g_hDb, checkZoneIdsCallback, szQuery, 1, DBPrio_High); -} -} - -public checkZoneIdsCallback(Handle owner, Handle hndl, const char[] error, any:data) -{ -if (hndl == null) -{ -LogError("[SurfTimer] SQL Error (checkZoneIdsCallback): %s", error); -return; -} - -if (SQL_HasResultSet(hndl)) -{ -int i = 0; -char szQuery[258]; -while (SQL_FetchRow(hndl)) -{ -if (SQL_FetchInt(hndl, 0) == i) -{ -i++; -continue; -} -else -{ -PrintToServer("[SurfTimer] Found an error in ZoneID's. Fixing..."); -Format(szQuery, 258, "UPDATE `ck_zones` SET zoneid = %i WHERE mapname = '%s' AND zoneid = %i", i, g_szMapName, SQL_FetchInt(hndl, 0)); -SQL_LockDatabase(g_hDb); -SQL_FastQuery(g_hDb, szQuery); -SQL_UnlockDatabase(g_hDb); -i++; -} -} - -char szQuery2[258]; -Format(szQuery2, 258, "SELECT `zonegroup` FROM `ck_zones` WHERE `mapname` = '%s' ORDER BY `zonegroup` ASC;", g_szMapName); -SQL_TQuery(g_hDb, checkZoneGroupIds, szQuery2, 1, DBPrio_Low); -} -} - -public checkZoneGroupIds(Handle owner, Handle hndl, const char[] error, any:data) -{ -if (hndl == null) -{ -LogError("[SurfTimer] SQL Error (checkZoneGroupIds): %s", error); -return; -} - -if (SQL_HasResultSet(hndl)) -{ -int i = 0; -char szQuery[258]; -while (SQL_FetchRow(hndl)) -{ -if (SQL_FetchInt(hndl, 0) == i) -continue; -else if (SQL_FetchInt(hndl, 0) == (i+1)) -i++; -else -{ -i++; -PrintToServer("[SurfTimer] Found an error in zoneGroupID's. Fixing..."); -Format(szQuery, 258, "UPDATE `ck_zones` SET `zonegroup` = %i WHERE `mapname` = '%s' AND `zonegroup` = %i", i, g_szMapName, SQL_FetchInt(hndl, 0)); -SQL_LockDatabase(g_hDb); -SQL_FastQuery(g_hDb, szQuery); -SQL_UnlockDatabase(g_hDb); -} -} -db_selectMapZones(); -} -} -*/ public void db_selectMapZones() { From aec30efbb402423f63f8002c56187d4bf2eabbfa Mon Sep 17 00:00:00 2001 From: shipyy Date: Tue, 30 Aug 2022 17:07:48 +0100 Subject: [PATCH 5/5] --remove unecessary query --- addons/sourcemod/scripting/surftimer/sql.sp | 30 +++------------------ 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/addons/sourcemod/scripting/surftimer/sql.sp b/addons/sourcemod/scripting/surftimer/sql.sp index 1cbf7f58..e6538a8f 100644 --- a/addons/sourcemod/scripting/surftimer/sql.sp +++ b/addons/sourcemod/scripting/surftimer/sql.sp @@ -7169,37 +7169,13 @@ public void SQL_selectPersonalPrestrafeSpeeds_BonusCallback(Handle owner, Handle public void db_GetTotalStages() { // Check if map has stages, if not don't bother loading this - if (!g_bhasStages) - { + if (!g_bhasStages) { db_selectTotalBonusCount(); return; } - char szQuery[512]; - - Format(szQuery, 512, "SELECT COUNT(`zonetype`) AS stages FROM `ck_zones` WHERE `zonetype` = '3' AND `mapname` = '%s'", g_szMapName); - SQL_TQuery(g_hDb, db_GetTotalStagesCallback, szQuery, _, DBPrio_Low); -} - -public void db_GetTotalStagesCallback(Handle owner, Handle hndl, const char[] error, any data) -{ - if (hndl == null) - { - LogError("[SurfTimer] SQL Error (db_GetTotalStagesCallback): %s ", error); - db_viewStageRecords(); - return; - } - - if (SQL_HasResultSet(hndl) && SQL_FetchRow(hndl)) - { - //g_TotalStages = SQL_FetchInt(hndl, 0) + 1; - - //for(int i = 1;i <= g_TotalStages;i++) - //{ - // g_fStageRecord[i] = 0.0; - // fluffys comeback yo - //} - } + for (int i = 1; i <= g_TotalStages ;i++) + g_fStageRecord[i] = 0.0; if (!g_bServerDataLoaded) db_viewStageRecords();