Guest User

Untitled

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