Advertisement
Guchay

Untitled

Sep 30th, 2016
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 97.31 KB | None | 0 0
  1. void disableServerHibernate()
  2. {
  3. Handle hServerHibernate = FindConVar("sv_hibernate_when_empty");
  4. g_iServerHibernationValue = GetConVarInt(hServerHibernate);
  5. if (g_iServerHibernationValue > 0)
  6. {
  7. PrintToServer("[ckSurf] Disabling server hibernation.");
  8. SetConVarInt(hServerHibernate, 0, false, false);
  9. }
  10. CloseHandle(hServerHibernate);
  11. return;
  12. }
  13.  
  14. void revertServerHibernateSettings()
  15. {
  16. Handle hServerHibernate = FindConVar("sv_hibernate_when_empty");
  17. if (GetConVarInt(hServerHibernate) != g_iServerHibernationValue)
  18. {
  19. PrintToServer("[ckSurf] Resetting Server Hibernation CVar");
  20. SetConVarInt(hServerHibernate, g_iServerHibernationValue, false, false);
  21. }
  22. CloseHandle(hServerHibernate);
  23. return;
  24. }
  25. void setBotQuota()
  26. {
  27. // Get bot_quota value
  28. ConVar hBotQuota = FindConVar("bot_quota");
  29.  
  30. // Initialize
  31. SetConVarInt(hBotQuota, 0, false, false);
  32.  
  33. // Check how many bots are needed
  34. int count = 0;
  35. if (g_bMapReplay)
  36. count++;
  37. if (GetConVarBool(g_hInfoBot))
  38. count++;
  39. if (g_BonusBotCount > 0)
  40. count++;
  41.  
  42. SetConVarInt(hBotQuota, count, false, false);
  43.  
  44. CloseHandle(hBotQuota);
  45.  
  46. return;
  47. }
  48.  
  49. bool IsValidZonegroup(int zGrp)
  50. {
  51. if (-1 < zGrp < g_mapZoneGroupCount)
  52. return true;
  53. return false;
  54. }
  55.  
  56. /**
  57. * Checks if coordinates are inside a zone
  58. * Return: zone id where location is in, or -1 if not inside a zone
  59. **/
  60. int IsInsideZone (float location[3], float extraSize = 0.0)
  61. {
  62. float tmpLocation[3];
  63. Array_Copy(location, tmpLocation, 3);
  64. tmpLocation[2] += 5.0;
  65. int iChecker;
  66.  
  67. for (int i = 0; i < g_mapZonesCount; i++)
  68. {
  69. iChecker = 0;
  70. for(int x = 0; x < 3; x++)
  71. {
  72. if((g_fZoneCorners[i][7][x] >= g_fZoneCorners[i][0][x] && (tmpLocation[x] <= (g_fZoneCorners[i][7][x] + extraSize) && tmpLocation[x] >= (g_fZoneCorners[i][0][x] - extraSize))) ||
  73. (g_fZoneCorners[i][0][x] >= g_fZoneCorners[i][7][x] && (tmpLocation[x] <= (g_fZoneCorners[i][0][x] + extraSize) && tmpLocation[x] >= (g_fZoneCorners[i][7][x] - extraSize))))
  74. iChecker++;
  75. }
  76. if(iChecker == 3)
  77. return i;
  78. }
  79.  
  80. return -1;
  81. }
  82.  
  83. public void loadAllClientSettings()
  84. {
  85. for (int i = 1; i < MAXPLAYERS + 1; i++)
  86. {
  87. if (IsValidClient(i) && !IsFakeClient(i) && !g_bSettingsLoaded[i] && !g_bLoadingSettings[i])
  88. {
  89. db_viewPersonalRecords(i, g_szSteamID[i], g_szMapName);
  90. g_bLoadingSettings[i] = true;
  91. break;
  92. }
  93. }
  94.  
  95. g_bServerDataLoaded = true;
  96. }
  97. public void getSteamIDFromClient(int client, char[] buffer, int length)
  98. {
  99. // Get steamid - Points are being recalculated by an admin (pretty much going through top 20k players)
  100. if (client > MAXPLAYERS)
  101. {
  102. if (!g_pr_RankingRecalc_InProgress && !g_bProfileRecalc[client])
  103. return;
  104. Format(buffer, length, "%s", g_pr_szSteamID[client]);
  105. }
  106. else // Get steamid - Normal point increase
  107. {
  108. if (!GetConVarBool(g_hPointSystem) || !IsValidClient(client))
  109. return;
  110. GetClientAuthId(client, AuthId_Steam2, buffer, length, true);
  111. }
  112. return;
  113. }
  114.  
  115. /*
  116. Handles teleporting of players
  117. Zonegroup: 0 = normal map, >0 bonuses.
  118. Zone types: 1 = Start zone, >1 Stage zones.
  119. */
  120. public void teleportClient(int client, int zonegroup, int zone, bool stopTime)
  121. {
  122. if (!IsValidClient(client))
  123. return;
  124. if (!IsValidZonegroup(zonegroup))
  125. {
  126. PrintToChat(client, "[%cCK%c] Zonegroup not found.", MOSSGREEN, WHITE);
  127. return;
  128. }
  129.  
  130. if (g_bPracticeMode[client])
  131. Command_normalMode(client, 1);
  132.  
  133. // Check for spawn locations
  134. if (zone == 1 && g_bGotSpawnLocation[zonegroup])
  135. {
  136. if (GetClientTeam(client) == 1 || GetClientTeam(client) == 0) // Spectating
  137. {
  138. if (stopTime)
  139. Client_Stop(client, 0);
  140.  
  141. Array_Copy(g_fSpawnLocation[zonegroup], g_fTeleLocation[client], 3);
  142.  
  143. g_specToStage[client] = true;
  144. g_bRespawnPosition[client] = false;
  145.  
  146. TeamChangeActual(client, 0);
  147. return;
  148. }
  149. else
  150. {
  151. SetEntPropVector(client, Prop_Data, "m_vecVelocity", view_as<float>( { 0.0, 0.0, -100.0 } ));
  152.  
  153. teleportEntitySafe(client, g_fSpawnLocation[zonegroup], g_fSpawnAngle[zonegroup], view_as<float>( { 0.0, 0.0, -100.0 } ), stopTime);
  154.  
  155. return;
  156. }
  157. }
  158. else
  159. {
  160. // Check if the map has zones
  161. if (g_mapZonesCount > 0)
  162. {
  163. // Search for the zoneid we're teleporting to:
  164. int destinationZoneId = getZoneID(zonegroup, zone);
  165.  
  166. // Check if zone was found
  167. if (destinationZoneId > -1)
  168. {
  169. // Check if client is spectating, or not chosen a team yet
  170. if (GetClientTeam(client) == 1 || GetClientTeam(client) == 0)
  171. {
  172.  
  173. if (stopTime)
  174. Client_Stop(client, 0);
  175.  
  176. // Set spawn location to the destination zone:
  177. Array_Copy(g_mapZones[destinationZoneId][CenterPoint], g_fTeleLocation[client], 3);
  178.  
  179. // Set specToStage flag
  180. g_bRespawnPosition[client] = false;
  181. g_specToStage[client] = true;
  182.  
  183. // Spawn player
  184. TeamChangeActual(client, 0);
  185. }
  186. else // Teleport normally
  187. {
  188. // Set client speed to 0
  189. SetEntPropVector(client, Prop_Data, "m_vecVelocity", view_as<float>( { 0.0, 0.0, -100.0 } ));
  190.  
  191. float fLocation[3];
  192. Array_Copy(g_mapZones[destinationZoneId][CenterPoint], fLocation, 3);
  193.  
  194. // Teleport
  195. teleportEntitySafe(client, fLocation, NULL_VECTOR, view_as<float>( { 0.0, 0.0, -100.0 } ), stopTime);
  196. }
  197. }
  198. else
  199. PrintToChat(client, "[%cCK%c] Destination zone not found!", MOSSGREEN, WHITE);
  200. }
  201. else
  202. PrintToChat(client, "[%cCK%c] No zones found in the map.", MOSSGREEN, WHITE);
  203. }
  204. return;
  205. }
  206.  
  207. void teleportEntitySafe(int client, float fDestination[3], float fAngles[3], float fVelocity[3], bool stopTimer)
  208. {
  209. if (stopTimer)
  210. Client_Stop(client, 1);
  211.  
  212. int zId = setClientLocation(client, fDestination); // Set new location
  213.  
  214. if (zId > -1 && g_bTimeractivated[client] && g_mapZones[zId][zoneType] == 2) // If teleporting to the end zone, stop timer
  215. Client_Stop(client, 0);
  216.  
  217. // Teleport
  218. TeleportEntity(client, fDestination, fAngles, fVelocity);
  219. }
  220.  
  221. int setClientLocation(int client, float fDestination[3])
  222. {
  223. int zId = IsInsideZone(fDestination);
  224.  
  225. if (zId != g_iClientInZone[client][3]) // Ignore location changes, if teleporting to the same zone they are already in
  226. {
  227. if (g_iClientInZone[client][0] != -1) // Ignore end touch if teleporting from within a zone
  228. g_bIgnoreZone[client] = true;
  229.  
  230. if (zId > -1)
  231. {
  232. g_iClientInZone[client][0] = g_mapZones[zId][zoneType];
  233. g_iClientInZone[client][1] = g_mapZones[zId][zoneTypeId];
  234. g_iClientInZone[client][2] = g_mapZones[zId][zoneGroup];
  235. g_iClientInZone[client][3] = zId;
  236. }
  237. else
  238. {
  239. g_iClientInZone[client][0] = -1;
  240. g_iClientInZone[client][1] = -1;
  241. g_iClientInZone[client][3] = -1;
  242. }
  243. }
  244. return zId;
  245. }
  246.  
  247. stock void WriteChatLog(int client, const char[] sayOrSayTeam, const char[] msg)
  248. {
  249. char name[MAX_NAME_LENGTH], steamid[32], teamName[10];
  250.  
  251. GetClientName(client, name, MAX_NAME_LENGTH);
  252. GetTeamName(GetClientTeam(client), teamName, sizeof(teamName));
  253. GetClientAuthId(client, AuthId_Steam2, steamid, 32, true);
  254. LogToGame("\"%s<%i><%s><%s>\" %s \"%s\"", name, GetClientUserId(client), steamid, teamName, sayOrSayTeam, msg);
  255. }
  256.  
  257. // PushFix by Mev, George, & Blacky
  258. // https://forums.alliedmods.net/showthread.php?t=267131
  259. public void SinCos(float radians, float &sine, float &cosine)
  260. {
  261. sine = Sine(radians);
  262. cosine = Cosine(radians);
  263. }
  264.  
  265. void DoPush(int entity, int other, float m_vecPushDir[3])
  266. {
  267. if (0 < other <= MaxClients)
  268. {
  269. if (!DoesClientPassFilter(entity, other))
  270. {
  271. return;
  272. }
  273.  
  274. float newVelocity[3], angRotation[3], fPushSpeed;
  275.  
  276. fPushSpeed = GetEntPropFloat(entity, Prop_Data, "m_flSpeed");
  277. GetEntPropVector(entity, Prop_Data, "m_angRotation", angRotation);
  278.  
  279. // Rotate vector according to world
  280. float sr, sp, sy, cr, cp, cy;
  281. float matrix[3][4];
  282.  
  283. SinCos(DegToRad(angRotation[1]), sy, cy);
  284. SinCos(DegToRad(angRotation[0]), sp, cp);
  285. SinCos(DegToRad(angRotation[2]), sr, cr);
  286.  
  287. matrix[0][0] = cp * cy;
  288. matrix[1][0] = cp * sy;
  289. matrix[2][0] = -sp;
  290.  
  291. float crcy = cr * cy;
  292. float crsy = cr * sy;
  293. float srcy = sr * cy;
  294. float srsy = sr * sy;
  295.  
  296. matrix[0][1] = sp * srcy - crsy;
  297. matrix[1][1] = sp * srsy + crcy;
  298. matrix[2][1] = sr * cp;
  299.  
  300. matrix[0][2] = (sp * crcy + srsy);
  301. matrix[1][2] = (sp * crsy - srcy);
  302. matrix[2][2] = cr * cp;
  303.  
  304. matrix[0][3] = angRotation[0];
  305. matrix[1][3] = angRotation[1];
  306. matrix[2][3] = angRotation[2];
  307.  
  308. float vecAbsDir[3];
  309. vecAbsDir[0] = m_vecPushDir[0] * matrix[0][0] + m_vecPushDir[1] * matrix[0][1] + m_vecPushDir[2] * matrix[0][2];
  310. vecAbsDir[1] = m_vecPushDir[0] * matrix[1][0] + m_vecPushDir[1] * matrix[1][1] + m_vecPushDir[2] * matrix[1][2];
  311. vecAbsDir[2] = m_vecPushDir[0] * matrix[2][0] + m_vecPushDir[1] * matrix[2][1] + m_vecPushDir[2] * matrix[2][2];
  312.  
  313. ScaleVector(vecAbsDir, fPushSpeed);
  314.  
  315. // Apply the base velocity directly to abs velocity
  316. GetEntPropVector(other, Prop_Data, "m_vecVelocity", newVelocity);
  317.  
  318. newVelocity[2] = newVelocity[2] + (vecAbsDir[2] * GetTickInterval());
  319. g_bPushing[other] = true;
  320. TeleportEntity(other, NULL_VECTOR, NULL_VECTOR, newVelocity);
  321.  
  322. // Remove the base velocity z height so abs velocity can do it and add old base velocity if there is any
  323. vecAbsDir[2] = 0.0;
  324. if (GetEntityFlags(other) & FL_BASEVELOCITY)
  325. {
  326. float vecBaseVel[3];
  327. GetEntPropVector(other, Prop_Data, "m_vecBaseVelocity", vecBaseVel);
  328. AddVectors(vecAbsDir, vecBaseVel, vecAbsDir);
  329. }
  330.  
  331. SetEntPropVector(other, Prop_Data, "m_vecBaseVelocity", vecAbsDir);
  332. SetEntityFlags(other, GetEntityFlags(other) | FL_BASEVELOCITY);
  333. }
  334. }
  335.  
  336. void GetFilterTargetName(char[] filtername, char[] buffer, int maxlen)
  337. {
  338. int filter = FindEntityByTargetname(filtername);
  339. if (filter != -1)
  340. {
  341. GetEntPropString(filter, Prop_Data, "m_iFilterName", buffer, maxlen);
  342. }
  343. }
  344.  
  345. int FindEntityByTargetname(char[] targetname)
  346. {
  347. int entity = -1;
  348. char sName[64];
  349. while ((entity = FindEntityByClassname(entity, "filter_activator_name")) != -1)
  350. {
  351. GetEntPropString(entity, Prop_Data, "m_iName", sName, 64);
  352. if (StrEqual(sName, targetname))
  353. {
  354. return entity;
  355. }
  356. }
  357.  
  358. return -1;
  359. }
  360.  
  361. bool DoesClientPassFilter(int entity, int client)
  362. {
  363. char sPushFilter[64];
  364. GetEntPropString(entity, Prop_Data, "m_iFilterName", sPushFilter, sizeof sPushFilter);
  365. if (StrEqual(sPushFilter, ""))
  366. {
  367. return true;
  368. }
  369. char sFilterName[64];
  370. GetFilterTargetName(sPushFilter, sFilterName, sizeof sFilterName);
  371. char sClientName[64];
  372. GetEntPropString(client, Prop_Data, "m_iName", sClientName, sizeof sClientName);
  373.  
  374. return StrEqual(sFilterName, sClientName, true);
  375. }
  376.  
  377. //https://forums.alliedmods.net/showthread.php?t=206308
  378. void TeamChangeActual(int client, int toteam)
  379. {
  380. if (GetConVarBool(g_hForceCT)) {
  381. if (toteam == 0 || toteam == 2) {
  382. toteam = 3;
  383. }
  384. } else {
  385. if (toteam == 0) { // client is auto-assigning
  386. toteam = GetRandomInt(2, 3);
  387. }
  388. }
  389.  
  390. if (g_bSpectate[client])
  391. {
  392. if (g_fStartTime[client] != -1.0 && g_bTimeractivated[client] == true)
  393. g_fPauseTime[client] = GetGameTime() - g_fStartPauseTime[client];
  394. g_bSpectate[client] = false;
  395. }
  396.  
  397. // if (!IsPlayerAlive(client) && toteam > 1)
  398. // CS_RespawnPlayer(client);
  399.  
  400. ChangeClientTeam(client, toteam);
  401.  
  402. return;
  403. }
  404.  
  405.  
  406. public int getZoneID(int zoneGrp, int stage)
  407. {
  408. if (0 < stage < 2) // Search for map's starting zone
  409. {
  410. for (int i = 0; i < g_mapZonesCount; i++)
  411. {
  412. if (g_mapZones[i][zoneGroup] == zoneGrp && (g_mapZones[i][zoneType] == 1 || g_mapZones[i][zoneType] == 5) && g_mapZones[i][zoneTypeId] == 0)
  413. return i;
  414. }
  415. for (int i = 0; i < g_mapZonesCount; i++) // If no start zone with typeId 0 found, return any start zone
  416. {
  417. if (g_mapZones[i][zoneGroup] == zoneGrp && (g_mapZones[i][zoneType] == 1 || g_mapZones[i][zoneType] == 5))
  418. return i;
  419. }
  420. }
  421. else if (stage > 1) // Search for a stage
  422. {
  423. for (int i = 0; i < g_mapZonesCount; i++)
  424. {
  425. if (g_mapZones[i][zoneGroup] == zoneGrp && g_mapZones[i][zoneType] == 3 && g_mapZones[i][zoneTypeId] == (stage - 2))
  426. {
  427. return i;
  428. }
  429. }
  430. }
  431. else if (stage < 0) // Search for the end zone
  432. {
  433. for (int i = 0; i < g_mapZonesCount; i++)
  434. {
  435. if (g_mapZones[i][zoneType] == 2 && g_mapZones[i][zoneGroup] == zoneGrp)
  436. {
  437. return i;
  438. }
  439. }
  440. }
  441. return -1;
  442. }
  443.  
  444. public void readMultiServerMapcycle()
  445. {
  446. char sPath[PLATFORM_MAX_PATH];
  447. char line[128];
  448.  
  449. ClearArray(g_MapList);
  450. g_pr_MapCount = 0;
  451. BuildPath(Path_SM, sPath, sizeof(sPath), "%s", MULTI_SERVER_MAPCYCLE);
  452. Handle fileHandle = OpenFile(sPath, "r");
  453.  
  454. if (fileHandle != null)
  455. {
  456. while (!IsEndOfFile(fileHandle) && ReadFileLine(fileHandle, line, sizeof(line)))
  457. {
  458. TrimString(line); // Only take the map name
  459. if (StrContains(line, "//", true) == -1) // Escape comments
  460. {
  461. g_pr_MapCount++;
  462. PushArrayString(g_MapList, line);
  463. }
  464. }
  465. }
  466. else
  467. SetFailState("[ckSurf] %s is empty or does not exist.", MULTI_SERVER_MAPCYCLE);
  468.  
  469. if (fileHandle != null)
  470. CloseHandle(fileHandle);
  471.  
  472. return;
  473. }
  474.  
  475. public void readMapycycle()
  476. {
  477. char map[128];
  478. char map2[128];
  479. int mapListSerial = -1;
  480. g_pr_MapCount = 0;
  481. if (ReadMapList(g_MapList,
  482. mapListSerial,
  483. "mapcyclefile",
  484. MAPLIST_FLAG_CLEARARRAY | MAPLIST_FLAG_NO_DEFAULT)
  485. == null)
  486. {
  487. if (mapListSerial == -1)
  488. {
  489. SetFailState("[ckSurf] mapcycle.txt is empty or does not exist.");
  490. }
  491. }
  492. for (int i = 0; i < GetArraySize(g_MapList); i++)
  493. {
  494. GetArrayString(g_MapList, i, map, sizeof(map));
  495. if (!StrEqual(map, "", false))
  496. {
  497. //fix workshop map name
  498. char mapPieces[6][128];
  499. int lastPiece = ExplodeString(map, "/", mapPieces, sizeof(mapPieces), sizeof(mapPieces[]));
  500. Format(map2, sizeof(map2), "%s", mapPieces[lastPiece - 1]);
  501. SetArrayString(g_MapList, i, map2);
  502. g_pr_MapCount++;
  503. }
  504. }
  505. return;
  506. }
  507.  
  508. public bool loadHiddenChatCommands()
  509. {
  510. char sPath[PLATFORM_MAX_PATH];
  511. char line[64];
  512.  
  513. //add blocked chat commands list
  514. for (int x = 0; x < 256; x++)
  515. Format(g_BlockedChatText[x], sizeof(g_BlockedChatText), "");
  516.  
  517. BuildPath(Path_SM, sPath, sizeof(sPath), "%s", BLOCKED_LIST_PATH);
  518. int count = 0;
  519. Handle fileHandle = OpenFile(sPath, "r");
  520. if (fileHandle != null)
  521. {
  522. while (!IsEndOfFile(fileHandle) && ReadFileLine(fileHandle, line, sizeof(line)))
  523. {
  524. TrimString(line);
  525. if ((StrContains(line, "//", true) == -1) && count < 256)
  526. {
  527. Format(g_BlockedChatText[count], sizeof(g_BlockedChatText), "%s", line);
  528. count++;
  529. }
  530. }
  531. }
  532. else
  533. LogError("[ckSurf] %s is empty or does not exist.", BLOCKED_LIST_PATH);
  534.  
  535. if (fileHandle != null)
  536. CloseHandle(fileHandle);
  537.  
  538. return true;
  539. }
  540.  
  541.  
  542. public bool loadCustomTitles()
  543. {
  544. char sPath[PLATFORM_MAX_PATH];
  545. g_iCustomTitleCount = 0;
  546. // Load custom titles:
  547. for (int i = 0; i < TITLE_COUNT; i++)
  548. {
  549. Format(g_szflagTitle[i], 128, "");
  550. Format(g_szflagTitle_Colored[i], 128, "");
  551. }
  552.  
  553. BuildPath(Path_SM, sPath, sizeof(sPath), "%s", CUSTOM_TITLE_PATH);
  554.  
  555. Handle kv = CreateKeyValues("Custom Titles");
  556. FileToKeyValues(kv, sPath);
  557.  
  558. if (!KvGotoFirstSubKey(kv))
  559. {
  560. return false;
  561. }
  562.  
  563. for (int i = 0; i < TITLE_COUNT; i++)
  564. {
  565. KvGetString(kv, "title_name", g_szflagTitle_Colored[i], 128);
  566. KvGetString(kv, "title_name", g_szflagTitle[i], 128);
  567. if (!g_szflagTitle[i][0])
  568. {
  569. // Disable unused titles from all players
  570. if (i != (TITLE_COUNT - 1))
  571. sql_disableTitleFromAllbyIndex(i);
  572. break;
  573. }
  574. else
  575. g_iCustomTitleCount++;
  576.  
  577. //addColorToString(g_szflagTitle_Colored[i], 32);
  578. normalizeChatString(g_szflagTitle[i], 32);
  579.  
  580. if (!KvGotoNextKey(kv))
  581. break;
  582. }
  583. CloseHandle(kv);
  584. return true;
  585. }
  586.  
  587. public void normalizeChatString(char[] ParseString, int size)
  588. {
  589. //players are using special ASCII chars to simulate 0x** colors
  590. //this will prevent it by replacing ASCII characters outside of the normal range with a space
  591. //CTag comes from colors.inc
  592. for (int i = 0 ; i < MAX_COLORS ; i++)
  593. {
  594. ReplaceString(ParseString, size, CTag[i], "", false);
  595. ReplaceString(ParseString, size, CTagCode[i],"",false);
  596. }
  597. }
  598.  
  599. public void checkChangesInTitle(int client)
  600. {
  601. if (!IsValidClient(client))
  602. return;
  603.  
  604. for (int i = 0; i < TITLE_COUNT; i++)
  605. {
  606. if (g_bflagTitles[client][i] != g_bflagTitles_orig[client][i])
  607. {
  608. if (g_bflagTitles[client][i])
  609. ClientCommand(client, "play commander\\commander_comment_0%i", GetRandomInt(1, 9));
  610. else
  611. ClientCommand(client, "play commander\\commander_comment_%i", GetRandomInt(20, 23));
  612.  
  613. switch (i)
  614. {
  615. case 0:
  616. {
  617. g_bflagTitles_orig[client][i] = g_bflagTitles[client][i];
  618. if (g_bflagTitles[client][i])
  619. PrintToChat(client, "[%cCK%c] Congratulations! You have gained the VIP privileges!", MOSSGREEN, WHITE);
  620. else
  621. PrintToChat(client, "[%cCK%c] You have lost your VIP privileges!", MOSSGREEN, WHITE);
  622. break;
  623. }
  624. case 1:
  625. {
  626. g_bflagTitles_orig[client][i] = g_bflagTitles[client][i];
  627. if (g_bflagTitles[client][i])
  628. PrintToChat(client, "[%cCK%c] Congratulations! You have gained the Mapper title!", MOSSGREEN, WHITE);
  629. else
  630. PrintToChat(client, "[%cCK%c] You have lost your Mapper title!", MOSSGREEN, WHITE);
  631. break;
  632. }
  633. case 2:
  634. {
  635. g_bflagTitles_orig[client][i] = g_bflagTitles[client][i];
  636. if (g_bflagTitles[client][i])
  637. PrintToChat(client, "[%cCK%c] Congratulations! You have gained the Teacher title!", MOSSGREEN, WHITE);
  638. else
  639. PrintToChat(client, "[%cCK%c] You have lost your Teacher title!", MOSSGREEN, WHITE);
  640. break;
  641. }
  642. default:
  643. {
  644. g_bflagTitles_orig[client][i] = g_bflagTitles[client][i];
  645. if (g_bflagTitles[client][i])
  646. PrintToChat(client, "[%cCK%c] Congratulations! You have gained the custom title \"%s\"!", MOSSGREEN, WHITE, g_szflagTitle_Colored[i]);
  647. else
  648. PrintToChat(client, "[%cCK%c] You have lost your custom title \"%s\"!", MOSSGREEN, WHITE, g_szflagTitle_Colored[i]);
  649. break;
  650. }
  651. }
  652. }
  653. }
  654. }
  655.  
  656. public void checkSpawnPoints()
  657. {
  658. int tEnt, ctEnt;
  659. float f_spawnLocation[3], f_spawnAngle[3];
  660.  
  661. if (FindEntityByClassname(ctEnt, "info_player_counterterrorist") == -1 || FindEntityByClassname(tEnt, "info_player_terrorist") == -1) // No proper zones were found, try to recreate
  662. {
  663. // Check if spawn point has been added to the database with !addspawn
  664. char szQuery[256];
  665. Format(szQuery, 256, "SELECT pos_x, pos_y, pos_z, ang_x, ang_y, ang_z FROM ck_spawnlocations WHERE mapname = '%s' AND zonegroup = 0;", g_szMapName);
  666. Handle query = SQL_Query(g_hDb, szQuery);
  667. if (query == INVALID_HANDLE)
  668. {
  669. char szError[255];
  670. SQL_GetError(g_hDb, szError, sizeof(szError));
  671. PrintToServer("Failed to query map's spawn points (error: %s)", szError);
  672. }
  673. else
  674. {
  675. if (SQL_HasResultSet(query) && SQL_FetchRow(query))
  676. {
  677. f_spawnLocation[0] = SQL_FetchFloat(query, 0);
  678. f_spawnLocation[1] = SQL_FetchFloat(query, 1);
  679. f_spawnLocation[2] = SQL_FetchFloat(query, 2);
  680. f_spawnAngle[0] = SQL_FetchFloat(query, 3);
  681. f_spawnAngle[1] = SQL_FetchFloat(query, 4);
  682. f_spawnAngle[2] = SQL_FetchFloat(query, 5);
  683. }
  684. CloseHandle(query);
  685. }
  686.  
  687. if (f_spawnLocation[0] == 0.0 && f_spawnLocation[1] == 0.0 && f_spawnLocation[2] == 0.0) // No spawnpoint added to map with !addspawn, try to find spawns from map
  688. {
  689. PrintToServer("[CK] No valid spawns found in the map.");
  690. int zoneEnt = -1;
  691. zoneEnt = FindEntityByClassname(zoneEnt, "info_player_teamspawn"); // CSS/TF spawn found
  692.  
  693. if (zoneEnt != -1)
  694. {
  695. GetEntPropVector(zoneEnt, Prop_Data, "m_angRotation", f_spawnAngle);
  696. GetEntPropVector(zoneEnt, Prop_Send, "m_vecOrigin", f_spawnLocation);
  697.  
  698. PrintToServer("[CK] Found info_player_teamspawn in location %f, %f, %f", f_spawnLocation[0], f_spawnLocation[1], f_spawnLocation[2]);
  699. }
  700. else
  701. {
  702. zoneEnt = FindEntityByClassname(zoneEnt, "info_player_start"); // Random spawn
  703. if (zoneEnt != -1)
  704. {
  705. GetEntPropVector(zoneEnt, Prop_Data, "m_angRotation", f_spawnAngle);
  706. GetEntPropVector(zoneEnt, Prop_Send, "m_vecOrigin", f_spawnLocation);
  707.  
  708. PrintToServer("[CK] Found info_player_start in location %f, %f, %f", f_spawnLocation[0], f_spawnLocation[1], f_spawnLocation[2]);
  709. }
  710. else
  711. {
  712. PrintToServer("No valid spawn points found in the map! Record bots will not work. Try adding a spawn point with !addspawn");
  713. return;
  714. }
  715. }
  716. }
  717.  
  718. // Start creating new spawnpoints
  719. int pointT, pointCT, count = 0;
  720. while (count < 64)
  721. {
  722. pointT = CreateEntityByName("info_player_terrorist");
  723. ActivateEntity(pointT);
  724. pointCT = CreateEntityByName("info_player_counterterrorist");
  725. ActivateEntity(pointCT);
  726. if (IsValidEntity(pointT) && IsValidEntity(pointCT) && DispatchSpawn(pointT) && DispatchSpawn(pointCT))
  727. {
  728. TeleportEntity(pointT, f_spawnLocation, f_spawnAngle, NULL_VECTOR);
  729. TeleportEntity(pointCT, f_spawnLocation, f_spawnAngle, NULL_VECTOR);
  730. count++;
  731. }
  732. }
  733.  
  734. // Remove possiblt bad spawns
  735. char sClassName[128];
  736. for (int i = 0; i < GetMaxEntities(); i++)
  737. {
  738. if (IsValidEdict(i) && IsValidEntity(i) && GetEdictClassname(i, sClassName, sizeof(sClassName)))
  739. {
  740. if (StrEqual(sClassName, "info_player_start") || StrEqual(sClassName, "info_player_teamspawn"))
  741. {
  742. RemoveEdict(i);
  743. }
  744. }
  745. }
  746. }
  747. else // Valid spawns were found, check that there is enough of them
  748. {
  749. int ent, spawnpoint;
  750. ent = -1;
  751. while ((ent = FindEntityByClassname(ent, "info_player_terrorist")) != -1)
  752. {
  753. if (tEnt == 0)
  754. {
  755. GetEntPropVector(ent, Prop_Data, "m_angRotation", f_spawnAngle);
  756. GetEntPropVector(ent, Prop_Send, "m_vecOrigin", f_spawnLocation);
  757. }
  758. tEnt++;
  759. }
  760. while ((ent = FindEntityByClassname(ent, "info_player_counterterrorist")) != -1)
  761. {
  762. if (ctEnt == 0 && tEnt == 0)
  763. {
  764. GetEntPropVector(ent, Prop_Data, "m_angRotation", f_spawnAngle);
  765. GetEntPropVector(ent, Prop_Send, "m_vecOrigin", f_spawnLocation);
  766. }
  767. ctEnt++;
  768. }
  769.  
  770. if (tEnt > 0 || ctEnt > 0)
  771. {
  772. if (tEnt < 64)
  773. {
  774. while (tEnt < 64)
  775. {
  776. spawnpoint = CreateEntityByName("info_player_terrorist");
  777. if (IsValidEntity(spawnpoint) && DispatchSpawn(spawnpoint))
  778. {
  779. ActivateEntity(spawnpoint);
  780. TeleportEntity(spawnpoint, f_spawnLocation, f_spawnAngle, NULL_VECTOR);
  781. tEnt++;
  782. }
  783. }
  784. }
  785.  
  786. if (ctEnt < 64)
  787. {
  788. while (ctEnt < 64)
  789. {
  790. spawnpoint = CreateEntityByName("info_player_counterterrorist");
  791. if (IsValidEntity(spawnpoint) && DispatchSpawn(spawnpoint))
  792. {
  793. ActivateEntity(spawnpoint);
  794. TeleportEntity(spawnpoint, f_spawnLocation, f_spawnAngle, NULL_VECTOR);
  795. ctEnt++;
  796. }
  797. }
  798. }
  799. }
  800. }
  801. }
  802.  
  803. public Action CallAdmin_OnDrawOwnReason(int client)
  804. {
  805. g_bClientOwnReason[client] = true;
  806. return Plugin_Continue;
  807. }
  808.  
  809. public bool checkSpam(int client)
  810. {
  811. float time = GetGameTime();
  812. if (GetConVarFloat(g_hChatSpamFilter) == 0.0)
  813. return false;
  814.  
  815. if (!IsValidClient(client) || (GetUserFlagBits(client) & ADMFLAG_ROOT) || (GetUserFlagBits(client) & ADMFLAG_GENERIC))
  816. return false;
  817.  
  818. bool result = false;
  819.  
  820. if (time - g_fLastChatMessage[client] < GetConVarFloat(g_hChatSpamFilter))
  821. {
  822. result = true;
  823. g_messages[client]++;
  824. }
  825. else
  826. g_messages[client] = 0;
  827.  
  828.  
  829. if (4 < g_messages[client] < 8)
  830. PrintToChat(client, "[%cCK%c] %cStop spamming or you will get kicked!", MOSSGREEN, WHITE, RED);
  831. else
  832. if (g_messages[client] >= 8)
  833. {
  834. KickClient(client, "Kicked for spamming.");
  835. return true;
  836. }
  837.  
  838. g_fLastChatMessage[client] = time;
  839. return result;
  840. }
  841.  
  842. stock bool IsValidClient(int client)
  843. {
  844. if (client >= 1 && client <= MaxClients && IsValidEntity(client) && IsClientConnected(client) && IsClientInGame(client))
  845. return true;
  846. return false;
  847. }
  848.  
  849. public void PrintConsoleInfo(int client)
  850. {
  851.  
  852. if (g_hSkillGroups == null)
  853. {
  854. CreateTimer(5.0, reloadConsoleInfo, client);
  855. return;
  856. }
  857.  
  858. int iConsoleTimeleft;
  859. GetMapTimeLeft(iConsoleTimeleft);
  860. int mins, secs;
  861. char finalOutput[1024];
  862. mins = iConsoleTimeleft / 60;
  863. secs = iConsoleTimeleft % 60;
  864. Format(finalOutput, 1024, "%d:%02d", mins, secs);
  865. float fltickrate = 1.0 / GetTickInterval();
  866.  
  867. if (!IsValidClient(client) || IsFakeClient(client))
  868. return;
  869.  
  870. PrintToConsole(client, "-----------------------------------------------------------------------------------------------------------");
  871. PrintToConsole(client, "This server is running ckSurf v%s - Author: Elzi - Server tickrate: %i", VERSION, RoundToNearest(fltickrate));
  872. if (iConsoleTimeleft > 0)
  873. PrintToConsole(client, "iConsoleTimeleft on %s: %s", g_szMapName, finalOutput);
  874. PrintToConsole(client, "Menu formatting is optimized for 1920x1080!");
  875. PrintToConsole(client, " ");
  876. PrintToConsole(client, "client commands:");
  877. PrintToConsole(client, "!r, !stages, !s, !bonus, !b, !teleport, !stuck, !tele");
  878. PrintToConsole(client, "!help, !help2, !menu, !options, !profile, !compare,");
  879. PrintToConsole(client, "!maptop, !top, !start, !stop, !pause, !challenge, !surrender, !goto, !spec, !avg,");
  880. PrintToConsole(client, "!showsettings, !latest, !measure, !ranks, !flashlight, !language, !usp, !wr");
  881. PrintToConsole(client, "(options menu contains: !info");
  882. PrintToConsole(client, "!hide, !hidespecs, !disablegoto, !bhop)");
  883. PrintToConsole(client, "!hidechat, !hideweapon)");
  884. PrintToConsole(client, " ");
  885. PrintToConsole(client, "Practice Mode:");
  886. PrintToConsole(client, "Create checkpoints with !cp / !checkpoint");
  887. PrintToConsole(client, "Start practice mode with !tele / !prac");
  888. PrintToConsole(client, "Undo failed checkpoints with !undo");
  889. PrintToConsole(client, "Get back to normal mode with !n / !normal");
  890. PrintToConsole(client, "");
  891. PrintToConsole(client, "Live scoreboard:");
  892. PrintToConsole(client, "Kills: Time in seconds");
  893. PrintToConsole(client, "Assists: Number of % finished on current map");
  894. PrintToConsole(client, "Score: How many players are lower ranked than the player. Higher number means higher rank");
  895. PrintToConsole(client, "MVP Stars: Number of finished map runs on the current map");
  896. PrintToConsole(client, " ");
  897. PrintToConsole(client, "Practice Mode:");
  898. PrintToConsole(client, "Create checkpoints with !cp / !checkpoint");
  899. PrintToConsole(client, "Start practice mode with !tele / !prac");
  900. PrintToConsole(client, "Undo failed checkpoints with !undo");
  901. PrintToConsole(client, "Get back to normal mode with !n / !normal");
  902. PrintToConsole(client, "");
  903. PrintToConsole(client, "Skill groups:");
  904. char ChatLine[512];
  905. int i, RankValue[SkillGroup];
  906. for (i = 0; i < GetArraySize(g_hSkillGroups); i++)
  907. {
  908. GetArrayArray(g_hSkillGroups, i, RankValue[0]);
  909.  
  910. if (i != 0 && i % 5 == 0)
  911. {
  912. PrintToConsole(client, ChatLine);
  913. Format(ChatLine, 512, "");
  914. }
  915.  
  916. Format(ChatLine, 512, "%s%s (%ip) ", ChatLine, RankValue[RankName], RankValue[PointReq]);
  917. }
  918. PrintToConsole(client, ChatLine);
  919.  
  920. PrintToConsole(client, "");
  921. PrintToConsole(client, "-----------------------------------------------------------------------------------------------------------");
  922. PrintToConsole(client, " ");
  923. return;
  924. }
  925. stock void FakePrecacheSound(const char[] szPath)
  926. {
  927. AddToStringTable(FindStringTable("soundprecache"), szPath);
  928. }
  929.  
  930. public Action BlockRadio(int client, const char[] command, int args)
  931. {
  932. if (!GetConVarBool(g_hRadioCommands) && IsValidClient(client))
  933. {
  934. PrintToChat(client, "%t", "RadioCommandsDisabled", LIMEGREEN, WHITE);
  935. return Plugin_Handled;
  936. }
  937. return Plugin_Continue;
  938. }
  939.  
  940. public void StringToUpper(char[] input)
  941. {
  942. for (int i = 0; ; i++)
  943. {
  944. if (input[i] == '\0')
  945. return;
  946. input[i] = CharToUpper(input[i]);
  947. }
  948. }
  949.  
  950. public void GetCountry(int client)
  951. {
  952. if (client != 0)
  953. {
  954. if (!IsFakeClient(client))
  955. {
  956. char IP[16];
  957. char code2[3];
  958. GetClientIP(client, IP, 16);
  959.  
  960. //COUNTRY
  961. GeoipCountry(IP, g_szCountry[client], 100);
  962. if (!strcmp(g_szCountry[client], NULL_STRING))
  963. Format(g_szCountry[client], 100, "Unknown", g_szCountry[client]);
  964. else
  965. if (StrContains(g_szCountry[client], "United", false) != -1 ||
  966. StrContains(g_szCountry[client], "Republic", false) != -1 ||
  967. StrContains(g_szCountry[client], "Federation", false) != -1 ||
  968. StrContains(g_szCountry[client], "Island", false) != -1 ||
  969. StrContains(g_szCountry[client], "Netherlands", false) != -1 ||
  970. StrContains(g_szCountry[client], "Isle", false) != -1 ||
  971. StrContains(g_szCountry[client], "Bahamas", false) != -1 ||
  972. StrContains(g_szCountry[client], "Maldives", false) != -1 ||
  973. StrContains(g_szCountry[client], "Philippines", false) != -1 ||
  974. StrContains(g_szCountry[client], "Vatican", false) != -1)
  975. {
  976. Format(g_szCountry[client], 100, "The %s", g_szCountry[client]);
  977. }
  978. //CODE
  979. if (GeoipCode2(IP, code2))
  980. {
  981. Format(g_szCountryCode[client], 16, "%s", code2);
  982. }
  983. else
  984. Format(g_szCountryCode[client], 16, "??");
  985. }
  986. }
  987. }
  988.  
  989. stock void StripAllWeapons(int client)
  990. {
  991. int iEnt;
  992. for (int i = 0; i <= 5; i++)
  993. {
  994. if (i != 2)
  995. while ((iEnt = GetPlayerWeaponSlot(client, i)) != -1)
  996. {
  997. RemovePlayerItem(client, iEnt);
  998. RemoveEdict(iEnt);
  999. }
  1000. }
  1001. if (GetPlayerWeaponSlot(client, 2) == -1)
  1002. GivePlayerItem(client, "weapon_knife");
  1003. }
  1004.  
  1005. public void MovementCheck(int client)
  1006. {
  1007. MoveType mt;
  1008. mt = GetEntityMoveType(client);
  1009. if (mt == MOVETYPE_FLYGRAVITY)
  1010. {
  1011. Client_Stop(client, 1);
  1012. }
  1013. }
  1014.  
  1015. public void PlayButtonSound(int client)
  1016. {
  1017. if (!GetConVarBool(g_hSoundEnabled))
  1018. return;
  1019.  
  1020. // Players button sound
  1021. if (!IsFakeClient(client))
  1022. {
  1023. char buffer[255];
  1024. GetConVarString(g_hSoundPath, buffer, 255);
  1025. Format(buffer, sizeof(buffer), "play %s", buffer);
  1026. ClientCommand(client, buffer);
  1027. }
  1028.  
  1029. // Spectators button sound
  1030. for (int i = 1; i <= MaxClients; i++)
  1031. {
  1032. if (IsValidClient(i) && !IsPlayerAlive(i))
  1033. {
  1034. int SpecMode = GetEntProp(i, Prop_Send, "m_iObserverMode");
  1035. if (SpecMode == 4 || SpecMode == 5)
  1036. {
  1037. int Target = GetEntPropEnt(i, Prop_Send, "m_hObserverTarget");
  1038. if (Target == client)
  1039. {
  1040. char szsound[255];
  1041. GetConVarString(g_hSoundPath, szsound, 256);
  1042. Format(szsound, sizeof(szsound), "play %s", szsound);
  1043. ClientCommand(i, szsound);
  1044. }
  1045. }
  1046. }
  1047. }
  1048. }
  1049.  
  1050. public void FixPlayerName(int client)
  1051. {
  1052. char szName[64];
  1053. char szOldName[64];
  1054. GetClientName(client, szName, 64);
  1055. Format(szOldName, 64, "%s ", szName);
  1056. ReplaceChar("'", "`", szName);
  1057. if (!(StrEqual(szOldName, szName)))
  1058. {
  1059. SetClientInfo(client, "name", szName);
  1060. SetEntPropString(client, Prop_Data, "m_szNetname", szName);
  1061. SetClientName(client, szName);
  1062. }
  1063. }
  1064.  
  1065. public void LimitSpeed(int client)
  1066. {
  1067. // Dont limits speed if in practice mode, or if there is no end zone in current zonegroup
  1068. if (!IsValidClient(client) || !IsPlayerAlive(client) || IsFakeClient(client) || g_bPracticeMode[client] || g_mapZonesTypeCount[g_iClientInZone[client][2]][2] == 0)
  1069. return;
  1070.  
  1071. float speedCap = 0.0, CurVelVec[3];
  1072.  
  1073. if (g_iClientInZone[client][0] == 1 && g_iClientInZone[client][2] > 0)
  1074. speedCap = GetConVarFloat(g_hBonusPreSpeed);
  1075. else
  1076. if (g_iClientInZone[client][0] == 1)
  1077. speedCap = GetConVarFloat(g_hStartPreSpeed);
  1078. else
  1079. if (g_iClientInZone[client][0] == 5)
  1080. {
  1081. if (!g_bNoClipUsed[client])
  1082. speedCap = GetConVarFloat(g_hSpeedPreSpeed);
  1083. else
  1084. speedCap = GetConVarFloat(g_hStartPreSpeed); // If noclipping, top speed at normal start zone speed
  1085. }
  1086.  
  1087. if (speedCap == 0.0)
  1088. return;
  1089.  
  1090. GetEntPropVector(client, Prop_Data, "m_vecVelocity", CurVelVec);
  1091.  
  1092. if (CurVelVec[0] == 0.0)
  1093. CurVelVec[0] = 1.0;
  1094. if (CurVelVec[1] == 0.0)
  1095. CurVelVec[1] = 1.0;
  1096. if (CurVelVec[2] == 0.0)
  1097. CurVelVec[2] = 1.0;
  1098.  
  1099. float currentspeed = SquareRoot(Pow(CurVelVec[0], 2.0) + Pow(CurVelVec[1], 2.0));
  1100.  
  1101. if (currentspeed > speedCap)
  1102. {
  1103. NormalizeVector(CurVelVec, CurVelVec);
  1104. ScaleVector(CurVelVec, speedCap);
  1105. TeleportEntity(client, NULL_VECTOR, NULL_VECTOR, CurVelVec);
  1106. }
  1107. }
  1108.  
  1109. public void changeTrailColor(int client)
  1110. {
  1111. if (!IsValidClient(client))
  1112. return;
  1113.  
  1114. if (g_iTrailColor[client] < (sizeof(RGB_COLOR_NAMES) - 1))
  1115. g_iTrailColor[client]++;
  1116. else
  1117. g_iTrailColor[client] = 0;
  1118. return;
  1119. }
  1120.  
  1121. public void refreshTrailClient(int client)
  1122. {
  1123. if (!IsValidClient(client) || !g_bTrailOn[client])
  1124. return;
  1125.  
  1126. int ent = GetPlayerWeaponSlot(client, 2);
  1127.  
  1128. if (!IsValidEntity(ent))
  1129. ent = client;
  1130.  
  1131. g_bTrailApplied[client] = true;
  1132.  
  1133. if (!IsFakeClient(client))
  1134. {
  1135. for (int i = 1; i < MAXPLAYERS + 1; i++)
  1136. {
  1137. if (i == client)
  1138. {
  1139. int ownTrailColor[4];
  1140. Array_Copy(RGB_COLORS[g_iTrailColor[client]], ownTrailColor, 4);
  1141. ownTrailColor[3] = 50;
  1142. TE_SetupBeamFollow(ent,
  1143. g_BeamSprite,
  1144. 0,
  1145. BEAMLIFE,
  1146. 4.0,
  1147. 1.0,
  1148. 1,
  1149. ownTrailColor);
  1150. TE_SendToClient(i);
  1151. }
  1152. else
  1153. {
  1154. if (IsValidClient(i) && !g_bHide[i])
  1155. {
  1156. TE_SetupBeamFollow(ent,
  1157. g_BeamSprite,
  1158. 0,
  1159. BEAMLIFE,
  1160. 4.0,
  1161. 1.0,
  1162. 1,
  1163. RGB_COLORS[g_iTrailColor[client]]);
  1164. TE_SendToClient(i);
  1165. }
  1166. }
  1167. }
  1168. }
  1169. }
  1170.  
  1171. void refreshTrailBot(int bot)
  1172. {
  1173.  
  1174. if (!IsValidClient(bot))
  1175. return;
  1176.  
  1177. int ent = GetPlayerWeaponSlot(bot, 2);
  1178. if (!IsValidEntity(ent))
  1179. ent = bot;
  1180.  
  1181. if ((GetConVarBool(g_hBonusBotTrail) && GetConVarBool(g_hBonusBot)) && bot == g_BonusBot)
  1182. {
  1183. for (int i = 1; i < MAXPLAYERS+1; i++)
  1184. {
  1185. if (IsValidClient(i) && ((g_iClientInZone[i][2] == g_iClientInZone[bot][2] && g_Stage[g_iClientInZone[i][2]][i] == g_Stage[g_iClientInZone[bot][2]][bot]) || g_bSpectate[i]))
  1186. {
  1187. TE_SetupBeamFollow(ent,
  1188. g_BeamSprite,
  1189. 0,
  1190. BEAMLIFE,
  1191. 4.0,
  1192. 1.0,
  1193. 1,
  1194. g_BonusBotTrailColor);
  1195. TE_SendToClient(i);
  1196. }
  1197. }
  1198. }
  1199. else if ((GetConVarBool(g_hRecordBotTrail) && GetConVarBool(g_hReplayBot)) && bot == g_RecordBot)
  1200. {
  1201. for (int i = 1; i < MAXPLAYERS+1; i++)
  1202. {
  1203. if (IsValidClient(i) && ((g_iClientInZone[i][2] == g_iClientInZone[bot][2] && g_Stage[g_iClientInZone[i][2]][i] == g_Stage[g_iClientInZone[bot][2]][bot]) || g_bSpectate[i]))
  1204. {
  1205. TE_SetupBeamFollow(ent,
  1206. g_BeamSprite,
  1207. 0,
  1208. BEAMLIFE,
  1209. 4.0,
  1210. 1.0,
  1211. 1,
  1212. g_ReplayBotTrailColor);
  1213. TE_SendToClient(i);
  1214. }
  1215. }
  1216. }
  1217. }
  1218.  
  1219. public void toggleTrail(int client)
  1220. {
  1221. if (!IsValidClient(client))
  1222. return;
  1223.  
  1224. if (!g_bTrailOn[client])
  1225. {
  1226. PrintToChat(client, "[%cCK%c] Player trail %cenabled", MOSSGREEN, WHITE, MOSSGREEN);
  1227. g_bTrailOn[client] = true;
  1228.  
  1229. if (!g_bTrailApplied[client])
  1230. refreshTrailClient(client);
  1231. }
  1232. else
  1233. {
  1234. PrintToChat(client, "[%cCK%c] Player trail %cdisabled", MOSSGREEN, WHITE, RED);
  1235. g_bTrailOn[client] = false;
  1236. }
  1237. }
  1238.  
  1239. public bool Base_TraceFilter(int entity, int contentsMask, any data)
  1240. {
  1241. if (entity != data)
  1242. return (false);
  1243.  
  1244. return (true);
  1245. }
  1246.  
  1247.  
  1248.  
  1249. public void checkTrailStatus(int client, float speed)
  1250. {
  1251. if (!IsFakeClient(client))
  1252. {
  1253. if (speed < 5.0 && g_bOnGround[client]) // Not moving
  1254. {
  1255. g_bNoClipUsed[client] = false;
  1256. if (!g_bClientStopped[client]) // Get start time
  1257. {
  1258. g_fClientLastMovement[client] = GetGameTime();
  1259. g_bClientStopped[client] = true;
  1260. }
  1261. else if (GetGameTime() - g_fClientLastMovement[client] >= BEAMLIFE) // Trail has died, refresh
  1262. {
  1263. g_bTrailApplied[client] = false;
  1264. g_fClientLastMovement[client] = GetGameTime();
  1265. refreshTrailClient(client);
  1266. }
  1267. }
  1268. else
  1269. {
  1270. if (!IsFakeClient(client))
  1271. g_bClientStopped[client] = false;
  1272. }
  1273. }
  1274. }
  1275.  
  1276. public void SetClientDefaults(int client)
  1277. {
  1278. float GameTime = GetGameTime();
  1279. g_fLastCommandBack[client] = GameTime;
  1280. g_ClientSelectedZone[client] = -1;
  1281. g_Editing[client] = 0;
  1282.  
  1283. g_bClientRestarting[client] = false;
  1284. g_fClientRestarting[client] = GameTime;
  1285. g_fErrorMessage[client] = GameTime;
  1286. g_bPushing[client] = false;
  1287.  
  1288. g_bLoadingSettings[client] = false;
  1289. g_bSettingsLoaded[client] = false;
  1290.  
  1291. g_bClientStopped[client] = false;
  1292. g_bTrailApplied[client] = false;
  1293. g_fClientLastMovement[client] = GameTime;
  1294. g_fLastDifferenceTime[client] = 0.0;
  1295. g_bTrailOn[client] = false;
  1296.  
  1297. g_bHasTitle[client] = false;
  1298. g_iTitleInUse[client] = -1;
  1299.  
  1300. g_flastClientUsp[client] = GameTime;
  1301.  
  1302. g_ClientRenamingZone[client] = false;
  1303.  
  1304. g_bNewReplay[client] = false;
  1305. g_bNewBonus[client] = false;
  1306.  
  1307. g_bFirstTimerStart[client] = true;
  1308. g_pr_Calculating[client] = false;
  1309.  
  1310. g_bTimeractivated[client] = false;
  1311. g_specToStage[client] = false;
  1312. g_bSpectate[client] = false;
  1313. if (!g_bLateLoaded)
  1314. g_bFirstTeamJoin[client] = true;
  1315. g_bFirstSpawn[client] = true;
  1316. g_bRecalcRankInProgess[client] = false;
  1317. g_bPause[client] = false;
  1318. g_bPositionRestored[client] = false;
  1319. g_bRestorePositionMsg[client] = false;
  1320. g_bRestorePosition[client] = false;
  1321. g_bRespawnPosition[client] = false;
  1322. g_bNoClip[client] = false;
  1323. g_bChallenge[client] = false;
  1324. g_bOverlay[client] = false;
  1325. g_bChallenge_Request[client] = false;
  1326. g_bClientOwnReason[client] = false;
  1327. g_AdminMenuLastPage[client] = 0;
  1328. g_OptionsMenuLastPage[client] = 0;
  1329. g_MenuLevel[client] = -1;
  1330. g_AttackCounter[client] = 0;
  1331. g_SpecTarget[client] = -1;
  1332. g_pr_points[client] = 0;
  1333. g_fCurrentRunTime[client] = -1.0;
  1334. g_fPlayerCordsLastPosition[client] = view_as<float>( { 0.0, 0.0, 0.0 } );
  1335. g_fLastChatMessage[client] = GetGameTime();
  1336. g_fLastTimeNoClipUsed[client] = -1.0;
  1337. g_fStartTime[client] = -1.0;
  1338. g_fPlayerLastTime[client] = -1.0;
  1339. g_fLastTimePracUsed[client] = -1.0;
  1340. g_fPauseTime[client] = 0.0;
  1341. g_MapRank[client] = 99999;
  1342. g_OldMapRank[client] = 99999;
  1343. g_PlayerRank[client] = 99999;
  1344. g_fProfileMenuLastQuery[client] = GameTime;
  1345. Format(g_szPlayerPanelText[client], 512, "");
  1346. Format(g_pr_rankname[client], 128, "");
  1347. g_PlayerChatRank[client] = -1;
  1348. g_bValidRun[client] = false;
  1349. g_fMaxPercCompleted[client] = 0.0;
  1350. Format(g_szLastSRDifference[client], 64, "");
  1351. Format(g_szLastPBDifference[client], 64, "");
  1352.  
  1353. Format(g_szPersonalRecord[client], 64, "");
  1354.  
  1355.  
  1356. // Player Checkpoints
  1357. for (int x = 0; x < 3; x++)
  1358. {
  1359. g_fCheckpointLocation[client][x] = 0.0;
  1360. g_fCheckpointVelocity[client][x] = 0.0;
  1361. g_fCheckpointAngle[client][x] = 0.0;
  1362.  
  1363. g_fCheckpointLocation_undo[client][x] = 0.0;
  1364. g_fCheckpointVelocity_undo[client][x] = 0.0;
  1365. g_fCheckpointAngle_undo[client][x] = 0.0;
  1366. }
  1367.  
  1368. for (int x = 0; x < MAXZONEGROUPS; x++)
  1369. {
  1370. Format(g_szPersonalRecordBonus[x][client], 64, "N/A");
  1371. g_bCheckpointsFound[x][client] = false;
  1372. g_MapRankBonus[x][client] = 9999999;
  1373. g_Stage[x][client] = 0;
  1374. for (int i = 0; i < CPLIMIT; i++)
  1375. {
  1376. g_fCheckpointTimesNew[x][client][i] = 0.0;
  1377. g_fCheckpointTimesRecord[x][client][i] = 0.0;
  1378. }
  1379. }
  1380.  
  1381. for (int i = 0; i < TITLE_COUNT; i++)
  1382. {
  1383. g_bflagTitles[client][i] = false;
  1384. g_bflagTitles_orig[client][i] = false;
  1385. }
  1386.  
  1387. g_fLastPlayerCheckpoint[client] = GameTime;
  1388. g_bCreatedTeleport[client] = false;
  1389. g_bPracticeMode[client] = false;
  1390.  
  1391. // client options
  1392. g_bInfoPanel[client] = true;
  1393. g_bShowNames[client] = true;
  1394. g_bGoToClient[client] = true;
  1395. g_bShowTime[client] = false;
  1396. g_bHide[client] = false;
  1397. g_bStartWithUsp[client] = false;
  1398. g_bShowSpecs[client] = true;
  1399. g_bAutoBhopClient[client] = true;
  1400. g_bHideChat[client] = false;
  1401. g_bViewModel[client] = true;
  1402. g_bCheckpointsEnabled[client] = true;
  1403. g_bEnableQuakeSounds[client] = true;
  1404. }
  1405.  
  1406. public void clearPlayerCheckPoints(int client)
  1407. {
  1408. for (int x = 0; x < 3; x++)
  1409. {
  1410. g_fCheckpointLocation[client][x] = 0.0;
  1411. g_fCheckpointVelocity[client][x] = 0.0;
  1412. g_fCheckpointAngle[client][x] = 0.0;
  1413.  
  1414. g_fCheckpointLocation_undo[client][x] = 0.0;
  1415. g_fCheckpointVelocity_undo[client][x] = 0.0;
  1416. g_fCheckpointAngle_undo[client][x] = 0.0;
  1417. }
  1418. g_fLastPlayerCheckpoint[client] = GetGameTime();
  1419. g_bCreatedTeleport[client] = false;
  1420. }
  1421.  
  1422. // - Get Runtime -
  1423. public void GetcurrentRunTime(int client)
  1424. {
  1425. g_fCurrentRunTime[client] = GetGameTime() - g_fStartTime[client] - g_fPauseTime[client];
  1426. }
  1427.  
  1428. public float GetSpeed(int client)
  1429. {
  1430. float fVelocity[3];
  1431. GetEntPropVector(client, Prop_Data, "m_vecVelocity", fVelocity);
  1432. float speed = SquareRoot(Pow(fVelocity[0], 2.0) + Pow(fVelocity[1], 2.0));
  1433. return speed;
  1434. }
  1435.  
  1436. public void SetCashState()
  1437. {
  1438. ServerCommand("mp_startmoney 0; mp_playercashawards 0; mp_teamcashawards 0");
  1439. for (int i = 1; i <= MaxClients; i++)
  1440. {
  1441. if (IsValidClient(i))
  1442. SetEntProp(i, Prop_Send, "m_iAccount", 0);
  1443. }
  1444. }
  1445.  
  1446. public void PlayRecordSound(int iRecordtype)
  1447. {
  1448. char buffer[255];
  1449. if (iRecordtype == 1)
  1450. {
  1451. for (int i = 1; i <= GetMaxClients(); i++)
  1452. {
  1453. if (IsValidClient(i) && !IsFakeClient(i) && g_bEnableQuakeSounds[i] == true)
  1454. {
  1455. Format(buffer, sizeof(buffer), "play %s", PRO_RELATIVE_SOUND_PATH);
  1456. ClientCommand(i, buffer);
  1457. }
  1458. }
  1459. }
  1460. else
  1461. if (iRecordtype == 2)
  1462. {
  1463. for (int i = 1; i <= GetMaxClients(); i++)
  1464. {
  1465. if (IsValidClient(i) && !IsFakeClient(i) && g_bEnableQuakeSounds[i] == true)
  1466. {
  1467. Format(buffer, sizeof(buffer), "play %s", CP_RELATIVE_SOUND_PATH);
  1468. ClientCommand(i, buffer);
  1469. }
  1470. }
  1471. }
  1472. }
  1473.  
  1474. public void PlayUnstoppableSound(int client)
  1475. {
  1476. char buffer[255];
  1477. Format(buffer, sizeof(buffer), "play %s", UNSTOPPABLE_RELATIVE_SOUND_PATH);
  1478. if (!IsFakeClient(client) && g_bEnableQuakeSounds[client])
  1479. ClientCommand(client, buffer);
  1480. //spec stop sound
  1481. for (int i = 1; i <= MaxClients; i++)
  1482. {
  1483. if (IsValidClient(i) && !IsPlayerAlive(i))
  1484. {
  1485. int SpecMode = GetEntProp(i, Prop_Send, "m_iObserverMode");
  1486. if (SpecMode == 4 || SpecMode == 5)
  1487. {
  1488. int Target = GetEntPropEnt(i, Prop_Send, "m_hObserverTarget");
  1489. if (Target == client && g_bEnableQuakeSounds[i])
  1490. ClientCommand(i, buffer);
  1491. }
  1492. }
  1493. }
  1494. }
  1495.  
  1496.  
  1497. public void InitPrecache()
  1498. {
  1499. AddFileToDownloadsTable(UNSTOPPABLE_SOUND_PATH);
  1500. FakePrecacheSound(UNSTOPPABLE_RELATIVE_SOUND_PATH);
  1501. AddFileToDownloadsTable(PRO_FULL_SOUND_PATH);
  1502. FakePrecacheSound(PRO_RELATIVE_SOUND_PATH);
  1503. AddFileToDownloadsTable(PRO_FULL_SOUND_PATH);
  1504. FakePrecacheSound(PRO_RELATIVE_SOUND_PATH);
  1505. AddFileToDownloadsTable(CP_FULL_SOUND_PATH);
  1506. FakePrecacheSound(CP_RELATIVE_SOUND_PATH);
  1507.  
  1508. char szBuffer[256];
  1509. // Replay Player Model
  1510. GetConVarString(g_hReplayBotPlayerModel, szBuffer, 256);
  1511. AddFileToDownloadsTable(szBuffer);
  1512. PrecacheModel(szBuffer, true);
  1513. // Replay Arm Model
  1514. GetConVarString(g_hReplayBotArmModel, szBuffer, 256);
  1515. AddFileToDownloadsTable(szBuffer);
  1516. PrecacheModel(szBuffer, true);
  1517. // Player Arm Model
  1518. GetConVarString(g_hArmModel, szBuffer, 256);
  1519. AddFileToDownloadsTable(szBuffer);
  1520. PrecacheModel(szBuffer, true);
  1521. // Player Model
  1522. GetConVarString(g_hPlayerModel, szBuffer, 256);
  1523. AddFileToDownloadsTable(szBuffer);
  1524. PrecacheModel(szBuffer, true);
  1525.  
  1526. g_BeamSprite = PrecacheModel("materials/sprites/laserbeam.vmt", true);
  1527. g_HaloSprite = PrecacheModel("materials/sprites/halo.vmt", true);
  1528. PrecacheModel(ZONE_MODEL);
  1529. }
  1530.  
  1531.  
  1532. // thx to V952 https://forums.alliedmods.net/showthread.php?t=212886
  1533. stock int TraceClientViewEntity(int client)
  1534. {
  1535. float m_vecOrigin[3];
  1536. float m_angRotation[3];
  1537. GetClientEyePosition(client, m_vecOrigin);
  1538. GetClientEyeAngles(client, m_angRotation);
  1539. Handle tr = TR_TraceRayFilterEx(m_vecOrigin, m_angRotation, MASK_VISIBLE, RayType_Infinite, TRDontHitSelf, client);
  1540. int pEntity = -1;
  1541. if (TR_DidHit(tr))
  1542. {
  1543. pEntity = TR_GetEntityIndex(tr);
  1544. CloseHandle(tr);
  1545. return pEntity;
  1546. }
  1547. CloseHandle(tr);
  1548. return -1;
  1549. }
  1550.  
  1551. // thx to V952 https://forums.alliedmods.net/showthread.php?t=212886
  1552. public bool TRDontHitSelf(int entity, int mask, any data)
  1553. {
  1554. if (entity == data)
  1555. return false;
  1556. return true;
  1557. }
  1558.  
  1559. public void PrintMapRecords(int client)
  1560. {
  1561. if (g_fRecordMapTime != 9999999.0)
  1562. {
  1563. PrintToChat(client, "%t", "MapRecord", MOSSGREEN, WHITE, DARKBLUE, WHITE, g_szRecordMapTime, g_szRecordPlayer);
  1564. }
  1565. for (int i = 1; i <= g_mapZoneGroupCount; i++)
  1566. {
  1567. if (g_fBonusFastest[i] != 9999999.0) // BONUS
  1568. {
  1569. PrintToChat(client, "%t", "BonusRecord", MOSSGREEN, WHITE, YELLOW, g_szZoneGroupName[i], WHITE, g_szBonusFastestTime[i], g_szBonusFastest[i]);
  1570. }
  1571. }
  1572. }
  1573.  
  1574. stock void MapFinishedMsgs(int client, int rankThisRun = 0)
  1575. {
  1576. if (IsValidClient(client))
  1577. {
  1578. char szName[MAX_NAME_LENGTH];
  1579. GetClientName(client, szName, MAX_NAME_LENGTH);
  1580. int count = g_MapTimesCount;
  1581.  
  1582. if (rankThisRun == 0)
  1583. rankThisRun = g_MapRank[client];
  1584.  
  1585. // Check that ck_chat_record_type matches and ck_min_rank_announce matches
  1586. if ((GetConVarInt(g_hAnnounceRecord) == 0 ||
  1587. (GetConVarInt(g_hAnnounceRecord) == 1 && g_bMapPBRecord[client] || g_bMapSRVRecord[client] || g_bMapFirstRecord[client]) ||
  1588. (GetConVarInt(g_hAnnounceRecord) == 2 && g_bMapSRVRecord[client])) &&
  1589. (rankThisRun <= GetConVarInt(g_hAnnounceRank) || GetConVarInt(g_hAnnounceRank) == 0))
  1590. {
  1591. for (int i = 1; i <= GetMaxClients(); i++)
  1592. {
  1593. if (IsValidClient(i) && !IsFakeClient(i))
  1594. {
  1595. if (g_bMapFirstRecord[client]) // 1st time finishing
  1596. {
  1597. PrintToChat(i, "%t", "MapFinished1", MOSSGREEN, WHITE, LIMEGREEN, szName, GRAY, DARKBLUE, GRAY, LIMEGREEN, g_szFinalTime[client], GRAY, WHITE, LIMEGREEN, g_MapRank[client], WHITE, count, LIMEGREEN, g_szRecordMapTime, WHITE);
  1598. PrintToConsole(i, "%s finished the map with a time of (%s). [rank #%i/%i | record %s]", szName, g_szFinalTime[client], g_MapRank[client], count, g_szRecordMapTime);
  1599. }
  1600. else
  1601. if (g_bMapPBRecord[client]) // Own record
  1602. {
  1603. PlayUnstoppableSound(client);
  1604. PrintToChat(i, "%t", "MapFinished3", MOSSGREEN, WHITE, LIMEGREEN, szName, GRAY, DARKBLUE, GRAY, LIMEGREEN, g_szFinalTime[client], GRAY, GREEN, g_szTimeDifference[client], GRAY, WHITE, LIMEGREEN, g_MapRank[client], WHITE, count, LIMEGREEN, g_szRecordMapTime, WHITE);
  1605. PrintToConsole(i, "%s finished the map with a time of (%s). Improving their best time by (%s). [rank #%i/%i | record %s]", szName, g_szFinalTime[client], g_szTimeDifference[client], g_MapRank[client], count, g_szRecordMapTime);
  1606. }
  1607. else
  1608. if (!g_bMapSRVRecord[client] && !g_bMapFirstRecord[client] && !g_bMapPBRecord[client])
  1609. {
  1610. PrintToChat(i, "%t", "MapFinished5", MOSSGREEN, WHITE, LIMEGREEN, szName, GRAY, DARKBLUE, GRAY, LIMEGREEN, g_szFinalTime[client], GRAY, RED, g_szTimeDifference[client], GRAY, WHITE, LIMEGREEN, g_MapRank[client], WHITE, count, LIMEGREEN, g_szRecordMapTime, WHITE);
  1611. PrintToConsole(i, "%s finished the map with a time of (%s). Missing their best time by (%s). [rank #%i/%i | record %s]", szName, g_szFinalTime[client], g_szTimeDifference[client], g_MapRank[client], count, g_szRecordMapTime);
  1612. }
  1613.  
  1614. if (g_bMapSRVRecord[client])
  1615. {
  1616. PlayRecordSound(2);
  1617. PrintToChat(i, "%t", "NewMapRecord", MOSSGREEN, WHITE, LIMEGREEN, szName, GRAY, DARKBLUE);
  1618. PrintToConsole(i, "[CK] %s scored a new MAP RECORD", szName);
  1619. }
  1620. }
  1621. }
  1622. } else
  1623. { // Print to own chat only
  1624. if (IsValidClient(client) && !IsFakeClient(client))
  1625. {
  1626. if (g_bMapFirstRecord[client])
  1627. {
  1628. PrintToChat(client, "%t", "MapFinished1", MOSSGREEN, WHITE, LIMEGREEN, szName, GRAY, DARKBLUE, GRAY, LIMEGREEN, g_szFinalTime[client], GRAY, WHITE, LIMEGREEN, g_MapRank[client], WHITE, count, LIMEGREEN, g_szRecordMapTime, WHITE);
  1629. PrintToConsole(client, "%s finished the map with a time of (%s). [rank #%i/%i | record %s]", szName, g_szFinalTime[client], g_MapRank[client], count, g_szRecordMapTime);
  1630. }
  1631. else
  1632. {
  1633. if (g_bMapPBRecord[client])
  1634. {
  1635. PlayUnstoppableSound(client);
  1636. PrintToChat(client, "%t", "MapFinished3", MOSSGREEN, WHITE, LIMEGREEN, szName, GRAY, DARKBLUE, GRAY, LIMEGREEN, g_szFinalTime[client], GRAY, GREEN, g_szTimeDifference[client], GRAY, WHITE, LIMEGREEN, g_MapRank[client], WHITE, count, LIMEGREEN, g_szRecordMapTime, WHITE);
  1637. PrintToConsole(client, "%s finished the map with a time of (%s). Improving their best time by (%s). [rank #%i/%i | record %s]", szName, g_szFinalTime[client], g_szTimeDifference[client], g_MapRank[client], count, g_szRecordMapTime);
  1638. }
  1639. else
  1640. {
  1641. if (!g_bMapSRVRecord[client] && !g_bMapFirstRecord[client] && !g_bMapPBRecord[client])
  1642. {
  1643. PrintToChat(client, "%t", "MapFinished5", MOSSGREEN, WHITE, LIMEGREEN, szName, GRAY, DARKBLUE, GRAY, LIMEGREEN, g_szFinalTime[client], GRAY, RED, g_szTimeDifference[client], GRAY, WHITE, LIMEGREEN, g_MapRank[client], WHITE, count, LIMEGREEN, g_szRecordMapTime, WHITE);
  1644. PrintToConsole(client, "%s finished the map with a time of (%s). Missing their best time by (%s). [rank #%i/%i | record %s]", szName, g_szFinalTime[client], g_szTimeDifference[client], g_MapRank[client], count, g_szRecordMapTime);
  1645. }
  1646. }
  1647. }
  1648. }
  1649. }
  1650.  
  1651. if (g_MapRank[client] == 99999 && IsValidClient(client))
  1652. PrintToChat(client, "[%cCK%c] %cFailed to save your data correctly! Please contact an admin.", MOSSGREEN, WHITE, DARKRED, RED, DARKRED);
  1653.  
  1654. CreateTimer(0.0, UpdatePlayerProfile, client, TIMER_FLAG_NO_MAPCHANGE);
  1655.  
  1656. if (g_bMapFirstRecord[client] || g_bMapPBRecord[client] || g_bMapSRVRecord[client])
  1657. CheckMapRanks(client);
  1658.  
  1659. /* Start function call */
  1660. Call_StartForward(g_MapFinishForward);
  1661.  
  1662. /* Push parameters one at a time */
  1663. Call_PushCell(client);
  1664. Call_PushFloat(g_fFinalTime[client]);
  1665. Call_PushString(g_szFinalTime[client]);
  1666. Call_PushCell(g_MapRank[client]);
  1667. Call_PushCell(count);
  1668.  
  1669. /* Finish the call, get the result */
  1670. Call_Finish();
  1671.  
  1672. }
  1673. //recalc avg
  1674. db_CalcAvgRunTime();
  1675.  
  1676. return;
  1677. }
  1678.  
  1679. stock void PrintChatBonus (int client, int zGroup, int rank = 0)
  1680. {
  1681. if (!IsValidClient(client))
  1682. return;
  1683.  
  1684. float RecordDiff;
  1685. char szRecordDiff[54], szName[MAX_NAME_LENGTH];
  1686.  
  1687. if (rank == 0)
  1688. rank = g_MapRankBonus[zGroup][client];
  1689.  
  1690. GetClientName(client, szName, MAX_NAME_LENGTH);
  1691. if ((GetConVarInt(g_hAnnounceRecord) == 0 ||
  1692. (GetConVarInt(g_hAnnounceRecord) == 1 && g_bBonusSRVRecord[client] || g_bBonusPBRecord[client] || g_bBonusFirstRecord[client]) ||
  1693. (GetConVarInt(g_hAnnounceRecord) == 2 && g_bBonusSRVRecord[client])) &&
  1694. (rank <= GetConVarInt(g_hAnnounceRank) || GetConVarInt(g_hAnnounceRank) == 0))
  1695. {
  1696. if (g_bBonusSRVRecord[client])
  1697. {
  1698. PlayRecordSound(1);
  1699.  
  1700. RecordDiff = g_fOldBonusRecordTime[zGroup] - g_fFinalTime[client];
  1701. FormatTimeFloat(client, RecordDiff, 3, szRecordDiff, 54);
  1702. Format(szRecordDiff, 54, "-%s", szRecordDiff);
  1703. }
  1704. if (g_bBonusFirstRecord[client] && g_bBonusSRVRecord[client])
  1705. {
  1706. PrintToChatAll("%t", "BonusFinished2", MOSSGREEN, WHITE, LIMEGREEN, szName, YELLOW, g_szZoneGroupName[zGroup]);
  1707. if (g_tmpBonusCount[zGroup] == 0)
  1708. PrintToChatAll("%t", "BonusFinished3", MOSSGREEN, WHITE, LIMEGREEN, szName, GRAY, YELLOW, g_szZoneGroupName[zGroup], GRAY, LIMEGREEN, g_szFinalTime[client], GRAY, LIMEGREEN, WHITE, LIMEGREEN, g_szFinalTime[client], WHITE);
  1709. else
  1710. PrintToChatAll("%t", "BonusFinished4", MOSSGREEN, WHITE, LIMEGREEN, szName, GRAY, YELLOW, g_szZoneGroupName[zGroup], GRAY, LIMEGREEN, g_szFinalTime[client], GRAY, LIMEGREEN, szRecordDiff, GRAY, LIMEGREEN, g_MapRankBonus[zGroup][client], GRAY, g_iBonusCount[zGroup], LIMEGREEN, g_szFinalTime[client], WHITE);
  1711. }
  1712. if (g_bBonusPBRecord[client] && g_bBonusSRVRecord[client])
  1713. {
  1714. PrintToChatAll("%t", "BonusFinished2", MOSSGREEN, WHITE, LIMEGREEN, szName, YELLOW, g_szZoneGroupName[zGroup]);
  1715. PrintToChatAll("%t", "BonusFinished5", MOSSGREEN, WHITE, LIMEGREEN, szName, GRAY, YELLOW, g_szZoneGroupName[zGroup], GRAY, LIMEGREEN, g_szFinalTime[client], GRAY, LIMEGREEN, szRecordDiff, GRAY, LIMEGREEN, g_MapRankBonus[zGroup][client], GRAY, g_iBonusCount[zGroup], LIMEGREEN, g_szFinalTime[client], WHITE);
  1716. }
  1717. if (g_bBonusPBRecord[client] && !g_bBonusSRVRecord[client])
  1718. {
  1719. PlayUnstoppableSound(client);
  1720. PrintToChatAll("%t", "BonusFinished6", MOSSGREEN, WHITE, LIMEGREEN, szName, GRAY, YELLOW, g_szZoneGroupName[zGroup], GRAY, LIMEGREEN, g_szFinalTime[client], GRAY, LIMEGREEN, g_szBonusTimeDifference[client], GRAY, LIMEGREEN, g_MapRankBonus[zGroup][client], GRAY, g_iBonusCount[zGroup], LIMEGREEN, g_szBonusFastestTime[zGroup], WHITE);
  1721. }
  1722. if (g_bBonusFirstRecord[client] && !g_bBonusSRVRecord[client])
  1723. {
  1724. PrintToChatAll("%t", "BonusFinished7", MOSSGREEN, WHITE, LIMEGREEN, szName, GRAY, YELLOW, g_szZoneGroupName[zGroup], GRAY, LIMEGREEN, g_szFinalTime[client], GRAY, LIMEGREEN, g_MapRankBonus[zGroup][client], GRAY, g_iBonusCount[zGroup], LIMEGREEN, g_szBonusFastestTime[zGroup], WHITE);
  1725. }
  1726. if (!g_bBonusSRVRecord[client] && !g_bBonusFirstRecord[client] && !g_bBonusPBRecord[client])
  1727. {
  1728. PrintToChatAll("%t", "BonusFinished1", MOSSGREEN, WHITE, LIMEGREEN, szName, GRAY, YELLOW, g_szZoneGroupName[zGroup], GRAY, RED, g_szFinalTime[client], GRAY, RED, g_szBonusTimeDifference[client], GRAY, LIMEGREEN, g_MapRankBonus[zGroup][client], GRAY, g_iBonusCount[zGroup], LIMEGREEN, g_szBonusFastestTime[zGroup], GRAY);
  1729. }
  1730. }
  1731. else
  1732. {
  1733. if (g_bBonusSRVRecord[client])
  1734. {
  1735. PlayRecordSound(1);
  1736. RecordDiff = g_fOldBonusRecordTime[zGroup] - g_fFinalTime[client];
  1737. FormatTimeFloat(client, RecordDiff, 3, szRecordDiff, 54);
  1738. Format(szRecordDiff, 54, "-%s", szRecordDiff);
  1739. }
  1740. if (g_bBonusFirstRecord[client] && g_bBonusSRVRecord[client])
  1741. {
  1742. PrintToChat(client, "%t", "BonusFinished2", MOSSGREEN, WHITE, LIMEGREEN, szName, YELLOW, g_szZoneGroupName[zGroup]);
  1743. if (g_tmpBonusCount[zGroup] == 0)
  1744. PrintToChat(client, "%t", "BonusFinished3", MOSSGREEN, WHITE, LIMEGREEN, szName, GRAY, YELLOW, g_szZoneGroupName[zGroup], GRAY, LIMEGREEN, g_szFinalTime[client], GRAY, LIMEGREEN, WHITE, LIMEGREEN, g_szFinalTime[client], WHITE);
  1745. else
  1746. PrintToChat(client, "%t", "BonusFinished4", MOSSGREEN, WHITE, LIMEGREEN, szName, GRAY, YELLOW, g_szZoneGroupName[zGroup], GRAY, LIMEGREEN, g_szFinalTime[client], GRAY, LIMEGREEN, szRecordDiff, GRAY, LIMEGREEN, g_MapRankBonus[zGroup][client], GRAY, g_iBonusCount[zGroup], LIMEGREEN, g_szFinalTime[client], WHITE);
  1747. }
  1748. if (g_bBonusPBRecord[client] && g_bBonusSRVRecord[client])
  1749. {
  1750. PrintToChat(client, "%t", "BonusFinished2", MOSSGREEN, WHITE, LIMEGREEN, szName, YELLOW, g_szZoneGroupName[zGroup]);
  1751. PrintToChat(client, "%t", "BonusFinished5", MOSSGREEN, WHITE, LIMEGREEN, szName, GRAY, YELLOW, g_szZoneGroupName[zGroup], GRAY, LIMEGREEN, g_szFinalTime[client], GRAY, LIMEGREEN, szRecordDiff, GRAY, LIMEGREEN, g_MapRankBonus[zGroup][client], GRAY, g_iBonusCount[zGroup], LIMEGREEN, g_szFinalTime[client], WHITE);
  1752. }
  1753. if (g_bBonusPBRecord[client] && !g_bBonusSRVRecord[client])
  1754. {
  1755. PlayUnstoppableSound(client);
  1756. PrintToChat(client, "%t", "BonusFinished6", MOSSGREEN, WHITE, LIMEGREEN, szName, GRAY, YELLOW, g_szZoneGroupName[zGroup], GRAY, LIMEGREEN, g_szFinalTime[client], GRAY, LIMEGREEN, g_szBonusTimeDifference[client], GRAY, LIMEGREEN, g_MapRankBonus[zGroup][client], GRAY, g_iBonusCount[zGroup], LIMEGREEN, g_szBonusFastestTime[zGroup], WHITE);
  1757. }
  1758. if (g_bBonusFirstRecord[client] && !g_bBonusSRVRecord[client])
  1759. {
  1760. PrintToChat(client, "%t", "BonusFinished7", MOSSGREEN, WHITE, LIMEGREEN, szName, GRAY, YELLOW, g_szZoneGroupName[zGroup], GRAY, LIMEGREEN, g_szFinalTime[client], GRAY, LIMEGREEN, g_MapRankBonus[zGroup][client], GRAY, g_iBonusCount[zGroup], LIMEGREEN, g_szBonusFastestTime[zGroup], WHITE);
  1761. }
  1762. if (!g_bBonusSRVRecord[client] && !g_bBonusFirstRecord[client] && !g_bBonusPBRecord[client])
  1763. {
  1764. if (IsValidClient(client))
  1765. PrintToChat(client, "%t", "BonusFinished1", MOSSGREEN, WHITE, LIMEGREEN, szName, GRAY, YELLOW, g_szZoneGroupName[zGroup], GRAY, RED, g_szFinalTime[client], GRAY, RED, g_szBonusTimeDifference[client], GRAY, LIMEGREEN, g_MapRankBonus[zGroup][client], GRAY, g_iBonusCount[zGroup], LIMEGREEN, g_szBonusFastestTime[zGroup], GRAY);
  1766. }
  1767.  
  1768. }
  1769.  
  1770. /* Start function call */
  1771. Call_StartForward(g_BonusFinishForward);
  1772.  
  1773. /* Push parameters one at a time */
  1774. Call_PushCell(client);
  1775. Call_PushFloat(g_fFinalTime[client]);
  1776. Call_PushString(g_szFinalTime[client]);
  1777. Call_PushCell(rank);
  1778. Call_PushCell(g_iBonusCount[zGroup]);
  1779. Call_PushCell(zGroup);
  1780.  
  1781. /* Finish the call, get the result */
  1782. Call_Finish();
  1783.  
  1784. CheckBonusRanks(client, zGroup);
  1785. db_CalcAvgRunTimeBonus();
  1786.  
  1787. if (rank == 9999999 && IsValidClient(client))
  1788. PrintToChat(client, "[%cCK%c] %cFailed to save your data correctly! Please contact an admin.", MOSSGREEN, WHITE, DARKRED, RED, DARKRED);
  1789.  
  1790. return;
  1791. }
  1792.  
  1793. public void CheckMapRanks(int client)
  1794. {
  1795. // if client has risen in rank,
  1796. if (g_OldMapRank[client] > g_MapRank[client])
  1797. {
  1798. for (int i = 1; i <= MaxClients; i++)
  1799. {
  1800. if (IsValidClient(i) && !IsFakeClient(i) && i != client)
  1801. { //if clients rank used to be bigger than i's, 2nd: clients new rank is at least as big as i's
  1802. if (g_OldMapRank[client] > g_MapRank[i] && g_MapRank[client] <= g_MapRank[i])
  1803. g_MapRank[i]++;
  1804. }
  1805. }
  1806. }
  1807. }
  1808.  
  1809. public void CheckBonusRanks(int client, int zGroup)
  1810. {
  1811. // if client has risen in rank,
  1812. if (g_OldMapRankBonus[zGroup][client] > g_MapRankBonus[zGroup][client])
  1813. {
  1814. for (int i = 1; i <= MaxClients; i++)
  1815. {
  1816. if (IsValidClient(i) && !IsFakeClient(i) && i != client)
  1817. { //if clients rank used to be bigger than i's, 2nd: clients new rank is at least as big as i's
  1818. if (g_OldMapRankBonus[zGroup][client] > g_MapRankBonus[zGroup][i] && g_MapRankBonus[zGroup][client] <= g_MapRankBonus[zGroup][i])
  1819. g_MapRankBonus[zGroup][i]++;
  1820. }
  1821. }
  1822. }
  1823. }
  1824.  
  1825. public void ReplaceChar(char[] sSplitChar, char[] sReplace, char sString[64])
  1826. {
  1827. StrCat(sString, sizeof(sString), " ");
  1828. char sBuffer[16][256];
  1829. ExplodeString(sString, sSplitChar, sBuffer, sizeof(sBuffer), sizeof(sBuffer[]));
  1830. strcopy(sString, sizeof(sString), "");
  1831. for (int i = 0; i < sizeof(sBuffer); i++)
  1832. {
  1833. if (strcmp(sBuffer[i], "") == 0)
  1834. continue;
  1835. if (i != 0)
  1836. {
  1837. char sTmpStr[256];
  1838. Format(sTmpStr, sizeof(sTmpStr), "%s%s", sReplace, sBuffer[i]);
  1839. StrCat(sString, sizeof(sString), sTmpStr);
  1840. }
  1841. else
  1842. {
  1843. StrCat(sString, sizeof(sString), sBuffer[i]);
  1844. }
  1845. }
  1846. }
  1847.  
  1848. public void FormatTimeFloat(int client, float time, int type, char[] string, int length)
  1849. {
  1850. char szMilli[16];
  1851. char szSeconds[16];
  1852. char szMinutes[16];
  1853. char szHours[16];
  1854. char szMilli2[16];
  1855. char szSeconds2[16];
  1856. char szMinutes2[16];
  1857. int imilli;
  1858. int imilli2;
  1859. int iseconds;
  1860. int iminutes;
  1861. int ihours;
  1862. time = FloatAbs(time);
  1863. imilli = RoundToZero(time * 100);
  1864. imilli2 = RoundToZero(time * 10);
  1865. imilli = imilli % 100;
  1866. imilli2 = imilli2 % 10;
  1867. iseconds = RoundToZero(time);
  1868. iseconds = iseconds % 60;
  1869. iminutes = RoundToZero(time / 60);
  1870. iminutes = iminutes % 60;
  1871. ihours = RoundToZero((time / 60) / 60);
  1872.  
  1873. if (imilli < 10)
  1874. Format(szMilli, 16, "0%dms", imilli);
  1875. else
  1876. Format(szMilli, 16, "%dms", imilli);
  1877. if (iseconds < 10)
  1878. Format(szSeconds, 16, "0%ds", iseconds);
  1879. else
  1880. Format(szSeconds, 16, "%ds", iseconds);
  1881. if (iminutes < 10)
  1882. Format(szMinutes, 16, "0%dm", iminutes);
  1883. else
  1884. Format(szMinutes, 16, "%dm", iminutes);
  1885.  
  1886.  
  1887. Format(szMilli2, 16, "%d", imilli2);
  1888. if (iseconds < 10)
  1889. Format(szSeconds2, 16, "0%d", iseconds);
  1890. else
  1891. Format(szSeconds2, 16, "%d", iseconds);
  1892. if (iminutes < 10)
  1893. Format(szMinutes2, 16, "0%d", iminutes);
  1894. else
  1895. Format(szMinutes2, 16, "%d", iminutes);
  1896. //Time: 00m 00s 00ms
  1897. if (type == 0)
  1898. {
  1899. Format(szHours, 16, "%dm", iminutes);
  1900. if (ihours > 0)
  1901. {
  1902. Format(szHours, 16, "%d", ihours);
  1903. Format(string, length, "%s:%s:%s.%s", szHours, szMinutes2, szSeconds2, szMilli2);
  1904. }
  1905. else
  1906. {
  1907. Format(string, length, "%s:%s.%s", szMinutes2, szSeconds2, szMilli2);
  1908. }
  1909. }
  1910. //00m 00s 00ms
  1911. if (type == 1)
  1912. {
  1913. Format(szHours, 16, "%dm", iminutes);
  1914. if (ihours > 0)
  1915. {
  1916. Format(szHours, 16, "%dh", ihours);
  1917. Format(string, length, "%s %s %s %s", szHours, szMinutes, szSeconds, szMilli);
  1918. }
  1919. else
  1920. Format(string, length, "%s %s %s", szMinutes, szSeconds, szMilli);
  1921. }
  1922. else
  1923. //00h 00m 00s 00ms
  1924. if (type == 2)
  1925. {
  1926. imilli = RoundToZero(time * 1000);
  1927. imilli = imilli % 1000;
  1928. if (imilli < 10)
  1929. Format(szMilli, 16, "00%dms", imilli);
  1930. else
  1931. if (imilli < 100)
  1932. Format(szMilli, 16, "0%dms", imilli);
  1933. else
  1934. Format(szMilli, 16, "%dms", imilli);
  1935. Format(szHours, 16, "%dh", ihours);
  1936. Format(string, 32, "%s %s %s %s", szHours, szMinutes, szSeconds, szMilli);
  1937. }
  1938. else
  1939. //00:00:00
  1940. if (type == 3)
  1941. {
  1942. if (imilli < 10)
  1943. Format(szMilli, 16, "0%d", imilli);
  1944. else
  1945. Format(szMilli, 16, "%d", imilli);
  1946. if (iseconds < 10)
  1947. Format(szSeconds, 16, "0%d", iseconds);
  1948. else
  1949. Format(szSeconds, 16, "%d", iseconds);
  1950. if (iminutes < 10)
  1951. Format(szMinutes, 16, "0%d", iminutes);
  1952. else
  1953. Format(szMinutes, 16, "%d", iminutes);
  1954. if (ihours > 0)
  1955. {
  1956. Format(szHours, 16, "%d", ihours);
  1957. Format(string, length, "%s:%s:%s:%s", szHours, szMinutes, szSeconds, szMilli);
  1958. }
  1959. else
  1960. Format(string, length, "%s:%s:%s", szMinutes, szSeconds, szMilli);
  1961. }
  1962. //Time: 00:00:00
  1963. if (type == 4)
  1964. {
  1965. if (imilli < 10)
  1966. Format(szMilli, 16, "0%d", imilli);
  1967. else
  1968. Format(szMilli, 16, "%d", imilli);
  1969. if (iseconds < 10)
  1970. Format(szSeconds, 16, "0%d", iseconds);
  1971. else
  1972. Format(szSeconds, 16, "%d", iseconds);
  1973. if (iminutes < 10)
  1974. Format(szMinutes, 16, "0%d", iminutes);
  1975. else
  1976. Format(szMinutes, 16, "%d", iminutes);
  1977. if (ihours > 0)
  1978. {
  1979. Format(szHours, 16, "%d", ihours);
  1980. Format(string, length, "Time: %s:%s:%s", szHours, szMinutes, szSeconds);
  1981. }
  1982. else
  1983. Format(string, length, "Time: %s:%s", szMinutes, szSeconds);
  1984. }
  1985. // goes to 00:00
  1986. if (type == 5)
  1987. {
  1988. if (imilli < 10)
  1989. Format(szMilli, 16, "0%d", imilli);
  1990. else
  1991. Format(szMilli, 16, "%d", imilli);
  1992. if (iseconds < 10)
  1993. Format(szSeconds, 16, "0%d", iseconds);
  1994. else
  1995. Format(szSeconds, 16, "%d", iseconds);
  1996. if (iminutes < 10)
  1997. Format(szMinutes, 16, "0%d", iminutes);
  1998. else
  1999. Format(szMinutes, 16, "%d", iminutes);
  2000. if (ihours > 0)
  2001. {
  2002.  
  2003. Format(szHours, 16, "%d", ihours);
  2004. Format(string, length, "%s:%s:%s:%s", szHours, szMinutes, szSeconds, szMilli);
  2005. }
  2006. else
  2007. if (iminutes > 0)
  2008. Format(string, length, "%s:%s:%s", szMinutes, szSeconds, szMilli);
  2009. else
  2010. Format(string, length, "%s:%ss", szSeconds, szMilli);
  2011. }
  2012. }
  2013.  
  2014. public void SetSkillGroups()
  2015. {
  2016. //Map Points
  2017. int mapcount;
  2018. if (g_pr_MapCount < 1)
  2019. mapcount = 1;
  2020. else
  2021. mapcount = g_pr_MapCount;
  2022.  
  2023. g_pr_PointUnit = 1;
  2024. float MaxPoints = (float(mapcount) * 700.0) + (float(g_totalBonusCount) * 400.0);
  2025.  
  2026. // Load rank cfg
  2027. char sPath[PLATFORM_MAX_PATH];
  2028. BuildPath(Path_SM, sPath, sizeof(sPath), SKILLGROUP_PATH);
  2029. if (FileExists(sPath))
  2030. {
  2031. Handle hKeyValues = CreateKeyValues("ckSurf.SkillGroups");
  2032. if (FileToKeyValues(hKeyValues, sPath) && KvGotoFirstSubKey(hKeyValues))
  2033. {
  2034. int RankValue[SkillGroup];
  2035.  
  2036. if (g_hSkillGroups == null)
  2037. g_hSkillGroups = CreateArray(sizeof(RankValue));
  2038. else
  2039. ClearArray(g_hSkillGroups);
  2040.  
  2041. char sRankName[128], sRankNameColored[128],sNameColor[32]; //color string size is "enough"
  2042. float fPercentage;
  2043. int points;
  2044. do
  2045. {
  2046. // Get section as Rankname
  2047. KvGetString(hKeyValues, "name", sRankName, 128);
  2048. KvGetString(hKeyValues, "name", sRankNameColored, 128);
  2049. KvGetString(hKeyValues, "rankColor", sNameColor, 32);
  2050.  
  2051. // Get percentage
  2052. fPercentage = KvGetFloat(hKeyValues, "percentage");
  2053.  
  2054. // Calculate required points for the rank
  2055. if (fPercentage < 0.0)
  2056. points = 0;
  2057. else
  2058. points = RoundToCeil(MaxPoints * fPercentage);
  2059.  
  2060. RankValue[PointReq] = points;
  2061.  
  2062. // Replace colors on name
  2063. //addColorToString(sRankNameColored, 128);
  2064.  
  2065. // Get player name color
  2066. //I cringe reading this...
  2067.  
  2068. // Remove colors from then non-colored rank name
  2069. normalizeChatString(sRankName, 128);
  2070.  
  2071. Format(RankValue[RankName], 128, "%s", sRankName);
  2072. Format(RankValue[RankNameColored], 128, "%s", sRankNameColored);
  2073. Format(RankValue[NameColor], 32 ,"%s",sNameColor);
  2074.  
  2075. PushArrayArray(g_hSkillGroups, RankValue[0]);
  2076.  
  2077. } while (KvGotoNextKey(hKeyValues));
  2078. }
  2079. if (hKeyValues != null)
  2080. CloseHandle(hKeyValues);
  2081. }
  2082. else
  2083. SetFailState("[ckSurf] %s not found.", SKILLGROUP_PATH);
  2084.  
  2085. }
  2086.  
  2087. public void SetPlayerRank(int client)
  2088. {
  2089. if (IsFakeClient(client))
  2090. return;
  2091.  
  2092. if (g_hSkillGroups == null)
  2093. {
  2094. CreateTimer(5.0, reloadRank, client);
  2095. return;
  2096. }
  2097.  
  2098. int RankValue[SkillGroup];
  2099. int index = GetSkillgroupFromPoints(g_pr_points[client]);
  2100.  
  2101. if (g_iTitleInUse[client] == -1)
  2102. {
  2103. // Player is not using a title
  2104. if (GetConVarBool(g_hPointSystem))
  2105. {
  2106. GetArrayArray(g_hSkillGroups, index, RankValue[0]);
  2107.  
  2108. Format(g_pr_rankname[client], 128, "[%s]", RankValue[RankName]);
  2109. Format(g_pr_chat_coloredrank[client], 128, "[%s%c]", RankValue[RankNameColored], WHITE);
  2110. Format(g_pr_rankColor[client],32,"%s", RankValue[NameColor]);
  2111. }
  2112. }
  2113. else
  2114. {
  2115. Format(g_pr_rankname[client], 128, "[%s]", g_szflagTitle[g_iTitleInUse[client]]);
  2116. Format(g_pr_chat_coloredrank[client], 128, "[%s%c]", g_szflagTitle_Colored[g_iTitleInUse[client]], WHITE);
  2117. }
  2118.  
  2119. // Admin Clantag
  2120. if (GetConVarBool(g_hAdminClantag))
  2121. { if (GetUserFlagBits(client) & ADMFLAG_ROOT || GetUserFlagBits(client) & ADMFLAG_GENERIC)
  2122. {
  2123. Format(g_pr_chat_coloredrank[client], 128, "%s %cADMIN%c", g_pr_chat_coloredrank[client], LIMEGREEN, WHITE);
  2124. Format(g_pr_rankname[client], 128, "ADMIN");
  2125. return;
  2126. }
  2127. }
  2128. }
  2129.  
  2130. public int GetSkillgroupFromPoints(int points)
  2131. {
  2132. int size = GetArraySize(g_hSkillGroups);
  2133. for (int i = 0; i < size; i++)
  2134. {
  2135. int RankValue[SkillGroup];
  2136. GetArrayArray(g_hSkillGroups, i, RankValue[0]);
  2137.  
  2138. if (i == (size-1)) // Last rank
  2139. {
  2140. if (points >= RankValue[PointReq])
  2141. {
  2142. return i;
  2143. }
  2144. }
  2145. else if (i == 0) // First rank
  2146. {
  2147. if (points <= RankValue[PointReq])
  2148. {
  2149. return i;
  2150. }
  2151. }
  2152. else // Mid ranks
  2153. {
  2154. int RankValueNext[SkillGroup];
  2155. GetArrayArray(g_hSkillGroups, (i+1), RankValueNext[0]);
  2156. if (points > RankValue[PointReq] && points <= RankValueNext[PointReq])
  2157. {
  2158. return i;
  2159. }
  2160. }
  2161. }
  2162. // Return 0 if not found
  2163. return 0;
  2164. }
  2165.  
  2166. stock Action PrintSpecMessageAll(int client)
  2167. {
  2168. char szName[64];
  2169. GetClientName(client, szName, sizeof(szName));
  2170. normalizeChatString(szName, 64);
  2171.  
  2172. char szTextToAll[1024];
  2173. GetCmdArgString(szTextToAll, sizeof(szTextToAll));
  2174. StripQuotes(szTextToAll);
  2175. if (StrEqual(szTextToAll, "") || StrEqual(szTextToAll, " ") || StrEqual(szTextToAll, " "))
  2176. return Plugin_Handled;
  2177.  
  2178. normalizeChatString(szTextToAll, 1024);
  2179. char szChatRank[64];
  2180. Format(szChatRank, 64, "%s", g_pr_chat_coloredrank[client]);
  2181.  
  2182. if (GetConVarBool(g_hPointSystem) && GetConVarBool(g_hColoredNames))
  2183. Format(szName,sizeof(szName),"%s%s",g_pr_rankColor[client],szName);
  2184.  
  2185. if (GetConVarBool(g_hCountry) && (GetConVarBool(g_hPointSystem) || ((StrEqual(g_pr_rankname[client], "ADMIN", false)) && GetConVarBool(g_hAdminClantag))))
  2186. CPrintToChatAll("{green}%s{default} %s *SPEC* {grey}%s{default}: %s", g_szCountryCode[client], szChatRank, szName, szTextToAll);
  2187. else
  2188. if (GetConVarBool(g_hPointSystem) || ((StrEqual(g_pr_rankname[client], "ADMIN", false)) && GetConVarBool(g_hAdminClantag)))
  2189. CPrintToChatAll("%s *SPEC* {grey}%s{default}: %s", szChatRank, szName, szTextToAll);
  2190. else
  2191. if (GetConVarBool(g_hCountry))
  2192. CPrintToChatAll("[{green}%s{default}] *SPEC* {grey}%s{default}: %s", g_szCountryCode[client], szName, szTextToAll);
  2193. else
  2194. CPrintToChatAll("*SPEC* {grey}%s{default}: %s", szName, szTextToAll);
  2195.  
  2196. for (int i = 1; i <= MaxClients; i++)
  2197. if (IsValidClient(i))
  2198. {
  2199. if (GetConVarBool(g_hCountry) && (GetConVarBool(g_hPointSystem) || ((StrEqual(g_pr_rankname[client], "ADMIN", false)) && GetConVarBool(g_hAdminClantag))))
  2200. PrintToConsole(i, "%s [%s] *SPEC* %s: %s", g_szCountryCode[client], g_pr_rankname[client], szName, szTextToAll);
  2201. else
  2202. if (GetConVarBool(g_hPointSystem) || ((StrEqual(g_pr_rankname[client], "ADMIN", false)) && GetConVarBool(g_hAdminClantag)))
  2203. PrintToConsole(i, "[%s] *SPEC* %s: %s", g_szCountryCode[client], szName, szTextToAll);
  2204. else
  2205. if (GetConVarBool(g_hPointSystem))
  2206. PrintToConsole(i, "[%s] *SPEC* %s: %s", g_pr_rankname[client], szName, szTextToAll);
  2207. else
  2208. PrintToConsole(i, "*SPEC* %s: %s", szName, szTextToAll);
  2209. }
  2210. return Plugin_Handled;
  2211. }
  2212. //http://pastebin.com/YdUWS93H
  2213. public bool CheatFlag(const char[] voice_inputfromfile, bool isCommand, bool remove)
  2214. {
  2215. if (remove)
  2216. {
  2217. if (!isCommand)
  2218. {
  2219. Handle hConVar = FindConVar(voice_inputfromfile);
  2220. if (hConVar != null)
  2221. {
  2222. int flags = GetConVarFlags(hConVar);
  2223. SetConVarFlags(hConVar, flags &= ~FCVAR_CHEAT);
  2224. return true;
  2225. }
  2226. else
  2227. return false;
  2228. }
  2229. else
  2230. {
  2231. int flags = GetCommandFlags(voice_inputfromfile);
  2232. if (SetCommandFlags(voice_inputfromfile, flags &= ~FCVAR_CHEAT))
  2233. return true;
  2234. else
  2235. return false;
  2236. }
  2237. }
  2238. else
  2239. {
  2240. if (!isCommand)
  2241. {
  2242. Handle hConVar = FindConVar(voice_inputfromfile);
  2243. if (hConVar != null)
  2244. {
  2245. int flags = GetConVarFlags(hConVar);
  2246. SetConVarFlags(hConVar, flags & FCVAR_CHEAT);
  2247. return true;
  2248. }
  2249. else
  2250. return false;
  2251.  
  2252.  
  2253. } else
  2254. {
  2255. int flags = GetCommandFlags(voice_inputfromfile);
  2256. if (SetCommandFlags(voice_inputfromfile, flags & FCVAR_CHEAT))
  2257. return true;
  2258. else
  2259. return false;
  2260.  
  2261. }
  2262. }
  2263. }
  2264.  
  2265. public void StringRGBtoInt(char color[24], intColor[4])
  2266. {
  2267. char sPart[4][24];
  2268. ExplodeString(color, " ", sPart, sizeof(sPart), sizeof(sPart[]));
  2269. intColor[0] = StringToInt(sPart[0]);
  2270. intColor[1] = StringToInt(sPart[1]);
  2271. intColor[2] = StringToInt(sPart[2]);
  2272. intColor[3] = 255;
  2273. }
  2274.  
  2275. public void GetRGBColor(int bot, char color[256])
  2276. {
  2277. char sPart[4][24];
  2278. ExplodeString(color, " ", sPart, sizeof(sPart), sizeof(sPart[]));
  2279.  
  2280. if (bot == 0)
  2281. {
  2282. g_ReplayBotColor[0] = StringToInt(sPart[0]);
  2283. g_ReplayBotColor[1] = StringToInt(sPart[1]);
  2284. g_ReplayBotColor[2] = StringToInt(sPart[2]);
  2285. }
  2286. else
  2287. if (bot == 1)
  2288. {
  2289. g_BonusBotColor[0] = StringToInt(sPart[0]);
  2290. g_BonusBotColor[1] = StringToInt(sPart[1]);
  2291. g_BonusBotColor[2] = StringToInt(sPart[2]);
  2292. }
  2293.  
  2294. if (bot == 0 && g_RecordBot != -1 && IsValidClient(g_RecordBot))
  2295. SetEntityRenderColor(g_RecordBot, g_ReplayBotColor[0], g_ReplayBotColor[1], g_ReplayBotColor[2], 50);
  2296. else
  2297. if (bot == 1 && g_BonusBot != -1 && IsValidClient(g_BonusBot))
  2298. SetEntityRenderColor(g_BonusBot, g_BonusBotColor[0], g_BonusBotColor[1], g_BonusBotColor[2], 50);
  2299.  
  2300. }
  2301.  
  2302. public void SpecList(int client)
  2303. {
  2304. if (!IsValidClient(client) || IsFakeClient(client) || GetClientMenu(client) != MenuSource_None)
  2305. return;
  2306.  
  2307. if (!StrEqual(g_szPlayerPanelText[client], ""))
  2308. {
  2309. Handle panel = CreatePanel();
  2310. DrawPanelText(panel, g_szPlayerPanelText[client]);
  2311. SendPanelToClient(panel, client, PanelHandler, 1);
  2312. CloseHandle(panel);
  2313. }
  2314. }
  2315.  
  2316. public int PanelHandler(Handle menu, MenuAction action, int param1, int param2)
  2317. {
  2318. }
  2319.  
  2320. public bool TraceRayDontHitSelf(int entity, int mask, any data)
  2321. {
  2322. return entity != data && !(0 < entity <= MaxClients);
  2323. }
  2324.  
  2325. stock int BooltoInt(bool status)
  2326. {
  2327. return (status) ? 1:0;
  2328. }
  2329.  
  2330. public void PlayQuakeSound_Spec(int client, char[] buffer)
  2331. {
  2332. int SpecMode;
  2333. for (int x = 1; x <= MaxClients; x++)
  2334. {
  2335. if (IsValidClient(x) && !IsPlayerAlive(x))
  2336. {
  2337. SpecMode = GetEntProp(x, Prop_Send, "m_iObserverMode");
  2338. if (SpecMode == 4 || SpecMode == 5)
  2339. {
  2340. int Target = GetEntPropEnt(x, Prop_Send, "m_hObserverTarget");
  2341. if (Target == client)
  2342. if (g_bEnableQuakeSounds[x])
  2343. ClientCommand(x, buffer);
  2344. }
  2345. }
  2346. }
  2347. }
  2348.  
  2349. public void AttackProtection(int client, int &buttons)
  2350. {
  2351. if (GetConVarBool(g_hAttackSpamProtection))
  2352. {
  2353. char classnamex[64];
  2354. GetClientWeapon(client, classnamex, 64);
  2355. if (StrContains(classnamex, "knife", true) == -1 && g_AttackCounter[client] >= 40)
  2356. {
  2357. if (buttons & IN_ATTACK)
  2358. {
  2359. int ent;
  2360. ent = GetEntPropEnt(client, Prop_Data, "m_hActiveWeapon");
  2361. if (IsValidEntity(ent))
  2362. SetEntPropFloat(ent, Prop_Send, "m_flNextPrimaryAttack", GetGameTime() + 2.0);
  2363. }
  2364. }
  2365. }
  2366. }
  2367.  
  2368. public void CheckRun(int client)
  2369. {
  2370. if (!IsValidClient(client) || IsFakeClient(client))
  2371. return;
  2372.  
  2373. if (g_bTimeractivated[client])
  2374. {
  2375. if (g_fCurrentRunTime[client] > g_fPersonalRecord[client] && !g_bMissedMapBest[client] && !g_bPause[client] && g_iClientInZone[client][2] == 0)
  2376. {
  2377. g_bMissedMapBest[client] = true;
  2378. if (g_fPersonalRecord[client] > 0.0)
  2379. PrintToChat(client, "%t", "MissedMapBest", MOSSGREEN, WHITE, GRAY, DARKBLUE, g_szPersonalRecord[client], GRAY);
  2380. EmitSoundToClient(client, "buttons/button18.wav", client);
  2381. }
  2382. else
  2383. {
  2384. if (g_fCurrentRunTime[client] > g_fPersonalRecordBonus[g_iClientInZone[client][2]][client] && g_iClientInZone[client][2] > 0 && !g_bPause[client] && !g_bMissedBonusBest[client])
  2385. {
  2386. if (g_fPersonalRecordBonus[g_iClientInZone[client][2]][client] > 0.0)
  2387. {
  2388. g_bMissedBonusBest[client] = true;
  2389. PrintToChat(client, "[%cCK%c] %cYou have missed your best bonus time of (%c%s%c)", MOSSGREEN, WHITE, GRAY, YELLOW, g_szPersonalRecordBonus[g_iClientInZone[client][2]][client], GRAY);
  2390. EmitSoundToClient(client, "buttons/button18.wav", client);
  2391. }
  2392. }
  2393. }
  2394. }
  2395. }
  2396.  
  2397. public void NoClipCheck(int client)
  2398. {
  2399. MoveType mt;
  2400. mt = GetEntityMoveType(client);
  2401. if (!(g_bOnGround[client]))
  2402. {
  2403. if (mt == MOVETYPE_NOCLIP)
  2404. g_bNoClipUsed[client] = true;
  2405. }
  2406. if (mt == MOVETYPE_NOCLIP && (g_bTimeractivated[client]))
  2407. {
  2408. Client_Stop(client, 1);
  2409. }
  2410. }
  2411.  
  2412.  
  2413. public void AutoBhopFunction(int client, int &buttons)
  2414. {
  2415. if (!IsValidClient(client))
  2416. return;
  2417. if (g_bAutoBhop && g_bAutoBhopClient[client])
  2418. {
  2419. if (buttons & IN_JUMP)
  2420. if (!(g_bOnGround[client]))
  2421. if (!(GetEntityMoveType(client) & MOVETYPE_LADDER))
  2422. if (GetEntProp(client, Prop_Data, "m_nWaterLevel") <= 1)
  2423. buttons &= ~IN_JUMP;
  2424.  
  2425. }
  2426. }
  2427.  
  2428. public void SpecListMenuDead(int client) // What Spectators see
  2429. {
  2430. char szTick[32];
  2431. Format(szTick, 32, "%i", g_Server_Tickrate);
  2432. int ObservedUser;
  2433. ObservedUser = -1;
  2434. char sSpecs[512];
  2435. Format(sSpecs, 512, "");
  2436. int SpecMode;
  2437. ObservedUser = GetEntPropEnt(client, Prop_Send, "m_hObserverTarget");
  2438. SpecMode = GetEntProp(client, Prop_Send, "m_iObserverMode");
  2439.  
  2440. if (SpecMode == 4 || SpecMode == 5)
  2441. {
  2442. g_SpecTarget[client] = ObservedUser;
  2443. int count;
  2444. count = 0;
  2445. //Speclist
  2446. if (1 <= ObservedUser <= MaxClients)
  2447. {
  2448. int x;
  2449. char szTime2[32];
  2450. char szProBest[32];
  2451. char szPlayerRank[64];
  2452. Format(szPlayerRank, 32, "");
  2453. char szStage[32];
  2454.  
  2455. for (x = 1; x <= MaxClients; x++)
  2456. {
  2457. if (IsValidClient(x) && !IsFakeClient(client) && !IsPlayerAlive(x) && GetClientTeam(x) >= 1 && GetClientTeam(x) <= 3)
  2458. {
  2459.  
  2460. SpecMode = GetEntProp(x, Prop_Send, "m_iObserverMode");
  2461. if (SpecMode == 4 || SpecMode == 5)
  2462. {
  2463. int ObservedUser2;
  2464. ObservedUser2 = GetEntPropEnt(x, Prop_Send, "m_hObserverTarget");
  2465. if (ObservedUser == ObservedUser2)
  2466. {
  2467. count++;
  2468. if (count < 6)
  2469. Format(sSpecs, 512, "%s%N\n", sSpecs, x);
  2470. }
  2471. if (count == 6)
  2472. Format(sSpecs, 512, "%s...", sSpecs);
  2473. }
  2474. }
  2475. }
  2476.  
  2477. //rank
  2478. if (GetConVarBool(g_hPointSystem))
  2479. {
  2480. if (g_pr_points[ObservedUser] != 0)
  2481. {
  2482. char szRank[32];
  2483. if (g_PlayerRank[ObservedUser] > g_pr_RankedPlayers)
  2484. Format(szRank, 32, "-");
  2485. else
  2486. Format(szRank, 32, "%i", g_PlayerRank[ObservedUser]);
  2487. Format(szPlayerRank, 32, "Rank: #%s/%i", szRank, g_pr_RankedPlayers);
  2488. }
  2489. else
  2490. Format(szPlayerRank, 32, "Rank: NA / %i", g_pr_RankedPlayers);
  2491. }
  2492.  
  2493. if (g_fPersonalRecord[ObservedUser] > 0.0)
  2494. {
  2495. FormatTimeFloat(client, g_fPersonalRecord[ObservedUser], 3, szTime2, sizeof(szTime2));
  2496. Format(szProBest, 32, "%s (#%i/%i)", szTime2, g_MapRank[ObservedUser], g_MapTimesCount);
  2497. }
  2498. else
  2499. Format(szProBest, 32, "None");
  2500.  
  2501. if (g_bhasStages) // There are stages
  2502. Format(szStage, 32, "%i / %i", g_Stage[g_iClientInZone[ObservedUser][2]][ObservedUser], (g_mapZonesTypeCount[g_iClientInZone[ObservedUser][2]][3] + 1));
  2503. else
  2504. Format(szStage, 32, "Linear map");
  2505.  
  2506. if (g_Stage[g_iClientInZone[client][2]][ObservedUser] == 999) // if player is in stage 999
  2507. Format(szStage, 32, "Bonus");
  2508.  
  2509. if (!StrEqual(sSpecs, ""))
  2510. {
  2511. char szName[MAX_NAME_LENGTH];
  2512. GetClientName(ObservedUser, szName, MAX_NAME_LENGTH);
  2513. if (g_bTimeractivated[ObservedUser])
  2514. {
  2515. char szTime[32];
  2516. float Time;
  2517. Time = GetGameTime() - g_fStartTime[ObservedUser] - g_fPauseTime[ObservedUser];
  2518. FormatTimeFloat(client, Time, 4, szTime, sizeof(szTime));
  2519. if (!g_bPause[ObservedUser])
  2520. {
  2521. if (!IsFakeClient(ObservedUser))
  2522. {
  2523. Format(g_szPlayerPanelText[client], 512, "Specs (%i):\n%s\n \n%s\n%s\nRecord: %s\n\nStage: %s\n", count, sSpecs, szTime, szPlayerRank, szProBest, szStage);
  2524. if (!g_bShowSpecs[client])
  2525. Format(g_szPlayerPanelText[client], 512, "Specs (%i)\n \n%s\n%s\nRecord: %s\n\nStage: %s\n", count, szTime, szPlayerRank, szProBest, szStage);
  2526. }
  2527. else
  2528. {
  2529. if (ObservedUser == g_RecordBot)
  2530. Format(g_szPlayerPanelText[client], 512, "[Map Record Replay]\n%s\nTickrate: %s\nSpecs: %i\n\nStage: %s\n", szTime, szTick, count, szStage);
  2531. else
  2532. if (ObservedUser == g_BonusBot)
  2533. Format(g_szPlayerPanelText[client], 512, "[%s Record Replay]\n%s\nTickrate: %s\nSpecs: %i\n\nStage: %s\n", g_szZoneGroupName[g_iClientInZone[g_BonusBot][2]], szTime, szTick, count, szStage);
  2534.  
  2535. }
  2536. }
  2537. else
  2538. {
  2539. if (ObservedUser == g_RecordBot)
  2540. Format(g_szPlayerPanelText[client], 512, "[Map Record Replay]\nTime: PAUSED\nTickrate: %s\nSpecs: %i\n\nStage: %s\n", szTick, count, szStage);
  2541. else
  2542. if (ObservedUser == g_BonusBot)
  2543. Format(g_szPlayerPanelText[client], 512, "[%s Record Replay]\nTime: PAUSED\nTickrate: %s\nSpecs: %i\n\nStage: Bonus\n", g_szZoneGroupName[g_iClientInZone[g_BonusBot][2]], szTick, count);
  2544. }
  2545. }
  2546. else
  2547. {
  2548. if (ObservedUser != g_RecordBot)
  2549. {
  2550. Format(g_szPlayerPanelText[client], 512, "%Specs (%i):\n%s\n \n%s\nRecord: %s\n", count, sSpecs, szPlayerRank, szProBest);
  2551. if (!g_bShowSpecs[client])
  2552. Format(g_szPlayerPanelText[client], 512, "Specs (%i)\n \n%s\nRecord: %s\n", count, szPlayerRank, szProBest);
  2553. }
  2554. }
  2555.  
  2556. if (!g_bShowTime[client] && g_bShowSpecs[client])
  2557. {
  2558. if (ObservedUser != g_RecordBot && ObservedUser != g_BonusBot)
  2559. Format(g_szPlayerPanelText[client], 512, "%Specs (%i):\n%s\n \n%s\nRecord: %s\n\nStage: %s\n", count, sSpecs, szPlayerRank, szProBest, szStage);
  2560. else
  2561. {
  2562. if (ObservedUser == g_RecordBot)
  2563. Format(g_szPlayerPanelText[client], 512, "Record replay of\n%s\n \nTickrate: %s\nSpecs (%i):\n%s\n\nStage: %s\n", g_szReplayName, szTick, count, sSpecs, szStage);
  2564. else
  2565. if (ObservedUser == g_BonusBot)
  2566. Format(g_szPlayerPanelText[client], 512, "Bonus replay of\n%s\n \nTickrate: %s\nSpecs (%i):\n%s\n\nStage: Bonus\n", g_szBonusName, szTick, count, sSpecs);
  2567.  
  2568. }
  2569. }
  2570. if (!g_bShowTime[client] && !g_bShowSpecs[client])
  2571. {
  2572. if (ObservedUser != g_RecordBot)
  2573. Format(g_szPlayerPanelText[client], 512, "%s\nRecord: %s\n\nStage: %s\n", szPlayerRank, szProBest, szStage);
  2574. else
  2575. {
  2576. if (ObservedUser == g_RecordBot)
  2577. Format(g_szPlayerPanelText[client], 512, "Record replay of\n%s\n \nTickrate: %s\n\nStage: %s\n", g_szReplayName, szTick, szStage);
  2578. else
  2579. if (ObservedUser == g_BonusBot)
  2580. Format(g_szPlayerPanelText[client], 512, "Bonus replay of\n%s\n \nTickrate: %s\n\nStage: Bonus\n", g_szBonusName, szTick, szStage);
  2581.  
  2582. }
  2583. }
  2584. SpecList(client);
  2585. }
  2586. }
  2587. }
  2588. else
  2589. g_SpecTarget[client] = -1;
  2590. }
  2591.  
  2592. public void SpecListMenuAlive(int client) // What player sees
  2593. {
  2594.  
  2595. if (IsFakeClient(client) || !g_bShowSpecs[client] || GetClientMenu(client) != MenuSource_None)
  2596. return;
  2597.  
  2598. //Spec list for players
  2599. Format(g_szPlayerPanelText[client], 512, "");
  2600. char sSpecs[512];
  2601. int SpecMode;
  2602. Format(sSpecs, 512, "");
  2603. int count;
  2604. count = 0;
  2605. for (int i = 1; i <= MaxClients; i++)
  2606. {
  2607. if (IsValidClient(i) && !IsFakeClient(client) && !IsPlayerAlive(i) && !g_bFirstTeamJoin[i] && g_bSpectate[i])
  2608. {
  2609. SpecMode = GetEntProp(i, Prop_Send, "m_iObserverMode");
  2610. if (SpecMode == 4 || SpecMode == 5)
  2611. {
  2612. int Target;
  2613. Target = GetEntPropEnt(i, Prop_Send, "m_hObserverTarget");
  2614. if (Target == client)
  2615. {
  2616. count++;
  2617. if (count < 6)
  2618. Format(sSpecs, 512, "%s%N\n", sSpecs, i);
  2619.  
  2620. }
  2621. if (count == 6)
  2622. Format(sSpecs, 512, "%s...", sSpecs);
  2623. }
  2624. }
  2625. }
  2626. if (count > 0)
  2627. {
  2628. if (g_bShowSpecs[client])
  2629. Format(g_szPlayerPanelText[client], 512, "Specs (%i):\n%s ", count, sSpecs);
  2630.  
  2631. SpecList(client);
  2632. }
  2633. else
  2634. Format(g_szPlayerPanelText[client], 512, "");
  2635. }
  2636.  
  2637. public void LoadInfoBot()
  2638. {
  2639. if (!GetConVarBool(g_hInfoBot))
  2640. return;
  2641.  
  2642. g_InfoBot = -1;
  2643. for (int i = 1; i <= MaxClients; i++)
  2644. {
  2645. if (!IsValidClient(i) || !IsFakeClient(i) || i == g_RecordBot || i == g_BonusBot)
  2646. continue;
  2647. g_InfoBot = i;
  2648. break;
  2649. }
  2650. if (IsValidClient(g_InfoBot))
  2651. {
  2652. Format(g_pr_rankname[g_InfoBot], 128, "BOT");
  2653. CS_SetClientClanTag(g_InfoBot, "");
  2654. SetEntProp(g_InfoBot, Prop_Send, "m_iAddonBits", 0);
  2655. SetEntProp(g_InfoBot, Prop_Send, "m_iPrimaryAddon", 0);
  2656. SetEntProp(g_InfoBot, Prop_Send, "m_iSecondaryAddon", 0);
  2657. SetEntProp(g_InfoBot, Prop_Send, "m_iObserverMode", 1);
  2658. SetInfoBotName(g_InfoBot);
  2659. }
  2660. else
  2661. {
  2662. setBotQuota();
  2663. CreateTimer(0.5, RefreshInfoBot, TIMER_FLAG_NO_MAPCHANGE);
  2664. }
  2665. }
  2666.  
  2667. public void CreateNavFiles()
  2668. {
  2669. char DestFile[256];
  2670. char SourceFile[256];
  2671. Format(SourceFile, sizeof(SourceFile), "maps/replay_bot.nav");
  2672. if (!FileExists(SourceFile))
  2673. {
  2674. LogError("<ckSurf> Failed to create .nav files. Reason: %s doesn't exist!", SourceFile);
  2675. return;
  2676. }
  2677. char map[256];
  2678. int mapListSerial = -1;
  2679. if (ReadMapList(g_MapList, mapListSerial, "mapcyclefile", MAPLIST_FLAG_CLEARARRAY | MAPLIST_FLAG_NO_DEFAULT) == null)
  2680. if (mapListSerial == -1)
  2681. return;
  2682.  
  2683. for (int i = 0; i < GetArraySize(g_MapList); i++)
  2684. {
  2685. GetArrayString(g_MapList, i, map, sizeof(map));
  2686. if (map[0])
  2687. {
  2688. Format(DestFile, sizeof(DestFile), "maps/%s.nav", map);
  2689. if (!FileExists(DestFile))
  2690. File_Copy(SourceFile, DestFile);
  2691. }
  2692. }
  2693. }
  2694.  
  2695. public Action RefreshInfoBot(Handle timer)
  2696. {
  2697. LoadInfoBot();
  2698. }
  2699.  
  2700.  
  2701. public void SetInfoBotName(int ent)
  2702. {
  2703. char szBuffer[64];
  2704. char sNextMap[128];
  2705. if (!IsValidClient(g_InfoBot) || !GetConVarBool(g_hInfoBot))
  2706. return;
  2707. if (g_bMapChooser && EndOfMapVoteEnabled() && !HasEndOfMapVoteFinished())
  2708. Format(sNextMap, sizeof(sNextMap), "Pending Vote");
  2709. else
  2710. {
  2711. GetNextMap(sNextMap, sizeof(sNextMap));
  2712. char mapPieces[6][128];
  2713. int lastPiece = ExplodeString(sNextMap, "/", mapPieces, sizeof(mapPieces), sizeof(mapPieces[]));
  2714. Format(sNextMap, sizeof(sNextMap), "%s", mapPieces[lastPiece - 1]);
  2715. }
  2716. int iInfoBotTimeleft;
  2717. GetMapTimeLeft(iInfoBotTimeleft);
  2718. float ftime = float(iInfoBotTimeleft);
  2719. char szTime[32];
  2720. FormatTimeFloat(g_InfoBot, ftime, 4, szTime, sizeof(szTime));
  2721. Handle hTmp;
  2722. hTmp = FindConVar("mp_timelimit");
  2723. int iTimeLimit = GetConVarInt(hTmp);
  2724. if (hTmp != null)
  2725. CloseHandle(hTmp);
  2726. if (GetConVarBool(g_hMapEnd) && iTimeLimit > 0)
  2727. Format(szBuffer, sizeof(szBuffer), "%s (in %s)", sNextMap, szTime);
  2728. else
  2729. Format(szBuffer, sizeof(szBuffer), "Pending Vote (no time limit)");
  2730. SetClientName(g_InfoBot, szBuffer);
  2731. Client_SetScore(g_InfoBot, 9999);
  2732. CS_SetClientClanTag(g_InfoBot, "NEXTMAP");
  2733. }
  2734.  
  2735. public void CenterHudDead(int client)
  2736. {
  2737. char szTick[32];
  2738. char obsAika[128];
  2739. float obsTimer;
  2740. Format(szTick, 32, "%i", g_Server_Tickrate);
  2741. int ObservedUser;
  2742. ObservedUser = -1;
  2743. int SpecMode;
  2744. ObservedUser = GetEntPropEnt(client, Prop_Send, "m_hObserverTarget");
  2745. SpecMode = GetEntProp(client, Prop_Send, "m_iObserverMode");
  2746. if (SpecMode == 4 || SpecMode == 5)
  2747. {
  2748. g_SpecTarget[client] = ObservedUser;
  2749. //keys
  2750. char sResult[256];
  2751. int Buttons;
  2752. if (g_bInfoPanel[client] && IsValidClient(ObservedUser))
  2753. {
  2754. Buttons = g_LastButton[ObservedUser];
  2755. if (Buttons & IN_MOVELEFT)
  2756. Format(sResult, sizeof(sResult), "<font color='#00CC00'>A</font>");
  2757. else
  2758. Format(sResult, sizeof(sResult), "_");
  2759. if (Buttons & IN_FORWARD)
  2760. Format(sResult, sizeof(sResult), "%s <font color='#00CC00'>W</font>", sResult);
  2761. else
  2762. Format(sResult, sizeof(sResult), "%s _", sResult);
  2763. if (Buttons & IN_BACK)
  2764. Format(sResult, sizeof(sResult), "%s <font color='#00CC00'>S</font>", sResult);
  2765. else
  2766. Format(sResult, sizeof(sResult), "%s _", sResult);
  2767. if (Buttons & IN_MOVERIGHT)
  2768. Format(sResult, sizeof(sResult), "%s <font color='#00CC00'>D</font>", sResult);
  2769. else
  2770. Format(sResult, sizeof(sResult), "%s _", sResult);
  2771. if (Buttons & IN_DUCK)
  2772. Format(sResult, sizeof(sResult), "%s - <font color='#00CC00'>DUCK</font>", sResult);
  2773. else
  2774. Format(sResult, sizeof(sResult), "%s - _", sResult);
  2775. if (Buttons & IN_JUMP)
  2776. Format(sResult, sizeof(sResult), "%s <font color='#00CC00'>JUMP</font>", sResult);
  2777. else
  2778. Format(sResult, sizeof(sResult), "%s _", sResult);
  2779.  
  2780. if (g_bTimeractivated[ObservedUser]) {
  2781. obsTimer = GetGameTime() - g_fStartTime[ObservedUser] - g_fPauseTime[ObservedUser];
  2782. FormatTimeFloat(client, obsTimer, 3, obsAika, sizeof(obsAika));
  2783. } else {
  2784. obsAika = "<font color='#FF0000'>Stopped</font>";
  2785. }
  2786. char timerText[32] = "";
  2787. if (g_iClientInZone[ObservedUser][2] > 0)
  2788. Format(timerText, 32, "[%s] ", g_szZoneGroupName[g_iClientInZone[ObservedUser][2]]);
  2789. if (g_bPracticeMode[ObservedUser])
  2790. Format(timerText, 32, "[Practice] ");
  2791.  
  2792. PrintHintText(client, "<font face=''><font color='#75D1FF'>%sTimer:</font> %s\n<font color='#75D1FF'>Speed:</font> %.1f u/s\n%s", timerText, obsAika, g_fLastSpeed[ObservedUser], sResult);
  2793. }
  2794. }
  2795. else
  2796. g_SpecTarget[client] = -1;
  2797. }
  2798.  
  2799. public void CenterHudAlive(int client)
  2800. {
  2801. if (!IsValidClient(client))
  2802. return;
  2803.  
  2804. char pAika[54], timerText[32], StageString[24];
  2805.  
  2806. if (g_bInfoPanel[client])
  2807. {
  2808. if (!g_bhasStages) // map is linear
  2809. {
  2810. Format(StageString, 24, "Linear\t");
  2811. }
  2812. else // map has stages
  2813. {
  2814. if (g_Stage[g_iClientInZone[client][2]][client] > 9)
  2815. Format(StageString, 24, "%i / %i\t", g_Stage[g_iClientInZone[client][2]][client], (g_mapZonesTypeCount[g_iClientInZone[client][2]][3] + 1)); // less \t's to make lines align
  2816. else
  2817. Format(StageString, 24, "%i / %i\t\t", g_Stage[g_iClientInZone[client][2]][client], (g_mapZonesTypeCount[g_iClientInZone[client][2]][3] + 1));
  2818. }
  2819.  
  2820. if (g_bTimeractivated[client] && !g_bPause[client])
  2821. {
  2822. FormatTimeFloat(client, g_fCurrentRunTime[client], 3, pAika, 128);
  2823. if (g_bMissedMapBest[client] && g_fPersonalRecord[client] > 0.0) // missed best personal time
  2824. {
  2825. Format(pAika, 128, "<font color='#FFFFB2'>%s</font>", pAika);
  2826. }
  2827. else if (g_fPersonalRecord[client] < 0.1) // hasn't finished the map yet
  2828. {
  2829. Format(pAika, 128, "<font color='#7F7FFF'>%s</font>", pAika);
  2830. }
  2831. else
  2832. {
  2833. Format(pAika, 128, "<font color='#99FF99'>%s</font>", pAika); // hasn't missed best personal time yet
  2834. }
  2835. }
  2836.  
  2837. if (g_bPracticeMode[client])
  2838. Format(timerText, 32, "[PRAC]: ");
  2839. else
  2840. Format(timerText, 32, "");
  2841.  
  2842. // Set Checkpoint back to normal
  2843. if (GetGameTime() - g_fLastDifferenceTime[client] > 5.0)
  2844. {
  2845. if (g_iClientInZone[client][2] == 0)
  2846. {
  2847. if (g_fRecordMapTime != 9999999.0)
  2848. {
  2849. Format(g_szLastSRDifference[client], 64, "\t\tSR: %s", g_szRecordMapTime);
  2850. if (g_fPersonalRecord[client] > 0.0)
  2851. {
  2852. Format(g_szLastPBDifference[client], 64, "%s", g_szPersonalRecord[client]);
  2853. }
  2854. else
  2855. {
  2856. Format(g_szLastPBDifference[client], 64, "N/A");
  2857. }
  2858. }
  2859. else
  2860. {
  2861. Format(g_szLastSRDifference[client], 64, "\t\tSR: N/A");
  2862. Format(g_szLastPBDifference[client], 64, "N/A");
  2863. }
  2864. }
  2865. else
  2866. {
  2867. Format(g_szLastPBDifference[client], 64, "%s", g_szPersonalRecordBonus[g_iClientInZone[client][2]][client]);
  2868. Format(g_szLastSRDifference[client], 64, "\t\tSR: %s", g_szBonusFastestTime[g_iClientInZone[client][2]]);
  2869. }
  2870. }
  2871.  
  2872.  
  2873.  
  2874. char szRank[32];
  2875. if (g_iClientInZone[client][2] > 0) // if in bonus stage, get bonus times
  2876. {
  2877. if (g_fPersonalRecordBonus[g_iClientInZone[client][2]][client] > 0.0)
  2878. Format(szRank, 64, "\tRank: %i / %i", g_MapRankBonus[g_iClientInZone[client][2]][client], g_iBonusCount[g_iClientInZone[client][2]]);
  2879. else
  2880. if (g_iBonusCount[g_iClientInZone[client][2]] > 0)
  2881. Format(szRank, 64, "\t\tRank: N/A / %i", g_iBonusCount[g_iClientInZone[client][2]]);
  2882. else
  2883. Format(szRank, 64, "\t\tRank: N/A");
  2884.  
  2885. }
  2886. else // if in normal map, get normal times
  2887. {
  2888. if (g_fPersonalRecord[client] > 0.0)
  2889. Format(szRank, 64, "\tRank: %i / %i", g_MapRank[client], g_MapTimesCount);
  2890. else
  2891. if (g_MapTimesCount > 0)
  2892. Format(szRank, 64, "\t\tRank: N/A / %i", g_MapTimesCount);
  2893. else
  2894. Format(szRank, 64, "\t\tRank: N/A");
  2895. }
  2896.  
  2897. if (IsValidEntity(client) && 1 <= client <= MaxClients && !g_bOverlay[client])
  2898. {
  2899. if (g_bTimeractivated[client])
  2900. {
  2901. if (g_bPause[client])
  2902. {
  2903. PrintHintText(client, "<font face=''>%s<font color='#FF0000'>Paused</font> %s\nPB: %s%s\nStage: %sSpeed: %i</font>", timerText, g_szLastSRDifference[client], g_szLastPBDifference[client], szRank, StageString, RoundToNearest(g_fLastSpeed[client])); //ZoneColor
  2904. }
  2905. else
  2906. {
  2907. PrintHintText(client, "<font face=''>%s%s %s\nPB: %s%s\nStage: %sSpeed: %i</font>", timerText, pAika, g_szLastSRDifference[client], g_szLastPBDifference[client], szRank, StageString, RoundToNearest(g_fLastSpeed[client]));
  2908. }
  2909. }
  2910. else
  2911. PrintHintText(client, "<font face=''>%s<font color='#FF0000'>Stopped</font> %s\nPB: %s%s\nStage: %sSpeed: %i</font>", timerText, g_szLastSRDifference[client], g_szLastPBDifference[client], szRank, StageString, RoundToNearest(g_fLastSpeed[client]));
  2912. }
  2913. }
  2914. }
  2915.  
  2916. public void Checkpoint(int client, int zone, int zonegroup)
  2917. {
  2918. if (!IsValidClient(client) || g_bPositionRestored[client] || IsFakeClient(client) || zone >= CPLIMIT)
  2919. return;
  2920.  
  2921. float time = g_fCurrentRunTime[client];
  2922. float percent = -1.0;
  2923. int totalPoints = 0;
  2924. char szPercnt[24];
  2925. char szSpecMessage[512];
  2926.  
  2927. if (g_bhasStages) // If staged map
  2928. totalPoints = g_mapZonesTypeCount[zonegroup][3];
  2929. else
  2930. if (g_mapZonesTypeCount[zonegroup][4] > 0) // If Linear Map and checkpoints
  2931. totalPoints = g_mapZonesTypeCount[zonegroup][4];
  2932.  
  2933. // Count percent of completion
  2934. percent = (float(zone + 1) / float(totalPoints + 1));
  2935. percent = percent * 100.0;
  2936. Format(szPercnt, 24, "%1.f%%", percent);
  2937.  
  2938. if (g_bTimeractivated[client] && !g_bPracticeMode[client]) {
  2939. if (g_fMaxPercCompleted[client] < 1.0) // First time a checkpoint is reached
  2940. g_fMaxPercCompleted[client] = percent;
  2941. else
  2942. if (g_fMaxPercCompleted[client] < percent) // The furthest checkpoint reached
  2943. g_fMaxPercCompleted[client] = percent;
  2944. }
  2945.  
  2946. g_fCheckpointTimesNew[zonegroup][client][zone] = time;
  2947.  
  2948.  
  2949. // Server record difference
  2950. char sz_srDiff[128];
  2951. char sz_srDiff_colorless[128];
  2952.  
  2953. if (g_bCheckpointRecordFound[zonegroup] && g_fCheckpointServerRecord[zonegroup][zone] > 0.1 && g_bTimeractivated[client])
  2954. {
  2955. float f_srDiff = (g_fCheckpointServerRecord[zonegroup][zone] - time);
  2956.  
  2957. FormatTimeFloat(client, f_srDiff, 5, sz_srDiff, 128);
  2958.  
  2959. if (f_srDiff > 0)
  2960. {
  2961. Format(sz_srDiff_colorless, 128, "-%s", sz_srDiff);
  2962. Format(sz_srDiff, 128, " %c%cSR: %c-%s%c", YELLOW, PURPLE, GREEN, sz_srDiff, YELLOW);
  2963. if (zonegroup > 0)
  2964. Format(g_szLastSRDifference[client], 64, "SR: <font color='#99ff99'>%s</font>", sz_srDiff_colorless);
  2965. else
  2966. Format(g_szLastSRDifference[client], 64, "\t\tSR: <font color='#99ff99'>%s</font>", sz_srDiff_colorless);
  2967.  
  2968. }
  2969. else
  2970. {
  2971. Format(sz_srDiff_colorless, 128, "+%s", sz_srDiff);
  2972. Format(sz_srDiff, 128, " %c%cSR: %c+%s%c", YELLOW, PURPLE, RED, sz_srDiff, YELLOW);
  2973. if (zonegroup > 0)
  2974. Format(g_szLastSRDifference[client], 64, "SR: <font color='#FF9999'>%s</font>", sz_srDiff_colorless);
  2975. else
  2976. Format(g_szLastSRDifference[client], 64, "\t\tSR: <font color='#FF9999'>%s</font>", sz_srDiff_colorless);
  2977. }
  2978. g_fLastDifferenceTime[client] = GetGameTime();
  2979. }
  2980. else
  2981. Format(sz_srDiff, 128, "");
  2982.  
  2983.  
  2984. // Get client name for spectators
  2985. char szName[MAX_NAME_LENGTH];
  2986. GetClientName(client, szName, MAX_NAME_LENGTH);
  2987.  
  2988. // Has completed the map before
  2989. if (g_bCheckpointsFound[zonegroup][client] && g_bTimeractivated[client] && !g_bPracticeMode[client] && g_fCheckpointTimesRecord[zonegroup][client][zone] > 0.1)
  2990. {
  2991. // Set percent of completion to assist
  2992. if (CS_GetMVPCount(client) < 1)
  2993. CS_SetClientAssists(client, RoundToFloor(g_fMaxPercCompleted[client]));
  2994. else
  2995. CS_SetClientAssists(client, 100);
  2996.  
  2997. // Own record difference
  2998. float diff = (g_fCheckpointTimesRecord[zonegroup][client][zone] - time);
  2999. char szDiff[32];
  3000. char szDiff_colorless[32];
  3001.  
  3002. FormatTimeFloat(client, diff, 5, szDiff, 32);
  3003.  
  3004. // MOVE TO PB variable
  3005. if (diff > 0)
  3006. {
  3007. Format(szDiff_colorless, 32, "-%s", szDiff);
  3008. Format(szDiff, sizeof(szDiff), " %c-%s", GREEN, szDiff);
  3009. if (zonegroup > 0)
  3010. Format(g_szLastPBDifference[client], 64, "<font color='#99ff99'>%s</font>\t", szDiff_colorless);
  3011. else
  3012. Format(g_szLastPBDifference[client], 64, "<font color='#99ff99'>%s</font>\t", szDiff_colorless);
  3013. }
  3014. else
  3015. {
  3016. Format(szDiff_colorless, 32, "+%s", szDiff);
  3017. Format(szDiff, sizeof(szDiff), " %c+%s", RED, szDiff);
  3018. if (zonegroup > 0)
  3019. Format(g_szLastPBDifference[client], 64, "<font color='#FF9999'>%s</font>\t", szDiff_colorless);
  3020. else
  3021. Format(g_szLastPBDifference[client], 64, "<font color='#FF9999'>%s</font>\t", szDiff_colorless);
  3022. }
  3023. g_fLastDifferenceTime[client] = GetGameTime();
  3024.  
  3025.  
  3026. if (g_fCheckpointTimesRecord[zonegroup][client][zone] <= 0.0)
  3027. Format(szDiff, 128, "");
  3028.  
  3029. // First checkpoint
  3030. if (tmpDiff[client] == 9999.0)
  3031. {
  3032. //"#format" "{1:c},{2:c},{3:c},{4:s},{5:c},{6:c},{7:s},{8:c}, {9:s}"
  3033. //"en" "[{1}CK{2}] {3}CP: {4} {5}compared to your best run. ({6}{7}{8}).{9}"
  3034. if (g_bCheckpointsEnabled[client])
  3035. PrintToChat(client, "%t", "Checkpoint1", MOSSGREEN, WHITE, YELLOW, szDiff, YELLOW, WHITE, szPercnt, YELLOW, sz_srDiff);
  3036. Format(szSpecMessage, sizeof(szSpecMessage), "%t", "Checkpoint1-spec", MOSSGREEN, WHITE, YELLOW, szDiff, YELLOW, WHITE, szName, YELLOW, WHITE, szPercnt, YELLOW, sz_srDiff);
  3037. CheckpointToSpec(client, szSpecMessage);
  3038. }
  3039. else
  3040. {
  3041. // Other checkpoints have catchup messages
  3042. float catchUp = diff - tmpDiff[client];
  3043. char szCatchUp[128];
  3044.  
  3045. FormatTimeFloat(client, catchUp, 5, szCatchUp, 128);
  3046.  
  3047. if (catchUp > 0)
  3048. Format(szCatchUp, 128, " %c-%s", GREEN, szCatchUp);
  3049. else
  3050. Format(szCatchUp, 128, " %c+%s", RED, szCatchUp);
  3051.  
  3052. // Formatting CatchUp message
  3053. if (diff > 0) // If player is faster than his record
  3054. {
  3055. if (catchUp > 0) // If player grew lead from last checkpoint
  3056. Format(szCatchUp, 128, "%t:%s", "GrewCheckpoint", szCatchUp);
  3057. else // Player lost lead from last checkpoint
  3058. Format(szCatchUp, 128, "%t:%s", "LostCheckpoint", szCatchUp);
  3059. }
  3060. else // If player is slower than his record
  3061. {
  3062. if (catchUp > 0) // Caught up players best time
  3063. Format(szCatchUp, 128, "%t:%s", "CaughtCheckpoint", szCatchUp);
  3064. else // Fell behind
  3065. Format(szCatchUp, 128, "%t:%s", "FellCheckpoint", szCatchUp);
  3066. }
  3067.  
  3068. //"#format" "{1:c},{2:c},{3:c},{4:s},{5:c},{6:s},{7:c},{8:c},{9:s},{10:c},{11:s}"
  3069. //"en" "[{1}CK{2}] {3}CP: {4} {5}compared to your PB. {6} {7}({8}{9}{10}).{11}"
  3070. if (g_bCheckpointsEnabled[client])
  3071. PrintToChat(client, "%t", "Checkpoint2", MOSSGREEN, WHITE, YELLOW, szDiff, YELLOW, szCatchUp, YELLOW, WHITE, szPercnt, YELLOW, sz_srDiff);
  3072. Format(szSpecMessage, sizeof(szSpecMessage), "%t", "Checkpoint2-spec", MOSSGREEN, WHITE, YELLOW, szDiff, YELLOW, WHITE, szName, YELLOW, szCatchUp, YELLOW, WHITE, szPercnt, YELLOW, sz_srDiff);
  3073. CheckpointToSpec(client, szSpecMessage);
  3074. }
  3075. // Saving difference time for next checkpoint
  3076. tmpDiff[client] = diff;
  3077. }
  3078. else // if first run
  3079. if (g_bTimeractivated[client] && !g_bPracticeMode[client])
  3080. {
  3081. // Set percent of completion to assist
  3082. if (CS_GetMVPCount(client) < 1)
  3083. CS_SetClientAssists(client, RoundToFloor(g_fMaxPercCompleted[client]));
  3084. else
  3085. CS_SetClientAssists(client, 100);
  3086.  
  3087. char szTime[32];
  3088. FormatTimeFloat(client, time, 3, szTime, 32);
  3089.  
  3090. // "#format" "{1:c},{2:c},{3:c},{4:c},{5:s},{6:c},{7:c},{8:s},{9:s}"
  3091. // "en" "[{1}CK{2}]{3} CP: Completed{4} {5} {6}of the map in {7}{8}.{9}"
  3092. if (percent > -1.0)
  3093. {
  3094. if (g_bCheckpointsEnabled[client])
  3095. PrintToChat(client, "%t", "Checkpoint3", MOSSGREEN, WHITE, YELLOW, WHITE, szPercnt, YELLOW, WHITE, szTime, sz_srDiff);
  3096. Format(szSpecMessage, sizeof(szSpecMessage), "%t", "Checkpoint3-spec", MOSSGREEN, WHITE, YELLOW, WHITE, szName, YELLOW, WHITE, szPercnt, YELLOW, WHITE, szTime, sz_srDiff);
  3097. CheckpointToSpec(client, szSpecMessage);
  3098. }
  3099. }
  3100. else
  3101. {
  3102. if (g_bCheckpointsEnabled[client])
  3103. PrintToChat(client, "%t", "Checkpoint4", MOSSGREEN, WHITE, YELLOW, WHITE, (1 + zone));
  3104. Format(szSpecMessage, sizeof(szSpecMessage), "%t", "Checkpoint4-spec", MOSSGREEN, WHITE, YELLOW, WHITE, szName, YELLOW, WHITE, (1 + zone));
  3105. CheckpointToSpec(client, szSpecMessage);
  3106. }
  3107. }
  3108.  
  3109. public void CheckpointToSpec(int client, char[] buffer)
  3110. {
  3111. int SpecMode;
  3112. for (int x = 1; x <= MaxClients; x++)
  3113. {
  3114. if (IsValidClient(x) && !IsPlayerAlive(x))
  3115. {
  3116. SpecMode = GetEntProp(x, Prop_Send, "m_iObserverMode");
  3117. if (SpecMode == 4 || SpecMode == 5)
  3118. {
  3119. int Target = GetEntPropEnt(x, Prop_Send, "m_hObserverTarget");
  3120. if (Target == client)
  3121. PrintToChat(x, "%s", buffer);
  3122. }
  3123. }
  3124. }
  3125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement