HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. /* Ski2 Shop by Seta00
  2.  *
  3.  * This code is released under the GPLv3 License:
  4.  * http://www.gnu.org/licenses/gpl-3.0.html
  5.  *
  6.  * This plugin enables gameplay funcionalities to
  7.  * the surf_ski_2 map.
  8.  *
  9.  * When the player enters the Mario room, a menu
  10.  * is displayed with the Ski 2 Shop Items.
  11.  *
  12.  * All item costs are changeable by cvar, changes
  13.  * are applied on round start.
  14.  *
  15.  * Items description:
  16.  *
  17.  * - Get Out Of Jail ($1500) - One shot
  18.  *
  19.  * Inspired by the "Get Out Of Jail Free Card"
  20.  * from GTA2, this item removes you from the
  21.  * jail as soon as you enter it.
  22.  *
  23.  * Note: Users with the Eye of the Spy can see
  24.  * you entering the jail, but not leaving it.
  25.  * You can use this to attract enemies to the
  26.  * jail area.
  27.  *
  28.  * - Health Reload ($7500) - One shot
  29.  *
  30.  * Reloads your HP to 100. Useful but expensive.
  31.  *
  32.  * Note: Be careful, two Health Reloads and you
  33.  * are left with ~1000 in your pocket.
  34.  *
  35.  * - Extra Amor ($2500) - 3 rounds
  36.  *
  37.  * Sets your maximum armor to 150.
  38.  *
  39.  * Note: If you are already wearing armor, it gets
  40.  * filled to 100 AP.
  41.  *
  42.  * - M3 and M4 ($5000) - 3 rounds
  43.  *
  44.  * The second most expensive item in the shop, it's
  45.  * a really god choice in surf_ski_2. Remember, if
  46.  * you die with this item, you have to reach the
  47.  * Mario room to get a new M3 and M4.
  48.  *
  49.  * - Eye of the Spy ($1000) - 5 rounds
  50.  *
  51.  * An item for the strategists. It warns you every
  52.  * time someone enters the jail.
  53.  *
  54.  * - Save ($2500) - One shot
  55.  *
  56.  * Saves your current items. When you reconnect, items
  57.  * are automatically restored.
  58.  *
  59.  * Plugin Thread: http://forums.alliedmods.net/showthread.php?p=1092198
  60.  *
  61.  * Thanks to xPaw for his surf_ski_2 rules watcher plugin.
  62.  * Thanks to Arkshine for pointing me the message issue and by doing so allowed me to remove fakemeta dependency.
  63.  * Thanks for ConnorMcLeod for reviving this trash from the deeper layer of hell. NOT!
  64.  */
  65.  
  66. #include <amxmodx>
  67. #include <engine>
  68. #include <nvault>
  69. #include <cstrike>
  70. #include <fun>
  71. #include <hamsandwich>
  72.  
  73. #define PLUGIN "Ski2 Shop"
  74. #define AUTHOR "Seta00"
  75. #define VERSION "1.7.1"
  76.  
  77. #pragma semicolon 1
  78.  
  79. /////////////////////////////////////////////////////////////////////////////////////////
  80. /////////////////////////////////////////////////////////////////////////////////////////
  81. // ENUMERATIONS / TYPEs
  82.  
  83. enum __cvar_t {
  84. cvName[50],
  85. cvValue[10],
  86. cvPtr
  87. };
  88.  
  89. enum __duration_t {
  90. duration,
  91. lostMlStr[50]
  92. };
  93.  
  94. enum {
  95. GET_OUT_OF_JAIL, // FREE_CARD
  96. HEALTH_RELOAD,
  97. EXTRA_ARMOR,
  98. M3_AND_M4,
  99. EYE_OF_THE_SPY,
  100. SAVE,
  101.  
  102. LAST_ITEM
  103. };
  104.  
  105. enum {
  106. JAIL,
  107. MARIOROOM,
  108.  
  109. LAST_ZONE
  110. };
  111.  
  112. enum Color {
  113. NORMAL = 1, // clients scr_concolor cvar color
  114. GREEN, // Green Color
  115. TEAM_COLOR, // Red, grey, blue
  116. GREY, // grey
  117. RED, // Red
  118. BLUE, // Blue
  119. };
  120.  
  121. enum {
  122. M3,
  123. M4
  124. };
  125.  
  126. /////////////////////////////////////////////////////////////////////////////////////////
  127. /////////////////////////////////////////////////////////////////////////////////////////
  128. // GLOBAL VARS
  129.  
  130. new const Classname[] = "trigger_ski2_shop";
  131. new UserItems[33], UserIPs[33][15], UserRoundStart[33][LAST_ITEM], M3AndM4[33][2], RoundCount, MaxPlayers;
  132. new Float:LastTouch[33][LAST_ZONE];
  133. new bool:IsOnMario[33], bool:IsOnJail[33];
  134.  
  135. new const CVARS[][__cvar_t] = {
  136. {"ss_getoutofjail_price", "1500", 0},
  137. {"ss_getoutofjail_duration", "-1", 0},
  138. {"ss_healthreload_price", "7500", 0},
  139. {"ss_healthreload_duration", "-1", 0},
  140. {"ss_extraarmor_price", "2500", 0},
  141. {"ss_extraarmor_duration", "3", 0},
  142. {"ss_m3andm4_price", "5000", 0},
  143. {"ss_m3andm4_duration", "3", 0},
  144. {"ss_eyeofthespy_price", "750", 0},
  145. {"ss_eyeofthespy_duration", "5", 0},
  146. {"ss_save_price", "2500", 0},
  147. {"ss_save_duration", "-1", 0},
  148. {"ss_version", VERSION, 0} // always the last one
  149. };
  150.  
  151. new COST[LAST_ITEM] = {
  152. 1500,
  153. 7500,
  154. 2500,
  155. 5000,
  156. 750,
  157. 2500
  158. };
  159.  
  160. new DURATION[LAST_ITEM][__duration_t] = {
  161. {-1, "LOST_GET_OUT_OF_JAIL"},
  162. {-1, ""},
  163. {3, "LOST_EXTRA_ARMOR"},
  164. {3, "LOST_M3_AND_M4"},
  165. {5, "LOST_EYE_OF_THE_SPY"},
  166. {-1, ""}
  167. };
  168.  
  169. new TeamName[][] = {
  170. "",
  171. "TERRORIST",
  172. "CT",
  173. "SPECTATOR"
  174. };
  175.  
  176. /////////////////////////////////////////////////////////////////////////////////////////
  177. /////////////////////////////////////////////////////////////////////////////////////////
  178. // MACROS
  179.  
  180. #define HAS_GET_OUT_OF_JAIL(%1) (UserItems[%1] & (1 << GET_OUT_OF_JAIL))
  181. #define HAS_HEALTH_RELOAD(%1) (UserItems[%1] & (1 << HEALTH_RELOAD))
  182. #define HAS_EXTRA_ARMOR(%1) (UserItems[%1] & (1 << EXTRA_ARMOR))
  183. #define HAS_M3_AND_M4(%1) (UserItems[%1] & (1 << M3_AND_M4))
  184. #define HAS_EYE_OF_THE_SPY(%1) (UserItems[%1] & (1 << EYE_OF_THE_SPY))
  185. #define HAS_SAVE(%1) (UserItems[%1] & (1 << SAVE))
  186.  
  187. #define SET_GET_OUT_OF_JAIL(%1,%2) (UserItems[%1] |= (_:%2 << GET_OUT_OF_JAIL))
  188. #define SET_HEALTH_RELOAD(%1,%2) (UserItems[%1] |= (_:%2 << HEALTH_RELOAD))
  189. #define SET_EXTRA_ARMOR(%1,%2) (UserItems[%1] |= (_:%2 << EXTRA_ARMOR))
  190. #define SET_M3_AND_M4(%1,%2) (UserItems[%1] |= (_:%2 << M3_AND_M4))
  191. #define SET_EYE_OF_THE_SPY(%1,%2) (UserItems[%1] |= (_:%2 << EYE_OF_THE_SPY))
  192. #define SET_SAVE(%1,%2) (UserItems[%1] |= (_:%2 << SAVE))
  193.  
  194. #define MAX_MENU_ITEMS 7
  195. #define ML(%1) formatex(menuStr, charsmax(menuStr), "%L", id, %1)
  196.  
  197. /////////////////////////////////////////////////////////////////////////////////////////
  198. /////////////////////////////////////////////////////////////////////////////////////////
  199.  
  200. public plugin_init() {
  201. register_plugin(PLUGIN, VERSION, AUTHOR);
  202. register_dictionary("ski2_shop.txt");
  203.  
  204. new mapname[11];
  205. get_mapname(mapname, charsmax(mapname));
  206. if (equali(mapname, "surf_ski_2")) {
  207. CreateTrigger(JAIL, Float:{-579.0, 2983.0, 586.0}, Float:{-309.0, 3288.0, 796.0});
  208. CreateTrigger(MARIOROOM, Float:{2735.0, 193.0, -2361.0}, Float:{3709.0, 1180.0, -2087.0});
  209.  
  210. register_touch(Classname, "player", "EnteredSpecialZone");
  211.  
  212. RegisterHam(Ham_Spawn, "player", "FwdPlayerSpawn", 1);
  213.  
  214. register_event("HLTV", "NewRound", "a", "1=0", "2=0");
  215. register_event("ItemPickup", "OnItemPickup", "be");
  216.  
  217. register_clcmd("say /menu", "ShowShopMenu");
  218. register_clcmd("say_team /menu", "ShowShopMenu");
  219. register_clcmd("shop_menu", "ShowShopMenu");
  220.  
  221. for (new i = 0; i < sizeof(CVARS)-1; ++i) {
  222. CVARS[i][cvPtr] = register_cvar(CVARS[i][cvName], CVARS[i][cvValue]);
  223. }
  224.  
  225. // version cvar
  226. register_cvar(CVARS[sizeof(CVARS)-1][cvName], CVARS[sizeof(CVARS)-1][cvValue], FCVAR_SERVER|FCVAR_SPONLY);
  227.  
  228. CacheCvars();
  229.  
  230. MaxPlayers = get_maxplayers();
  231. }
  232. }
  233.  
  234. /////////////////////////////////////////////////////////////////////////////////////////
  235. /////////////////////////////////////////////////////////////////////////////////////////
  236. // FORWARDS
  237.  
  238. public client_connect(id) {
  239. get_user_ip(id, UserIPs[id], 15, 1);
  240. if (LoadUserItems(id) == -1) {
  241. UserItems[id] = 0;
  242. }
  243. }
  244.  
  245. public client_disconnect(id) {
  246. if (HAS_SAVE(id))
  247. SaveUserItems(id);
  248. }
  249.  
  250. /////////////////////////////////////////////////////////////////////////////////////////
  251. /////////////////////////////////////////////////////////////////////////////////////////
  252. // EVENTS / TOUCHS / HAMS
  253.  
  254. public NewRound() {
  255. RoundCount++;
  256.  
  257. CacheCvars();
  258.  
  259. new players[32], num, i;
  260. get_players(players, num, "ch");
  261.  
  262. for (new k = 0; k < num; ++k) {
  263. i = players[k];
  264. for (new j = 0; j < sizeof(UserItems[]); ++j) {
  265. if (DURATION[j][duration] == -1) break;
  266. if (~UserItems[i] & (1 << j)) break;
  267.  
  268. if (RoundCount == UserRoundStart[i][j] + DURATION[j][duration]) {
  269. UserItems[i] &= ~(1 << j);
  270. client_print(i, print_chat, "%L", i, DURATION[j][lostMlStr]);
  271. }
  272. }
  273. }
  274. }
  275.  
  276. public OnItemPickup(player) {
  277. if (!HAS_EXTRA_ARMOR(player))
  278. return;
  279.  
  280. new itemName[17];
  281. read_data(1, itemName, charsmax(itemName));
  282.  
  283. if (!(equal(itemName, "item_kevlar") || equal(itemName, "item_assaultsuit"))) {
  284. return;
  285. }
  286.  
  287. entity_set_float(player, EV_FL_armorvalue, 150.0);
  288.  
  289. return;
  290. }
  291.  
  292. // used xPaw idea for avoiding multiple touchs
  293. public EnteredSpecialZone(entity, id) {
  294. static Float:gametime;
  295. gametime = get_gametime();
  296.  
  297. static location;
  298. location = entity_get_int(entity, EV_INT_iuser1);
  299.  
  300. if( gametime > (LastTouch[id][location] + 1.2)) {
  301. LastTouch[id][location] = gametime;
  302. if(location)
  303. IsOnJail[id] = false;
  304. else
  305. IsOnMario[id] = false;
  306.  
  307. } else if (LastTouch[id][location] < gametime) {
  308. switch (location) {
  309. case MARIOROOM: {
  310. if (!IsOnMario[id]) {
  311. IsOnMario[id] = true;
  312. client_print(id, print_chat, "%L", id, "MENU_ADVERTISING");
  313. ShowShopMenu(id);
  314. if (HAS_M3_AND_M4(id)) {
  315. if (M3AndM4[id][M3] <= 0) {
  316. M3AndM4[id][M3] = give_item(id, "weapon_m3");
  317. cs_set_user_bpammo(id, CSW_M3, 32);
  318. }
  319. if (M3AndM4[id][M4] <= 0) {
  320. M3AndM4[id][M3] = give_item(id, "weapon_m4a1");
  321. cs_set_user_bpammo(id, CSW_M4A1, 90);
  322. }
  323. }
  324. }
  325. }
  326.  
  327. case JAIL:{
  328. if (!IsOnJail[id]) {
  329. IsOnJail[id] = true;
  330. if (HAS_GET_OUT_OF_JAIL(id)) {
  331. client_print(id, print_chat, "%L", id, "LOST_GET_OUT_OF_JAIL");
  332. entity_set_vector(id, EV_VEC_angles, Float:{0.0, 270.0, 0.0});
  333. entity_set_int(id, EV_INT_fixangle, 1);
  334. entity_set_origin(id, Float:{-405.0, 2900.0,720.0});
  335. SET_GET_OUT_OF_JAIL(id, false);
  336. }
  337. AnnounceJailEnter(id);
  338. }
  339. }
  340. }
  341. LastTouch[id][location] = gametime + 1.0;
  342. }
  343. }
  344.  
  345. public FwdPlayerSpawn(id) {
  346. if(!is_user_alive(id))
  347. return HAM_IGNORED;
  348.  
  349. for (new i = 0; i < sizeof(LastTouch[]); ++i) {
  350. LastTouch[id][i] = 0.0;
  351. }
  352. IsOnMario[id] = false;
  353. IsOnJail[id] = false;
  354.  
  355. if (!HAS_M3_AND_M4(id)) {
  356. if (M3AndM4[id][M3] > 0)
  357. remove_entity(M3AndM4[id][M3]);
  358. if (M3AndM4[id][M4] > 0)
  359. remove_entity(M3AndM4[id][M4]);
  360. }
  361.  
  362. if (!HAS_EXTRA_ARMOR(id) && get_user_armor(id) > 100) {
  363. new CsArmorType:armorType;
  364. cs_get_user_armor(id, armorType);
  365. cs_set_user_armor(id, 100, armorType);
  366. }
  367.  
  368. return HAM_HANDLED;
  369. }
  370.  
  371. /////////////////////////////////////////////////////////////////////////////////////////
  372. /////////////////////////////////////////////////////////////////////////////////////////
  373. // COMMANDS
  374.  
  375. public ShowShopMenu(id) {
  376. if (!IsOnMario[id]) {
  377. client_print(id, print_chat, "%L", id, "NOT_ON_MARIO");
  378. return PLUGIN_HANDLED;
  379. }
  380.  
  381. new menuStr[50]; // used by macro, do NOT rename or delete
  382. ML("MENU_TITLE");
  383.  
  384. new menu = menu_create(menuStr, "ShopMenuHandler");
  385.  
  386. new const mlPrefix[] = "MENU_ITEM_";
  387. new mlKey[12], nbToStr[2];
  388.  
  389. for(new i = 1; i <= MAX_MENU_ITEMS; ++i) {
  390. copy(mlKey, charsmax(mlKey), mlPrefix);
  391. num_to_str(i, nbToStr, charsmax(nbToStr));
  392. add(mlKey, charsmax(mlKey), nbToStr);
  393.  
  394. ML(mlKey);
  395. menu_additem(menu, menuStr, nbToStr);
  396. }
  397.  
  398. menu_setprop(menu, MPROP_EXIT, 0);
  399.  
  400. menu_display(id, menu);
  401.  
  402. return PLUGIN_HANDLED;
  403. }
  404.  
  405. /////////////////////////////////////////////////////////////////////////////////////////
  406. /////////////////////////////////////////////////////////////////////////////////////////
  407. // PUBLIC FUNCTIONS
  408.  
  409. public ShopMenuHandler(id, menu, item) {
  410. if (item == MENU_EXIT) {
  411. menu_destroy(menu);
  412. return;
  413. }
  414.  
  415. new data[3], name[64], access, callback;
  416. menu_item_getinfo(menu, item, access, data, charsmax(data), name, charsmax(name), callback);
  417. new key = str_to_num(data);
  418.  
  419. new cost;
  420. cost = COST[key-1];
  421.  
  422. if (UserItems[id] & (1 << key-1)) {
  423. client_print(id, print_chat, "%L", id, "CANT_BUY_ITEM");
  424. return;
  425. }
  426.  
  427. switch (key) {
  428. case 1: { // Get Out of Jail
  429. if(CheckAndSubtractUserMoney(id, cost)) {
  430. SET_GET_OUT_OF_JAIL(id, true);
  431. client_print(id, print_chat, "%L", id, "GET_OUT_OF_JAIL");
  432. }
  433. }
  434.  
  435. case 2: { // Health Reload
  436. if (CheckAndSubtractUserMoney(id, cost)) {
  437. set_user_health(id, 100);
  438. client_print(id, print_chat, "%L", id, "HEALTH_RELOAD");
  439. }
  440. }
  441.  
  442. case 3: { // Extra Armor
  443. if (CheckAndSubtractUserMoney(id, cost)) {
  444. SET_EXTRA_ARMOR(id, true);
  445.  
  446. new CsArmorType:armorType;
  447. cs_get_user_armor(id, armorType);
  448. if (armorType != CS_ARMOR_NONE)
  449. cs_set_user_armor(id, 150, armorType);
  450.  
  451. UserRoundStart[id][EXTRA_ARMOR] = RoundCount;
  452. client_print(id, print_chat, "%L", id, "EXTRA_ARMOR");
  453. }
  454. }
  455.  
  456. case 4: { // M3 and M4
  457. if (CheckAndSubtractUserMoney(id, cost)) {
  458. SET_M3_AND_M4(id, true);
  459.  
  460. if ((M3AndM4[id][M3] = give_item(id, "weapon_m3"))) {
  461. cs_set_user_bpammo(id, CSW_M3, 32);
  462. }
  463. if ((M3AndM4[id][M4] = give_item(id, "weapon_m4a1"))) {
  464. cs_set_user_bpammo(id, CSW_M4A1, 90);
  465. }
  466.  
  467. UserRoundStart[id][M3_AND_M4] = RoundCount;
  468.  
  469. client_print(id, print_chat, "%L", id, "M3_AND_M4");
  470. }
  471. }
  472.  
  473. case 5: { // Eye of the Spy
  474. if (CheckAndSubtractUserMoney(id, cost)) {
  475. SET_EYE_OF_THE_SPY(id, true);
  476. UserRoundStart[id][EYE_OF_THE_SPY] = RoundCount;
  477. client_print(id, print_chat, "%L", id, "EYE_OF_THE_SPY");
  478. }
  479. }
  480.  
  481. case 6: { // Save
  482. if (CheckAndSubtractUserMoney(id, cost)) {
  483. SaveUserItems(id);
  484. client_print(id, print_chat, "%L", id, "SAVE");
  485. }
  486. }
  487. }
  488.  
  489. menu_destroy(menu);
  490. return;
  491. }
  492.  
  493. /////////////////////////////////////////////////////////////////////////////////////////
  494. /////////////////////////////////////////////////////////////////////////////////////////
  495. // PRIVATE FUNCTIONS
  496.  
  497. AnnounceJailEnter(id) {
  498. for (new i = 1; i < MaxPlayers; i++) {
  499. if (i == id) continue;
  500.  
  501. if (HAS_EYE_OF_THE_SPY(i)) {
  502. new name[32];
  503. get_user_name(id, name, charsmax(name));
  504. ColorChat(i, (cs_get_user_team(id) == CS_TEAM_CT ? BLUE : RED), "%L", id, "PLAYER_ON_JAIL", name);
  505. }
  506. }
  507. }
  508.  
  509. CheckAndSubtractUserMoney(id, money) {
  510. new m = cs_get_user_money(id);
  511. if (m < money) {
  512. client_print(id, print_center, "%L", id, "NOT_ENOUGH_MONEY");
  513. return 0;
  514. }
  515. cs_set_user_money(id, m-money);
  516. return 1;
  517. }
  518.  
  519. SaveUserItems(id) {
  520. new vault = nvault_open("ski_2_shop");
  521.  
  522. new value[100], i, tmpStr[10];
  523.  
  524. format(value, charsmax(value), "%d", UserItems[id]);
  525.  
  526. add(value, charsmax(value), "#");
  527.  
  528. for (i = 0; i < sizeof(UserRoundStart[]); ++i) {
  529. num_to_str(UserRoundStart[id][i], tmpStr, charsmax(tmpStr));
  530. add(value, charsmax(value), tmpStr);
  531. if (i < sizeof(UserRoundStart[])-1) add(value, charsmax(value), "-");
  532. }
  533.  
  534. nvault_set(vault, UserIPs[id], value);
  535.  
  536. nvault_close(vault);
  537. return 0;
  538. }
  539.  
  540. LoadUserItems(id) {
  541. new vault = nvault_open("ski_2_shop");
  542.  
  543. new value[100], timestamp, i, j, tmpStr[30], tmpStr2[30];
  544.  
  545. if (!nvault_lookup(vault, UserIPs[id], value, charsmax(value), timestamp))
  546. return -1;
  547.  
  548. strtok(value, tmpStr, charsmax(tmpStr), tmpStr2, charsmax(tmpStr2), '#');
  549.  
  550. UserItems[id] = str_to_num(tmpStr);
  551.  
  552. for (i += 2; i < strlen(value); ++i) {
  553. strtok(value[i], tmpStr, charsmax(tmpStr), tmpStr2, charsmax(tmpStr2), '-');
  554. UserRoundStart[id][j] = str_to_num(tmpStr);
  555. i += strlen(tmpStr)+2;
  556. }
  557.  
  558. nvault_remove(vault, UserIPs[id]);
  559. nvault_close(vault);
  560. return 0;
  561. }
  562.  
  563. // took from surf_ski_2 ruleswatcher by xPaw
  564. CreateTrigger( iType, Float:flMins[ 3 ], Float:flMaxs[ 3 ] ) {
  565. new iEntity = create_entity( "info_target" );
  566.  
  567. if( !is_valid_ent( iEntity ) ) {
  568. return 0;
  569. }
  570.  
  571. entity_set_string( iEntity, EV_SZ_classname, Classname );
  572. entity_set_int( iEntity, EV_INT_iuser1, iType );
  573. entity_set_int( iEntity, EV_INT_movetype, MOVETYPE_FLY );
  574. entity_set_int( iEntity, EV_INT_solid, SOLID_TRIGGER );
  575. entity_set_size( iEntity, flMins, flMaxs );
  576.  
  577. return iEntity;
  578. }
  579.  
  580. CacheCvars() {
  581. for (new i = 0; i < (sizeof(CVARS)-1)/2; i++) {
  582. COST[i] = get_pcvar_num(CVARS[i][cvPtr]);
  583. DURATION[i][duration] = get_pcvar_num(CVARS[i+1][cvPtr]);
  584. }
  585. }
  586.  
  587. /////////////////////////////////////////////////////////////////////////////////////////
  588. /////////////////////////////////////////////////////////////////////////////////////////
  589. // COLORCHAT FUNCTIONS
  590.  
  591. ColorChat(id, Color:type, const msg[], {Float,Sql,Result,_}:...) {
  592. if( !get_playersnum() ) return;
  593.  
  594. new message[256];
  595.  
  596. switch(type) {
  597. case NORMAL: { // clients scr_concolor cvar color
  598. message[0] = 0x01;
  599. }
  600. case GREEN: { // Green
  601. message[0] = 0x04;
  602. }
  603. default: {// White, Red, Blue
  604. message[0] = 0x03;
  605. }
  606. }
  607.  
  608. vformat(message[1], 251, msg, 4);
  609.  
  610. // Make sure message is not longer than 192 character. Will crash the server.
  611. message[192] = '^0';
  612.  
  613. new team, ColorChange, index, MSG_Type;
  614.  
  615. if(id) {
  616. MSG_Type = MSG_ONE;
  617. index = id;
  618. } else {
  619. index = FindPlayer();
  620. MSG_Type = MSG_ALL;
  621. }
  622.  
  623. team = get_user_team(index);
  624. ColorChange = ColorSelection(index, MSG_Type, type);
  625.  
  626. ShowColorMessage(index, MSG_Type, message);
  627.  
  628. if(ColorChange) {
  629. Team_Info(index, MSG_Type, TeamName[team]);
  630. }
  631. }
  632.  
  633. ShowColorMessage(id, type, message[]) {
  634. static bool:saytext_used;
  635. static get_user_msgid_saytext;
  636. if(!saytext_used)
  637. {
  638. get_user_msgid_saytext = get_user_msgid("SayText");
  639. saytext_used = true;
  640. }
  641. message_begin(type, get_user_msgid_saytext, _, id);
  642. write_byte(id);
  643. write_string(message);
  644. message_end();
  645. }
  646.  
  647. Team_Info(id, type, team[]) {
  648. static bool:teaminfo_used;
  649. static get_user_msgid_teaminfo;
  650. if(!teaminfo_used) {
  651. get_user_msgid_teaminfo = get_user_msgid("TeamInfo");
  652. teaminfo_used = true;
  653. }
  654. message_begin(type, get_user_msgid_teaminfo, _, id);
  655. write_byte(id);
  656. write_string(team);
  657. message_end();
  658.  
  659. return 1;
  660. }
  661.  
  662. ColorSelection(index, type, Color:Type) {
  663. switch(Type) {
  664. case RED: {
  665. return Team_Info(index, type, TeamName[1]);
  666. }
  667. case BLUE: {
  668. return Team_Info(index, type, TeamName[2]);
  669. }
  670. case GREY: {
  671. return Team_Info(index, type, TeamName[0]);
  672. }
  673. }
  674.  
  675. return 0;
  676. }
  677.  
  678. FindPlayer() {
  679. new i = -1;
  680.  
  681. while(i <= get_maxplayers()) {
  682. if(is_user_connected(++i))
  683. return i;
  684. }
  685.  
  686. return -1;
  687. }