HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. #pragma semicolon 1
  2. #include <sourcemod>
  3. #include <sdktools>
  4.  
  5.  
  6. #define VERSION "3.1 - Ateszᴴᴰ"
  7.  
  8. new JugadoEspectador[MAXPLAYERS+1] = 0;
  9. new JugadoT[MAXPLAYERS+1] = 0;
  10. new JugadoCT[MAXPLAYERS+1] = 0;
  11.  
  12. new bool:conectado[MAXPLAYERS+1] = {false, ...};
  13.  
  14. new bool:in_db[MAXPLAYERS+1] = {false, ...};
  15. new bool:checked_db[MAXPLAYERS+1] = {false, ...};
  16.  
  17.  
  18. // DB handle
  19. new Handle:g_hDB = INVALID_HANDLE;
  20.  
  21.  
  22. new Handle:auto_createDatabase;
  23.  
  24. public Plugin:myinfo =
  25. {
  26. name = "Players Activity Time",
  27. author = "Made by Franc1sco, Hun-Made by Atesz",
  28. description = "A rank based in time played",
  29. version = VERSION,
  30. url = "http://flyboys.eu/"
  31. };
  32.  
  33. public OnPluginStart()
  34. {
  35.  
  36. CreateConVar("sm_mostactive_version", VERSION, "version", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
  37. RegAdminCmd("sm_resetdb", Command_Clear, ADMFLAG_ROOT);
  38. RegAdminCmd("sm_savedb", Command_save, ADMFLAG_ROOT);
  39. RegConsoleCmd("sm_active", DOMenu);
  40.  
  41. auto_createDatabase = CreateConVar("mostactive_createsqlite", "1", "1 = Create mostactive sqlite database automatically to your config (Restart your Server after first lunch!) (Mysql you have to add for yourself, see how to install!!), 0 = off");
  42.  
  43. InitDB();
  44. }
  45.  
  46. public OnMapStart()
  47. {
  48. if (GetConVarBool(auto_createDatabase)) otherlib_createDB();
  49.  
  50. CreateTimer(1.0, Temporizador, _, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
  51. }
  52.  
  53. public OnMapEnd()
  54. {
  55. SyncDB();
  56. }
  57.  
  58.  
  59. // by stamm
  60. public otherlib_createDB()
  61. {
  62. new String:dbPath[PLATFORM_MAX_PATH + 1];
  63.  
  64. BuildPath(Path_SM, dbPath, sizeof(dbPath), "configs/databases.cfg");
  65.  
  66. new Handle:dbHandle = CreateKeyValues("Databases");
  67. FileToKeyValues(dbHandle, dbPath);
  68.  
  69. if (!KvJumpToKey(dbHandle, "mostactive_sql"))
  70. {
  71. KvJumpToKey(dbHandle, "mostactive_sql", true);
  72.  
  73. KvSetString(dbHandle, "driver", "sqlite");
  74. KvSetString(dbHandle, "host", "localhost");
  75. KvSetString(dbHandle, "database", "Mostactive-DB");
  76. KvSetString(dbHandle, "user", "root");
  77.  
  78. KvGoBack(dbHandle);
  79.  
  80. KeyValuesToFile(dbHandle, dbPath);
  81.  
  82. for (new i=0; i <= 20; i++) PrintToServer("Created Mostactive DB. To use it, please restart your Server now!!");
  83. }
  84. CloseHandle(dbHandle);
  85. }
  86. //
  87.  
  88. public Action:Temporizador(Handle:timer)
  89. {
  90. for(new i = 1; i <= MaxClients; i++)
  91. {
  92. if(IsClientInGame(i))
  93. {
  94. new team = GetClientTeam(i);
  95.  
  96. if(team == 2)
  97. {
  98. ++JugadoT[i];
  99.  
  100. }
  101. else if(team == 3)
  102. {
  103. ++JugadoCT[i];
  104. }
  105. else
  106. {
  107. ++JugadoEspectador[i];
  108. }
  109. }
  110. }
  111. }
  112.  
  113. public Action:Command_save(admin, args)
  114. {
  115.  
  116. for (new client = 1; client <= MaxClients; client++)
  117. {
  118. if (IsClientInGame(client) && !IsFakeClient(client) && IsClientAuthorized(client) && checked_db[client])
  119. {
  120. InsertScoreInDB(client);
  121. }
  122. }
  123.  
  124. ReplyToCommand(admin, "Players rank has been saved");
  125.  
  126. return Plugin_Handled;
  127. }
  128.  
  129.  
  130. public OnClientPostAdminCheck(client)
  131. {
  132. if (!client || IsFakeClient(client))
  133. return;
  134.  
  135. conectado[client] = true;
  136.  
  137. JugadoEspectador[client] = 0;
  138. JugadoT[client] = 0;
  139. JugadoCT[client] = 0;
  140. in_db[client] = false;
  141. checked_db[client] = false;
  142.  
  143. GetScoreFromDB(client);
  144. }
  145.  
  146. public OnClientDisconnect(client)
  147. {
  148. if(!conectado[client])
  149. return;
  150.  
  151. if (!client || IsFakeClient(client))
  152. return;
  153.  
  154.  
  155. InsertScoreInDB(client);
  156.  
  157. conectado[client] = false;
  158. }
  159.  
  160.  
  161.  
  162. // database
  163.  
  164.  
  165.  
  166. // Here we are creating SQL DB
  167. public InitDB()
  168. {
  169. new String:sqlError[255];
  170.  
  171. g_hDB = SQL_Connect("mostactive_sql", true, sqlError, sizeof(sqlError));
  172.  
  173. if (g_hDB == INVALID_HANDLE)
  174. {
  175. LogError("[ MOSTACTIVE ] couldn't connect to the Database!! Error: %s", sqlError);
  176.  
  177.  
  178. }
  179. else
  180. {
  181.  
  182. SQL_LockDatabase(g_hDB);
  183. SQL_FastQuery(g_hDB, "VACUUM");
  184. SQL_FastQuery(g_hDB, "CREATE TABLE IF NOT EXISTS saverank_time2 (steamid VARCHAR( 20 ) NOT NULL DEFAULT '', Nombre VARCHAR( 255 ) NOT NULL DEFAULT '',JugadoEspectador INT( 255 ) NOT NULL DEFAULT 0,JugadoT INT( 255 ) NOT NULL DEFAULT 0,JugadoCT INT( 255 ) NOT NULL DEFAULT 0,total INT( 255 ) NOT NULL DEFAULT 0, PRIMARY KEY (steamid));");
  185. SQL_UnlockDatabase(g_hDB);
  186. }
  187. }
  188.  
  189.  
  190. // Admin command that clears all player's scores
  191. public Action:Command_Clear(admin, args)
  192. {
  193.  
  194. ClearDBQuery();
  195.  
  196.  
  197. for (new client = 1; client <= MaxClients; client++)
  198. {
  199. if (IsClientInGame(client) && !IsFakeClient(client))
  200. {
  201. JugadoEspectador[client] = 0;
  202. JugadoT[client] = 0;
  203. JugadoCT[client] = 0;
  204. in_db[client] = false;
  205.  
  206. }
  207. }
  208.  
  209. ReplyToCommand(admin, "Players rank has been reset");
  210.  
  211. return Plugin_Handled;
  212. }
  213.  
  214.  
  215. // Doing clearing stuff
  216. public ClearDBQuery()
  217. {
  218. // Clearing SQL DB
  219. SQL_LockDatabase(g_hDB);
  220. SQL_FastQuery(g_hDB, "DELETE FROM saverank_time2;");
  221. SQL_UnlockDatabase(g_hDB);
  222. }
  223.  
  224.  
  225. public InsertScoreInDB(client)
  226. {
  227. decl String:steamId[30];
  228. GetClientAuthString(client, steamId, sizeof(steamId));
  229.  
  230. new save1 = JugadoEspectador[client];
  231. new save2 = JugadoT[client];
  232. new save3 = JugadoCT[client];
  233. new save4 = (save1 + save2 + save3);
  234.  
  235.  
  236. decl String:name[32],String:name2[32];
  237. GetClientName(client, name, sizeof(name));
  238.  
  239. SQL_EscapeString(g_hDB, name, name2, sizeof(name2));
  240.  
  241. decl String:query[256];
  242.  
  243. if(!in_db[client])
  244. {
  245. Format(query, sizeof(query), "INSERT INTO saverank_time2 VALUES ('%s', '%s',%d,%d,%d,%d);", steamId, name2,save1,save2,save3,save4);
  246. in_db[client] = true;
  247. }
  248. else
  249. Format(query, sizeof(query), "UPDATE saverank_time2 SET Nombre='%s', JugadoEspectador='%d', JugadoT='%d', JugadoCT='%d', total='%d' WHERE steamid = '%s';", name2,save1,save2,save3,save4,steamId);
  250.  
  251.  
  252. SQL_FastQuery(g_hDB, query);
  253.  
  254.  
  255. }
  256.  
  257. // Syncronize DB with score varibles
  258. public SyncDB()
  259. {
  260. for (new client = 1; client <= MaxClients; client++)
  261. {
  262. if (IsClientInGame(client) && !IsFakeClient(client) && IsClientAuthorized(client) && checked_db[client])
  263. {
  264. InsertScoreInDB(client);
  265. }
  266. }
  267. }
  268.  
  269. // Now we need get this information back...
  270. public GetScoreFromDB(client)
  271. {
  272.  
  273. decl String:steamId[30];
  274. decl String:query[200];
  275.  
  276. GetClientAuthString(client, steamId, sizeof(steamId));
  277. Format(query, sizeof(query), "SELECT * FROM saverank_time2 WHERE steamId = '%s';", steamId);
  278. SQL_TQuery(g_hDB, SetPlayerScore, query, client);
  279. }
  280.  
  281. // ...and set player's score and cash if needed
  282. public SetPlayerScore(Handle:owner, Handle:hndl, const String:error[], any:client)
  283. {
  284. if (hndl == INVALID_HANDLE)
  285. {
  286. LogError("SQL Error: %s", error);
  287. return;
  288. }
  289.  
  290. if (SQL_GetRowCount(hndl) == 0)
  291. {
  292. checked_db[client] = true;
  293. return;
  294. }
  295.  
  296. if(!SQL_FetchRow(hndl))
  297. {
  298. checked_db[client] = true;
  299. return;
  300. }
  301.  
  302.  
  303. new save1 = SQL_FetchInt(hndl,2);
  304. new save2 = SQL_FetchInt(hndl,3);
  305. new save3 = SQL_FetchInt(hndl,4);
  306.  
  307.  
  308. JugadoEspectador[client] = save1;
  309. JugadoT[client] = save2;
  310. JugadoCT[client] = save3;
  311.  
  312. checked_db[client] = true;
  313. in_db[client] = true;
  314.  
  315. //LogMessage("%N se le han restaurado el tiempo", client);
  316. }
  317.  
  318.  
  319. public showTOP(client){
  320.  
  321. if (g_hDB != INVALID_HANDLE)
  322. {
  323. decl String:buffer[200];
  324. Format(buffer, sizeof(buffer), "SELECT * FROM saverank_time2 ORDER BY total DESC LIMIT 999");
  325. SQL_TQuery(g_hDB, SQLTopShow, buffer, client);
  326. } else {
  327. PrintToChat(client, "Rank System is now not avilable");
  328. }
  329. }
  330.  
  331. public SQLTopShow(Handle:owner, Handle:hndl, const String:error[], any:client){
  332.  
  333. if(hndl == INVALID_HANDLE)
  334. {
  335. LogError(error);
  336. PrintToServer("Last Connect SQL Error: %s", error);
  337. return;
  338. }
  339.  
  340. new Handle:menu2 = CreateMenu(DIDMenuHandler2);
  341. SetMenuTitle(menu2, "Ranglista");
  342.  
  343.  
  344. new orden = 0;
  345. decl String:numero[64];
  346. decl String:name[64];
  347. decl String:texto[128];
  348.  
  349. if (SQL_HasResultSet(hndl))
  350. {
  351. while (SQL_FetchRow(hndl))
  352. {
  353. orden++;
  354. Format(numero,64, "option%i", orden);
  355. SQL_FetchString(hndl, 1, name, sizeof(name));
  356. new Time = SQL_FetchInt(hndl,5);
  357. new Hours = (Time/60/60);
  358. new Minutes = (Time/60)%(60);
  359. new Seconds = (Time%60);
  360.  
  361.  
  362.  
  363. Format(texto,128, "n%i %s - %d Ó. %d P. %d Mp.", orden,name,Hours, Minutes, Seconds);
  364.  
  365. AddMenuItem(menu2, numero, texto);
  366.  
  367.  
  368. }
  369. }
  370.  
  371. if(orden < 1)
  372. {
  373. AddMenuItem(menu2, "empty", "TOP is empty!");
  374. }
  375.  
  376. SetMenuExitButton(menu2, true);
  377. DisplayMenu(menu2, client, MENU_TIME_FOREVER);
  378.  
  379. }
  380.  
  381. public showTOP2(client){
  382.  
  383. if (g_hDB != INVALID_HANDLE)
  384. {
  385. decl String:buffer[200];
  386. Format(buffer, sizeof(buffer), "SELECT * FROM saverank_time2 ORDER BY JugadoEspectador DESC LIMIT 999");
  387. SQL_TQuery(g_hDB, SQLTopShow2, buffer, client);
  388. } else {
  389. PrintToChat(client, "Rank System is now not avilable");
  390. }
  391. }
  392.  
  393. public SQLTopShow2(Handle:owner, Handle:hndl, const String:error[], any:client){
  394.  
  395. if(hndl == INVALID_HANDLE)
  396. {
  397. LogError(error);
  398. PrintToServer("Last Connect SQL Error: %s", error);
  399. return;
  400. }
  401.  
  402. new Handle:menu2 = CreateMenu(DIDMenuHandler2);
  403. SetMenuTitle(menu2, "Top Megfigyelő");
  404.  
  405.  
  406. new orden = 0;
  407. decl String:numero[64];
  408. decl String:name[64];
  409. decl String:texto[128];
  410.  
  411. if (SQL_HasResultSet(hndl))
  412. {
  413. while (SQL_FetchRow(hndl))
  414. {
  415. orden++;
  416. Format(numero,64, "option%i", orden);
  417. SQL_FetchString(hndl, 1, name, sizeof(name));
  418. new Time = SQL_FetchInt(hndl,2);
  419. new Hours = (Time/60/60);
  420. new Minutes = (Time/60)%(60);
  421. new Seconds = (Time%60);
  422.  
  423.  
  424.  
  425. Format(texto,128, "n%i %s - %d Ó. %d P. %d Mp.", orden,name,Hours, Minutes, Seconds);
  426.  
  427. AddMenuItem(menu2, numero, texto);
  428.  
  429.  
  430. }
  431. }
  432.  
  433. if(orden < 1)
  434. {
  435. AddMenuItem(menu2, "empty", "TOP is empty!");
  436. }
  437.  
  438. SetMenuExitButton(menu2, true);
  439. DisplayMenu(menu2, client, MENU_TIME_FOREVER);
  440.  
  441. }
  442.  
  443. public showTOP3(client){
  444.  
  445. if (g_hDB != INVALID_HANDLE)
  446. {
  447. decl String:buffer[200];
  448. Format(buffer, sizeof(buffer), "SELECT * FROM saverank_time2 ORDER BY JugadoT DESC LIMIT 999");
  449. SQL_TQuery(g_hDB, SQLTopShow3, buffer, client);
  450. } else {
  451. PrintToChat(client, "Rank System is now not avilable");
  452. }
  453. }
  454.  
  455. public SQLTopShow3(Handle:owner, Handle:hndl, const String:error[], any:client){
  456.  
  457. if(hndl == INVALID_HANDLE)
  458. {
  459. LogError(error);
  460. PrintToServer("Last Connect SQL Error: %s", error);
  461. return;
  462. }
  463.  
  464. new Handle:menu2 = CreateMenu(DIDMenuHandler2);
  465. SetMenuTitle(menu2, "Top Terrorista");
  466.  
  467.  
  468. new orden = 0;
  469. decl String:numero[64];
  470. decl String:name[64];
  471. decl String:texto[128];
  472.  
  473. if (SQL_HasResultSet(hndl))
  474. {
  475. while (SQL_FetchRow(hndl))
  476. {
  477. orden++;
  478. Format(numero,64, "option%i", orden);
  479. SQL_FetchString(hndl, 1, name, sizeof(name));
  480. new Time = SQL_FetchInt(hndl,3);
  481. new Hours = (Time/60/60);
  482. new Minutes = (Time/60)%(60);
  483. new Seconds = (Time%60);
  484.  
  485.  
  486. Format(texto,128, "n%i %s - %d Ó. %d M. %d Mp.", orden,name,Hours, Minutes, Seconds);
  487.  
  488. AddMenuItem(menu2, numero, texto);
  489.  
  490.  
  491. }
  492. }
  493.  
  494. if(orden < 1)
  495. {
  496. AddMenuItem(menu2, "empty", "TOP is empty!");
  497. }
  498.  
  499. SetMenuExitButton(menu2, true);
  500. DisplayMenu(menu2, client, MENU_TIME_FOREVER);
  501.  
  502. }
  503.  
  504. public showTOP4(client){
  505.  
  506. if (g_hDB != INVALID_HANDLE)
  507. {
  508. decl String:buffer[200];
  509. Format(buffer, sizeof(buffer), "SELECT * FROM saverank_time2 ORDER BY JugadoCT DESC LIMIT 999");
  510. SQL_TQuery(g_hDB, SQLTopShow4, buffer, client);
  511. } else {
  512. PrintToChat(client, "Rank System is now not avilable");
  513. }
  514. }
  515.  
  516. public SQLTopShow4(Handle:owner, Handle:hndl, const String:error[], any:client){
  517.  
  518. if(hndl == INVALID_HANDLE)
  519. {
  520. LogError(error);
  521. PrintToServer("Last Connect SQL Error: %s", error);
  522. return;
  523. }
  524.  
  525. new Handle:menu2 = CreateMenu(DIDMenuHandler2);
  526. SetMenuTitle(menu2, "Top Terror-Elhárító");
  527.  
  528.  
  529. new orden = 0;
  530. decl String:numero[64];
  531. decl String:name[64];
  532. decl String:texto[128];
  533.  
  534. if (SQL_HasResultSet(hndl))
  535. {
  536. while (SQL_FetchRow(hndl))
  537. {
  538. orden++;
  539. Format(numero,64, "option%i", orden);
  540. SQL_FetchString(hndl, 1, name, sizeof(name));
  541. new Time = SQL_FetchInt(hndl,4);
  542. new Hours = (Time/60/60);
  543. new Minutes = (Time/60)%(60);
  544. new Seconds = (Time%60);
  545.  
  546.  
  547.  
  548. Format(texto,128, "n%i %s - %d Ó. %d M. %d Mp.", orden,name,Hours, Minutes, Seconds);
  549.  
  550. AddMenuItem(menu2, numero, texto);
  551.  
  552.  
  553. }
  554. }
  555.  
  556. if(orden < 1)
  557. {
  558. AddMenuItem(menu2, "empty", "TOP is empty!");
  559. }
  560.  
  561. SetMenuExitButton(menu2, true);
  562. DisplayMenu(menu2, client, MENU_TIME_FOREVER);
  563.  
  564. }
  565.  
  566. stock mostrartiempo(Time, any:client)
  567. {
  568.  
  569. new Hours = (Time/60/60);
  570. new Minutes = (Time/60)%(60);
  571. new Seconds = (Time%60);
  572.  
  573.  
  574. if(Hours >= 1)
  575. {
  576. PrintToChat(client, "\x04%d Óra %d Perc %d Másodperc", Hours, Minutes, Seconds );
  577. }
  578. else if(Minutes >= 1)
  579. {
  580. PrintToChat(client, "\x04%d Perc %d Másodperc", Minutes, Seconds );
  581. }
  582. else PrintToChat(client, "\x04%d Másodperc", Seconds );
  583. }
  584.  
  585. public DIDMenuHandler2(Handle:menu, MenuAction:action, client, itemNum)
  586. {
  587. /*if ( action == MenuAction_Select )
  588.   {
  589.  
  590.   }*/
  591. if (action == MenuAction_Cancel)
  592. {
  593. PrintToServer("Client %d's menu was cancelled. Reason: %d", client, itemNum);
  594. }
  595.  
  596. else if (action == MenuAction_End)
  597. {
  598. CloseHandle(menu);
  599. }
  600. }
  601.  
  602. public Action:DOMenu(clientId,args)
  603. {
  604. new Handle:menu = CreateMenu(DIDMenuHandler);
  605. SetMenuTitle(menu, "Szerver Játékidő");
  606. AddMenuItem(menu, "option1", "Saját Idő");
  607. AddMenuItem(menu, "option2", "Ranglista");
  608. AddMenuItem(menu, "option3", "Top Megfigyelő");
  609. AddMenuItem(menu, "option4", "Top Terrorista");
  610. AddMenuItem(menu, "option5", "Top Terror-Elhárító");
  611. SetMenuExitButton(menu, true);
  612. DisplayMenu(menu, clientId, MENU_TIME_FOREVER);
  613.  
  614.  
  615. return Plugin_Handled;
  616. }
  617.  
  618.  
  619. public DIDMenuHandler(Handle:menu, MenuAction:action, client, itemNum)
  620. {
  621. if ( action == MenuAction_Select )
  622. {
  623. new String:info[32];
  624.  
  625. GetMenuItem(menu, itemNum, info, sizeof(info));
  626.  
  627. if ( strcmp(info,"option1") == 0 )
  628. {
  629. PrintToChat(client, "\x03Megfigyelőként:");
  630. mostrartiempo(JugadoEspectador[client], client);
  631. PrintToChat(client, "\x03Terroristaként:");
  632. mostrartiempo(JugadoT[client], client);
  633. PrintToChat(client, "\x03Terror-Elhárítóként:");
  634. mostrartiempo(JugadoCT[client], client);
  635. PrintToChat(client, "\x03Összesen:");
  636. new totalt = (JugadoT[client] + JugadoCT[client] + JugadoEspectador[client]);
  637. mostrartiempo(totalt, client);
  638. //DID(client);
  639. }
  640.  
  641. else if ( strcmp(info,"option2") == 0 )
  642. {
  643. showTOP(client);
  644. //DID(client);
  645.  
  646. }
  647. else if ( strcmp(info,"option3") == 0 )
  648. {
  649. showTOP2(client);
  650. //DID(client);
  651.  
  652. }
  653. else if ( strcmp(info,"option4") == 0 )
  654. {
  655. showTOP3(client);
  656. //DID(client);
  657.  
  658. }
  659. else if ( strcmp(info,"option5") == 0 )
  660. {
  661. showTOP4(client);
  662. //DID(client);
  663.  
  664. }
  665. }
  666. else if (action == MenuAction_Cancel)
  667. {
  668. PrintToServer("Client %d's menu was cancelled. Reason: %d", client, itemNum);
  669. }
  670.  
  671. else if (action == MenuAction_End)
  672. {
  673. CloseHandle(menu);
  674. }
  675. }
  676.