HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. /** Give the Bomb!
  2.  *
  3.  * By DrFreeze - Version: 1.0 - Release 17-05-2015
  4.  *
  5.  * Simple plugin that enables the carriers of the bomb to write /give and to pass it to another
  6.  * player. Also the admins with flag T can write /take and to take the bomb from the current
  7.  * carrier.
  8.  *
  9.  * Client commands:
  10.  * say /give
  11.  * say /givebomb
  12.  *
  13.  * Admin commands:
  14.  * say /take
  15.  *
  16.  * There are no CVARS yet!
  17.  */
  18. #include <amxmodx>
  19. #include <amxmisc>
  20. #include <cstrike>
  21. #include <engine>
  22. #include <fakemeta>
  23. #include <fakemeta_util>
  24. #include <hamsandwich>
  25.  
  26. #define PLUGIN "Give the Bomb"
  27. #define VERSION "1.0"
  28. #define AUTHOR "DrFreeze"
  29.  
  30. #define iPrefix "[Bomba átadás]"
  31.  
  32. enum Color {
  33. NORMAL = 1,
  34. GREEN,
  35. TEAM_COLOR,
  36. GREY,
  37. RED,
  38. BLUE,
  39. }
  40.  
  41. new TeamName[][] = {
  42. "",
  43. "TERRORIST",
  44. "CT",
  45. "SPECTATOR"
  46. }
  47.  
  48. public plugin_init() {
  49. register_plugin(PLUGIN, VERSION, AUTHOR);
  50. register_dictionary("give_bomb.txt")
  51. register_clcmd("say /atad", "GiveBombMenu");
  52. }
  53.  
  54. public TakeBombMenu(id)
  55. {
  56.  
  57. if (get_user_team(id) != 1 || !is_user_alive(id) || user_has_weapon(id, CSW_C4))
  58. {
  59. ColorChat( id, GREEN, "%s^1 Ezzel a menüvel^3 át tudjuk adni csapattársunknak a bombát!", iPrefix );
  60. return PLUGIN_HANDLED;
  61. }
  62.  
  63. new menu = menu_create( "\\yBomba Átvétel Menü:", "take_bomb_handler" );
  64.  
  65. new players[32], pnum, tempid;
  66. new szName[32], szUserId[32];
  67.  
  68. get_players( players, pnum, "ae", "TERRORIST");
  69.  
  70. for ( new i; i<pnum; i++ )
  71. {
  72. tempid = players[i];
  73. if (user_has_weapon(tempid, CSW_C4))
  74. {
  75. get_user_name( tempid, szName, charsmax( szName ) );
  76. formatex( szUserId, charsmax( szUserId ), "%d", get_user_userid( tempid ));
  77. menu_additem( menu, szName, szUserId, 0 );
  78. }
  79. }
  80. menu_display (id, menu, 0);
  81. return PLUGIN_CONTINUE;
  82. }
  83.  
  84. public take_bomb_handler(id, menu, item)
  85. {
  86. if ( item == MENU_EXIT )
  87. {
  88. menu_destroy( menu );
  89. return PLUGIN_HANDLED;
  90. }
  91.  
  92. new szData[6], szName[64];
  93. new _access, item_callback;
  94. menu_item_getinfo( menu, item, _access, szData,charsmax( szData ), szName,charsmax( szName ), item_callback );
  95.  
  96. new userid = str_to_num( szData );
  97.  
  98. new player = find_player( "k", userid ); // flag "k" : find player from userid
  99.  
  100. new current_carrier[32]
  101. get_user_name(id, current_carrier, charsmax ( current_carrier ) );
  102.  
  103. if ( has_flag( id, "t" ) && player && is_user_alive(player) && user_has_weapon(player, CSW_C4) )
  104. {
  105. fm_transfer_user_gun(player, id, CSW_C4)
  106. ColorChat( id, GREEN, "%s^1 A bombát^3 átadták^4 %s-nak!", iPrefix, szName, current_carrier );
  107. }
  108.  
  109. else
  110. {
  111. ColorChat( id, GREEN, "%s^1 A bombát^3 nem vették át!", iPrefix);
  112. }
  113.  
  114. menu_destroy( menu );
  115. return PLUGIN_CONTINUE;
  116. }
  117.  
  118. public GiveBombMenu(id) {
  119.  
  120. if (get_user_team(id) != 1 || !is_user_alive(id) || !user_has_weapon(id, CSW_C4)){
  121. ColorChat( id, GREEN, "%s^1 Ezzel a menüvel^3 át tudjuk adni csapattársunknak a bombát!", iPrefix );
  122. return PLUGIN_HANDLED;
  123. }
  124.  
  125. new menu = menu_create( "\\rBomba Átadás Menü:", "give_bomb_handler" );
  126. new players[32], pnum, tempid;
  127. new szName[32], szUserId[32];
  128.  
  129. get_players( players, pnum, "ae", "TERRORIST");
  130.  
  131. for(new i; i<pnum; i++)
  132. {
  133. tempid = players[i];
  134. if (!user_has_weapon(tempid, CSW_C4)){
  135. get_user_name( tempid, szName, charsmax( szName ) );
  136. formatex( szUserId, charsmax( szUserId ), "%d", get_user_userid( tempid ) );
  137.  
  138. menu_additem( menu, szName, szUserId, 0 );
  139. }
  140.  
  141. }
  142. menu_display(id, menu, 0);
  143. return PLUGIN_CONTINUE;
  144. }
  145.  
  146. public give_bomb_handler( id, menu, item )
  147. {
  148. if ( item == MENU_EXIT )
  149. {
  150. menu_destroy( menu );
  151. return PLUGIN_HANDLED;
  152. }
  153.  
  154. new szData[6], szName[64];
  155. new _access, item_callback;
  156. menu_item_getinfo( menu, item, _access, szData,charsmax( szData ), szName,charsmax( szName ), item_callback );
  157.  
  158. new userid = str_to_num( szData );
  159.  
  160. new player = find_player( "k", userid ); // flag "k" : find player from userid
  161.  
  162. new current_carrier[32]
  163. get_user_name(id, current_carrier, charsmax ( current_carrier ) );
  164.  
  165. if ( player && is_user_alive(player) && !user_has_weapon(player, CSW_C4) )
  166. {
  167. fm_transfer_user_gun(id, player, CSW_C4)
  168. ColorChat( id, GREEN, "%s^1 A bombát^3 átadták^4 %s-nak!", iPrefix, szName, current_carrier );
  169. }
  170.  
  171. else
  172. {
  173. ColorChat( id, GREEN, "%s^1 A bombát^3 nem vették at!", iPrefix);
  174. }
  175.  
  176. menu_destroy( menu );
  177. return PLUGIN_CONTINUE;
  178. }
  179.  
  180.  
  181. ColorChat(id, Color:type, const msg[], {Float,Sql,Result,_}:...)
  182. {
  183. static message[256];
  184.  
  185. switch(type)
  186. {
  187. case NORMAL:
  188. {
  189. message[0] = 0x01;
  190. }
  191. case GREEN:
  192. {
  193. message[0] = 0x04;
  194. }
  195. default:
  196. {
  197. message[0] = 0x03;
  198. }
  199. }
  200.  
  201. vformat(message[1], 251, msg, 4);
  202.  
  203. message[192] = '^0';
  204.  
  205. static team, ColorChange, index, MSG_Type;
  206.  
  207. if(id)
  208. {
  209. MSG_Type = MSG_ONE;
  210. index = id;
  211. }
  212. else
  213. {
  214. index = FindPlayer();
  215. MSG_Type = MSG_ALL;
  216. }
  217.  
  218. team = get_user_team(index);
  219. ColorChange = ColorSelection(index, MSG_Type, type);
  220.  
  221. ShowColorMessage(index, MSG_Type, message);
  222.  
  223. if(ColorChange)
  224. {
  225. Team_Info(index, MSG_Type, TeamName[team]);
  226. }
  227. }
  228.  
  229. ShowColorMessage(id, type, message[])
  230. {
  231. message_begin(type, get_user_msgid("SayText"), _, id);
  232. write_byte(id)
  233. write_string(message);
  234. message_end();
  235. }
  236.  
  237. Team_Info(id, type, team[])
  238. {
  239. message_begin(type, get_user_msgid("TeamInfo"), _, id);
  240. write_byte(id);
  241. write_string(team);
  242. message_end();
  243.  
  244. return 1;
  245. }
  246.  
  247. ColorSelection(index, type, Color:Type)
  248. {
  249. switch(Type)
  250. {
  251. case RED:
  252. {
  253. return Team_Info(index, type, TeamName[1]);
  254. }
  255. case BLUE:
  256. {
  257. return Team_Info(index, type, TeamName[2]);
  258. }
  259. case GREY:
  260. {
  261. return Team_Info(index, type, TeamName[0]);
  262. }
  263. }
  264.  
  265. return 0;
  266. }
  267.  
  268. FindPlayer()
  269. {
  270. static i;
  271. i = -1;
  272.  
  273. while(i <= get_maxplayers())
  274. {
  275. if(is_user_connected(++i))
  276. {
  277. return i;
  278. }
  279. }
  280.  
  281. return -1;
  282. }