MegastoRM

Untitled

May 21st, 2013
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.03 KB | None | 0 0
  1. /* Kviz Pogodi Broj v1.0 © 2012, ->UrOS<-
  2. Contact e-mail [email protected]
  3.  
  4. Formatright
  5.  
  6. *English*
  7. This plugin is free software;
  8. you can modify it under the terms of the
  9. GNU General Public License as published by the Free Software Foundation.
  10.  
  11. *Serbian*
  12. Ovaj plugin je besplatni program;
  13. mozete ga menjati postujuci prava autora, samo ga ne smete prodavati.
  14.  
  15. */
  16.  
  17. #include <amxmodx>
  18. #include <amxmisc>
  19. #include <colorchat>
  20. #include <nvault>
  21. #include <fakemeta>
  22.  
  23. #define PLUGIN "Kviz Pogodi Broj"
  24. #define VERSION "1.0"
  25. #define AUTHOR "->UrOS<-"
  26.  
  27. new resenje = 0
  28. new bool:kviz = false
  29. new pokusaji[33]
  30. new rank[33]
  31. new meni[33]
  32. new vreme
  33. new ucestalost
  34. new nagrada
  35. new opseg
  36.  
  37. public plugin_init()
  38. {
  39. register_plugin(PLUGIN, VERSION, AUTHOR)
  40. register_cvar("pogodibroj", VERSION, (FCVAR_SERVER|FCVAR_SPONLY))
  41.  
  42. register_concmd("say", "provera")
  43. register_concmd("say_team", "provera")
  44.  
  45. register_clcmd("say /kviz","prikazimenu")
  46. register_clcmd("say_team /kviz","prikazimenu")
  47.  
  48. register_clcmd("say /kviztop15","prikazitop15")
  49. register_clcmd("say_team /kviztop15","prikazitop15")
  50.  
  51. register_clcmd("say /kvizrank","prikazirank")
  52. register_clcmd("say_team /kvizrank","prikazirank")
  53.  
  54. vreme = register_cvar("pogodibroj_vreme", "60", ADMIN_RCON)
  55. ucestalost = register_cvar("pogodibroj_ucestalost", "90", ADMIN_RCON)
  56. nagrada = register_cvar("pogodibroj_nagrada", "16000", ADMIN_RCON)
  57. opseg = register_cvar("pogodibroj_opseg", "500", ADMIN_RCON)
  58.  
  59. set_task(get_pcvar_float(ucestalost),"generisi")
  60. }
  61.  
  62. public plugin_precache()
  63. {
  64. precache_sound("ambience/lv2.wav")
  65. precache_sound("buttons/bell1.wav")
  66. precache_sound("vox/bravo.wav")
  67. }
  68.  
  69. public client_putinserver(id)
  70. {
  71. set_task(15.0, "reklama", id, _, _, "a", 1)
  72. rank[id] = ucitajrank(id)
  73. }
  74.  
  75. public generisi()
  76. {
  77. resenje = random_num(1,get_pcvar_num(opseg))
  78. kviz = true
  79. set_hudmessage(85, 170, 255, 0.02, 0.65, 0, 6.0, 10.0)
  80. show_hudmessage(0, "[Kviz] Pogodi trazeni broj izmedju 1 i %d",get_pcvar_num(opseg))
  81. ColorChat(0, TEAM_COLOR, "^4[Kviz] ^1Pogodi trazeni broj izmedju^4 1 ^1i^4 %d",get_pcvar_num(opseg))
  82. client_cmd(0, "speak ambience/lv2.wav")
  83. set_task(get_pcvar_float(vreme),"vremeisteklo")
  84. for(new id=0;id<33;id++)
  85. pokusaji[id]=0
  86. }
  87.  
  88. public vremeisteklo()
  89. {
  90. if(kviz)
  91. {
  92. kviz = false
  93. ColorChat(0, TEAM_COLOR, "^4[Kviz] ^1Vreme je isteklo, trazeni broj je bio ^3%d",resenje)
  94. client_cmd(0, "speak buttons/bell1.wav")
  95. }
  96. set_task(get_pcvar_float(ucestalost),"generisi")
  97. }
  98.  
  99. public provera(id)
  100. {
  101. if(kviz)
  102. {
  103. new text[32]
  104. read_argv(1,text,31)
  105. new odgovor = str_to_num(text)
  106.  
  107. if(odgovor==0 && (resenje != 0 || text[ 0 ] != '0'))
  108. return
  109.  
  110. pokusaji[id]++
  111.  
  112. if(odgovor>get_pcvar_num(opseg))
  113. {
  114. ColorChat(id, TEAM_COLOR, "^4[Kviz] ^1Trazi se samo broj izmedju^4 1 ^1i^4 %d",get_pcvar_num(opseg))
  115. }
  116. else if(resenje>odgovor)
  117. {
  118. ColorChat(id, TEAM_COLOR, "^4[Kviz] ^1Trazeni broj je ^3VECI ^1od unetog broja^3 %d",odgovor)
  119. }
  120. else if(resenje<odgovor)
  121. {
  122. ColorChat(id, TEAM_COLOR, "^4[Kviz] ^1Trazeni broj je ^4MANJI ^1od unetog broja^4 %d",odgovor)
  123. }
  124. else if(odgovor==resenje)
  125. {
  126. kviz = false
  127. new ime[32]
  128. get_user_name(id, ime, 31)
  129. set_pev(id, pev_frags, pev(id, pev_frags) + get_pcvar_num(nagrada)/pokusaji[id])
  130. message_begin( MSG_BROADCAST, get_user_msgid("ScoreInfo") )
  131. write_byte( id )
  132. write_short( pev(id, pev_frags))
  133. write_short( get_pdata_int(id, 444, 5) )
  134. write_short( 0 )
  135. write_short( get_pdata_int(id, 114, 5) )
  136. message_end( )
  137. rank[id] += 1
  138. sacuvajrank(id, rank[id])
  139. ColorChat(0, TEAM_COLOR, "^4[Kviz]^3 %s ^1je prvi pogodio trazeni broj^4 %d ^1sa^3 %d ^1pokusaja, nagrada^4 %d$",ime,resenje,pokusaji[id],get_pcvar_num(nagrada)/pokusaji[id])
  140. client_cmd(0, "speak buttons/bell1.wav")
  141. {
  142. client_cmd(id, "speak vox/bravo.wav")
  143. ColorChat(id, TEAM_COLOR, "^4[Kviz] ^1Cestitamo pogodili ste trazeni broj^4 %d ^1sa^3 %d ^1pokusaja, osvajate^4 %d fragova",resenje,pokusaji[id],get_pcvar_num(nagrada)/pokusaji[id])
  144. }
  145. }
  146. }
  147. }
  148.  
  149. public ucitajrank( id )
  150. {
  151. new valut = nvault_open("kviz")
  152.  
  153. new authid[33]
  154. new vaultkey[64], vaultdata[64]
  155.  
  156. get_user_authid(id, authid, 32)
  157.  
  158. format(vaultkey, 63, "_%s_BODOVI_", authid)
  159.  
  160. nvault_get(valut, vaultkey, vaultdata, 63)
  161. nvault_close(valut)
  162.  
  163. return str_to_num(vaultdata)
  164. }
  165.  
  166. public sacuvajrank(id, bodovi)
  167. {
  168. new valut = nvault_open("kviz")
  169.  
  170. if(valut == INVALID_HANDLE)
  171. set_fail_state("Greska nValut kviz (invalid handle)")
  172.  
  173. new authid[32]
  174. new vaultkey[64], vaultdata[64]
  175.  
  176. get_user_authid(id, authid, 31)
  177.  
  178. format(vaultkey, 63, "_%s_BODOVI_", authid)
  179. format(vaultdata, 63, "%d^n", bodovi)
  180.  
  181. nvault_set(valut, vaultkey, vaultdata)
  182. nvault_close(valut)
  183. }
  184.  
  185. public prikazirank(id)
  186. ColorChat(id, TEAM_COLOR,"^4[Kviz] ^1Pogodili ste trazeni broj ^4%d ^1puta", rank[id])
  187.  
  188. public prikazitop15(id)
  189. {
  190. new i, count, name[98]
  191. static sort[34][2]
  192.  
  193.  
  194. for(i=0;i<33;i++)
  195. {
  196. sort[count][0] = i
  197. sort[count][1] = rank[i]
  198. count++
  199. }
  200.  
  201. SortCustom2D(sort,count,"stats")
  202.  
  203. new buffer[2048]
  204. new line[256]
  205.  
  206. new len = format( buffer, 2047, "<body bgcolor=#000000 style=^"color:#ffffff^"><pre><Center><img src=^"http://img62.imageshack.us/img62/2709/kvizzz.gif^"><table width=100%% cellpadding=1 cellspacing=1 border=0>")
  207. len += format( buffer[len], 2047-len, "<tr style=^"color:#8FABFF^"><th width=5%%>#<th width=60%%>Nick<th width=35%%>Broj pogodaka")
  208.  
  209. new players[32], num
  210. get_players(players, num)
  211.  
  212. new b = clamp(count,0,15)
  213.  
  214. for(new a = 0; a < b; a++)
  215. {
  216. get_user_name(sort[a][0], name, 97)
  217.  
  218. while (containi(name, "<") != -1)
  219. replace(name, 96, "<", "&lt;")
  220. while (containi(name, ">") != -1)
  221. replace(name, 96, ">", "&gt;")
  222.  
  223. //if(sort[a][1] != 0) // ako ima 0 bodova ne prikazuje ga u listi
  224. {
  225. format(line, 255, "<tr %s><td>%d<td style=^"color:%s^">%s<td>%d", ((a%2)==0) ? " bgcolor=#333333" : " bgcolor=#262626", a+1,((a%2)==0) ? "#9CFF7A" : "red", name, sort[a][1])
  226. len += format( buffer[len], 2047-len, line )
  227. }
  228. }
  229. format(line, 255, "</table><font color=^"red^">(Statistika trenutno pristutnih igra&#269;a)</body></pre>" )
  230. len += format( buffer[len], 2047-len, line )
  231. show_motd(id, buffer, "Kviz - Top 15")
  232.  
  233. return PLUGIN_CONTINUE
  234. }
  235.  
  236. public stats(elem1[],elem2[])
  237. {
  238. if(elem1[1] > elem2[1]) return -1
  239. else if(elem1[1] < elem2[1]) return 1
  240.  
  241. return 0
  242. }
  243.  
  244. public prikazimotd(id)
  245. {
  246. static motd[1501], len
  247.  
  248. len = format(motd, 1500,"<body bgcolor=#000000><font color=#87cefa><pre>")
  249. len += format(motd[len], 1500-len,"<center><img src=^"http://img62.imageshack.us/img62/2709/kvizzz.gif^"></center></img>")
  250. len += format(motd[len], 1500-len,"<center><h4><font color=^"red^"><B>%s - Verzija %s</B> </font></h4></center>", PLUGIN, VERSION)
  251. len += format(motd[len], 1500-len,"<center><h4><font color=^"blue^"><B>Plugin napravio %s</B> </font></h4></center>", AUTHOR)
  252. len += format(motd[len], 1500-len,"<center><h4><font color=^"white^"><B>Kontakt e-mail [email protected]</B> </font></h4></center>")
  253. len += format(motd[len], 1500-len,"<center><font color=^"white^"> </font></center>")
  254. len += format(motd[len], 1500-len,"<center><h4><font color=^"red^"><B>-----------------------</B> </font></h4></center>")
  255. len += format(motd[len], 1500-len,"<center><font color=^"white^">Za sva pitanja i informacije</font></center>")
  256. len += format(motd[len], 1500-len,"<center><font color=^"white^">pisite na gore navdeni e-mail</font></center>")
  257. len += format(motd[len], 1500-len,"<center><h4><font color=^"red^"><B>-----------------------</B> </font></h4></center>")
  258.  
  259. show_motd(id, motd, "Kviz - Informacije")
  260.  
  261. return 0
  262. }
  263.  
  264. public prikazimenu(id)
  265. {
  266. formatex( meni, charsmax( meni ), "\rKviz Pogodi Broj \yv1.0")
  267. new menu = menu_create( meni, "menuakcija")
  268.  
  269. formatex( meni, charsmax( meni ), "\d Vidi Rank")
  270. menu_additem( menu, meni, "0")
  271.  
  272. formatex( meni, charsmax( meni ), "\d Vidi Top15")
  273. menu_additem( menu, meni, "1")
  274.  
  275. formatex( meni, charsmax( meni ), "\d Informacije o pluginu")
  276. menu_additem( menu, meni, "2" )
  277.  
  278. menu_display( id, menu )
  279. }
  280.  
  281. public menuakcija( id, menu, item )
  282. {
  283. if( item >= 0 )
  284. {
  285. new access, callback, actionString[ 2 ]
  286. menu_item_getinfo( menu, item, access, actionString, charsmax( actionString ), _, _, callback )
  287.  
  288. new action = str_to_num( actionString )
  289. {
  290. switch( action )
  291. {
  292. case 0:
  293. {
  294. prikazirank(id)
  295. set_task(0.1, "prikazimenu", id, _, _, "a", 1)
  296. }
  297. case 1:
  298. {
  299. prikazitop15(id)
  300. set_task(0.1, "prikazimenu", id, _, _, "a", 1)
  301. }
  302. case 2:
  303. {
  304. prikazimotd(id)
  305. set_task(0.1, "prikazimenu", id, _, _, "a", 1)
  306. }
  307. }
  308. }
  309. }
  310. menu_destroy( menu )
  311. return PLUGIN_HANDLED
  312. }
  313.  
  314. public reklama(id)
  315. {
  316. if(is_user_connected(id))
  317. {
  318. ColorChat(id, TEAM_COLOR, "^4[Kviz] ^1Ovaj server koristi ^3%s v%s ^1za informacije o pluginu ^3say /kviz", PLUGIN, VERSION)
  319. set_task(600.0, "reklama", id, _, _, "a", 1)
  320. }
  321. }
Advertisement
Add Comment
Please, Sign In to add comment