Advertisement
Guest User

Untitled

a guest
Dec 16th, 2019
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.39 KB | None | 0 0
  1. /*
  2. _ _
  3. | | | |
  4. _.__ | | __ _ _ _ ___ __| |
  5. | `_ \| |/ _` | | | |/ _ \/ _` |
  6. | |_) | | (_| | \ / | __/ (_| |
  7. | ,__/|_|\__,_|\__, |\___|\__,_|
  8. | | __/ |
  9. |_| |___/
  10.  
  11.  
  12.  
  13. _ _
  14. | | (_)
  15. | |_ _ _ __ __ ___
  16. | __| | '_ \/_ \ / _ \
  17. | | | | | | | | | __/
  18. \__||_|_| |_| |_|\___|
  19.  
  20.  
  21.  
  22. (c)2011 www.godplay.ro
  23.  
  24.  
  25. Plugin: Played Time
  26. Version: 0.5.5
  27. Author: sPuf ?
  28.  
  29. Changelog:
  30.  
  31.  
  32. v 0.0.5 - prima publicare a pluginului.
  33. v 0.1.0 - acum orele si minutele sunt salvate.
  34. v 0.1.5 - poti vedea primii 10 jucatori cu cele mai multe ore jucate,/topore.
  35. v 0.2.0 - poti sa iti vezi orele, /ore
  36. v 0.2.5 - detalii despre un jucator, /ore <nume>.
  37. v 0.3.0 - numele nu poate fi schimbat pe server.
  38. v 0.3.5 - numele nu poate avea mai mult sau mai putin de 15 si respectiv 3 litere<minim 3,maxim 15>.
  39. v 0.4.0 - editarea motd`ului si restructurarea pluginului.
  40. v 0.4.5 - stergerea unui jucator din top acum este posibila,amx_removetop <pozitie>.
  41. v 0.5.0 - editarea mesajelor din chat si rezolvarea unui bug la amx_removetop.
  42. v 0.5.5 - adaugarea cvarului pt_prefix pentru prefixul mesajelor din chat si consola.( ideea lui Rap^)
  43. - schimbarea numarului de litere minime si respectiv maxime(20 si 2).
  44. Credite:
  45. kNOWLEDGE,Simple,STORIES,VeNoM
  46. diabolykul,ahonen,Ch1o - multe teste..
  47.  
  48. nescafezalau - pentru cateva idei.
  49. Ex3cuTioN aka Arion - pentru sprijinul acordat
  50.  
  51. Rap^ - pentru ca a gasit bug-ul de la amx_removetop si pentru multe teste ( v0.5.0- v0.5.5)
  52. */
  53. #include <amxmodx>
  54. #include <amxmisc>
  55.  
  56. #include <nvault>
  57. #include <fakemeta>
  58.  
  59. #include <ColorChat>
  60.  
  61. #pragma semicolon 1
  62.  
  63. #define INFO_ZERO 0
  64. #define NTOP 10
  65. #define TIME 60.0
  66.  
  67. static const PLUGIN_NAME[] = "Played Time";
  68. static const PLUGIN_AUTHOR[] = "sPuf ?";
  69. static const PLUGIN_VERSION[] = "0.5.5";
  70.  
  71. new tophours[33],topminutes[33];
  72. new topnames[33][33],topauth[33][33];
  73.  
  74. new Data[64],g_vault;
  75. new gHours[33],gMinutes[33];
  76.  
  77. new cvar_tag,TAG[64];
  78.  
  79. public plugin_init() {
  80. register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR);
  81. register_clcmd( "say", "hook_say" );
  82.  
  83. register_concmd("amx_removetop", "remove_info");
  84. register_concmd("amx_ore", "show_info");
  85. register_concmd("amx_time", "show_info");
  86. register_concmd("amx_topore", "show_top");
  87.  
  88. cvar_tag = register_cvar("pt_prefix","[D/C]");
  89.  
  90. register_forward(FM_ClientUserInfoChanged, "fwClientUserInfoChanged");
  91. g_vault = nvault_open("played_time");
  92.  
  93. if(g_vault == INVALID_HANDLE){
  94. set_fail_state("nValut returned invalid handle");
  95. }
  96. get_datadir(Data, 63);
  97. read_top();
  98.  
  99. }
  100.  
  101. public client_putinserver(id) {
  102. if(!is_user_bot(id)) {
  103. LoadTime(id);
  104. set_task(TIME,"RefreshTime",id,_,_,"b",0);
  105. set_task(0.1,"CheckName",id);
  106. }
  107. }
  108. public client_disconnected(id) {
  109. if(!is_user_bot(id)) {
  110. SaveTime(id);
  111. remove_task(id);
  112. }
  113. }
  114. public plugin_end() {
  115. nvault_close( g_vault );
  116. }
  117. public hook_say(id) {
  118.  
  119. static args[192], command[192];
  120. read_args(args,charsmax(args));
  121.  
  122. if(!args[0]) {
  123. return PLUGIN_CONTINUE;
  124. }
  125. remove_quotes(args[0]);
  126. if( equal(args, "/ore", strlen("/ore") )) {
  127. replace(args,charsmax(args), "/", "" );
  128. formatex( command, charsmax(command) , "amx_%s", args );
  129. client_cmd(id, command);
  130. return PLUGIN_HANDLED;
  131. }
  132.  
  133. if( equal(args, "/time", strlen("/time") )) {
  134. replace(args,charsmax(args), "/", "" );
  135. formatex( command, charsmax(command) , "amx_%s", args );
  136. client_cmd(id, command);
  137. return PLUGIN_HANDLED;
  138. }
  139.  
  140. if( equal(args, "/topore", strlen("/topore") )) {
  141. replace(args,charsmax(args), "/", "" );
  142. formatex( command, charsmax(command) , "amx_%s", args );
  143. client_cmd(id, command);
  144. return PLUGIN_HANDLED;
  145. }
  146. return PLUGIN_CONTINUE;
  147. }
  148. public RefreshTime(id) {
  149. gMinutes[id] += 1;
  150.  
  151. if(gMinutes[id] >= 60) {
  152. gHours[id] += 1;
  153. gMinutes[id] -= 60;
  154. }
  155. checkandupdatetop(id,gHours[id],gMinutes[id]);
  156. return PLUGIN_HANDLED;
  157. }
  158. public CheckName(id) {
  159. static name[32];
  160. get_user_name(id, name, 31);
  161. get_pcvar_string(cvar_tag, TAG, 63);
  162.  
  163. new iLen;
  164. while(!equali(name[iLen], "^0")) {
  165. iLen++;
  166. }
  167. if(iLen < 2) {
  168. new userid;
  169. userid = get_user_userid(id);
  170. ColorChat(0, RED, "^x04%s^x01 Jucatorul^x03 %s^x01 a primit kick datorita nick-ului prea scurt !", TAG, name);
  171. server_cmd("kick #%d ^"Nick prea scurt, minim 2 litere^"", userid);
  172. client_print(id,print_console,"Nick prea scurt, minim 2 litere");
  173.  
  174. } else if(iLen > 20) {
  175. new userid;
  176. userid = get_user_userid(id);
  177. ColorChat(0, RED, "^x04%s^x01 Jucatorul^x03 %s^x01 a primit kick datorita nick-ului prea lung !", TAG, name);
  178. server_cmd("kick #%d ^"Nick prea lung, maxim 20 litere^"", userid);
  179. client_print(id,print_console,"Nick prea lung, maxim 20 litere");
  180. }
  181. return PLUGIN_HANDLED;
  182. }
  183. public fwClientUserInfoChanged(id, buffer) {
  184. if (!is_user_connected(id)) {
  185. return FMRES_IGNORED;
  186. }
  187. static val[32];
  188. static name[32];
  189. get_user_name(id, name, 31);
  190. engfunc(EngFunc_InfoKeyValue, buffer, "name", val, sizeof val- 1);
  191. if (equal(val, name)) {
  192. return FMRES_IGNORED;
  193. }
  194. engfunc(EngFunc_SetClientKeyValue, id, buffer, "name", name);
  195. get_pcvar_string(cvar_tag, TAG, 63);
  196. ColorChat(id, RED, "^x04%s^x03 NU este permisa schimbarea nick-ului pe server !", TAG);
  197. console_print(id,"NU este permisa schimbarea nick-ului pe server !");
  198. return FMRES_SUPERCEDE;
  199. }
  200. public show_info(id) {
  201. get_pcvar_string(cvar_tag, TAG, 63);
  202.  
  203. new target[32];
  204. read_argv(1, target, 31);
  205.  
  206. if(equali(target,"")) {
  207. new ptime,Steamid[35];
  208. get_user_authid(id, Steamid, 34);
  209. ptime = get_user_time(id, 1) / 60;
  210. ColorChat(id, BLUE, "^x04%s^x01 Statisticile tale:", TAG);
  211. ColorChat(id, BLUE, "^x04%s^x01 Ai acumulat pana acum^x03 %d^x01 or%s si^x03 %d^x01 minut%s", TAG,gHours[id],gHours[id] == 1 ? "a" : "e",gMinutes[id],gMinutes[id] == 1 ? "" : "e");
  212. ColorChat(id, BLUE, "^x04%s^x01 Te-ai conectat pe server de^x03 %d^x01 minut%s", TAG, ptime, ptime == 1 ? "" : "e");
  213. ColorChat(id, RED, "^x04%s^x01 SteamID tau este:^x03 %s", TAG, Steamid);
  214. return PLUGIN_HANDLED;
  215. }
  216.  
  217. new player = cmd_target(id, target, 8);
  218. if(!player || player == id) {
  219. return PLUGIN_HANDLED;
  220. }
  221. else {
  222.  
  223. new name[32];
  224. get_user_name(player, name, 31);
  225.  
  226. new ptime,Steamid[35];
  227. get_user_authid(player, Steamid, 34);
  228. ptime = get_user_time(player, 1) / 60;
  229.  
  230. ColorChat(id, BLUE, "^x04%s^x01 Statisticile lui^x03 %s^x01:", TAG, name);
  231. ColorChat(id, BLUE, "^x04%s^x01 A acumulat pana acum^x03 %d^x01 or%s si^x03 %d^x01 minut%s", TAG, gHours[player],gHours[player] == 1 ? "a" : "e",gMinutes[player],gMinutes[player] == 1 ? "" : "e");
  232. ColorChat(id, BLUE, "^x04%s^x01 S-a conectat pe server de^x03 %d^x01 minut%s", TAG, ptime, ptime == 1 ? "" : "e");
  233. ColorChat(id, RED, "^x04%s^x01 SteamID lui^x03 %s^x01 :^x03 %s", TAG,name, Steamid);
  234. return PLUGIN_HANDLED;
  235. }
  236. //return PLUGIN_CONTINUE;
  237. }
  238. public remove_info(id) {
  239. if( !(get_user_flags(id) == read_flags("abcdefghijklmnopqrstu"))) {
  240. return PLUGIN_HANDLED;
  241. }
  242. get_pcvar_string(cvar_tag, TAG, 63);
  243. new target[32];
  244. read_argv(1, target, 31);
  245. new poz = str_to_num(target);
  246. if( !poz|| poz > 10 || poz < 1) {
  247. console_print(id,"%s Foloseste amx_removetop <pozitie>, de la 1 la 10 !",TAG);
  248. return PLUGIN_HANDLED;
  249. }
  250. new aname[32],Steamid[35];
  251. get_user_name(id, aname, 31);
  252. get_user_authid(id, Steamid, 34);
  253.  
  254. if(equal(topnames[poz-1],"")) {
  255. console_print(id,"%s Nu se afla nimeni pe aceasta pozitie !",TAG);
  256. ColorChat(id, RED,"^x04%s^x01 Nu se afla nimeni pe aceasta pozitie !", TAG);
  257. return PLUGIN_HANDLED;
  258. }
  259. ColorChat(0, BLUE,"^x04%s^x01 Adminul^x03 %s^x01 il sterge din top ore pe^x03 %s^x01 !", TAG, aname,topnames[poz-1]);
  260. static i;
  261.  
  262. for (i= poz-1;i<NTOP;i++) {
  263. formatex(topauth[i], 31, topauth[i+1]);
  264. formatex(topnames[i], 31, topnames[i+1]);
  265. tophours[i] = tophours[i+1];
  266. topminutes[i] = topminutes[i+1];
  267.  
  268. save_top();
  269. }
  270.  
  271. return PLUGIN_HANDLED;
  272. }
  273. public SaveTime(id) {
  274. new Name[32];
  275. get_user_name(id, Name, 32);
  276.  
  277. new vaultkey[64],vaultdata[256];
  278. format(vaultkey,63,"%s",Name);
  279. format(vaultdata,255," ^"%i^" ^"%i^"",gHours[id],gMinutes[id]);
  280. nvault_set(g_vault,vaultkey,vaultdata);
  281.  
  282. return PLUGIN_HANDLED;
  283. }
  284. public LoadTime(id) {
  285. new Name[32];
  286. get_user_name(id, Name, 32);
  287.  
  288. new vaultkey[64],vaultdata[256];
  289. format(vaultkey,63,"%s",Name);
  290. format(vaultdata,255," ^"%i^" ^"%i^"",gHours[id],gMinutes[id]);
  291. nvault_get(g_vault, vaultkey, vaultdata, 255);
  292.  
  293. new phours[32], pmins[32] ;
  294.  
  295. parse(vaultdata, phours, sizeof(phours) - 1, pmins, sizeof(pmins) - 1);
  296.  
  297. gHours[id] = str_to_num(phours);
  298. gMinutes[id] = str_to_num(pmins);
  299.  
  300. return PLUGIN_HANDLED;
  301. }
  302. public save_top() {
  303. new path[128];
  304. formatex(path, 127, "%s/TopOre.dat", Data);
  305. if( file_exists(path) ) {
  306. delete_file(path);
  307. }
  308. new Buffer[256];
  309. new f = fopen(path, "at");
  310. for(new i = INFO_ZERO; i < NTOP; i++)
  311. {
  312. formatex(Buffer, 255, "^"%s^" ^"%d^" ^"%d^"^n",topnames[i], tophours[i],topminutes[i] );
  313. fputs(f, Buffer);
  314. }
  315. fclose(f);
  316. }
  317. public checkandupdatetop(id, hours, minutes) {
  318.  
  319. new authid[35],name[32];
  320. get_user_name(id, name, 31);
  321. get_user_authid(id, authid ,34);
  322. for (new i = INFO_ZERO; i < NTOP; i++)
  323. {
  324. if( hours > tophours[i] || hours == tophours[i] && minutes > topminutes[i])
  325. {
  326. new pos = i;
  327. while( !equal(topnames[pos],name) && pos < NTOP )
  328. {
  329. pos++;
  330. }
  331.  
  332. for (new j = pos; j > i; j--)
  333. {
  334. formatex(topauth[j], 31, topauth[j-1]);
  335. formatex(topnames[j], 31, topnames[j-1]);
  336. tophours[j] = tophours[j-1];
  337. topminutes[j] = topminutes[j-1];
  338.  
  339. }
  340. formatex(topauth[i], 31, authid);
  341. formatex(topnames[i], 31, name);
  342.  
  343. tophours[i]= hours;
  344. topminutes[i] = minutes;
  345. //ColorChat(0, BLUE,"^x04%s^x03 %s^x01 este pe locul^x04 %i^x01 in top ore cu^x03 %d^x01 or%s^x03 %d^x01 minut%s. ", TAG, name,(i+1),hours,hours == 1 ? "a" : "e",minutes,minutes == 1 ? "" : "e");
  346. save_top();
  347. break;
  348. }
  349. else if( equal(topnames[i], name))
  350. break;
  351. }
  352. }
  353. public read_top() {
  354. new Buffer[256],path[128];
  355. formatex(path, 127, "%s/TopOre.dat", Data);
  356.  
  357. new f = fopen(path, "rt" );
  358. new i = INFO_ZERO;
  359. while( !feof(f) && i < NTOP+1)
  360. {
  361. fgets(f, Buffer, 255);
  362. new hours[25], minutes[25];
  363. parse(Buffer, topnames[i], 31, topauth[i], 31, hours, 25, minutes, 25);
  364. tophours[i]= str_to_num(hours);
  365. topminutes[i]= str_to_num(minutes);
  366.  
  367. i++;
  368. }
  369. fclose(f);
  370. }
  371. public show_top(id) {
  372. static buffer[2368], name[131], len, i;
  373. len = format(buffer[len], 2367-len,"<STYLE>body{background:#232323;color:#cfcbc2;font-family:sans-serif}table{border-style:solid;border-width:1px;border-color:#FFFFFF;font-size:13px}</STYLE><table align=center width=100%% cellpadding=2 cellspacing=0");
  374. len += format(buffer[len], 2367-len, "<tr align=center bgcolor=#52697B><th width=4%% > # <th width=24%%> Nume Jucator <th width=24%%>SteamID <th width=24%%> Ore Jucate <th width=24%%> Minute Jucate");
  375. for( i = INFO_ZERO; i < NTOP; i++ ) {
  376. if( tophours[i] == 0 && topminutes[i] == 0) {
  377. len += format(buffer[len], 2367-len, "<tr align=center bgcolor=#232323><td> %d <td> %s <td> %s<td> %s <td> %s", (i+1), "-", "-", "-","-");
  378. //i = NTOP
  379. }
  380. else {
  381. name = topnames[i];
  382. while( containi(name, "<") != -1 )
  383. replace(name, 129, "<", "&lt;");
  384. while( containi(name, ">") != -1 )
  385. replace(name, 129, ">", "&gt;");
  386. new plname[32];
  387. get_user_name(id, plname ,32);
  388. if(equal(topnames[i],plname)) {
  389. len += format(buffer[len], 2367-len, "<tr align=center bgcolor=#2D2D2D><td> %d <td> %s <td> %s<td> %d <td> %d", (i+1), name,topauth[i], tophours[i],topminutes[i]);
  390. }
  391. else {
  392. len += format(buffer[len], 2367-len, "<tr align=center bgcolor=#232323><td> %d <td> %s <td> %s<td> %d <td> %d", (i+1), name,topauth[i], tophours[i],topminutes[i]);
  393. }
  394. }
  395. }
  396. len += format(buffer[len], 2367-len, "</table>");
  397. len += formatex(buffer[len], 2367-len, "<tr align=bottom font-size:11px><Center><br><br><br><br>Primii 10 Jucatori Cu Cele Mai Multe Ore Acumulate</body>");
  398. static strin[20];
  399. format(strin,33, "Top 10 ore jucate");
  400. show_motd(id, buffer, strin);
  401. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement