Guest User

Untitled

a guest
Oct 19th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.56 KB | None | 0 0
  1. // Rukia: YAP Ready code
  2.  
  3. // Ready mode is very intuitive.
  4. // In reality, we just wait for everyone to ready up, and restore state
  5. // So, in simplest form, "ready" is a vote that can last an infinitely long time. Very simple.
  6.  
  7. #include <amxmodx>
  8. #include <amxmisc>
  9.  
  10. #include <yap_const>
  11. #include <yap_stocks>
  12. #include <yap_natives>
  13. #include <yap_forwards>
  14. #include <yap_modspecific>
  15.  
  16. new const plugin_author[] = "Twilight Suzuka"
  17. new const plugin_name[] = "YAP-RDY"
  18. new const plugin_version[] = "0.0.1"
  19.  
  20. CREATE_GEN_FORW_ID(pug_forward_ready);
  21.  
  22. public plugin_init()
  23. {
  24. // Rukia: Plugin definition
  25. new p_id = register_plugin(plugin_name,plugin_version,plugin_author);
  26.  
  27. register_dictionary("yap.txt")
  28. register_dictionary("yap_ready.txt")
  29.  
  30. register_pug_clcmd("ready","ready_up",_,"Tells the server player is ready")
  31. register_pug_clcmd("notready","ready_down",_,"Tells the server player is not ready")
  32.  
  33. register_pug_admincmd("forceready","cmd_forceready",PUG_CMD_LVL,"<name or #userid> Forces a client to be ready")
  34. register_pug_admincmd("forceunready","cmd_forceunready",PUG_CMD_LVL,"<name or #userid> Forces a client to be unready")
  35.  
  36. pug_forward_ready = create_gen_forward("pug_all_ready",p_id,get_func_id("pug_ready_handler") )
  37.  
  38. //parse_header("BOE-E",pug_header,5)
  39. register_event("ResetHUD","pug_keepup_menu","b")
  40.  
  41. pug_change_display(get_func_id("pug_ready_display_really") , -1)
  42. }
  43.  
  44. // Rukia: Ready variables
  45. new pug_players_ready[33]
  46. new pug_total_ready = 0;
  47.  
  48. #define TASK_READY 2345
  49.  
  50. // Rukia: make sure we keep up menu as much as possible, so that it updates correctly
  51. public client_connect(id) set_task(15.0,"pug_keepup_menu")
  52. public client_putinserver(id)
  53. {
  54. pug_keepup_menu()
  55.  
  56. if(GET_PUG_STATUS() != PUG_STATUS_LIVE)
  57. set_task(60.0, "Check_Ready", id+TASK_READY)
  58. }
  59.  
  60. public Check_Ready(id)
  61. {
  62. if(GET_PUG_STATUS() == PUG_STATUS_LIVE) return
  63.  
  64. id-=TASK_READY
  65.  
  66. if(!pug_players_ready[id])
  67. server_cmd("kick #%d not type .ready in 60 seconds", get_user_userid(id))
  68. }
  69.  
  70. // Rukia: If someone disconnects, we need to take them out of the line up, and make sure that everything is cool
  71. public client_disconnect(id)
  72. {
  73. if( GET_PUG_STAGE() != PUG_STAGE_READY ) return;
  74.  
  75. if(pug_players_ready[id])
  76. {
  77. pug_players_ready[id] = 0;
  78. pug_total_ready--;
  79.  
  80. if(task_exists(id+TASK_READY))
  81. remove_task(id+TASK_READY)
  82. }
  83.  
  84. pug_keepup_menu()
  85. }
  86.  
  87. // Rukia: Make sure to change HUD when people change names
  88. public client_infochanged(id) set_task(0.1,"pug_keepup_menu")
  89.  
  90. // Rukia: Dynamic native code
  91. public plugin_natives()
  92. {
  93. register_native("pug_ready_players","native_pug_ready_players")
  94. register_native("register_ready_display","native_register_ready_display")
  95. }
  96.  
  97. public native_pug_ready_players(id,params)
  98. {
  99. new p_id = get_param(2)
  100. pug_ready_players(get_param(1),(p_id == -1) ? id : p_id)
  101. }
  102.  
  103. public native_register_ready_display(id,params)
  104. {
  105. new p_id = get_param(2)
  106. pug_change_display(get_param(1),(p_id == -1) ? id : p_id)
  107. }
  108.  
  109. public cmd_forceready(id,level,cid)
  110. {
  111. if (!cmd_access(id, level, cid, 2) ) return PLUGIN_HANDLED;
  112.  
  113. static victim_arg[32]
  114. read_argv(1,victim_arg,31)
  115.  
  116. if(equali(victim_arg,"all")) return cmd_force_all_ready(id);
  117.  
  118. new target = cmd_target(id,victim_arg,1)
  119. if (!target) return PLUGIN_HANDLED
  120.  
  121. pug_admin_cmd_c(id,"PugForceReady","PUG_FORCE_READY",target,ready_up(target));
  122. return PLUGIN_HANDLED;
  123. }
  124.  
  125. public cmd_forceunready(id,level,cid)
  126. {
  127. if (!cmd_access(id, level, cid, 2) ) return PLUGIN_HANDLED;
  128.  
  129. static victim_arg[32]
  130. read_argv(1,victim_arg,31)
  131.  
  132. if(equali(victim_arg,"all")) return cmd_force_all_unready(id);
  133.  
  134. new target = cmd_target(id,victim_arg,1)
  135. if (!target) return PLUGIN_HANDLED
  136.  
  137. pug_admin_cmd_c(id,"PugForceUnReady","PUG_FORCE_UNREADY",target,ready_down(target));
  138. return PLUGIN_HANDLED;
  139. }
  140.  
  141. public cmd_force_all_ready(id)
  142. {
  143. static Players[32]
  144. new playerCount, i
  145. get_players(Players, playerCount, "h")
  146.  
  147. for (i=0; i<playerCount; i++) ready_up(Players[i])
  148.  
  149. pug_admin_cmd(id,"PugForceAllReady","PUG_FORCE_ALL_READY",1);
  150. return PLUGIN_HANDLED
  151. }
  152.  
  153. public cmd_force_all_unready(id)
  154. {
  155. static Players[32]
  156. new playerCount, i
  157. get_players(Players, playerCount, "h")
  158.  
  159. for (i=0; i<playerCount; i++) ready_down(Players[i])
  160.  
  161. pug_admin_cmd(id,"PugForceAllUnReady","PUG_FORCE_ALL_UNREADY",1);
  162. return PLUGIN_HANDLED
  163. }
  164.  
  165.  
  166. // Rukia: Ready code
  167.  
  168. public pug_ready_funcid;
  169. public pug_ready_plugin_id;
  170. public pug_ready_prev_stage;
  171.  
  172. // Rukia: save the handler function
  173. pug_ready_players(f_id, p_id = -1)
  174. {
  175. if(GET_PUG_STAGE() == PUG_STAGE_READY) return;
  176. pug_ready_funcid = f_id;
  177. pug_ready_plugin_id = p_id;
  178.  
  179. pug_start_ready_players()
  180. }
  181.  
  182. // Rukia: Save state, sub in our own, and start the ready!
  183. public pug_start_ready_players()
  184. {
  185. if(GET_PUG_STATUS() != PUG_STATUS_LIVE) return pug_set_pause_call(get_func_id("pug_start_ready_players"));
  186.  
  187. pug_ready_prev_stage = GET_PUG_STAGE();
  188. SET_PUG_STAGE(PUG_STAGE_READY);
  189. SET_PUG_STATUS(PUG_STATUS_WAITING);
  190.  
  191. arrayset(pug_players_ready,0,33)
  192. pug_total_ready = 0;
  193.  
  194. pug_msg_tmp_empty(0,"PUG_READY_UP")
  195. pug_keepup_menu()
  196.  
  197. return 1;
  198. }
  199.  
  200. public ready_up(id)
  201. {
  202. if((pug_players_ready[id] == 1)
  203. || GET_PUG_STATUS() != PUG_STATUS_WAITING || GET_PUG_STAGE() != PUG_STAGE_READY
  204. || is_user_hltv(id)
  205. )
  206. {
  207. return pug_msg_tmp_empty(id,"PUG_CMD_NOTALLOWED")
  208. }
  209.  
  210. if(task_exists(id+TASK_READY))
  211. remove_task(id+TASK_READY)
  212.  
  213. pug_players_ready[id] = 1;
  214. pug_total_ready++;
  215.  
  216. static name[32]
  217. get_user_name(id,name,31)
  218. client_print(0,print_chat,"%s %L",pug_header, LANG_PLAYER, "PUG_PLAYER_READYED",name);
  219.  
  220. pug_check_ready();
  221.  
  222. return PLUGIN_HANDLED;
  223. }
  224.  
  225. public ready_down(id)
  226. {
  227. if((pug_players_ready[id] == 0)
  228. || GET_PUG_STATUS() != PUG_STATUS_WAITING || GET_PUG_STAGE() != PUG_STAGE_READY
  229. || is_user_hltv(id)
  230. )
  231. {
  232. return pug_msg_tmp_empty(id,"PUG_CMD_NOTALLOWED")
  233. }
  234.  
  235. pug_players_ready[id] = 0;
  236. pug_total_ready--;
  237.  
  238. pug_ready_display(9999.0)
  239.  
  240. static name[32]
  241. get_user_name(id,name,31)
  242. client_print(0,print_chat,"%s %L",pug_header, LANG_PLAYER, "PUG_PLAYER_UNREADYED",name);
  243.  
  244. return PLUGIN_HANDLED;
  245. }
  246.  
  247. public pug_keepup_menu()
  248. {
  249. if(GET_PUG_STAGE() == PUG_STAGE_READY)
  250. {
  251. pug_ready_display(99999.0)
  252. }
  253. }
  254.  
  255.  
  256. public pug_check_ready()
  257. {
  258. if(pug_total_ready >= GET_CVAR_MINPLAYERS() )
  259. {
  260. pug_ready_display(1.0)
  261. pug_ready()
  262. }
  263. else pug_ready_display(9999.0)
  264. }
  265.  
  266.  
  267. public pug_ready_display_funcid
  268. public pug_ready_display_plugin_id
  269.  
  270. public pug_change_display(f_id, p_id)
  271. {
  272. pug_ready_display_funcid = f_id;
  273. pug_ready_display_plugin_id = p_id;
  274. pug_keepup_menu()
  275. }
  276.  
  277. // Rukia: NOTE TO DO: Allow for subbing in own ready display in other plugins.
  278. public pug_ready_display(Float:hold_time)
  279. {
  280. callfunc_begin_i(pug_ready_display_funcid,pug_ready_display_plugin_id)
  281. callfunc_push_float(hold_time)
  282. callfunc_end()
  283. }
  284.  
  285. public pug_ready_display_really(Float:hold_time)
  286. {
  287. static readys[1056], notreadys[1056], name[32]
  288.  
  289. readys[0] = '^0'
  290. notreadys[0] = '^0'
  291.  
  292. static Players[32]
  293. new playerCount, i, player
  294. get_players(Players, playerCount, "ch")
  295. for (i=0; i<playerCount; i++)
  296. {
  297. player = Players[i]
  298. get_user_name(player,name,31)
  299.  
  300. if(pug_players_ready[player]) format(readys,1054,"%s%s^n",readys,name)
  301. else format(notreadys,1054,"%s%s^n",notreadys,name)
  302. }
  303.  
  304. new minplayers = GET_CVAR_MINPLAYERS()
  305.  
  306. set_hudmessage(255, 0, 0, 0.8, 0.07, 0, 0.0, hold_time, 0.0, 0.0, 3)
  307. show_hudmessage(0,"Not Ready (%d of %d) :",pug_get_players() - pug_total_ready,minplayers )
  308.  
  309. set_hudmessage(0, 255, 0, 0.8, 0.50, 0, 0.0, hold_time, 0.0, 0.0, 2)
  310. show_hudmessage(0,"Ready (%d of %d) :",pug_total_ready,minplayers)
  311.  
  312. set_hudmessage(255, 255, 225, 0.80, 0.53, 0, 0.0, hold_time, 0.0, 0.0, 1)
  313. show_hudmessage(0,readys,1055)
  314.  
  315. set_hudmessage(255, 255, 225, 0.80, 0.10, 0, 0.0, hold_time, 0.0, 0.0, 4)
  316. show_hudmessage(0,notreadys,1055)
  317. }
  318.  
  319. // Rukia: We are ready to go! Tell everyone!
  320. public pug_ready()
  321. {
  322. if(GET_PUG_STAGE() != PUG_STAGE_READY) return 0;
  323. else if(GET_PUG_STATUS() != PUG_STATUS_WAITING) return pug_set_pause_call(get_func_id("pug_ready"));
  324.  
  325. execute_gen_forward(pug_forward_ready)
  326. return 1;
  327. }
  328.  
  329. // Rukia: Restore state, tell everyone we are ready, and call the handler function!
  330. public pug_ready_handler()
  331. {
  332. if(GET_PUG_STATUS() != PUG_STATUS_WAITING) return pug_set_pause_call(get_func_id("pug_ready_handler"));
  333.  
  334. SET_PUG_STATUS(PUG_STATUS_LIVE);
  335. SET_PUG_STAGE(pug_ready_prev_stage);
  336.  
  337. pug_msg_tmp_empty(0,"PUG_IS_READY")
  338.  
  339. callfunc_begin_i(pug_ready_funcid,pug_ready_plugin_id)
  340. callfunc_end()
  341.  
  342. return 1;
  343. }
Add Comment
Please, Sign In to add comment