Advertisement
Guest User

automatic_knife_duel in romana

a guest
Aug 7th, 2010
1,356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.64 KB | None | 0 0
  1. #define PLUGINNAME "Automatic knife duel"
  2. #define VERSION "0.3"
  3. #define AUTHOR "JGHG"
  4.  
  5. #include <amxmodx>
  6. #include <fakemeta>
  7. #include <fun>
  8.  
  9. #define DEBUG
  10.  
  11. #if defined DEBUG
  12. #include <amxmisc>
  13. #endif // defined DEBUG
  14.  
  15. #define MENUSELECT1 0
  16. #define MENUSELECT2 1
  17. #define TASKID_CHALLENGING 2348923
  18. #define TASKID_BOTTHINK 3242321
  19. #define DECIDESECONDS 10
  20. #define ALLOWED_WEAPONS 2
  21. #define KNIFESLASHES 3 // the nr of slashes within a short amount of time until a challenge starts...
  22. // Globals below
  23. new g_allowedWeapons[ALLOWED_WEAPONS] = {CSW_KNIFE, CSW_C4}
  24. new g_MAXPLAYERS
  25. new bool:g_challenging = false
  26. new bool:g_knifeArena = false
  27. new bool:g_noChallengingForAWhile = false
  28. new g_challengemenu
  29. new g_challenger
  30. new g_challenged
  31. new g_challenges[33]
  32. // Globals above
  33.  
  34. public plugin_modules()
  35. {
  36. require_module("fakemeta")
  37. require_module("fun")
  38. }
  39.  
  40. public forward_emitsound(const PIRATE, const Onceuponatimetherewasaverysmall, noise[], const Float:turtlewhoateabiggerturtleand, const Float:afterthatthesmallturtlegot, const veryveryverybig, const theend) {
  41. if (g_noChallengingForAWhile || g_knifeArena || g_challenging || PIRATE < 1 || PIRATE > g_MAXPLAYERS || !is_user_alive(PIRATE) || !equal(noise, "weapons/knife_hitwall1.wav"))
  42. return FMRES_IGNORED
  43.  
  44. new team = get_user_team(PIRATE), otherteam = 0, matchingOpponent = 0
  45. // Make sure exactly one person on each team is alive.
  46. for (new i = 1; i <= g_MAXPLAYERS; i++) {
  47. if (!is_user_connected(i) || !is_user_alive(i) || PIRATE == i)
  48. continue
  49. if (get_user_team(i) == team) {
  50. // No fun.
  51. return FMRES_IGNORED
  52. }
  53. else {
  54. if (++otherteam > 1) {
  55. // No fun.
  56. return FMRES_IGNORED
  57. }
  58. matchingOpponent = i
  59. }
  60. }
  61.  
  62. if (matchingOpponent == 0)
  63. return FMRES_IGNORED
  64.  
  65. if (++g_challenges[PIRATE] >= KNIFESLASHES) {
  66. Challenge(PIRATE, matchingOpponent)
  67. if (is_user_bot(matchingOpponent)) {
  68. new Float:val = float(DECIDESECONDS)
  69. if (val < 2.0)
  70. val = 2.0
  71. remove_task(TASKID_BOTTHINK)
  72. set_task(random_float(1.0, float(DECIDESECONDS) - 1.0), "BotDecides", TASKID_BOTTHINK)
  73. }
  74. g_challenges[PIRATE] = 0
  75. }
  76. else
  77. set_task(1.0, "decreaseChallenges", PIRATE)
  78.  
  79. //client_print(PIRATE, print_chat, "Your challenges: %d", g_challenges[PIRATE])
  80.  
  81. return FMRES_IGNORED
  82. }
  83.  
  84. public decreaseChallenges(id) {
  85. if (--g_challenges[id] < 0)
  86. g_challenges[id] = 0
  87. }
  88.  
  89. public BotDecides() {
  90. if (!g_challenging)
  91. return
  92.  
  93. if (random_num(0,9) > 0)
  94. Accept()
  95. else {
  96. DeclineMsg()
  97. }
  98. g_challenging = false
  99. remove_task(TASKID_CHALLENGING)
  100. }
  101.  
  102. Challenge(challenger, challenged) {
  103. g_challenger = challenger
  104. g_challenged = challenged
  105. g_challenging = true
  106. new challenger_name[32], challenged_name[32]
  107. get_user_name(challenger, challenger_name, 31)
  108. get_user_name(challenged, challenged_name, 31)
  109.  
  110. client_print(challenger, print_chat, "L-ai provocat pe %s la un duel.! Asteapta raspunsul in %d secunde...", challenged_name, DECIDESECONDS)
  111.  
  112. new menu[1024], keys = MENU_KEY_1 | MENU_KEY_2
  113. format(menu, 1023, "Ai fost provocat la duel de %s !^n^nCe vei face?Ai %d secunde ca sa rapunzi!^n^n\y1\w. Accept provocarea!^n\y2\w. Nu accept provocarea!", challenger_name, DECIDESECONDS)
  114. show_menu(challenged, keys, menu, DECIDESECONDS, "JGHG's automatic knife duel")
  115. set_task(float(DECIDESECONDS), "timed_toolate", TASKID_CHALLENGING)
  116. }
  117.  
  118. public timed_toolate() {
  119. if (g_challenging) {
  120. new challenger_name[32], challenged_name[32]
  121. get_user_name(g_challenger, challenger_name, 31)
  122. get_user_name(g_challenged, challenged_name, 31)
  123. client_print(0, print_chat, "%s n-a raspuns lui %s's pentru duel prea repede...", challenged_name, challenger_name)
  124. CancelAll()
  125. }
  126. }
  127.  
  128. public client_putinserver(id) {
  129. set_task(25.0, "Announcement", id)
  130.  
  131. return PLUGIN_CONTINUE
  132. }
  133.  
  134. public Announcement(id) {
  135. client_print(id, print_chat, "Cand tu si un inamic ati ramas singuri,il poti provoca la un duel de lame lovind cu lama de 3 ori in perete.")
  136. }
  137.  
  138. public challenged_menu(id, key) {
  139. switch (key) {
  140. case MENUSELECT1: {
  141. // Accept
  142. Accept()
  143. }
  144. case MENUSELECT2: {
  145. // Decline
  146. DeclineMsg()
  147. }
  148. }
  149. g_challenging = false
  150. remove_task(TASKID_CHALLENGING)
  151.  
  152. return PLUGIN_HANDLED
  153. }
  154.  
  155. DeclineMsg() {
  156. new challenger_name[32], challenged_name[32]
  157. get_user_name(g_challenger, challenger_name, 31)
  158. get_user_name(g_challenged, challenged_name, 31)
  159. client_print(0, print_chat, "%s a refuzat %s's acest duel...", challenged_name, challenger_name)
  160. }
  161.  
  162. Accept() {
  163. new challenger_name[32], challenged_name[32]
  164. get_user_name(g_challenger, challenger_name, 31)
  165. get_user_name(g_challenged, challenged_name, 31)
  166.  
  167. client_print(0, print_chat, "%s a acceptat %s's provocarea la duel!", challenged_name, challenger_name)
  168. g_knifeArena = true
  169. give_item(g_challenger, "weapon_knife")
  170. give_item(g_challenged, "weapon_knife")
  171. engclient_cmd(g_challenger, "weapon_knife")
  172. engclient_cmd(g_challenged, "weapon_knife")
  173. }
  174.  
  175. public event_holdwpn(id) {
  176. if (!g_knifeArena || !is_user_alive(id))
  177. return PLUGIN_CONTINUE
  178.  
  179. new weaponType = read_data(2)
  180.  
  181. for (new i = 0; i < ALLOWED_WEAPONS; i++) {
  182. if (weaponType == g_allowedWeapons[i])
  183. return PLUGIN_CONTINUE
  184. }
  185.  
  186. engclient_cmd(id, "weapon_knife")
  187.  
  188. return PLUGIN_CONTINUE
  189. }
  190.  
  191. public event_roundend() {
  192. if (g_challenging || g_knifeArena)
  193. CancelAll()
  194. g_noChallengingForAWhile = true
  195. set_task(4.0, "NoChallengingForAWhileToFalse")
  196.  
  197. return PLUGIN_CONTINUE
  198. }
  199.  
  200. public NoChallengingForAWhileToFalse() {
  201. g_noChallengingForAWhile = false
  202. }
  203.  
  204. CancelAll() {
  205. if (g_challenging) {
  206. g_challenging = false
  207. // Close menu of challenged
  208. if (is_user_connected(g_challenged)) {
  209. new usermenu, userkeys
  210. get_user_menu(g_challenged, usermenu, userkeys) // get user menu
  211.  
  212. // Hmm this ain't working :-/
  213. if (usermenu == g_challengemenu) // Close it!
  214. show_menu(g_challenged, 0, "blabla") // show empty menu
  215. }
  216. }
  217. if (g_knifeArena) {
  218. g_knifeArena = false
  219. }
  220. remove_task(TASKID_BOTTHINK)
  221. remove_task(TASKID_CHALLENGING)
  222. }
  223.  
  224. public event_death() {
  225. if (g_challenging || g_knifeArena)
  226. CancelAll()
  227.  
  228. return PLUGIN_CONTINUE
  229. }
  230.  
  231. #if defined DEBUG
  232. public challengefn(id, level, cid) {
  233. if (!cmd_access(id, level, cid, 3))
  234. return PLUGIN_HANDLED
  235.  
  236. new challenger[64], challenged[64]
  237. read_argv(1, challenger, 63)
  238. read_argv(2, challenged, 63)
  239.  
  240. console_print(id, "challenger: %s, challenged: %s", challenger, challenged)
  241.  
  242. new r = str_to_num(challenger)
  243. new d = str_to_num(challenged)
  244. Challenge(r, d)
  245. if (is_user_bot(d))
  246. Accept()
  247.  
  248. return PLUGIN_HANDLED
  249. }
  250. #endif // defined DEBUG
  251.  
  252. public plugin_init() {
  253. register_plugin(PLUGINNAME, VERSION, AUTHOR)
  254. register_event("CurWeapon", "event_holdwpn", "be", "1=1")
  255. register_forward(FM_EmitSound, "forward_emitsound")
  256. g_MAXPLAYERS = get_maxplayers()
  257.  
  258. g_challengemenu = register_menuid("JGHG's automatic knife duel"/*"Ai fost provocat!"*/)
  259. register_menucmd(g_challengemenu, MENU_KEY_1 | MENU_KEY_2, "challenged_menu")
  260.  
  261. register_event("DeathMsg", "event_death", "a")
  262. register_event("SendAudio", "event_roundend", "a", "2&%!MRAD_terwin")
  263. register_event("SendAudio", "event_roundend", "a", "2&%!MRAD_ctwin")
  264. register_event("SendAudio", "event_roundend", "a", "2&%!MRAD_rounddraw")
  265.  
  266. #if defined DEBUG
  267. register_clcmd("0challenge", "challengefn", ADMIN_CFG, "<challenger> <challenged> - start knife duel challenge")
  268. #endif // defined DEBUG
  269.  
  270. new Float:maptime = get_cvar_float("mp_timelimit")
  271. if (maptime == 0.0)
  272. maptime = 15.0
  273.  
  274. new Float:anntime = 60.0 * 5.0 // 5 minutes
  275. if (maptime < 5.0)
  276. anntime = maptime / 3.0
  277.  
  278. set_task(anntime, "Announcement", 0, "", 0, "b")
  279. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement