HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. #include <amxmodx>
  2. #include <amxmisc>
  3.  
  4. #define PLUGIN "TimeLimit vote"
  5. #define AUTHOR "many"
  6. #define VERSION "0.3"
  7.  
  8. #define MAX_RESULTS 5 //Maximális lehetõségek száma
  9.  
  10. new Float:g_timelimit
  11. new menu
  12.  
  13. new g_voteCount[MAX_RESULTS + 1]
  14. new g_tls[MAX_RESULTS]
  15. new tls[MAX_RESULTS]
  16.  
  17. public plugin_init()
  18. {
  19. register_plugin(PLUGIN, VERSION, AUTHOR)
  20.  
  21. new name[12], string[12]
  22. new multiplic = 20 // Itt állítod be az alap értékét, tehát ez lesz az elsõ lehetõség
  23.  
  24. for(new i=0;i<MAX_RESULTS;i++)
  25. {
  26. format(name, sizeof name -1, "amx_tl_%d", i+1)
  27.  
  28. format(string, sizeof string -1, "%d", multiplic)
  29.  
  30. tls[i] = register_cvar(name, string)
  31.  
  32. multiplic += 10 // Ennyivel fog nõni az idõhatár értéke a következõ lehetõségnél (tehát 20+10 = 30, utána 40..50..60)
  33. }
  34. }
  35.  
  36. public plugin_cfg()
  37. {
  38. menu = menu_create("\rHány percet legyünk ezen a pályán?", "menu_handler")
  39.  
  40. for(new i=0;i<MAX_RESULTS;i++)
  41. g_tls[i] = get_pcvar_num(tls[i])
  42.  
  43. set_task(30.0, "start_vote") // Pályaváltás után hány másodperc múlva indítsa el a szavazást
  44.  
  45. build_menu()
  46. }
  47.  
  48. build_menu()
  49. {
  50. new option[64], temp[12]
  51. for(new i=0;i<MAX_RESULTS;i++)
  52. {
  53. format(option, sizeof option -1, "\w%d percet", g_tls[i])
  54. format(temp, sizeof temp -1, "%d", i+1)
  55.  
  56. menu_additem(menu, option, temp, 0)
  57. }
  58.  
  59. menu_setprop(menu, MPROP_EXIT, MEXIT_ALL)
  60. }
  61.  
  62. public start_vote(id)
  63. {
  64. new players[32], inum, i
  65. get_players(players, inum, "ch")
  66.  
  67. for(i=0;i<inum;i++)
  68. menu_display(players[i], menu, 0)
  69.  
  70. set_task(15.0, "finish_vote")
  71.  
  72. for(i=1;i<(MAX_RESULTS+1);i++)
  73. g_voteCount[i] = 0
  74.  
  75. return PLUGIN_CONTINUE
  76. }
  77.  
  78. public menu_handler(id, menu, item)
  79. {
  80. if( !is_user_connected( id ) )
  81. return PLUGIN_HANDLED
  82.  
  83. if(item == MENU_EXIT)
  84. {
  85. menu_cancel(id)
  86.  
  87. return PLUGIN_HANDLED
  88. }
  89.  
  90. new data[6], name[32]
  91. new access, callback
  92.  
  93. menu_item_getinfo(menu, item, access, data, 5, "", 0, callback)
  94.  
  95. new key = str_to_num(data)
  96. get_user_name(id, name, 31)
  97.  
  98. client_print(0, print_chat, "%s a %d perces hosszúságra szavazott", name, g_tls[key -1])
  99.  
  100. g_voteCount[key]++
  101.  
  102. menu_cancel(id)
  103.  
  104. return PLUGIN_HANDLED
  105. }
  106.  
  107. public finish_vote()
  108. {
  109. g_timelimit = get_cvar_float("mp_timelimit")
  110.  
  111. new best = 0, i
  112.  
  113. for(i=0;i<(MAX_RESULTS+1);i++)
  114. {
  115. if(g_voteCount[i] > g_voteCount[best])
  116. best = i
  117. }
  118.  
  119. new votesNum = 0
  120. for(i=0;i<(MAX_RESULTS+1);i++)
  121. votesNum += g_voteCount[i]
  122.  
  123. new iRatio = votesNum ? floatround(get_cvar_float("amx_vote_ratio") * float(votesNum), floatround_ceil) : 1
  124. new iResult = g_voteCount[best]
  125.  
  126. if(iResult >= iRatio)
  127. {
  128. new new_time = g_tls[best -1]
  129.  
  130. client_print(0, print_chat, "Szavazás sikeres. A pálya %d perc hosszú lesz..", new_time)
  131.  
  132. set_cvar_num("mp_timelimit", new_time)
  133. }
  134. else
  135. {
  136. client_print(0, print_chat, "Szavazás sikertelen.")
  137. }
  138.  
  139. new players[32], inum
  140. get_players(players, inum, "ch")
  141.  
  142. for(i=0;i<inum;i++)
  143. client_cmd(players[i], "slot10")
  144. }
  145.  
  146. public plugin_end()
  147. {
  148. set_cvar_float("mp_timelimit", g_timelimit)
  149. }
  150.