HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. #define PLUGINNAME "Automatic knife duel"
  2. #define VERSION "0.3"
  3. #define AUTHOR "JGHG"
  4. /*
  5. Copyleft 2005
  6. Plugin topic: http://www.amxmodx.org/forums/viewtopic.php?p=91239
  7.  
  8.  
  9. AUTOMATIC KNIFE DUEL
  10. ====================
  11. Where I come from, if you cut the wall repeteadly with your knife it means you're challenging your last opponent to a knife duel. ;-)
  12.  
  13. I decided to automate this process.
  14.  
  15. If only you and another person on the opposite team remain in the round, you can hit a wall (or another object) with your knife, THREE TIMES in fast succession.
  16. By this action you challenge your opponent to a knife duel. The person you challenge gets a menu where he can accept/decline your
  17. challenge. The challenged person has 10 seconds to decide his mind, else the challenge is automatically declined, and the menu should be closed automatically.
  18.  
  19. Should a knife duel start, it works out pretty much like a round of Knife Arena: you can only use the knife (and the C4!).
  20. As soon as the round ends the Knife Arena mode is turned off.
  21.  
  22. /JGHG
  23.  
  24.  
  25. VERSIONS
  26. ========
  27. 050421 0.3 You must now slash with your knife three times in fast succession to challenge someone.
  28. 050208 0.2 Fixed seconds display.
  29. Bots should now respond correctly and a little human like. They will mostly accept challenges. ;-)
  30. Small fixes here and there. :-)
  31. 050208 0.1 First version - largely untested
  32. */
  33.  
  34. #include <amxmodx>
  35. #include <fakemeta>
  36. #include <fun>
  37.  
  38. #define DEBUG
  39.  
  40. #if defined DEBUG
  41. #include <amxmisc>
  42. #endif // defined DEBUG
  43.  
  44. #define MENUSELECT1 0
  45. #define MENUSELECT2 1
  46. #define TASKID_CHALLENGING 2348923
  47. #define TASKID_BOTTHINK 3242321
  48. #define DECIDESECONDS 20
  49. #define ALLOWED_WEAPONS 2
  50. #define KNIFESLASHES 3 // the nr of slashes within a short amount of time until a challenge starts...
  51. // Globals below
  52. new g_allowedWeapons[ALLOWED_WEAPONS] = {CSW_KNIFE, CSW_C4}
  53. new g_MAXPLAYERS
  54. new bool:g_challenging = false
  55. new bool:g_knifeArena = false
  56. new bool:g_noChallengingForAWhile = false
  57. new g_challengemenu
  58. new g_challenger
  59. new g_challenged
  60. new g_challenges[33]
  61. // Globals above
  62.  
  63. public plugin_modules()
  64. {
  65. require_module("fakemeta")
  66. require_module("fun")
  67. }
  68.  
  69. public forward_emitsound(const PIRATE, const Onceuponatimetherewasaverysmall, noise[], const Float:turtlewhoateabiggerturtleand, const Float:afterthatthesmallturtlegot, const veryveryverybig, const theend) {
  70. if (g_noChallengingForAWhile || g_knifeArena || g_challenging || PIRATE < 1 || PIRATE > g_MAXPLAYERS || !is_user_alive(PIRATE) || !equal(noise, "weapons/knife_hitwall1.wav"))
  71. return FMRES_IGNORED
  72.  
  73. new team = get_user_team(PIRATE), otherteam = 0, matchingOpponent = 0
  74. // Make sure exactly one person on each team is alive.
  75. for (new i = 1; i <= g_MAXPLAYERS; i++) {
  76. if (!is_user_connected(i) || !is_user_alive(i) || PIRATE == i)
  77. continue
  78. if (get_user_team(i) == team) {
  79. // No fun.
  80. return FMRES_IGNORED
  81. }
  82. else {
  83. if (++otherteam > 1) {
  84. // No fun.
  85. return FMRES_IGNORED
  86. }
  87. matchingOpponent = i
  88. }
  89. }
  90.  
  91. if (matchingOpponent == 0)
  92. return FMRES_IGNORED
  93.  
  94. if (++g_challenges[PIRATE] >= KNIFESLASHES) {
  95. Challenge(PIRATE, matchingOpponent)
  96. if (is_user_bot(matchingOpponent)) {
  97. new Float:val = float(DECIDESECONDS)
  98. if (val < 2.0)
  99. val = 2.0
  100. remove_task(TASKID_BOTTHINK)
  101. set_task(random_float(1.0, float(DECIDESECONDS) - 1.0), "BotDecides", TASKID_BOTTHINK)
  102. }
  103. g_challenges[PIRATE] = 0
  104. }
  105. else
  106. set_task(1.0, "decreaseChallenges", PIRATE)
  107.  
  108. //client_print(PIRATE, print_chat, "Your challenges: %d", g_challenges[PIRATE])
  109.  
  110. return FMRES_IGNORED
  111. }
  112.  
  113. public decreaseChallenges(id) {
  114. if (--g_challenges[id] < 0)
  115. g_challenges[id] = 0
  116. }
  117.  
  118. public BotDecides() {
  119. if (!g_challenging)
  120. return
  121.  
  122. if (random_num(0,9) > 0)
  123. Accept()
  124. else {
  125. DeclineMsg()
  126. }
  127. g_challenging = false
  128. remove_task(TASKID_CHALLENGING)
  129. }
  130.  
  131. Challenge(challenger, challenged) {
  132. g_challenger = challenger
  133. g_challenged = challenged
  134. g_challenging = true
  135. new challenger_name[32], challenged_name[32]
  136. get_user_name(challenger, challenger_name, 31)
  137. get_user_name(challenged, challenged_name, 31)
  138.  
  139. client_print(challenger, print_chat, "Megakarsz kuzdeni %s -val egy kesparbajban? Varj a valaszara %d masodpercet...", challenged_name, DECIDESECONDS)
  140.  
  141. new menu[1024], keys = MENU_KEY_1 | MENU_KEY_2
  142. format(menu, 1023, "Megakarsz kuzdeni %s egy kesparbajban?^n^nMit teszel? Van %d masodmeprced a valaszra!^n^n\y1\w. Vagjunk bele!^n\y2\w. Nem merek mert gyava kukac vagyok!", challenger_name, DECIDESECONDS)
  143. show_menu(challenged, keys, menu, DECIDESECONDS, "JGHG's automatic knife duel")
  144. set_task(float(DECIDESECONDS), "timed_toolate", TASKID_CHALLENGING)
  145. }
  146.  
  147. public timed_toolate() {
  148. if (g_challenging) {
  149. new challenger_name[32], challenged_name[32]
  150. get_user_name(g_challenger, challenger_name, 31)
  151. get_user_name(g_challenged, challenged_name, 31)
  152. client_print(0, print_chat, "%s Nem válaszolt %s a kihivasara eleg gyorsan...", challenged_name, challenger_name)
  153. CancelAll()
  154. }
  155. }
  156.  
  157. public client_putinserver(id) {
  158. set_task(25.0, "Announcement", id)
  159.  
  160. return PLUGIN_CONTINUE
  161. }
  162.  
  163. public Announcement(id) {
  164. client_print(id, print_chat, "Amikor mar csak te es egy ellenseged maradt ki tudod hivni ot egy kesparbajra, csak verd a kesed a falhoz! ")
  165. }
  166.  
  167. public challenged_menu(id, key) {
  168. switch (key) {
  169. case MENUSELECT1: {
  170. // Accept
  171. Accept()
  172. }
  173. case MENUSELECT2: {
  174. // Decline
  175. DeclineMsg()
  176. }
  177. }
  178. g_challenging = false
  179. remove_task(TASKID_CHALLENGING)
  180.  
  181. return PLUGIN_HANDLED
  182. }
  183.  
  184. DeclineMsg() {
  185. new challenger_name[32], challenged_name[32]
  186. get_user_name(g_challenger, challenger_name, 31)
  187. get_user_name(g_challenged, challenged_name, 31)
  188. client_print(0, print_chat, "%s Nem fogadta el %s a kihivasat...", challenged_name, challenger_name)
  189. }
  190.  
  191. Accept() {
  192. new challenger_name[32], challenged_name[32]
  193. get_user_name(g_challenger, challenger_name, 31)
  194. get_user_name(g_challenged, challenged_name, 31)
  195.  
  196. client_print(0, print_chat, "%s Elfogadta %s a kihivasat!", challenged_name, challenger_name)
  197. g_knifeArena = true
  198. give_item(g_challenger, "weapon_knife")
  199. give_item(g_challenged, "weapon_knife")
  200. engclient_cmd(g_challenger, "weapon_knife")
  201. engclient_cmd(g_challenged, "weapon_knife")
  202. }
  203.  
  204. public event_holdwpn(id) {
  205. if (!g_knifeArena || !is_user_alive(id))
  206. return PLUGIN_CONTINUE
  207.  
  208. new weaponType = read_data(2)
  209.  
  210. for (new i = 0; i < ALLOWED_WEAPONS; i++) {
  211. if (weaponType == g_allowedWeapons[i])
  212. return PLUGIN_CONTINUE
  213. }
  214.  
  215. engclient_cmd(id, "weapon_knife")
  216.  
  217. return PLUGIN_CONTINUE
  218. }
  219.  
  220. public event_roundend() {
  221. if (g_challenging || g_knifeArena)
  222. CancelAll()
  223. g_noChallengingForAWhile = true
  224. set_task(4.0, "NoChallengingForAWhileToFalse")
  225.  
  226. return PLUGIN_CONTINUE
  227. }
  228.  
  229. public NoChallengingForAWhileToFalse() {
  230. g_noChallengingForAWhile = false
  231. }
  232.  
  233. CancelAll() {
  234. if (g_challenging) {
  235. g_challenging = false
  236. // Close menu of challenged
  237. if (is_user_connected(g_challenged)) {
  238. new usermenu, userkeys
  239. get_user_menu(g_challenged, usermenu, userkeys) // get user menu
  240.  
  241. // Hmm this ain't working :-/
  242. if (usermenu == g_challengemenu) // Close it!
  243. show_menu(g_challenged, 0, "blabla") // show empty menu
  244. }
  245. }
  246. if (g_knifeArena) {
  247. g_knifeArena = false
  248. }
  249. remove_task(TASKID_BOTTHINK)
  250. remove_task(TASKID_CHALLENGING)
  251. }
  252.  
  253. public event_death() {
  254. if (g_challenging || g_knifeArena)
  255. CancelAll()
  256.  
  257. return PLUGIN_CONTINUE
  258. }
  259.  
  260. #if defined DEBUG
  261. public challengefn(id, level, cid) {
  262. if (!cmd_access(id, level, cid, 3))
  263. return PLUGIN_HANDLED
  264.  
  265. new challenger[64], challenged[64]
  266. read_argv(1, challenger, 63)
  267. read_argv(2, challenged, 63)
  268.  
  269. console_print(id, "challenger: %s, challenged: %s", challenger, challenged)
  270.  
  271. new r = str_to_num(challenger)
  272. new d = str_to_num(challenged)
  273. Challenge(r, d)
  274. if (is_user_bot(d))
  275. Accept()
  276.  
  277. return PLUGIN_HANDLED
  278. }
  279. #endif // defined DEBUG
  280.  
  281. public plugin_init() {
  282. register_plugin(PLUGINNAME, VERSION, AUTHOR)
  283. register_event("CurWeapon", "event_holdwpn", "be", "1=1")
  284. register_forward(FM_EmitSound, "forward_emitsound")
  285. g_MAXPLAYERS = get_maxplayers()
  286.  
  287. g_challengemenu = register_menuid("JGHG's automatic knife duel"/*"You are challenged"*/)
  288. register_menucmd(g_challengemenu, MENU_KEY_1 | MENU_KEY_2, "challenged_menu")
  289.  
  290. register_event("DeathMsg", "event_death", "a")
  291. register_event("SendAudio", "event_roundend", "a", "2&%!MRAD_terwin")
  292. register_event("SendAudio", "event_roundend", "a", "2&%!MRAD_ctwin")
  293. register_event("SendAudio", "event_roundend", "a", "2&%!MRAD_rounddraw")
  294.  
  295. #if defined DEBUG
  296. register_clcmd("0challenge", "challengefn", ADMIN_CFG, "<challenger> <challenged> - start knife duel challenge")
  297. #endif // defined DEBUG
  298.  
  299. new Float:maptime = get_cvar_float("mp_timelimit")
  300. if (maptime == 0.0)
  301. maptime = 15.0
  302.  
  303. new Float:anntime = 60.0 * 5.0 // 5 minutes
  304. if (maptime < 5.0)
  305. anntime = maptime / 3.0
  306.  
  307. set_task(anntime, "Announcement", 0, "", 0, "b")
  308. }