hlmod.hu
https://hlmod.hu/

Játszott idő
https://hlmod.hu/viewtopic.php?f=9&t=24565
Oldal: 1 / 1

Szerző:  Uwillpay [ 2016.04.08. 08:46 ]
Hozzászólás témája:  Játszott idő

Sziasztok!
Hogy lehet azt megoldani, hogy ha játszik valaki a szerveren
például 2000 PERCet akkor adjon neki a szerver pl. 500 pontok[id]-t.
És a játékos megtudja jeleníteni a játszott időt például menüben:


Teljesítmény menüpont--->
Játszott idő ---->
0/2000

Szerző:  kengurumancs [ 2016.04.08. 14:28 ]
Hozzászólás témája:  Re: Játszott idő

  1. new pont1
  2.  
  3. public plugin_init() {
  4.  
  5.     pont1= register_cvar("pont_pont1", "500")
  6. }
  7.  
  8. public client_connect(id)
  9. {
  10.     get_user_name(id, name[id], 31)
  11.     betoltes(id);
  12.     set_task(120000.0, "pont_1",id)
  13. }
  14.  
  15. public pont_1(id)
  16. {
  17.     new penz = get_pcvar_num(pont1);
  18.     client_print(id, print_chat, "[Pontrendszer] %d pont jár mert itt vagy már 2000 perce!", pont)
  19.     pont[id] += pont;
  20. }

Szerző:  Uwillpay [ 2016.04.08. 16:51 ]
Hozzászólás témája:  Re: Játszott idő

Valaki abba segítene, hogy ne egyhuzamba kelljen játszania 2000 percet pl.,
hanem mentse el a játszott idejét!

Szerző:  demon [ 2016.04.08. 20:06 ]
Hozzászólás témája:  Re: Játszott idő

  1. #include <amxmodx>
  2. #include <amxmisc>
  3.  
  4. #define PLUGIN "New Plug-In"
  5. #define VERSION "1.0"
  6. #define AUTHOR "Demon"
  7.  
  8. new played_time[33], pontok[33];
  9.  
  10. public plugin_init() {
  11.     register_plugin(PLUGIN, VERSION, AUTHOR);
  12.    
  13.     register_clcmd("say /ido", "ShowMyPlayedTime");
  14. }
  15.  
  16. public ShowMyPlayedTime(id)
  17. {
  18.     client_print(id, print_chat, "Jatszott ido a szerveren %d perc.", played_time[id]);
  19. }
  20.  
  21. public client_putinserver(id)
  22. {
  23.     played_time[id] = 0;
  24.     if(!is_user_bot(id))
  25.     {
  26.         Load(id);
  27.         set_task(60.0, "Counter", id);
  28.     }
  29. }
  30.  
  31. public client_disconnect(id)
  32. {
  33.     if(!is_user_bot(id))
  34.     {
  35.         Save(id);
  36.         if(task_exists(id))
  37.             remove_task(id);
  38.     }
  39. }
  40.  
  41. public Counter(id)
  42. {
  43.     if(task_exists(id))
  44.         remove_task(id);
  45.        
  46.     played_time[id]++;
  47.    
  48.     if(played_time[id] == 2000)
  49.         pontok[id] += 500;
  50.    
  51.     set_task(60.0, "Counter", id);
  52. }
  53.  
  54. public Save(id)
  55. {
  56.     new file[200];
  57.    
  58.     get_configsdir(file, 199);
  59.    
  60.     format(file, 199, "%s/played_time.ini", file);
  61.    
  62.     if (!file_exists(file))
  63.         write_file(file, "; Jatszott ido percben");
  64.    
  65.     new pFile, linetoadd[128];
  66.     pFile = fopen(file, "rt");
  67.    
  68.     if(pFile)
  69.     {
  70.         new szName[32], szName2[32], bool:Found;
  71.         get_user_name(id, szName, 31);
  72.         new Line[192], Lines;
  73.  
  74.         while(!feof(pFile) && !Found)
  75.         {
  76.             fgets(pFile, Line, 191);
  77.            
  78.             if(Line[0] == ';' || !strlen(Line))
  79.             {
  80.                 Lines++;
  81.                 continue;
  82.             }
  83.  
  84.             parse(Line, szName2, 31);
  85.            
  86.             if(equal(szName, szName2))
  87.             {
  88.                 formatex(linetoadd, 127, "^"%s^" ^"%d^"", szName, played_time[id]);
  89.                 write_file(file, linetoadd, Lines);
  90.                 Found = true;
  91.                 break;
  92.             }
  93.             Lines++;
  94.         }
  95.    
  96.         if(!Found)
  97.         {
  98.             formatex(linetoadd, 127, "^"%s^" ^"%d^"", szName, played_time[id]);
  99.             write_file(file, linetoadd);
  100.         }
  101.         fclose(pFile);
  102.     }
  103.     return PLUGIN_HANDLED;
  104. }
  105.  
  106. public Load(id)
  107. {
  108.     new file[200];
  109.  
  110.     get_configsdir(file, 199);
  111.     format(file, 199, "%s/played_time.ini", file);
  112.    
  113.     if (!file_exists(file))
  114.         return PLUGIN_HANDLED;
  115.    
  116.     new pFile;
  117.     pFile = fopen(file, "rt");
  118.    
  119.     if(pFile)
  120.     {
  121.         new Line[192];
  122.        
  123.         new szName[32], szName2[32], szTime[8];
  124.         get_user_name(id, szName, 31);
  125.         while(!feof(pFile))
  126.         {
  127.             fgets(pFile, Line, 191);
  128.             if(Line[0] == ';' || strlen(Line) < 10)
  129.                 continue;
  130.  
  131.             parse(Line, szName2, 31, szTime, 7);
  132.            
  133.             if(equal(szName, szName2))
  134.             {
  135.                 played_time[id] = str_to_num(szTime);
  136.                 break;
  137.             }
  138.         }
  139.         fclose(pFile);
  140.     }
  141.     return PLUGIN_HANDLED;
  142. }

Szerző:  mforce [ 2016.04.16. 09:54 ]
Hozzászólás témája:  Re: Játszott idő

set_taskozás helyett maradjunk annyiban, hogy
https://www.amxmodx.org/api/amxmodx/get_user_time

első csatlakozás - lementjük dc-nél get_user_time (másodperc)
Lekérésnél a beolvasott + jelenlegi get_user_time-ot kiiratjuk csak átszámolva percbe, órába,
dc-nél mentünk a beolvasott + get_user_time..

Oldal: 1 / 1 Minden időpont UTC+02:00 időzóna szerinti
Powered by phpBB® Forum Software © phpBB Limited
https://www.phpbb.com/