Advertisement
raizo21

Knife Duel [Invisible Arena]

May 12th, 2022
2,023
0
Never
2
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 82.63 KB | None | 0 0
  1. /* Plugin generated by AMXX-Studio */
  2.  
  3. #include <amxmodx>
  4. #include <amxmisc>
  5. #include <cstrike>
  6. #include <hamsandwich>
  7. #include <fakemeta>
  8. #include <fun>
  9. #include <engine>
  10. #include <xs>
  11. #include <fun>
  12. #include <fvault>
  13.  
  14.  
  15. #pragma tabsize 0
  16. #pragma compress 1
  17.  
  18. #define CHAT_TAG "^3[^4KnifeDuels^3]^1 " // add a space right after if you want one between the tag and the messages
  19.  
  20. #define DUEL_COMMAND "/duel" // this is the word used to start duel
  21. #define TOGGLE_COMMAND "/offduel" // this is the word used to go online or offline
  22. #define GIVEUP_COMMAND "/giveup" // this is the word used to end the duel
  23.  
  24. #define ARENA_ENT_NAME "entity_arena" // this is the arena's entity name
  25.  
  26. // here you can set the maximum number of arenas that can be used ingame
  27. #define MAX_ARENAS 4
  28.  
  29.  
  30. new const arena_names[][] = {
  31.     "",
  32.     "A",    
  33.     "B",    
  34.     "C",     
  35.     "D"
  36. }
  37.  
  38. // some arena codes...
  39. #define ARENA_CODE 305924
  40. #define FAKE_CODE 6969696969
  41. #define CENTER_CODE 9696969696
  42. #define EXTRA_CODE 911911911
  43.  
  44. // task code for advert
  45. #define TASK_AD 34585029
  46.  
  47. // some movement defines
  48. #define MOVE_UP 0
  49. #define MOVE_DOWN 1
  50. #define MOVE_RIGHT 2
  51. #define MOVE_LEFT 3
  52. #define MOVE_FRONT 4
  53. #define MOVE_BACK 5
  54.  
  55. // Arena ground size
  56. #define ARENA_MINS Float:{-380.0, -250.0, -10.0}
  57. #define ARENA_MAXS Float:{380.0, 250.0, 1.0}
  58.  
  59. #define BRIDGE_MINS Float:{-350.0, -10.0, 0.0}
  60. #define BRITGE_MAXS Float:{350.0, 10.0, 10.0}
  61.  
  62. #define BOX_MINS Float:{-35.0, -35.0, -40.0}
  63. #define BOX_MAXS Float:{35.0, 35.0, 40.0}
  64.  
  65. // arena coords offcourse, this is used to build the arena.
  66. new const Float:ARENA_COORDS[][2] = {
  67.     {0.0,0.0}
  68. }
  69.  
  70. new const Float:BOX_COORDS[][2] = {
  71.     {130.0,0.0},
  72.     {-130.0,0.0},
  73.     {130.0,100.0},
  74.     {-130.0,-100.0},
  75.     {130.0,-100.0},
  76.     {-130.0,100.0}
  77.    
  78. }
  79.  
  80. enum {
  81.     BLUE_SIDE = 0,
  82.     RED_SIDE = 1,
  83.     LEFT_SIDE = 2,
  84.     RIGHT_SIDE = 3,
  85.     TOP_SIDE = 4
  86. }
  87.  
  88. new const ARENA_FILE[] = "%s/duel_arena/%s.cfg"
  89.  
  90. // if you want to disable a sound, rename it with "common/null.wav"
  91. new const DUEL_SOUNDS[][] = {
  92.     "ambience/goal_1.wav",       // 0 round win
  93.     "x/nih_die2.wav",       // 1 round lose
  94.     "ambience/des_wind1.wav",   // 2 round draw
  95.     "buttons/bell1.wav",         // 3 round start
  96.     "buttons/blip1.wav" ,    // 4 accepted duel
  97.     "common/null.wav"// 5 Countdown
  98.     "common/null.wav"   // 6 "Go!"
  99. }
  100.  
  101. new const ARENA_MODELS[][] = {
  102.     "models/Duel/Duel_Platform.mdl", // Arena's ground
  103.     "models/Duel/Duel_Platform.mdl" // Arena's walls
  104. }
  105.  
  106. new const BRIDGE_MODELS[][] =
  107. {
  108.     "models/Duel/Duel_Bridge.mdl", // Arena's ground
  109.     "models/Duel/Duel_Bridge.mdl" // Arena's walls
  110. }
  111.  
  112. new const BOX_MODELS[][] = {
  113.     "models/Duel/Duel_Box.mdl", // Arena's ground
  114.     "models/Duel/Duel_Box.mdl" // Arena's walls
  115. }
  116.  
  117. new const MAP_FIX[][] = {
  118.     "ka_acer_2"
  119. }
  120.  
  121. new Float:MAP_FIX_Z_COORD[] = {
  122.     -864.253723
  123. }
  124.  
  125. new Head_shot[33][33]
  126. new fakes;
  127. new is_in_duel[33],his_countdown[33],is_frozen[33],his_challenger[33],his_asker[33],arena_number[33],his_wins[33],his_name[33][64];
  128. new rounds[MAX_ARENAS+1],Float:arena_coord[MAX_ARENAS+1][3]; // using +1 just incase...
  129. new got_spawn[33],Float:his_original_spawn[33][3];
  130. new next_empty_arena,total_arenas;
  131. new MAXPLAYERS,map_name[48]
  132. new cvar_z_fix,cvar_sounds,cvar_rounds,cvar_kills,cvar_cooldown,cvar_time;
  133. new Float:max_size[3],Float:min_size[3];
  134. new selected = 1,Float:move_size[33],his_timer[33],his_offline[33],his_HS[33];
  135. new map_default_hp;
  136. new map_id = -1;
  137. new his_previous_team[33];
  138. // using these for less cpu usage.
  139. new IS_BUGGED_MAP = 0,MAP_FIX_ENABLED,SOUNDS_ENABLED,MAX_ROUNDS,MAX_KILLS,MAX_COUNTDOWN,MAX_TIME;
  140. new Float:his_player_spawn[33][3],Float:his_player_angle[33][3];
  141.  
  142. #define P_NAME "Knife Duels"
  143. #define P_VERS "1.0"
  144. #define P_AUTH "raizo"
  145. #define P_REQ "Knife Server"
  146. new killed_forward;
  147.  
  148. /////////////////////////////////  Invisible  //////////////////////////////////////////////////////
  149. enum groups ( <<= 1 )
  150. {
  151.     GROUP_NONE,
  152.     GROUP_ENTITY = 1,
  153.     GROUP_PLAYER
  154. }
  155.  
  156. new p_Transparency
  157. new g_PlayerSolid[33]
  158. new bool:his_arena_entity[1386];
  159. new bool:his_player_arena_entity[33];
  160. new arena_selected;
  161. new prevent_bad_spawn[33];
  162. ///////////////////////////////////  Menu  ////////////////////////////////////////////////////////
  163.  
  164. #define MAX_WAYS 32
  165.  
  166. enum menu_arenas
  167. {
  168.     platform = 1,
  169.     britge
  170. }
  171.  
  172. enum menu_types
  173. {
  174.     Both = 1,
  175.     Stab,
  176.     Slash,
  177.     Headshot,
  178.     Nonstop,
  179.     Weapons
  180. }
  181.  
  182. enum principal_config
  183. {
  184.     menu_arenas:swich_arena,
  185.     menu_types:swich_types
  186. }
  187.  
  188. new principals[MAX_WAYS+1][principal_config]   
  189. new szTmp[192];
  190. new his_arena[33] = 0
  191. new his_types[33] = 0
  192.  
  193. #define Max_Weapons_Names 18
  194.  
  195.  
  196. new WeaponName[][] =
  197. {
  198.     "\r[\dNone\r]",
  199.     "\r[\yAK47\r]",
  200.     "\r[\yM4A1\r]",
  201.     "\r[\yAWP\r]",
  202.     "\r[\yDEAGLE\r]",
  203.     "\r[\ySCOUT\r]",
  204.     "\r[\yXM1014\r]",
  205.     "\r[\yMAC10\r]",
  206.     "\r[\yAUG\r]",
  207.     "\r[\yUMP45\r]",
  208.     "\r[\ySG550\r]",
  209.     "\r[\yGALIL\r]",
  210.     "\r[\yFAMAS\r]",
  211.     "\r[\yMP5 NAVY\r]",
  212.     "\r[\yM249\r]",
  213.     "\r[\yM3\r]",
  214.     "\r[\yG3SG\r]",
  215.     "\r[\ySG552\r]",
  216.     "\r[\yP90\r]"
  217. };
  218. new WeaponModel[][] =
  219. {
  220.     "weapon_knife",
  221.     "weapon_ak47",
  222.     "weapon_m4a1",
  223.     "weapon_awp",
  224.     "weapon_deagle",
  225.     "weapon_scout",
  226.     "weapon_xm1014",
  227.     "weapon_mac10",
  228.     "weapon_aug",
  229.     "weapon_ump45",
  230.     "weapon_sg550",
  231.     "weapon_galil",
  232.     "weapon_famas",
  233.     "weapon_mp5navy",
  234.     "weapon_m249",
  235.     "weapon_m3",
  236.     "weapon_g3sg1",
  237.     "weapon_sg552",
  238.     "weapon_p90"
  239. };
  240.  
  241. new Weapons_Settings[19];
  242. new display_hud
  243. new HamHook:fw_TraceAttack;
  244. new Float:fVelocity[3]
  245.  
  246. _Un_RegisterHamForwards(on = 0)
  247. {
  248. on ? EnableHamForward(fw_TraceAttack) : DisableHamForward(fw_TraceAttack);
  249. }
  250.  
  251. new bool:isBlocked[ 33 ][ 33 ]
  252.  
  253. new CSW_MAXAMMO[33]= {-2, 52, 0, 90, 1, 32, 1, 100, 90, 1, 120, 100, 100, 90, 90, 90, 100, 120, 30, 120, 200, 32, 90, 120, 90, 2, 35, 90, 90, 0, 100, -1, -1}
  254.  
  255. //////////////////////////////////////////////////////////
  256.  
  257. enum _:RankData
  258. {
  259.     Rank_Kills,
  260.     Rank_Name[ 32 ],
  261.     Rank_SteamID[ 35 ]
  262. };
  263.  
  264. new const g_szVaultName[ ] = "Knife_Duels_Rank";
  265.  
  266. new pCvar_Top;
  267. ///////////////////////////////////////////////////////////
  268.  
  269.  
  270. public plugin_init()
  271. {
  272.     register_plugin(P_NAME, P_VERS, P_AUTH)
  273.    
  274.          register_forward(FM_AddToFullPack,"ForwardAddToFullPack",1)
  275.          register_forward(FM_AddToFullPack,"ForwardAddToFullPackPost",1);
  276.          register_forward(FM_PlayerPreThink,"ForwardPlayerPreThink")
  277.          register_forward(FM_PlayerPostThink,"ForwardPlayerPostThink")
  278.          register_forward(FM_TraceLine,"ForwardTraceLine",1)
  279.          register_forward(FM_TraceHull,"ForwardTraceHull",1)
  280.          register_forward(FM_PlayerPreThink,"fw_PlayerPreThink")
  281.          register_forward(FM_CmdStart,"Rush_Non_Stop");
  282.     register_forward( FM_CmdStart , "Cmd_start" );
  283.     register_forward(FM_SetModel, "Fw_SetModel")
  284.     register_forward(FM_UpdateClientData, "block_moving", 1)
  285.    
  286.          RegisterHam(Ham_Spawn, "player", "OnCBasePlayer_Spawn_Post", true);
  287.     RegisterHam(Ham_Killed, "player", "Player_Killed")
  288.     RegisterHam(Ham_TakeDamage, "player", "Player_Take_Damage", 0)
  289.     RegisterHam(Ham_Spawn,"player","Player_spawn_post",1)
  290.          RegisterHam(Ham_TraceAttack, "player", "Ham_TraceAttack_player", 1)
  291.          RegisterHam(Ham_Player_PreThink, "player", "fwd_Player_PreThink");
  292.      
  293.     register_event("HLTV","round_start_event", "a", "1=0", "2=0")
  294.     register_event("CurWeapon", "event_curweapon", "be", "1=1")
  295.     register_touch(ARENA_ENT_NAME, "player", "forward_touch");
  296.     RegisterHam(Ham_Touch, "weaponbox", "HAM_Touch_Weapon");
  297.      
  298.     fw_TraceAttack = RegisterHam(Ham_TraceAttack, "player", "Forward_TraceAttack");
  299.     killed_forward = CreateMultiForward("duel_player_killed", ET_IGNORE, FP_CELL,FP_CELL);
  300.    
  301.     register_clcmd("say","say_hook")
  302.     register_clcmd("say_team","say_hook")
  303.     register_clcmd("say /origin","print_coords")
  304.     register_clcmd("say /kdc","Principal_Menu")
  305.    
  306.     register_clcmd("say /arena","editor_menu")
  307.  
  308.     cvar_z_fix = register_cvar("gld_z_map_fix","0")
  309.     cvar_sounds = register_cvar("gld_sounds","1")
  310.     cvar_rounds =register_cvar("gld_rounds","20")
  311.     cvar_kills =register_cvar("gld_kills","10")
  312.     cvar_cooldown = register_cvar("gld_cooldown","1")
  313.     cvar_time = register_cvar("gld_max_nokill_time","60")
  314.          p_Transparency = register_cvar("amx_duel_transparency","0")
  315.     display_hud = register_cvar("amx_hs_display", "1")
  316.    
  317.     MAXPLAYERS = get_maxplayers();
  318.  
  319.    
  320.     get_mapname(map_name,charsmax(map_name))
  321.     new size = sizeof(MAP_FIX)
  322.     for(new i; i <size;i++)
  323.     {
  324.         if(equal(map_name,MAP_FIX[i]))
  325.         {
  326.             map_id = i
  327.             IS_BUGGED_MAP = 1
  328.         }
  329.     }
  330.     if(containi(map_name,"35hp") != -1)
  331.         map_default_hp = 35
  332.     else if(containi(map_name,"1hp") != -1)
  333.         map_default_hp = 1
  334.     else map_default_hp = 100
  335.     load_arena_coords(-1)
  336.    
  337.     new cfgdir[32], urlfile[64]
  338.     get_configsdir(cfgdir, charsmax(cfgdir))
  339.     formatex(urlfile, charsmax(urlfile), "%s/duel_arena", cfgdir)
  340.     if(!dir_exists(urlfile))
  341.     {
  342.         mkdir(urlfile)
  343.         server_print("%sCreated new folder: %s",CHAT_TAG,urlfile)
  344.     }
  345.     update_cvars()
  346.    
  347.     set_task(10.0,"Advertise",TASK_AD)
  348.    
  349.  
  350.          register_srvcmd( "reset_duel_rank", "CmdReset" );
  351.    
  352.          register_clcmd( "say /drank", "CmdRank" );
  353.          register_clcmd( "say /dtop", "CmdTop" );
  354.    
  355.          RegisterHam(Ham_Killed, "player", "fw_PlayerKilled", 1);
  356.    
  357.          pCvar_Top = register_cvar( "amx_duels_top", "15" );
  358.    
  359. }
  360.  
  361. ////////////////////////////////////////////  MENU  ////////////////////////////////////////////////
  362. public Principal_Menu(id)
  363. {
  364.     new menu = menu_create("\r[\y Duel Menu \r]\w By raizo","Peincipal_Menu_Handled")
  365.  
  366.     if(is_in_duel[id] == 2)
  367.     {
  368.         client_print(id,print_chat,"You have no access to duel menu!")
  369.         return PLUGIN_HANDLED;
  370.     }
  371.        
  372.  
  373.     formatex(szTmp,charsmax(szTmp),"Select Player");
  374.     menu_additem(menu,szTmp,"1")
  375.  
  376.     if(his_types[id] == 4)
  377.     {
  378.         formatex(szTmp,charsmax(szTmp),"\wAuto Selected \r[\yBritge Arena\r]");
  379.         menu_additem(menu,szTmp,"2")    
  380.     }
  381.     else if(Weapons_Settings[id] >= 1)
  382.     {
  383.         formatex(szTmp,charsmax(szTmp),"\wAuto Selected \r[\yWeapons Arena\r]");
  384.         menu_additem(menu,szTmp,"2")    
  385.     }
  386.     else
  387.     {
  388.         formatex(szTmp,charsmax(szTmp),"Choose Arena \y%s",arenas_results(principals[id][swich_arena]));
  389.         menu_additem(menu,szTmp,"2")
  390.     }
  391.     if(his_types[id] == 5)
  392.     {
  393.         formatex(szTmp,charsmax(szTmp),"Battle Types \y%s", WeaponName[Weapons_Settings[id]]);
  394.         menu_additem(menu,szTmp,"3")
  395.     }
  396.     else
  397.     {
  398.         formatex(szTmp,charsmax(szTmp),"Battle Types \y%s", types_results(principals[id][swich_types]));
  399.         menu_additem(menu,szTmp,"3")
  400.     }
  401.    
  402.     formatex(szTmp,charsmax(szTmp),"Appear in list %s",his_offline[id] ?"\y[Enabled]":"\r[Disabled]");
  403.     menu_additem(menu,szTmp,"4")
  404.    
  405.     if(his_offline[id] == 1)
  406.     {
  407.         menu_addtext(menu, "\dYou cannot receive & send duel requests", 1);
  408.     }
  409.    
  410.     formatex(szTmp,charsmax(szTmp),"Block Player Menu");
  411.     menu_additem(menu,szTmp,"5")
  412.    
  413.     formatex(szTmp,charsmax(szTmp),"Rank & Top 15");
  414.     menu_additem(menu,szTmp,"6")
  415.    
  416.     menu_display(id,menu)
  417.  
  418.     return PLUGIN_HANDLED;
  419. }
  420.  
  421. public Peincipal_Menu_Handled(id,menu,item)
  422. {
  423.     if(item == MENU_EXIT)
  424.     {
  425.         menu_destroy(menu);
  426.  
  427.         return PLUGIN_HANDLED;
  428.     }
  429.  
  430.     new data[3], iName[64]
  431.     new access, callback;
  432.     menu_item_getinfo(menu, item, access, data,2, iName, 63, callback);
  433.     new key = str_to_num(data)
  434.  
  435.     switch(key)
  436.     {
  437.         case 1:
  438.         {
  439.             duel_players_list(id)
  440.             return PLUGIN_HANDLED;
  441.         }
  442.         case 2:
  443.         {
  444.             principals[id][swich_arena] = ( ++principals[id][swich_arena] > (menu_arenas:2) ) ? (menu_arenas:1) :principals[id][swich_arena]
  445.         }
  446.         case 3:
  447.         {
  448.             principals[id][swich_types] = ( ++principals[id][swich_types] > (menu_types:6) ) ? (menu_types:1) :principals[id][swich_types]
  449.         }
  450.         case 4:
  451.         {
  452.             toggle_offline(id)
  453.         }
  454.         case 5:
  455.         {
  456.             BlockMenu(id)
  457.        return PLUGIN_HANDLED;
  458.         }
  459.         case 6:
  460.         {
  461.             Rank_Menu(id)
  462.        return PLUGIN_HANDLED;
  463.         }
  464.     }
  465.     menu_destroy(menu);
  466.  
  467.     Principal_Menu(id)
  468.     bot(id)
  469.     return PLUGIN_HANDLED;
  470. }
  471.  
  472. public bot(id)
  473. {
  474.     if(is_user_connected(id))
  475.     {
  476.         arenas_handled(id)
  477.         types_handled(id)
  478.     }
  479. }
  480.  
  481. arenas_results(menu_arenas:part)
  482. {
  483.     new szResult[64]
  484.    
  485.     switch(part)
  486.     {
  487.         case platform:copy(szResult, charsmax(szResult), "Platform Arena");
  488.         case britge:copy(szResult, charsmax(szResult), "Britge Arena");
  489.    
  490.         default:copy(szResult, charsmax(szResult), "[Not Selected]");
  491.     }
  492.     return szResult;
  493. }
  494.  
  495.  
  496.  
  497. types_results(menu_types:part)
  498. {
  499.     new szResult[64]
  500.    
  501.     switch(part)
  502.     {
  503.         case Both:copy(szResult, charsmax(szResult), "Stab & Slash");
  504.         case Slash:copy(szResult, charsmax(szResult), "Slash");
  505.         case Stab:copy(szResult, charsmax(szResult), "Stab");
  506.         case Headshot:copy(szResult, charsmax(szResult), "Headshot");
  507.         case Nonstop:copy(szResult, charsmax(szResult), "Non Stop [Rush Arena]");
  508.         case Weapons:copy(szResult, charsmax(szResult), "Weapons Arena");
  509.    
  510.         default:copy(szResult, charsmax(szResult), "[Not Selected]");
  511.     }
  512.     return szResult;
  513. }
  514.  
  515.  
  516.  
  517. types_handled(id)
  518. {
  519.     switch(principals[id][swich_arena])
  520.     {
  521.         case platform:
  522.         {
  523.             his_arena[id] = 0
  524.         }
  525.         case britge:
  526.         {
  527.             his_arena[id] = 1
  528.         }
  529.     }
  530.     return 0;
  531. }
  532.  
  533. arenas_handled(id)
  534. {
  535.     switch(principals[id][swich_types])
  536.     {
  537.         case Both:
  538.         {
  539.             his_types[id] = 0;
  540.        Weapons_Settings[id] = 0;
  541.         }
  542.         case Stab:
  543.         {
  544.             his_types[id] = 2;
  545.        Weapons_Settings[id] = 0;
  546.         }
  547.         case Slash:
  548.         {
  549.             his_types[id] = 1;
  550.        Weapons_Settings[id] = 0;
  551.         }
  552.         case Headshot:
  553.         {
  554.             his_types[id] = 3;
  555.        Weapons_Settings[id] = 0;
  556.             _Un_RegisterHamForwards(display_hud);
  557.         }
  558.         case Nonstop:
  559.         {
  560.             his_types[id] = 4;
  561.        his_arena[id] = 1;
  562.        Weapons_Settings[id] = 0;
  563.         }
  564.         case Weapons:
  565.         {
  566.             his_types[id] = 5;
  567.        KDC_WEAPONS_MENU(id)
  568.        //return PLUGIN_HANDLED;
  569.         }
  570.     }
  571.     return 0;
  572. }
  573.  
  574.  
  575.  
  576.  
  577. public KDC_WEAPONS_MENU(id)
  578. {
  579.     Weapons_Settings[id] = 0;
  580.    
  581.     new menu = menu_create("\y[\r Weapons Menu \y]\w By raizo", "KDC_WEAPONS_MENU_HANDLED");
  582.  
  583.     for( new i = 0 ; i <= Max_Weapons_Names ; i++ )
  584.  
  585.     menu_additem( menu, WeaponName[ i ]);
  586.  
  587.     menu_display(id, menu, 0 );
  588. }
  589.  
  590. public KDC_WEAPONS_MENU_HANDLED(id, menu, item)
  591. {
  592.     Weapons_Settings[id] = item;
  593.    
  594.     KDC_SET_WEAPON_MODEL(id);
  595. }
  596.  
  597. public KDC_SET_WEAPON_MODEL(id)
  598. {
  599.     if (is_user_alive(id))
  600.     {
  601.         if (!equal(WeaponModel[Weapons_Settings[id]], ""))
  602.         {
  603.             //client_print(id, 3, "You selected %s !", WeaponModel[Weapons_Settings[id]]);
  604.        his_arena[id] = 2;
  605.         }
  606.     }
  607.     Principal_Menu(id)
  608. }
  609.  
  610.  
  611.  
  612. ////////////////////////////////////////////////////////////////////////////////////////////////////
  613.  
  614. public plugin_natives()
  615. {
  616.     register_library("knife_duels")
  617.     register_native("is_user_in_duel","_is_user_in_duel")
  618.     register_native("is_user_dueling_user","_is_user_dueling_user")
  619. }
  620.  
  621. public get_non_duelers_alive()
  622. {
  623.     new count = 0
  624.     for(new id; id < MAXPLAYERS;id++)
  625.     {
  626.         if(is_user_connected(id))
  627.         {
  628.             if(is_user_alive(id) && !is_in_duel[id])
  629.             {
  630.                 count++
  631.             }
  632.         }
  633.     }
  634.     return count
  635. }
  636.  
  637. public _is_user_in_duel(plugin, iParams)
  638. {
  639.     new id = get_param(1)
  640.     if(!is_user_connected(id))
  641.         return PLUGIN_CONTINUE
  642.     if(is_in_duel[id] == 2)
  643.         return PLUGIN_HANDLED
  644.     return PLUGIN_CONTINUE
  645. }
  646.  
  647. public _is_user_dueling_user(plugin, iParams)
  648. {
  649.     new id = get_param(1)
  650.     new enemy = get_param(2)
  651.     if(!is_user_connected(id))
  652.         return PLUGIN_CONTINUE
  653.     if(!is_user_connected(enemy))
  654.         return PLUGIN_CONTINUE
  655.     if(is_in_duel[id] != 2 || is_in_duel[enemy] != 2)
  656.         return PLUGIN_CONTINUE
  657.     if(id == his_challenger[enemy] && enemy == his_challenger[id])
  658.         return PLUGIN_HANDLED
  659.     return PLUGIN_CONTINUE
  660. }
  661.  
  662. public forward_touch(ent, id)
  663. {
  664.     if(!pev_valid(id))
  665.         return;
  666.     if(!pev_valid(ent))
  667.         return;
  668.     if(is_user_alive(id) && get_user_noclip(id))
  669.         return;
  670.     static class[32]
  671.     pev(ent,pev_classname,class,charsmax(class));
  672.     if(equal(class,ARENA_ENT_NAME))
  673.     {
  674.         if(is_user_alive(id))
  675.         {
  676.             if(is_player_stuck(id) && is_in_duel[id] != 2)
  677.             {
  678.                 back_to_the_spawn(id)
  679.             }
  680.         }
  681.        
  682.     }
  683.     return;
  684. }
  685.  
  686. public Ham_TraceAttack_player(victim, attacker, Float:Damage, Float:Direction[3], ptr, Damagebits)
  687. {
  688.     if(is_user_connected(attacker) && is_user_connected(victim))
  689.     {
  690.         Head_shot[attacker][victim] = bool:( get_tr2(ptr, TR_iHitgroup) == 1 )
  691.     }
  692. }
  693.  
  694. public editor_menu(id)
  695. {
  696.     if(!is_user_connected(id))
  697.         return PLUGIN_HANDLED
  698.     new flags = get_user_flags(id)
  699.     if(!(flags & ADMIN_RCON))
  700.     {
  701.         client_print(id,print_chat,"You have no access to this command")
  702.         return PLUGIN_HANDLED
  703.     }
  704.    
  705.     arena_selected = 0;
  706.    
  707.     new menu
  708.     menu = menu_create( "\rArena spawner:", "Arenaspawner_handler" );
  709.    
  710.     new nameu[32];
  711.    
  712.     formatex(nameu,charsmax(nameu), "Add");
  713.     menu_additem(menu, nameu, "", 0);
  714.     formatex(nameu,charsmax(nameu), "Remove");
  715.     menu_additem(menu, nameu, "", 0);
  716.     formatex(nameu,charsmax(nameu), "Remove all");
  717.     menu_additem(menu, nameu, "", 0);
  718.     formatex(nameu,charsmax(nameu), "Select");
  719.     menu_additem(menu, nameu, "", 0);
  720.     formatex(nameu,charsmax(nameu), "Select all");
  721.     menu_additem(menu, nameu, "", 0);
  722.     formatex(nameu,charsmax(nameu), "Move");
  723.     menu_additem(menu, nameu, "", 0);
  724.     formatex(nameu,charsmax(nameu), "Save");
  725.     menu_additem(menu, nameu, "", 0);
  726.     formatex(nameu,charsmax(nameu), "Load");
  727.     menu_additem(menu, nameu, "", 0);
  728.     menu_display(id, menu, 0 );
  729.     return PLUGIN_HANDLED
  730. }
  731.  
  732. public Arenaspawner_handler( id, menu, item )
  733. {
  734.     if ( item == MENU_EXIT )
  735.     {
  736.         menu_destroy( menu );
  737.         remove_the_fake_arena()
  738.         arena_selected = 1;
  739.         return PLUGIN_HANDLED;
  740.     }
  741.    
  742.     new szData[6], szName[64];
  743.     new _access, item_callback;
  744.     menu_item_getinfo( menu, item, _access, szData,charsmax( szData ), szName,charsmax( szName ), item_callback );
  745.     new arenas_found;
  746.     arenas_found = fakes_count()
  747.     if(equali(szName,"Add"))
  748.     {
  749.         if(next_fake_arena() != -1)
  750.         {
  751.             start_fake_build(id,-1)
  752.             if(fakes_count())
  753.             {
  754.                 if(selected > MAX_ARENAS || selected == -1)
  755.                 {
  756.                     selected = 1
  757.                     select_the_fake_arena(EXTRA_CODE+selected)
  758.                 }
  759.             }
  760.         } else client_print_color(id,"%s ^3Maximum arenas reached.^1",CHAT_TAG)
  761.     }
  762.     else if(equali(szName,"Remove"))
  763.     {
  764.         if(fakes_count())
  765.         {
  766.             if(selected > MAX_ARENAS || selected == -1)
  767.                 selected = 1
  768.             delete_the_fake_arena(EXTRA_CODE+selected)
  769.             if(fakes_count())
  770.                 next_selection()
  771.         } else client_print_color(id, "%s ^3No arenas found.",CHAT_TAG)
  772.     }
  773.     else if(equali(szName,"Remove all"))
  774.     {
  775.         //remove_menu(id)
  776.         remove_the_fake_arena()
  777.         client_print_color(id, "%s ^3All arenas removed.",CHAT_TAG)
  778.     }
  779.     else if(equali(szName,"Select"))
  780.     {
  781.         if(fakes_count())
  782.         {
  783.             next_selection()
  784.         } else client_print_color(id, "%s ^3No arenas found.",CHAT_TAG)
  785.     }
  786.     else if(equali(szName,"Select all"))
  787.     {
  788.         if(fakes_count())
  789.         {
  790.             selected = -1
  791.             select_the_fake_arena(EXTRA_CODE+selected)
  792.         } else client_print_color(id, "%s ^3No arenas found.",CHAT_TAG)
  793.     }
  794.     else if(equali(szName,"Move"))
  795.     {
  796.         if(fakes_count())
  797.         {
  798.             if(selected > MAX_ARENAS)
  799.                 selected = 1
  800.             select_the_fake_arena(EXTRA_CODE+selected)
  801.             menu_destroy( menu );
  802.             move_menu(id,EXTRA_CODE+selected)
  803.             return PLUGIN_CONTINUE;
  804.         }
  805.         else client_print_color(id, "%s ^3No arenas found.",CHAT_TAG)
  806.     }
  807.     else if(equali(szName,"Load"))
  808.     {
  809.         remove_the_fake_arena()
  810.         load_arena_coords(id)
  811.         //client_print_color(id, "%s ^3Arena coords loaded.",CHAT_TAG)
  812.         set_task(0.1,"delay_build",id)
  813.     }
  814.     else if(equali(szName,"Save"))
  815.     {
  816.         if(fakes_count())
  817.         {
  818.             save_arena_coords(id)
  819.             remove_the_fake_arena()
  820.             load_arena_coords(id)
  821.         }
  822.         else
  823.         {
  824.             client_print_color(id, "%s ^3No arenas found.",CHAT_TAG)
  825.         }
  826.     }
  827.     if(!arenas_found && fakes_count())
  828.     {
  829.         next_selection()
  830.     }
  831.     menu_destroy( menu );
  832.     editor_menu(id)
  833.     set_pev(id, pev_groupinfo, GROUP_ENTITY | GROUP_PLAYER);
  834.     return PLUGIN_CONTINUE;
  835. }
  836.  
  837. stock next_selection()
  838. {
  839.     if(selected == -1)
  840.     {
  841.         selected = 1
  842.     }
  843.     new size = MAX_ARENAS*3
  844.     for(new slct=0;slct < size;slct++)
  845.     {
  846.         selected++
  847.         if(selected > MAX_ARENAS)
  848.             selected = 1
  849.         if(fake_arena_exists(selected))
  850.         {
  851.             select_the_fake_arena(EXTRA_CODE+selected)
  852.             return;
  853.         }
  854.     }
  855. }
  856.  
  857. public fake_arena_exists(code)
  858. {
  859.     new arenas_ent = -1
  860.     new code_ent
  861.     while((arenas_ent=engfunc(EngFunc_FindEntityByString,arenas_ent,"classname",ARENA_ENT_NAME)))
  862.     {
  863.         if(entity_get_int(arenas_ent,EV_INT_iuser2) == CENTER_CODE && entity_get_int(arenas_ent,EV_INT_iuser1) == FAKE_CODE)
  864.         {
  865.             code_ent = entity_get_int(arenas_ent,EV_INT_iuser3)-EXTRA_CODE
  866.             if(code_ent == code)
  867.             {
  868.                 return PLUGIN_HANDLED
  869.             }
  870.         }
  871.     }
  872.     return PLUGIN_CONTINUE
  873. }
  874.  
  875. public fakes_count()
  876. {
  877.     new arenas_ent = -1
  878.     new found = 0
  879.     while((arenas_ent=engfunc(EngFunc_FindEntityByString,arenas_ent,"classname",ARENA_ENT_NAME)))
  880.     {
  881.         if(entity_get_int(arenas_ent,EV_INT_iuser2) == CENTER_CODE && entity_get_int(arenas_ent,EV_INT_iuser1) == FAKE_CODE)
  882.         {
  883.             found++
  884.         }
  885.     }
  886.     return found
  887. }
  888.  
  889. public arenas_count()
  890. {
  891.     new found = 0
  892.     for(new id;id < MAXPLAYERS;id++)
  893.     {
  894.         if(is_user_connected(id))
  895.         {
  896.             if(is_in_duel[id] == 2)
  897.                 found++
  898.         }
  899.     }
  900.     return found/2
  901. }
  902.  
  903. public delay_build(id)
  904. {
  905.     for(new i=1;i < total_arenas+1;i++)
  906.     {
  907.         start_fake_build(id,i)
  908.     }
  909.     if(fakes_count())
  910.     {
  911.         next_selection()
  912.     }
  913. }
  914. public move_menu(id,code)
  915. {
  916.     new menu
  917.     menu = menu_create( "\rMove arena:", "move_handler" );
  918.    
  919.     new nameu[32];
  920.     new code_t[32];
  921.     num_to_str(code,code_t,charsmax(code_t))
  922.     formatex(nameu,charsmax(nameu), "Move up");
  923.     menu_additem(menu, nameu, code_t, 0);
  924.    
  925.     formatex(nameu,charsmax(nameu), "Move down");
  926.     menu_additem(menu, nameu, code_t, 0);
  927.    
  928.     formatex(nameu,charsmax(nameu), "Move front");
  929.     menu_additem(menu, nameu, code_t, 0);
  930.    
  931.     formatex(nameu,charsmax(nameu), "Move back");
  932.     menu_additem(menu, nameu, code_t, 0);
  933.    
  934.     formatex(nameu,charsmax(nameu), "Move right");
  935.     menu_additem(menu, nameu, code_t, 0);
  936.    
  937.     formatex(nameu,charsmax(nameu), "Move left");
  938.     menu_additem(menu, nameu, code_t, 0);
  939.    
  940.     formatex(nameu,charsmax(nameu), "Remove the arena");
  941.     menu_additem(menu, nameu, code_t, 0);
  942.    
  943.     formatex(nameu,charsmax(nameu), "Move size: %.2f",move_size[id]);
  944.     menu_additem(menu, nameu, code_t, 0);
  945.     menu_display(id, menu, 0 );
  946.     return PLUGIN_HANDLED
  947. }
  948.  
  949. public move_handler( id, menu, item )
  950. {
  951.     if ( item == MENU_EXIT )
  952.     {
  953.         menu_destroy( menu );
  954.         set_task(0.1,"editor_menu",id)
  955.         return PLUGIN_HANDLED;
  956.     }
  957.    
  958.     new szData[32], szName[64];
  959.     new _access, item_callback;
  960.     menu_item_getinfo( menu, item, _access, szData,charsmax( szData ), szName,charsmax( szName ), item_callback );
  961.     new code = str_to_num(szData)
  962.     if(equali(szName,"remove the arena"))
  963.     {
  964.         delete_the_fake_arena(code)
  965.         menu_destroy( menu );
  966.         editor_menu(id)
  967.         unselect_the_fake_arena(0)
  968.         return PLUGIN_CONTINUE;
  969.     }
  970.     else if(containi(szName,"move size:") != -1)
  971.     {
  972.         move_size[id]+= 10.0
  973.         if(move_size[id] > 100.0)
  974.         {
  975.             move_size[id] = 10.0
  976.         }
  977.     }
  978.     else if(equali(szName,"move up"))
  979.     {
  980.         move_the_fake_arena(id,code,MOVE_UP)
  981.     }
  982.     else if(equali(szName,"move down"))
  983.     {
  984.         move_the_fake_arena(id,code,MOVE_DOWN)
  985.     }
  986.     else if(equali(szName,"move right"))
  987.     {
  988.         move_the_fake_arena(id,code,MOVE_RIGHT)
  989.     }
  990.     else if(equali(szName,"move left"))
  991.     {
  992.         move_the_fake_arena(id,code,MOVE_LEFT)
  993.     }
  994.     else if(equali(szName,"move front"))
  995.     {
  996.         move_the_fake_arena(id,code,MOVE_FRONT)
  997.     }
  998.     else if(equali(szName,"move back"))
  999.     {
  1000.         move_the_fake_arena(id,code,MOVE_BACK)
  1001.     }
  1002.     menu_destroy( menu );
  1003.     move_menu(id,code)
  1004.    
  1005.     return PLUGIN_CONTINUE;
  1006. }
  1007.  
  1008. public save_arena_coords(id)
  1009. {
  1010.     new found;
  1011.     new cfgdir[32], mapname[32], urlfile[64]
  1012.     get_configsdir(cfgdir, charsmax(cfgdir))
  1013.     get_mapname(mapname, charsmax(mapname))
  1014.     formatex(urlfile, charsmax(urlfile), ARENA_FILE, cfgdir, mapname)
  1015.  
  1016.     if (file_exists(urlfile))
  1017.         delete_file(urlfile)
  1018.    
  1019.     new lineset[128]
  1020.     new Float:origin[3]
  1021.     new arenas_ent=-1;
  1022.     while((arenas_ent=engfunc(EngFunc_FindEntityByString,arenas_ent,"classname",ARENA_ENT_NAME)))
  1023.     {
  1024.         if(entity_get_int(arenas_ent,EV_INT_iuser2) == CENTER_CODE && entity_get_int(arenas_ent,EV_INT_iuser1) == FAKE_CODE)
  1025.         {
  1026.             found++
  1027.             pev(arenas_ent,pev_origin,origin);
  1028.             format(lineset, charsmax(lineset), "%.f %.f %.f", origin[0], origin[1], origin[2])
  1029.             write_file(urlfile, lineset,found)
  1030.            
  1031.         }
  1032.     }
  1033.     if(!found)
  1034.         client_print_color(id, "%s Couldn't save:^3No arenas found.",CHAT_TAG)
  1035.     else client_print_color(id, "%s %d ^3Arena coords saved.",CHAT_TAG,found)
  1036. }
  1037.  
  1038. public print_coords(id)
  1039. {
  1040.     new Float:coord[3]
  1041.     pev(id,pev_origin,coord);
  1042.     client_print_color(id, "origin: ^3%.f %.f %.f",coord[0],coord[1],coord[2])
  1043.     return PLUGIN_HANDLED
  1044. }
  1045.  
  1046. public start_fake_build(id,zecode)
  1047. {
  1048.     if(!is_user_connected(id))
  1049.         return PLUGIN_HANDLED
  1050.     new ext_code
  1051.     if(zecode == -1)
  1052.     {
  1053.         ext_code = next_fake_arena()
  1054.         if(ext_code == -1)
  1055.             return PLUGIN_HANDLED
  1056.     }
  1057.     else
  1058.         ext_code = zecode
  1059.     ext_code+=EXTRA_CODE
  1060.     static Float:origin[3];
  1061.     if(zecode == -1)
  1062.         get_user_hitpoint(id,origin)
  1063.     else
  1064.     {
  1065.         origin[0]=arena_coord[zecode][0]
  1066.         origin[1]=arena_coord[zecode][1]
  1067.         origin[2]=arena_coord[zecode][2]
  1068.     }
  1069.    
  1070.     /*origin[0] = 1002.911376
  1071.     origin[1] = -1561.421997
  1072.     origin[2] = 0.0*/
  1073.     new Float:fake_origin[3]
  1074.     static size
  1075.     size = sizeof(ARENA_COORDS)
  1076.     new ent_code = FAKE_CODE
  1077.     fakes++
  1078.     for(new coords;coords < size; coords++)
  1079.     {
  1080.         fake_origin[0] = origin[0]
  1081.         fake_origin[1] = origin[1]
  1082.         if(bugged_map())
  1083.             fake_origin[2]= MAP_FIX_Z_COORD[map_id]
  1084.         else fake_origin[2] = origin[2]
  1085.         //fake_origin[2]=-712.876892
  1086.        
  1087.         fake_origin[0]+=ARENA_COORDS[coords][0]*1.7
  1088.         fake_origin[1]+=ARENA_COORDS[coords][1]*1.53
  1089.        
  1090.         new ent=engfunc(EngFunc_CreateNamedEntity,engfunc(EngFunc_AllocString,"func_wall"));
  1091.        
  1092.         set_pev(ent,pev_classname,ARENA_ENT_NAME);
  1093.         engfunc(EngFunc_SetModel,ent,ARENA_MODELS[0]);
  1094.         entity_set_int(ent, EV_INT_solid, SOLID_BBOX);
  1095.         engfunc(EngFunc_SetSize,ent,ARENA_MINS,ARENA_MAXS);
  1096.         entity_set_int(ent, EV_INT_movetype, MOVETYPE_NONE);
  1097.         entity_set_int(ent,EV_INT_iuser1,ent_code)
  1098.         entity_set_int(ent,EV_INT_iuser3,ext_code)
  1099.         set_pev(ent, pev_groupinfo, GROUP_ENTITY);
  1100.         engfunc(EngFunc_SetOrigin,ent,fake_origin);
  1101.         stuck_check(fake_origin,120.0)
  1102.         static Float:rvec[3];
  1103.         pev(ent,pev_v_angle,rvec);
  1104.        
  1105.         rvec[0]=0.0;
  1106.         set_pev(ent,pev_angles,rvec);
  1107.        
  1108.         if(ARENA_COORDS[coords][0] == 0.0 && ARENA_COORDS[coords][1] == 100.0)
  1109.         {
  1110.             fake_origin[0] += max_size[0]
  1111.             fake_origin[1] += max_size[1]
  1112.         }
  1113.         if(ARENA_COORDS[coords][0] == 0.0 && ARENA_COORDS[coords][1] == -100.0)
  1114.         {
  1115.             fake_origin[0] += max_size[2]
  1116.             fake_origin[1] += min_size[0]
  1117.         }
  1118.         if(ARENA_COORDS[coords][0] == 0.0 && ARENA_COORDS[coords][1] == 0.0)
  1119.         {
  1120.             entity_set_int(ent,EV_INT_iuser2,CENTER_CODE)
  1121.         }
  1122.         else if(ARENA_COORDS[coords][0] == 200.0 && ARENA_COORDS[coords][1] == 0.0)
  1123.         {
  1124.             fake_origin[0] += min_size[1]
  1125.         }
  1126.         else if(ARENA_COORDS[coords][0] == -100.0 && ARENA_COORDS[coords][1] == 0.0)
  1127.         {
  1128.             fake_origin[0] += min_size[2]
  1129.         }
  1130.  
  1131.        
  1132.        
  1133.         set_rendering(ent,kRenderFxGlowShell,0,50,0,kRenderNormal,10)
  1134.     }
  1135.     select_the_fake_arena(ext_code)
  1136.     return PLUGIN_HANDLED;
  1137. }
  1138.  
  1139. public move_the_fake_arena(id,code,moveto)
  1140. {
  1141.     new num;
  1142.     num = code-EXTRA_CODE
  1143.     new arenas_ent=-1;
  1144.     new Float:origin[3];
  1145.     while((arenas_ent=engfunc(EngFunc_FindEntityByString,arenas_ent,"classname",ARENA_ENT_NAME)))
  1146.     {
  1147.         if(entity_get_int(arenas_ent,EV_INT_iuser1) == FAKE_CODE)
  1148.         {
  1149.             if(entity_get_int(arenas_ent,EV_INT_iuser3) == code || num == -1)
  1150.             {
  1151.                 pev(arenas_ent,pev_origin,origin);
  1152.                 switch(moveto)
  1153.                 {
  1154.                     case MOVE_UP:
  1155.                     {
  1156.                         origin[2]+=move_size[id]
  1157.                     }
  1158.                     case MOVE_DOWN:
  1159.                     {
  1160.                         origin[2]-=move_size[id]
  1161.                     }
  1162.                     case MOVE_RIGHT:
  1163.                     {
  1164.                         origin[1]+=move_size[id]
  1165.                     }
  1166.                     case MOVE_LEFT:
  1167.                     {
  1168.                         origin[1]-=move_size[id]
  1169.                     }
  1170.                     case MOVE_FRONT:
  1171.                     {
  1172.                         origin[0]+=move_size[id]
  1173.                     }
  1174.                     case MOVE_BACK:
  1175.                     {
  1176.                         origin[0]-=move_size[id]
  1177.                     }
  1178.                 }
  1179.                 engfunc(EngFunc_SetOrigin,arenas_ent,origin);
  1180.                 stuck_check(origin,360.0)
  1181.             }
  1182.         }
  1183.     }
  1184.    
  1185. }
  1186.  
  1187. public select_the_fake_arena(code)
  1188. {
  1189.     new num;
  1190.     num = code-EXTRA_CODE
  1191.     new arenas_ent=-1;
  1192.     while((arenas_ent=engfunc(EngFunc_FindEntityByString,arenas_ent,"classname",ARENA_ENT_NAME)))
  1193.     {
  1194.         if(entity_get_int(arenas_ent,EV_INT_iuser1) == FAKE_CODE)
  1195.         {
  1196.             if(num == -1)
  1197.                 set_rendering(arenas_ent,kRenderFxGlowShell,250,0,0,kRenderNormal,10)
  1198.             else if(entity_get_int(arenas_ent,EV_INT_iuser3) == code)
  1199.                 set_rendering(arenas_ent,kRenderFxGlowShell,250,0,0,kRenderNormal,10)
  1200.         }
  1201.     }
  1202.     unselect_the_fake_arena(code)
  1203.    
  1204. }
  1205.  
  1206. public unselect_the_fake_arena(code)
  1207. {
  1208.     new num;
  1209.     num = code-EXTRA_CODE
  1210.     if(num == -1)
  1211.         return;
  1212.     new arenas_ent=-1;
  1213.     while((arenas_ent=engfunc(EngFunc_FindEntityByString,arenas_ent,"classname",ARENA_ENT_NAME)))
  1214.     {
  1215.         if(entity_get_int(arenas_ent,EV_INT_iuser1) == FAKE_CODE && entity_get_int(arenas_ent,EV_INT_iuser3) != code)
  1216.             set_rendering(arenas_ent,kRenderFxGlowShell,50,50,50,kRenderTransAdd,120)
  1217.     }
  1218.    
  1219. }
  1220.  
  1221. public delete_the_fake_arena(code)
  1222. {
  1223.     new arenas_ent=-1;
  1224.     new found = 0
  1225.     while((arenas_ent=engfunc(EngFunc_FindEntityByString,arenas_ent,"classname",ARENA_ENT_NAME)))
  1226.     {
  1227.         if(entity_get_int(arenas_ent,EV_INT_iuser1) == FAKE_CODE && entity_get_int(arenas_ent,EV_INT_iuser3) == code)
  1228.         {
  1229.             engfunc(EngFunc_RemoveEntity,arenas_ent)
  1230.             found++
  1231.         }
  1232.     }
  1233.     if(found)
  1234.     {
  1235.         fakes--
  1236.     }
  1237.    
  1238. }
  1239.  
  1240. public load_arena_coords(id)
  1241. {
  1242.     // Check for spawns points of the current map
  1243.     new cfgdir[32], mapname[32], filepath[100], linedata[64]
  1244.     get_configsdir(cfgdir, charsmax(cfgdir))
  1245.     get_mapname(mapname, charsmax(mapname))
  1246.     formatex(filepath, charsmax(filepath), ARENA_FILE, cfgdir, mapname)
  1247.     new arena = 0
  1248.     total_arenas = 0
  1249.     // Load spawns points
  1250.     if (file_exists(filepath))
  1251.     {
  1252.         new file = fopen(filepath,"rt"), row[4][6]
  1253.        
  1254.         while (file && !feof(file))
  1255.         {
  1256.             fgets(file, linedata, charsmax(linedata))
  1257.            
  1258.             // invalid spawn
  1259.             if(!linedata[0] || str_count(linedata,' ') < 2) continue;
  1260.            
  1261.             arena++
  1262.             if (arena > MAX_ARENAS)
  1263.             {
  1264.                 break
  1265.             }
  1266.            
  1267.             // get spawn point data
  1268.             parse(linedata,row[0],5,row[1],5,row[2],5)
  1269.            
  1270.             // origin
  1271.             arena_coord[arena][0] = floatstr(row[0])
  1272.             arena_coord[arena][1] = floatstr(row[1])
  1273.             if(bugged_map())
  1274.                 arena_coord[arena][2] = MAP_FIX_Z_COORD[map_id]
  1275.             else arena_coord[arena][2] = floatstr(row[2])
  1276.  
  1277.             total_arenas = arena
  1278.         }
  1279.         if (file) fclose(file)
  1280.     }
  1281.     if(id != -1)
  1282.     {
  1283.         if(!total_arenas)
  1284.         {
  1285.             client_print_color(id, "%sCouldn't load: ^3No arenas found.",CHAT_TAG)
  1286.         }
  1287.         else
  1288.         {
  1289.             client_print_color(id, "%s%d ^3arena%s loaded.",CHAT_TAG,total_arenas, (total_arenas > 1 ? "s" : ""))
  1290.         }
  1291.     }
  1292. }
  1293.  
  1294. stock bugged_map()
  1295. {
  1296.     if(!MAP_FIX_ENABLED)
  1297.         return PLUGIN_CONTINUE
  1298.     if(IS_BUGGED_MAP)
  1299.         return PLUGIN_HANDLED
  1300.     return PLUGIN_CONTINUE
  1301. }
  1302.  
  1303. stock str_count(const str[], searchchar)
  1304. {
  1305.     new count, i, len = strlen(str)
  1306.    
  1307.     for (i = 0; i <= len; i++)
  1308.     {
  1309.         if(str[i] == searchchar)
  1310.             count++
  1311.     }
  1312.    
  1313.     return count;
  1314. }
  1315.  
  1316. public Player_spawn_post(id)
  1317. {
  1318.     Set_Entity_Invisible(id, 0)
  1319.     if(is_user_alive(id))
  1320.     {
  1321.         if(is_in_duel[id] != 2)
  1322.         {
  1323.             set_task(1.0,"get_spawn_origin",id)
  1324.             return;
  1325.         }
  1326.         if(is_in_duel[id] == 2)
  1327.             spawn_back(id)
  1328.     }
  1329. }
  1330.  
  1331. public spawn_back(id)
  1332. {
  1333.     entity_set_origin(id,his_player_spawn[id])
  1334.     entity_set_vector(id, EV_VEC_angles, his_player_angle[id])
  1335.    
  1336.     set_user_armor(id,0)
  1337.     set_user_godmode(id, 0)
  1338.     if(is_user_connected(his_challenger[id]))
  1339.     {
  1340.         check_teams(id,his_challenger[id])
  1341.         entity_set_origin(his_challenger[id],his_player_spawn[his_challenger[id]])
  1342.         entity_set_vector(id, EV_VEC_angles, his_player_angle[id])
  1343.         set_user_armor(his_challenger[id],0)
  1344.         entity_set_int(id, EV_INT_fixangle, 1)
  1345.         entity_set_vector(his_challenger[id], EV_VEC_angles, his_player_angle[his_challenger[id]])
  1346.         entity_set_int(his_challenger[id], EV_INT_fixangle, 1)
  1347.  
  1348.         if(his_arena[id] == 2)
  1349.              {
  1350.                       his_arena[his_challenger[id]] = 2;
  1351.                  set_user_health(id,100)
  1352.             set_user_health(his_challenger[id],100)
  1353.              }
  1354.         else
  1355.         {
  1356.             set_user_health(his_challenger[id],map_default_hp)
  1357.             set_user_health(id,map_default_hp)
  1358.         }
  1359.        
  1360.         strip_user_weapons(id)
  1361.         strip_user_weapons(his_challenger[id])
  1362.        
  1363.         CopyWeaponSettings(id)
  1364.         CopyWeaponSettings(his_challenger[id])
  1365.        
  1366.         give_item(id, WeaponModel[Weapons_Settings[id]]);
  1367.         give_item(his_challenger[id], WeaponModel[Weapons_Settings[his_challenger[id]]]);
  1368.        
  1369.                   if(his_types[id] == 1)
  1370.                   {
  1371.                       his_types[his_challenger[id]] = 1
  1372.                   }
  1373.                   else if(his_types[id] == 2)
  1374.                   {
  1375.                       his_types[his_challenger[id]] = 2
  1376.                   }
  1377.                   if(his_types[id] == 3)
  1378.                   {
  1379.                       his_types[his_challenger[id]] = 3
  1380.                   }
  1381.                   else if(his_types[id] == 4)
  1382.                   {
  1383.                       his_types[his_challenger[id]] = 4
  1384.                   }
  1385.     }
  1386. }
  1387.  
  1388. public update_cvars()
  1389. {
  1390.     MAP_FIX_ENABLED = get_pcvar_num(cvar_z_fix)
  1391.     SOUNDS_ENABLED = get_pcvar_num(cvar_sounds)
  1392.     MAX_ROUNDS = get_pcvar_num(cvar_rounds)
  1393.     MAX_KILLS = get_pcvar_num(cvar_kills)
  1394.     MAX_COUNTDOWN = get_pcvar_num(cvar_cooldown)
  1395.     MAX_TIME = get_pcvar_num(cvar_time)
  1396. }
  1397.  
  1398. stock remove_allarenas()
  1399. {
  1400.     new arenas_ent=-1;
  1401.     while((arenas_ent=engfunc(EngFunc_FindEntityByString,arenas_ent,"classname",ARENA_ENT_NAME)))
  1402.     {
  1403.         engfunc(EngFunc_RemoveEntity,arenas_ent)
  1404.     }
  1405.     fakes = 0
  1406. }
  1407.  
  1408. public get_all_arena_coords(id)
  1409. {
  1410.     new Float:origin[3]
  1411.     new arenas_ent=-1;
  1412.     while((arenas_ent=engfunc(EngFunc_FindEntityByString,arenas_ent,"classname",ARENA_ENT_NAME)))
  1413.     {
  1414.         if(entity_get_int(arenas_ent,EV_INT_iuser2) == CENTER_CODE)
  1415.         {
  1416.             pev(arenas_ent,pev_origin,origin);
  1417.             client_print(id,print_console,"%.f %.f %.f",origin[0],origin[1],origin[2])
  1418.         }
  1419.     }
  1420.     client_print_color(id,  "%s ^4Coords printed in console.",CHAT_TAG)
  1421. }
  1422.  
  1423. public remove_the_fake_arena()
  1424. {
  1425.     new arenas_ent=-1;
  1426.     while((arenas_ent=engfunc(EngFunc_FindEntityByString,arenas_ent,"classname",ARENA_ENT_NAME)))
  1427.     {
  1428.         if(entity_get_int(arenas_ent,EV_INT_iuser1) == FAKE_CODE)
  1429.             engfunc(EngFunc_RemoveEntity,arenas_ent)
  1430.     }
  1431.     fakes = 0
  1432. }
  1433.  
  1434. public next_fake_arena()
  1435. {
  1436.     if(fakes_count() >= MAX_ARENAS)
  1437.         return -1
  1438.     for(new i=1;i < MAX_ARENAS+1;i++)
  1439.     {
  1440.         if(!fake_arena_exists(i))
  1441.         {
  1442.             return i
  1443.         }
  1444.     }
  1445.     return -1
  1446.     /*new num = fakes
  1447.     num++
  1448.     return num*/
  1449. }
  1450.  
  1451. public remove_the_arena(code)
  1452. {
  1453.     new arenas_ent=-1;
  1454.     while((arenas_ent=engfunc(EngFunc_FindEntityByString,arenas_ent,"classname",ARENA_ENT_NAME)))
  1455.     {
  1456.         if(entity_get_int(arenas_ent,EV_INT_iuser1) == code)
  1457.             engfunc(EngFunc_RemoveEntity,arenas_ent)
  1458.     }
  1459. }
  1460.  
  1461. public start_build(id)
  1462. {
  1463.     if(!is_user_connected(id))
  1464.         return PLUGIN_HANDLED
  1465.     if(is_in_duel[id] != 2)
  1466.         return PLUGIN_HANDLED
  1467.     if(!his_challenger[id])
  1468.         return PLUGIN_HANDLED
  1469.     if(!total_arenas)
  1470.     {
  1471.         return PLUGIN_HANDLED
  1472.     }
  1473.     static Float:origin[3];
  1474.        
  1475.  
  1476.     origin[0] = arena_coord[arena_number[id]][0]
  1477.     origin[1] = arena_coord[arena_number[id]][1]
  1478.     origin[2] = arena_coord[arena_number[id]][2]
  1479.  
  1480.     new Float:fake_origin[3]
  1481.     static size
  1482.     size = sizeof(ARENA_COORDS)
  1483.     new ent_code = arena_number[id]+ARENA_CODE
  1484.     for(new coords;coords < size; coords++)
  1485.     {
  1486.         fake_origin[0] = origin[0]
  1487.         fake_origin[1] = origin[1]
  1488.         fake_origin[2] = origin[2]
  1489.  
  1490.         fake_origin[0]+=ARENA_COORDS[coords][0]*1.7
  1491.         fake_origin[1]+=ARENA_COORDS[coords][1]*1.53
  1492.        
  1493.         if(his_arena[id] == 0)
  1494.         {
  1495.             new ent=engfunc(EngFunc_CreateNamedEntity,engfunc(EngFunc_AllocString,"func_wall"));
  1496.              
  1497.             set_pev(ent,pev_classname,ARENA_ENT_NAME)
  1498.             engfunc(EngFunc_SetModel,ent,ARENA_MODELS[0]);
  1499.             entity_set_int(ent, EV_INT_solid, SOLID_BBOX);
  1500.             engfunc(EngFunc_SetSize,ent,ARENA_MINS,ARENA_MAXS);
  1501.             entity_set_int(ent, EV_INT_movetype, MOVETYPE_NONE);
  1502.             entity_set_int(ent,EV_INT_iuser1,ent_code);
  1503.             engfunc(EngFunc_SetOrigin,ent,fake_origin);
  1504.             set_pev(ent, pev_groupinfo, GROUP_ENTITY);
  1505.         }
  1506.         if(his_arena[id] == 1)
  1507.         {
  1508.             new ent_bridge=engfunc(EngFunc_CreateNamedEntity,engfunc(EngFunc_AllocString,"func_wall"));
  1509.            
  1510.             set_pev(ent_bridge,pev_classname,ARENA_ENT_NAME);  
  1511.             engfunc(EngFunc_SetModel,ent_bridge,BRIDGE_MODELS[0]);
  1512.             entity_set_int(ent_bridge, EV_INT_solid, SOLID_BBOX);
  1513.             engfunc(EngFunc_SetSize,ent_bridge,BRIDGE_MINS,BRITGE_MAXS);
  1514.             entity_set_int(ent_bridge, EV_INT_movetype, MOVETYPE_NONE);
  1515.             entity_set_int(ent_bridge,EV_INT_iuser1,ent_code)
  1516.             engfunc(EngFunc_SetOrigin,ent_bridge,fake_origin);
  1517.             set_pev(ent_bridge, pev_groupinfo, GROUP_ENTITY);
  1518.         }
  1519.         if(his_arena[id] == 2)
  1520.         {
  1521.             new ent=engfunc(EngFunc_CreateNamedEntity,engfunc(EngFunc_AllocString,"func_wall"));
  1522.            
  1523.             set_pev(ent,pev_classname,ARENA_ENT_NAME)
  1524.             engfunc(EngFunc_SetModel,ent,ARENA_MODELS[0]);
  1525.        entity_set_int(ent, EV_INT_solid, SOLID_BBOX);
  1526.             engfunc(EngFunc_SetSize,ent,ARENA_MINS,ARENA_MAXS);
  1527.             entity_set_int(ent, EV_INT_movetype, MOVETYPE_NONE);
  1528.             entity_set_int(ent,EV_INT_iuser1,ent_code);
  1529.             engfunc(EngFunc_SetOrigin,ent,fake_origin);
  1530.        set_pev(ent, pev_groupinfo, GROUP_ENTITY);
  1531.            
  1532.             static Float:box_origin[3];
  1533.            
  1534.             box_origin[0] = arena_coord[arena_number[id]][0]
  1535.             box_origin[1] = arena_coord[arena_number[id]][1]
  1536.             box_origin[2] = arena_coord[arena_number[id]][2]
  1537.            
  1538.             new Float:box_fake_origin[3]
  1539.             static boxsize
  1540.             boxsize = sizeof(BOX_COORDS)
  1541.             new box_ent_code = arena_number[id]+ARENA_CODE
  1542.             for(new coords;coords < boxsize; coords++)
  1543.             {
  1544.                 box_fake_origin[0] = box_origin[0]
  1545.                 box_fake_origin[1] = box_origin[1]
  1546.                 box_fake_origin[2] = box_origin[2]+50
  1547.                
  1548.                 box_fake_origin[0]+=BOX_COORDS[coords][0]*1.7
  1549.                 box_fake_origin[1]+=BOX_COORDS[coords][1]*1.53
  1550.                 new entbox = engfunc(EngFunc_CreateNamedEntity,engfunc(EngFunc_AllocString,"func_wall"));
  1551.                 set_pev(entbox,pev_classname,ARENA_ENT_NAME);
  1552.                 engfunc(EngFunc_SetModel,entbox,BOX_MODELS[0]);
  1553.                 entity_set_int(entbox, EV_INT_solid, SOLID_BBOX);
  1554.                 engfunc(EngFunc_SetSize,entbox,BOX_MINS,BOX_MAXS);
  1555.                 entity_set_int(entbox, EV_INT_movetype, MOVETYPE_NONE);
  1556.                 entity_set_int(entbox,EV_INT_iuser1,box_ent_code);
  1557.                 engfunc(EngFunc_SetOrigin,entbox,box_fake_origin);
  1558.                 set_pev(entbox, pev_groupinfo, GROUP_ENTITY);
  1559.             }
  1560.         }
  1561.     }
  1562.     static Float:rvec[3];
  1563.  
  1564.     rvec[0]=0.0;
  1565.  
  1566.     cs_set_user_team(id,CS_TEAM_T)
  1567.     cs_set_user_team(his_challenger[id],CS_TEAM_CT)
  1568.        
  1569.     set_spawn_positions(id,fake_origin)
  1570.     set_spawn_positions(his_challenger[id],fake_origin)
  1571.  
  1572.     spawn_back(id)
  1573.  
  1574.     return PLUGIN_HANDLED;
  1575. }
  1576.  
  1577. public set_spawn_positions(id,Float:origin[3])
  1578. {
  1579.     if(get_user_team(id) == 1)
  1580.     {
  1581.         his_player_spawn[id][0] = origin[0]-340
  1582.         his_player_spawn[id][1] = origin[1]
  1583.         his_player_spawn[id][2] = origin[2]+50
  1584.         his_player_angle[id][1] = 0.0
  1585.         his_player_angle[id][0] = 0.0
  1586.     }
  1587.     if(get_user_team(id) == 2)
  1588.     {
  1589.         his_player_spawn[id][0] = origin[0]+340
  1590.         his_player_spawn[id][1] = origin[1]
  1591.         his_player_spawn[id][2] = origin[2]+50
  1592.         his_player_angle[id][1] = 180.0
  1593.         his_player_angle[id][0] = 0.0
  1594.     }
  1595.     entity_set_origin(id,his_player_spawn[id])
  1596. }
  1597.  
  1598.  
  1599.  
  1600. public stuck_check(Float:origin[3],Float:radius)
  1601. {
  1602.     new player=-1;
  1603.     while((player = find_ent_in_sphere(player,origin,radius)) != 0)
  1604.     {
  1605.         if(is_user_alive(player))
  1606.         {
  1607.             if(is_player_stuck(player) && is_in_duel[player] != 2)
  1608.             {
  1609.                 back_to_the_spawn(player)
  1610.             }
  1611.         }
  1612.     }
  1613. }
  1614.  
  1615. stock is_player_stuck(id)
  1616. {
  1617.     static Float:originF[3]
  1618.     pev(id, pev_origin, originF)
  1619.    
  1620.     engfunc(EngFunc_TraceHull, originF, originF, 0, (pev(id, pev_flags) & FL_DUCKING) ? HULL_HEAD : HULL_HUMAN, id, 0)
  1621.    
  1622.     if (get_tr2(0, TR_StartSolid) || get_tr2(0, TR_AllSolid) || !get_tr2(0, TR_InOpen))
  1623.         return true;
  1624.    
  1625.     return false;
  1626. }
  1627.  
  1628. public create_wall(type,alpha,solidity,code,code1,code2,Float:origin[3])
  1629. {
  1630.     new Float:wall_maxsize[3];
  1631.     new Float:wall_minsize[3];
  1632.     new Float:rvec[3];
  1633.     new ent=engfunc(EngFunc_CreateNamedEntity,engfunc(EngFunc_AllocString,"func_wall"));
  1634.     pev(ent,pev_v_angle,rvec);
  1635.     switch(type)
  1636.     {
  1637.         case BLUE_SIDE:
  1638.         {
  1639.             wall_maxsize[0] = 2.0
  1640.             wall_minsize[0] = 0.0
  1641.             wall_maxsize[1] = 230.0
  1642.             wall_minsize[1] = -230.0
  1643.             wall_maxsize[2] = 150.0
  1644.             wall_minsize[2] = -1.0
  1645.             rvec[1]=180.0
  1646.         }
  1647.         case RED_SIDE:
  1648.         {
  1649.             wall_maxsize[0] = -150.0
  1650.             wall_minsize[0] = -152.0
  1651.             wall_maxsize[1] = 230.0
  1652.             wall_minsize[1] = -230.0
  1653.             wall_maxsize[2] = 150.0
  1654.             wall_minsize[2] = -1.0
  1655.             rvec[1]=180.0
  1656.         }
  1657.         case LEFT_SIDE:
  1658.         {
  1659.             wall_maxsize[0] = 360.0
  1660.             wall_minsize[0] = -300.0
  1661.             wall_maxsize[1] = 65.0
  1662.             wall_minsize[1] = 63.0
  1663.             wall_maxsize[2] = 150.0
  1664.             wall_minsize[2] = -1.0
  1665.             rvec[1]=90.0
  1666.         }
  1667.         case RIGHT_SIDE:
  1668.         {
  1669.             wall_maxsize[0] = 360.0
  1670.             wall_minsize[0] = -300.0
  1671.             wall_maxsize[1] = -63.0
  1672.             wall_minsize[1] = -65.0
  1673.             wall_maxsize[2] = 150.0
  1674.             rvec[1]=90.0
  1675.         }
  1676.         case TOP_SIDE:
  1677.         {
  1678.             wall_maxsize[0] = 360.0
  1679.             wall_minsize[0] = -300.0
  1680.             wall_maxsize[1] = 230.0
  1681.             wall_minsize[1] = -230.0
  1682.             wall_maxsize[2] = 150.0
  1683.             wall_minsize[2] = 148.0
  1684.             rvec[0]=90.0          
  1685.         }
  1686.     }
  1687.     set_pev(ent,pev_angles,rvec);
  1688.    
  1689.     set_pev(ent,pev_classname,ARENA_ENT_NAME);
  1690.     engfunc(EngFunc_SetModel,ent,ARENA_MODELS[0]);
  1691.     entity_set_int(ent, EV_INT_solid, solidity);
  1692.     engfunc(EngFunc_SetSize,ent,wall_minsize,wall_maxsize);
  1693.     entity_set_int(ent, EV_INT_movetype, MOVETYPE_NONE);
  1694.     entity_set_int(ent,EV_INT_iuser1,code)
  1695.     entity_set_int(ent,EV_INT_iuser2,code1)
  1696.     entity_set_int(ent,EV_INT_iuser3,code2)
  1697.     engfunc(EngFunc_SetOrigin,ent,origin);
  1698.     set_rendering(ent,kRenderFxGlowShell,0,0,0,kRenderTransAlpha,alpha)
  1699. }
  1700.  
  1701. public get_spawn_origin(id)
  1702. {
  1703.     pev(id,pev_origin,his_original_spawn[id]);
  1704. }
  1705.  
  1706. stock get_user_hitpoint(id,Float:hOrigin[3])  {
  1707.     if(!is_user_alive(id))
  1708.         return 0;
  1709.  
  1710.     new Float:fOrigin[3],Float:fvAngle[3],Float:fvOffset[3],Float:fvOrigin[3],Float:feOrigin[3];
  1711.     new Float:fTemp[3];
  1712.  
  1713.     pev(id,pev_origin,fOrigin);
  1714.     pev(id,pev_v_angle,fvAngle);
  1715.     pev(id,pev_view_ofs,fvOffset);
  1716.  
  1717.     xs_vec_add(fOrigin,fvOffset,fvOrigin);
  1718.  
  1719.     engfunc(EngFunc_AngleVectors,fvAngle,feOrigin,fTemp,fTemp);
  1720.  
  1721.     xs_vec_mul_scalar(feOrigin,9999.9,feOrigin);
  1722.     xs_vec_add(fvOrigin,feOrigin,feOrigin);
  1723.  
  1724.     engfunc(EngFunc_TraceLine,fvOrigin,feOrigin,0,id);
  1725.     global_get(glb_trace_endpos,hOrigin);
  1726.  
  1727.     return 1;
  1728. }
  1729.  
  1730. public plugin_precache()
  1731. {
  1732.     new size;
  1733.     new bridge_size;
  1734.     new box_size;
  1735.     size = sizeof(ARENA_MODELS)
  1736.     bridge_size = sizeof(BRIDGE_MODELS)
  1737.     box_size = sizeof(BOX_MODELS)
  1738.    
  1739.     for(new i; i< size; i++)
  1740.     {
  1741.         engfunc(EngFunc_PrecacheModel,ARENA_MODELS[i]);
  1742.     }
  1743.     for(new i; i< bridge_size; i++)
  1744.     {
  1745.         engfunc(EngFunc_PrecacheModel,BRIDGE_MODELS[i]);
  1746.     }
  1747.     for(new i; i< box_size; i++)
  1748.     {
  1749.         engfunc(EngFunc_PrecacheModel,BOX_MODELS[i]);
  1750.     }
  1751. }
  1752.  
  1753.  
  1754. public round_start_event()
  1755. {
  1756.     update_cvars()
  1757.     // using a variable to store player's names instead of regenerating it all the time...
  1758.     for(new id;id < MAXPLAYERS;id++)
  1759.     {
  1760.         if(is_user_connected(id))
  1761.         {
  1762.             get_user_name(id,his_name[id],charsmax(his_name))
  1763.         }
  1764.     }
  1765. }
  1766.  
  1767. public Advertise(task)
  1768. {
  1769.     client_print_color(0, "%s^3%s ^1by ^4%s ^1for ^4%s^1.",CHAT_TAG,P_NAME,P_AUTH,P_REQ)
  1770.     set_task(300.0,"Advertise",TASK_AD)
  1771. }
  1772.  
  1773. public Cmd_start(id,hndle)
  1774. {
  1775.     if(!is_user_alive(id))
  1776.         return FMRES_IGNORED
  1777.     if(!is_frozen[id])
  1778.         return FMRES_IGNORED
  1779.     new Buttons = get_uc(hndle,UC_Buttons)
  1780.     if(Buttons & IN_ATTACK)
  1781.     {
  1782.         Buttons &= ~IN_ATTACK
  1783.         set_uc( hndle , UC_Buttons , Buttons )
  1784.         return FMRES_SUPERCEDE
  1785.     }
  1786.     if(Buttons & IN_ATTACK2)
  1787.     {
  1788.         Buttons &= ~IN_ATTACK2
  1789.         set_uc( hndle , UC_Buttons , Buttons )
  1790.         return FMRES_SUPERCEDE
  1791.     }
  1792.     return FMRES_IGNORED
  1793. }
  1794.  
  1795. public Player_Take_Damage(victim, inflictor, attacker, Float:damage, damage_bits)
  1796. {    
  1797.     if(is_user_connected(attacker)) // we make sure the attacker is a player
  1798.     {
  1799.         if(is_in_duel[victim] == 2 || is_in_duel[attacker] == 2)
  1800.         {
  1801.             if(his_challenger[victim] != attacker || his_challenger[attacker] != victim)
  1802.             {
  1803.                 // we protect the contenders from getting killed by other people or them killing others?
  1804.                 return HAM_SUPERCEDE
  1805.             }
  1806.         }
  1807.     }
  1808.     return HAM_IGNORED
  1809. }
  1810.  
  1811. public client_putinserver(id)
  1812. {
  1813.     get_user_name(id,his_name[id],charsmax(his_name))
  1814.     reset_values(id)
  1815.     move_size[id] = 10.0
  1816.     his_offline[id] = 0
  1817.     his_previous_team[id] = 0
  1818.     arena_selected = 1;
  1819. }
  1820.  
  1821. public client_disconnect(id)
  1822. {
  1823.     end_his_duel(id)
  1824. }
  1825.  
  1826. public end_his_duel(id)
  1827. {
  1828.     if(his_challenger[id])
  1829.     {
  1830.         client_print_color(0, "^3[^4Arena: %s^3] ^4%s^1's challenger ^4%s^1 has ^3left the game^1.",arena_names[arena_number[id]],his_name[his_challenger[id]],his_name[id])
  1831.        
  1832.         if(arena_number[id] == arena_number[his_challenger[id]])
  1833.             remove_the_arena(arena_number[id] +ARENA_CODE)
  1834.         back_to_the_spawn(id)
  1835.         back_to_the_spawn(his_challenger[id])
  1836.         reset_values(his_challenger[id])
  1837.     }
  1838.     reset_values(id)
  1839. }
  1840.  
  1841. public times_up_duel(id)
  1842. {
  1843.     client_print_color(0, "^3[^4Arena: %s^3] ^4%s^1 ^1and ^4%s^1 has taken long to ^3finish the battle^1.",arena_names[arena_number[id]],his_name[his_challenger[id]],his_name[id])
  1844.        
  1845.     if(his_challenger[id])
  1846.     {
  1847.         if(arena_number[id] == arena_number[his_challenger[id]])
  1848.             remove_the_arena(arena_number[id] +ARENA_CODE)
  1849.         user_kill(id,1)
  1850.         user_kill(his_challenger[id],1)
  1851.         back_to_the_spawn(id)
  1852.         back_to_the_spawn(his_challenger[id])
  1853.         reset_values(his_challenger[id])
  1854.     }
  1855.     reset_values(id)
  1856. }
  1857.  
  1858. public battle_timer(id)
  1859. {
  1860.     if(is_user_connected(id))
  1861.     {
  1862.         if(is_in_duel[id] == 2)
  1863.         {
  1864.             his_timer[id]++
  1865.             if(his_timer[id] > MAX_TIME)
  1866.             {
  1867.                 times_up_duel(id)
  1868.             }
  1869.             set_task(1.0,"battle_timer",id)
  1870.         }
  1871.     }
  1872. }
  1873.  
  1874. public say_hook(id)
  1875. {
  1876.     static Chat_C[32]
  1877.     read_args(Chat_C,charsmax(Chat_C))
  1878.     remove_quotes(Chat_C)
  1879.     if(equali(Chat_C,DUEL_COMMAND))
  1880.     {
  1881.         //request a duel
  1882.         Principal_Menu(id)
  1883.     }
  1884.     if(equali(Chat_C,TOGGLE_COMMAND))
  1885.     {
  1886.         //request a duel
  1887.         toggle_offline(id)
  1888.     }
  1889.     if(equali(Chat_C,GIVEUP_COMMAND))
  1890.     {
  1891.         //leave a duel
  1892.         if(is_in_duel[id] == 2)
  1893.         {
  1894.             give_up_player(id)
  1895.         }
  1896.         else
  1897.         {
  1898.             client_print_color(id, "%sYou're not part of any battle.",CHAT_TAG)
  1899.         }
  1900.     }
  1901.     return PLUGIN_CONTINUE
  1902. }
  1903.  
  1904. public toggle_offline(id)
  1905. {
  1906.     switch(his_offline[id])
  1907.     {
  1908.         case 0:
  1909.         {
  1910.             his_offline[id] = 1
  1911.             //client_print_color(0, "%s^4%s^1 disconnected from the duel list.",CHAT_TAG,his_name[id])
  1912.         }
  1913.         default:
  1914.         {
  1915.             his_offline[id] = 0
  1916.             //client_print_color(0, "%s^4%s^1 connected to the duel list.",CHAT_TAG,his_name[id])
  1917.         }
  1918.     }
  1919. }
  1920.  
  1921. public give_up_player(id)
  1922. {
  1923.     if(is_user_connected(his_challenger[id]))
  1924.     {
  1925.         strip_user_weapons(id)
  1926.         strip_user_weapons(his_challenger[id])
  1927.         give_item(id,"weapon_knife")
  1928.         give_item(his_challenger[id],"weapon_knife")
  1929.        
  1930.         client_print_color(0, "%s^4%s^3 got scared to face ^4%s^3! :)",CHAT_TAG,his_name[id],his_name[his_challenger[id]])
  1931.         if(arena_number[id] == arena_number[his_challenger[id]])
  1932.             remove_the_arena(arena_number[id] +ARENA_CODE)
  1933.         back_to_the_spawn(id)
  1934.         back_to_the_spawn(his_challenger[id])
  1935.         reset_values(his_challenger[id])
  1936.     }
  1937.     reset_values(id)
  1938. }
  1939.  
  1940. public reward_winner(id)
  1941. {
  1942.     if(is_user_connected(id))
  1943.     {
  1944.         strip_user_weapons(id)
  1945.         give_item(id,"weapon_knife")
  1946.         // here you can reward the winner with something
  1947.         client_print_color(id, "%s^4Congratulations!!!^1, You have ^3won this battle^1!",CHAT_TAG)
  1948.         if(SOUNDS_ENABLED)
  1949.             client_cmd(id,"spk ^"%s^"",DUEL_SOUNDS[0])
  1950.         if(cs_get_user_money(id)+15000 <= 16000)
  1951.         {
  1952.             cs_set_user_money(id,cs_get_user_money(id)+15000,1)
  1953.             //client_print_color(id, "%s^4You've earned ^3$15000^4!",CHAT_TAG)
  1954.         } else cs_set_user_money(id,16000,1)
  1955.     }
  1956. }
  1957.  
  1958. public reward_loser(id)
  1959. {
  1960.     if(is_user_connected(id))
  1961.     {
  1962.         // here you can reward the winner with something
  1963.         strip_user_weapons(id)
  1964.         give_item(id,"weapon_knife")
  1965.         user_kill(id,1)
  1966.         client_print_color(id, "%sYou've ^3lost this battle^1!",CHAT_TAG)
  1967.         if(SOUNDS_ENABLED)
  1968.             client_cmd(id,"spk ^"%s^"",DUEL_SOUNDS[1])
  1969.         if(cs_get_user_money(id)-15000 >= 0)
  1970.         {
  1971.             cs_set_user_money(id,cs_get_user_money(id)-15000,1)
  1972.             //client_print_color(id, "%s^4You've lost ^3$15000^4!",CHAT_TAG)
  1973.         } else cs_set_user_money(id,0,1)
  1974.     }
  1975. }
  1976.  
  1977. public duel_players_list(id)
  1978. {
  1979.     if(!is_user_alive(id))
  1980.     {
  1981.         client_print_color(id, "%sYou can't challenge anyone when you're ^3dead1.",CHAT_TAG)
  1982.         return PLUGIN_HANDLED
  1983.     }
  1984.     if(his_offline[id])
  1985.     {
  1986.         client_print_color(id, "%sYou can't challenge people when you're ^3offline^1.",CHAT_TAG)
  1987.         return PLUGIN_HANDLED
  1988.     }
  1989.     if(is_user_connected(his_challenger[id]))
  1990.     {
  1991.         client_print_color(id, "%s^4%s ^1is still ^4fighting against you^1.",CHAT_TAG,his_name[his_challenger[id]])
  1992.         return PLUGIN_HANDLED
  1993.     }
  1994.     if(is_user_connected(his_asker[id]))
  1995.     {
  1996.         client_print_color(id, "%sYou can only ^3challenge one person^1 at the time, you've challenged ^4%s^1.",CHAT_TAG,his_name[his_asker[id]])
  1997.         return PLUGIN_HANDLED
  1998.     }
  1999.     if(!available_duelers(id))
  2000.     {
  2001.         client_print_color(id, "%sThere's ^4nobody^1 you can challenge.",CHAT_TAG)
  2002.         return PLUGIN_HANDLED
  2003.     }
  2004.     if(get_next_arena() == -1)
  2005.     {
  2006.         client_print_color(id, "%s^4Maximum arenas reached.",CHAT_TAG)
  2007.         return PLUGIN_HANDLED
  2008.     }
  2009.     new menu,menuformat[64];
  2010.     formatex(menuformat,charsmax(menuformat),"\w[ \rKnifeDuels \w] \dArenas: %d/%d",arenas_count(),total_arenas)
  2011.     menu = menu_create( menuformat, "Duel_handler" );
  2012.    
  2013.     new players[32], pnum, tempid;
  2014.    
  2015.     new szName[32], szUserId[32],nameu[92],CsTeams:team;
  2016.     formatex(nameu,charsmax(nameu), "\yRefresh");
  2017.     menu_additem(menu, nameu,"rf_c", 0);
  2018.     menu_addblank(menu,0)
  2019.     get_players( players, pnum, "c" );
  2020.     for ( new e; e<pnum; e++ )
  2021.     {
  2022.         tempid = players[e]
  2023.         team = cs_get_user_team(tempid)
  2024.        
  2025.         if(tempid != id && team != CS_TEAM_SPECTATOR && team != CS_TEAM_UNASSIGNED)//  && !users_in_same_team(id,tempid))
  2026.         {
  2027.             get_user_name(tempid, szName, charsmax(szName));
  2028.             formatex(szUserId, charsmax(szUserId), "%d", get_user_userid(tempid));
  2029.             if(his_offline[tempid])
  2030.             {
  2031.                 formatex(nameu,charsmax(nameu), "\d%s [Offline]", szName);
  2032.                 menu_additem(menu, nameu, szUserId, 0);
  2033.             }
  2034.             if(isBlocked[tempid][id])
  2035.                            {
  2036.                                formatex(nameu,charsmax(nameu), "%s \w[\rBlocked\w]", szName);
  2037.                                menu_additem(menu, nameu, szUserId, 0);
  2038.                            }
  2039.             else
  2040.             {
  2041.                 if(is_in_duel[tempid] == 2)
  2042.                 {
  2043.                     formatex(nameu,charsmax(nameu), "\r%s [Duel]", szName);
  2044.                     menu_additem(menu, nameu, szUserId, 0);
  2045.                 }
  2046.                 else if(is_in_duel[tempid] == 1)
  2047.                 {
  2048.                     formatex(nameu,charsmax(nameu), "\y%s [Pending]", szName);
  2049.                     menu_additem(menu, nameu, szUserId, 0);
  2050.                 }
  2051.                 else
  2052.                 {
  2053.                     formatex(nameu,charsmax(nameu), "%s", szName);
  2054.                     menu_additem(menu, nameu, szUserId, 0);
  2055.                 }
  2056.             }
  2057.         }
  2058.     }
  2059.    
  2060.     menu_display(id, menu, 0 );
  2061.     return PLUGIN_HANDLED
  2062. }
  2063.  
  2064. public Duel_handler( id, menu, item )
  2065. {
  2066.     if ( item == MENU_EXIT )
  2067.     {
  2068.         menu_destroy( menu );
  2069.         return PLUGIN_HANDLED;
  2070.     }
  2071.    
  2072.     new szData[32], szName[64];
  2073.     new _access, item_callback;
  2074.     menu_item_getinfo( menu, item, _access, szData,charsmax( szData ), szName,charsmax( szName ), item_callback );
  2075.     if(equali(szData,"rf_c"))
  2076.     {
  2077.         menu_destroy( menu );
  2078.         duel_players_list(id)
  2079.         return PLUGIN_CONTINUE
  2080.     }
  2081.     new userid = str_to_num( szData );
  2082.     //spam_hud(id)
  2083.     new enem = find_player("k", userid); // flag "k" : find player from userid
  2084.     if (is_user_connected(enem))
  2085.     {
  2086.         if(his_offline[enem])
  2087.         {
  2088.             client_print_color(id, "%sYou can't challenge offline players.",CHAT_TAG)
  2089.         }
  2090.         if(isBlocked[enem][id])
  2091.              {
  2092.                  client_print_color(id,"%sThis user blocked you!",CHAT_TAG)
  2093.              }
  2094.         else
  2095.         {
  2096.             if(!is_in_duel[enem])
  2097.             {
  2098.                 //spam_hud(enem)
  2099.                 is_in_duel[enem] = 1
  2100.                 is_in_duel[id] = 1
  2101.                 his_player_arena_entity[id] = true;
  2102.                 his_asker[id] = enem
  2103.                 his_asker[enem] = id
  2104.                 ask_player(enem)
  2105.                 client_print_color(0, "%s^4%s^1 has ^3challenged^1 ^4%s^1 for a ^3duel^1!",CHAT_TAG,his_name[id],his_name[enem])
  2106.                
  2107.                 set_task(10.0,"taken_long",id)
  2108.             }
  2109.             else
  2110.             {
  2111.                 client_print_color(id, "%s^4%s^1 seems to be busy with another duel..",CHAT_TAG,his_name[enem])
  2112.             }
  2113.         }
  2114.     }
  2115.     menu_destroy( menu );
  2116.     return PLUGIN_CONTINUE;
  2117. }
  2118.  
  2119. public taken_long(id)
  2120. {
  2121.     if(is_in_duel[id] == 1)
  2122.     {
  2123.         client_print_color(0, "%s^4%s ^1has taken ^3too long to respond ^1to ^4%s^1's challenge.",CHAT_TAG,his_name[his_asker[id]],his_name[id])
  2124.         reset_values(his_asker[id])
  2125.         reset_values(id)
  2126.     }
  2127. }
  2128.  
  2129. stock available_duelers(asker)
  2130. {
  2131.     new num;
  2132.     num = 0 // just incase...
  2133.     for(new id;id < MAXPLAYERS;id++)
  2134.     {
  2135.         if(is_user_alive(id))
  2136.         {
  2137.             if(/*!is_in_duel[id] && */id != asker && !is_user_bot(id))
  2138.             {
  2139.                 num++
  2140.             }
  2141.         }
  2142.     }
  2143.     return num
  2144. }
  2145.  
  2146. public ask_player(id)
  2147. {
  2148.     if(!is_user_alive(id))
  2149.     {
  2150.         return PLUGIN_HANDLED
  2151.     }
  2152.     new asker_name[32],menu_title[64];
  2153.     get_user_name(his_asker[id],asker_name,charsmax(asker_name))
  2154.     formatex(menu_title,charsmax(menu_title),"\rAccept Duel \y%s\r %s %s",asker_name,arenas_results(principals[his_asker[id]][swich_arena]),types_results(principals[his_asker[id]][swich_types]))
  2155.     new menu
  2156.     menu = menu_create( menu_title, "Ask_handler" );
  2157.    
  2158.          
  2159.    
  2160.     menu_additem(menu, "Sure!", "user_said_yes", 0);
  2161.     menu_additem(menu, "Nope!","user_said_no", 0);
  2162.    
  2163.     menu_display(id, menu, 0 );
  2164.     return PLUGIN_HANDLED
  2165. }
  2166.  
  2167. public Ask_handler( id, menu, item )
  2168. {
  2169.     if ( item == MENU_EXIT )
  2170.     {
  2171.         menu_destroy( menu );
  2172.         return PLUGIN_HANDLED;
  2173.     }
  2174.    
  2175.     new szData[32], szName[64];
  2176.     new _access, item_callback;
  2177.     menu_item_getinfo( menu, item, _access, szData,charsmax( szData ), szName,charsmax( szName ), item_callback );
  2178.    
  2179.     if(equali(szData,"user_said_yes"))
  2180.     {
  2181.         if(get_next_arena() == -1)
  2182.         {
  2183.             client_print_color(his_asker[id], "%sMaximum arenas reached.",CHAT_TAG)
  2184.             reset_values(his_asker[id])
  2185.             reset_values(id)
  2186.         }
  2187.         else if(is_in_duel[his_asker[id]] == 1)
  2188.         {
  2189.             manage_battle(id)
  2190.             check_teams(id,his_challenger[id])
  2191.             begin_the_battle(id,his_challenger[id])
  2192.         } else
  2193.         {
  2194.             client_print_color(id, "%s%s either canceled the duel or chosen someone else to duel.",CHAT_TAG,his_name[his_asker[id]])
  2195.             reset_values(his_asker[id])
  2196.             reset_values(id)
  2197.         }
  2198.     }
  2199.     else if(equali(szData,"user_said_no"))
  2200.     {
  2201.         if(is_user_connected(his_asker[id]))
  2202.         {
  2203.             client_print_color(0, "%s^4%s^3 rejected ^4%s^3's challenge.",CHAT_TAG,his_name[id],his_name[his_asker[id]])
  2204.             reset_values(his_asker[id])
  2205.             reset_values(id)
  2206.         }
  2207.        
  2208.     }
  2209.     menu_destroy( menu );
  2210.     return PLUGIN_CONTINUE;
  2211. }
  2212.  
  2213. public Player_Killed(victim, attacker, shouldgib)
  2214. {
  2215.     if(!is_user_connected(victim))
  2216.         return //HAM_IGNORED;
  2217.     if(is_user_connected(his_challenger[victim]) && !is_user_connected(attacker))
  2218.     {
  2219.         if(!check_teams(victim,attacker))
  2220.             return //HAM_IGNORED
  2221.     }
  2222.     if(!is_user_connected(attacker))
  2223.         return //HAM_IGNORED
  2224.        
  2225.     if(attacker == victim)
  2226.         return //HAM_IGNORED
  2227.    
  2228.     if(is_in_duel[attacker] != 2 || is_in_duel[victim] != 2)
  2229.         return //HAM_IGNORED
  2230.    
  2231.     if(his_challenger[victim] == attacker || his_challenger[attacker] == victim )
  2232.     {
  2233.         //fake_death(attacker,victim)
  2234.         his_wins[attacker]++
  2235.         rounds[arena_number[attacker]]++
  2236.         static ret;
  2237.         ExecuteForward(killed_forward, ret, attacker,victim)
  2238.        
  2239.         if(Head_shot[attacker][victim])
  2240.         {
  2241.             his_HS[attacker]++
  2242.             Head_shot[attacker][victim] = false
  2243.         }
  2244.         user_silentkill(victim)
  2245.         if(rounds[arena_number[attacker]] >= MAX_ROUNDS || his_wins[attacker] >= MAX_KILLS)
  2246.         {
  2247.             if(!get_non_duelers_alive())
  2248.             {
  2249.                 ExecuteHamB(Ham_CS_RoundRespawn, victim)
  2250.                 Check_Results(attacker,victim)
  2251.                 //return HAM_SUPERCEDE
  2252.             }
  2253.             else
  2254.             {
  2255.                 ExecuteHamB(Ham_CS_RoundRespawn, victim)
  2256.                 Check_Results(attacker,victim)
  2257.             }
  2258.         }
  2259.         else
  2260.         {
  2261.             wait_for_enemy_loop(attacker)
  2262.             //client_print_color(attacker, "%s^4Rounds^1:^3%d^4/^3%d^1 | ^4You^1:^3%d^4/^3%d^1 | ^4%s^1:^3%d^4/^3%d^1.",CHAT_TAG,rounds[arena_number[attacker]],MAX_ROUNDS,his_wins[attacker],MAX_KILLS,his_name[victim],his_wins[victim],MAX_KILLS)
  2263.             //client_print_color(victim, "%s^4Rounds^1:^3%d^4/^3%d^1 | ^4You^1:^3%d^4/^3%d^1 | ^4%s^1:^3%d^4/^3%d^1.",CHAT_TAG,rounds[arena_number[attacker]],MAX_ROUNDS,his_wins[victim],MAX_KILLS,his_name[attacker],his_wins[attacker],MAX_KILLS)
  2264.         }
  2265.         Set_Entity_Invisible(victim, 1)
  2266.         set_task(0.1,"delay_respawn",victim)
  2267.         return //HAM_SUPERCEDE
  2268.     }
  2269.     return //HAM_IGNORED
  2270. }
  2271.  
  2272. public fake_death(attacker,victim)
  2273. {
  2274.     message_begin( MSG_ALL, get_user_msgid("DeathMsg"),{0,0,0},0)
  2275.     write_byte(attacker)
  2276.     write_byte(victim)
  2277.     write_byte(0)
  2278.     write_string("knife")
  2279.     message_end()
  2280. }
  2281.  
  2282. public delay_respawn(id)
  2283. {
  2284.     if(is_user_connected(id))
  2285.     {
  2286.         if(!is_user_alive(id))
  2287.         {
  2288.             ExecuteHamB(Ham_CS_RoundRespawn, id)
  2289.         }
  2290.         Set_Entity_Invisible(id, 0)
  2291.     }
  2292.     return PLUGIN_CONTINUE
  2293. }
  2294. public Check_Results(id,enemy)
  2295. {
  2296.     reset_teams(id)
  2297.     reset_teams(enemy)
  2298.     new id_name[64],enemy_name[64];
  2299.     get_user_name(id,id_name,charsmax(id_name))
  2300.     get_user_name(enemy,enemy_name,charsmax(enemy_name))
  2301.     if(his_wins[id] > his_wins[enemy])
  2302.     {
  2303.         client_print_color(0, "^3[^4Arena: %s^3] ^4%s ^1with ^3%d scores (HS:%d) ^1won against ^4%s ^1with ^3%d scores (HS:%d)",arena_names[arena_number[id]],id_name,his_wins[id],his_HS[id],enemy_name,his_wins[enemy],his_HS[enemy])
  2304.         reward_winner(id)
  2305.         reward_loser(enemy)
  2306.     }
  2307.     else if(his_wins[enemy] > his_wins[id])
  2308.     {
  2309.         client_print_color(0, "^3[^4Arena: %s^3] ^4%s ^1with ^3%d scores (HS:%d) ^1won against ^4%s ^1with ^3%d scores (HS:%d)",arena_names[arena_number[id]],enemy_name,his_wins[enemy],his_HS[enemy],id_name,his_wins[id],his_HS[id])
  2310.         reward_winner(enemy)
  2311.         reward_loser(id)
  2312.     }
  2313.     else
  2314.     {
  2315.         client_print_color(0, "^3[^4Arena: %s^3] ^4%s ^1with ^3%d scores (HS:%d) ^1and ^4%s ^1with ^3%d scores (HS:%d) ^1ended in a ^4draw match.",arena_names[arena_number[id]],id_name,his_wins[id],his_HS[id],enemy_name,his_wins[enemy],his_HS[enemy])
  2316.         if(SOUNDS_ENABLED)
  2317.         {
  2318.             client_cmd(id,"spk ^"%s^"",DUEL_SOUNDS[2])
  2319.             client_cmd(enemy,"spk ^"%s^"",DUEL_SOUNDS[2])
  2320.         }
  2321.         if(his_wins[id] == his_wins[enemy])
  2322.         {
  2323.             user_kill(id,1)
  2324.             user_kill(enemy,1)
  2325.         }
  2326.     }
  2327.     //client_print_color(0, "%s^3Headshots: ^4%s^1:^3%d ^4%s^1:^3%d^1.",CHAT_TAG,id_name,his_HS[id],enemy_name,his_HS[enemy])
  2328.     if(arena_number[id] == arena_number[enemy])
  2329.         remove_the_arena(arena_number[id] +ARENA_CODE)
  2330.     back_to_the_spawn(id)
  2331.     back_to_the_spawn(enemy)
  2332.     reset_values(enemy)
  2333.     reset_values(id)
  2334.    
  2335. }
  2336.  
  2337. public back_to_the_spawn(id)
  2338. {
  2339.     if(is_user_alive(id))
  2340.     {
  2341.         entity_set_origin(id,his_original_spawn[id])
  2342.         Set_Entity_Invisible(id, 0)
  2343.         set_user_health(id,map_default_hp)
  2344.     }
  2345.     set_user_armor(id,0)
  2346.     set_user_godmode(id, 0)
  2347. }
  2348.  
  2349.  
  2350.  
  2351. public manage_battle(id)
  2352. {
  2353.     is_in_duel[id] = 2
  2354.     his_challenger[id] = his_asker[id]
  2355.     his_challenger[his_challenger[id]] = id
  2356.     is_in_duel[his_challenger[id]] = 2
  2357.     his_asker[id] = 0
  2358.     his_wins[id] = 0
  2359.     his_wins[his_challenger[id]] = 0
  2360.     new aren_code = get_next_arena()
  2361.     arena_number[id] = aren_code
  2362.     arena_number[his_challenger[id]] = aren_code
  2363.     rounds[aren_code] = 0
  2364.     new CsTeams:teamid,CsTeams:teamenemy;
  2365.     teamid = cs_get_user_team(id)
  2366.     teamenemy = cs_get_user_team(his_challenger[id])
  2367.     if(teamid == CS_TEAM_T)
  2368.     {
  2369.         his_previous_team[id] = 2
  2370.     }
  2371.     else if(teamid == CS_TEAM_CT)
  2372.     {
  2373.         his_previous_team[id] = 1
  2374.     }
  2375.     else his_previous_team[id] = 0
  2376.    
  2377.     if(teamenemy == CS_TEAM_T)
  2378.     {
  2379.         his_previous_team[his_challenger[id]] = 2
  2380.     }
  2381.     else if(teamenemy == CS_TEAM_CT)
  2382.     {
  2383.         his_previous_team[his_challenger[id]] = 1
  2384.     }
  2385.     else his_previous_team[his_challenger[id]] = 0
  2386.     start_build(his_challenger[id])
  2387.     if(SOUNDS_ENABLED)
  2388.     {
  2389.         client_cmd(id,"spk ^"%s^"",DUEL_SOUNDS[4])
  2390.         client_cmd(his_challenger[id],"spk ^"%s^"",DUEL_SOUNDS[4])
  2391.     }
  2392.    
  2393.          if(his_arena[id] == 2)
  2394.          {
  2395.              his_arena[his_challenger[id]] = 2;
  2396.              set_user_health(id,100)
  2397.              set_user_health(his_challenger[id],100)
  2398.          }
  2399.     else
  2400.     {
  2401.         set_user_health(his_challenger[id],map_default_hp)
  2402.         set_user_health(id,map_default_hp)
  2403.     }
  2404.    
  2405.     battle_timer(id)
  2406.     battle_timer(his_challenger[id])
  2407.     hud_displayer(id)
  2408.     hud_displayer(his_challenger[id])
  2409.  
  2410.     CopyWeaponSettings(id)
  2411.     CopyWeaponSettings(his_challenger[id])
  2412.    
  2413.     strip_user_weapons(id)
  2414.     strip_user_weapons(his_challenger[id])
  2415.    
  2416.     give_item(id, WeaponModel[Weapons_Settings[id]]);
  2417.     give_item(his_challenger[id], WeaponModel[Weapons_Settings[his_challenger[id]]]);
  2418.    
  2419.     client_print_color(0, "%s^4%s^3 accepted ^4%s^3's challenge!",CHAT_TAG,his_name[id],his_name[his_challenger[id]])
  2420. }
  2421.  
  2422. public begin_the_battle(id,enemy)
  2423. {
  2424.     start_new_round(id,enemy)
  2425. }
  2426.  
  2427. public start_new_round(id,enemy)
  2428. {
  2429.     his_timer[id] = 0
  2430.     his_timer[enemy] = 0
  2431.     is_frozen[id] = 1
  2432.     is_frozen[enemy] = 1
  2433.     his_countdown[id] = MAX_COUNTDOWN
  2434.     his_countdown[enemy] = MAX_COUNTDOWN
  2435.     countdown(id)
  2436.     countdown(enemy)
  2437. }
  2438.  
  2439. public countdown(id)
  2440. {
  2441.     new name[64],his_name[64];
  2442.    
  2443.     get_user_name(id,name,charsmax(name))
  2444.     get_user_name(his_challenger[id],his_name,charsmax(his_name))
  2445.  
  2446.     if(is_user_connected(id))
  2447.     {
  2448.         his_countdown[id]--
  2449.         if(0 >= his_countdown[id])
  2450.         {
  2451.             is_frozen[id] = 0
  2452.             unfreeze_player(id)
  2453.             if(SOUNDS_ENABLED)
  2454.                 client_cmd(id,"spk ^"%s^"",DUEL_SOUNDS[6])
  2455.             client_print(id,print_center,"%s    [%d] VS [%d]   %s",name,his_wins[id],his_wins[his_challenger[id]],his_name)
  2456.             return PLUGIN_HANDLED
  2457.         }
  2458.         else
  2459.         {
  2460.             freeze_player(id)
  2461.             if(SOUNDS_ENABLED)
  2462.                 client_cmd(id,"spk ^"%s^"",DUEL_SOUNDS[5])
  2463.             client_print(id,print_center,"%d",his_countdown[id])
  2464.             if(!is_frozen[id]) // we prevent it from spamming
  2465.                 is_frozen[id] = 1
  2466.         }
  2467.         set_task(1.0,"countdown",id)
  2468.     }
  2469.     return PLUGIN_CONTINUE
  2470. }
  2471.  
  2472. public reset_teams(id)
  2473. {
  2474.     if(his_previous_team[id] == 1)
  2475.     {
  2476.         cs_set_user_team(id,CS_TEAM_CT)
  2477.     }
  2478.     else if(his_previous_team[id] == 2)
  2479.     {
  2480.         cs_set_user_team(id,CS_TEAM_T)
  2481.     }
  2482.     return PLUGIN_CONTINUE
  2483. }
  2484.  
  2485. public check_teams(id,enemy)
  2486. {
  2487.     new CsTeams:teamid,CsTeams:teamenemy;
  2488.     teamid = cs_get_user_team(id)
  2489.     teamenemy = cs_get_user_team(enemy)
  2490.     if(!users_in_same_team(id,enemy) && !is_in_false_team(id) && !is_in_false_team(enemy))
  2491.         return PLUGIN_HANDLED
  2492.     if(teamid == CS_TEAM_CT && teamenemy == CS_TEAM_CT )
  2493.     {
  2494.         cs_set_user_team(id,CS_TEAM_T)
  2495.     } else if(teamid == CS_TEAM_T && teamenemy == CS_TEAM_T)
  2496.     {
  2497.         cs_set_user_team(id,CS_TEAM_CT)
  2498.     }
  2499.     else
  2500.     {
  2501.         Check_Results(id,enemy)
  2502.         return PLUGIN_CONTINUE
  2503.     }
  2504.     return PLUGIN_HANDLED
  2505. }
  2506. stock is_in_false_team(id)
  2507. {
  2508.     if(cs_get_user_team(id) == CS_TEAM_SPECTATOR || cs_get_user_team(id) == CS_TEAM_UNASSIGNED)
  2509.         return PLUGIN_HANDLED
  2510.     return PLUGIN_CONTINUE
  2511. }
  2512. stock users_in_same_team(id,enemy)
  2513. {
  2514.     if(cs_get_user_team(id) == cs_get_user_team(enemy))
  2515.         return PLUGIN_HANDLED
  2516.     return PLUGIN_CONTINUE
  2517. }
  2518.  
  2519. stock get_next_arena()
  2520. {
  2521.     next_empty_arena = 0
  2522.     for(new id;id < MAXPLAYERS;id++)
  2523.     {
  2524.         if(is_user_connected(id))
  2525.         {
  2526.             if(arena_number[id] == next_empty_arena)
  2527.             {
  2528.                 next_empty_arena++
  2529.                 if(next_empty_arena > total_arenas)
  2530.                     return -1
  2531.             }
  2532.         }
  2533.     }
  2534.     if(next_empty_arena > total_arenas)
  2535.     {
  2536.         return -1
  2537.     }
  2538.     return next_empty_arena
  2539. }
  2540.  
  2541. stock reset_values(id)
  2542. {
  2543.     his_HS[id] = 0
  2544.     rounds[arena_number[id]] = 0
  2545.     is_in_duel[id] = 0
  2546.     his_challenger[id] = 0
  2547.     his_asker[id] = 0
  2548.     arena_number[id] = 0
  2549.     his_wins[id] = 0
  2550.     got_spawn[id] = 0
  2551.     his_timer[id] = 0
  2552.     prevent_bad_spawn[id] = 0
  2553.     his_arena[id] = 0
  2554.     his_types[id] = 0
  2555.     Weapons_Settings[id] = 0
  2556.     set_pev(id, pev_groupinfo, GROUP_PLAYER)
  2557. }
  2558.  
  2559. public freeze_player(id)
  2560. {
  2561.     set_user_maxspeed(id,1.0)
  2562. }
  2563.  
  2564. public unfreeze_player(id)
  2565. {
  2566.     set_user_maxspeed(id,250.0)
  2567. }
  2568.  
  2569.  
  2570.  
  2571. public wait_for_enemy_loop(id)
  2572. {
  2573.     if(is_user_connected(id))
  2574.     {
  2575.         if(is_in_duel[id] == 2)
  2576.         {
  2577.             if(is_user_connected(his_challenger[id]))
  2578.             {
  2579.                 if(is_in_duel[his_challenger[id]] == 2)
  2580.                 {
  2581.                     if(is_user_alive(his_challenger[id]))
  2582.                     {
  2583.                         begin_the_battle(id,his_challenger[id])
  2584.                         return PLUGIN_HANDLED
  2585.                     }
  2586.                     set_task(0.1,"wait_for_enemy_loop",id)
  2587.                 }
  2588.             }
  2589.         }
  2590.     }
  2591.     return PLUGIN_CONTINUE
  2592. }
  2593.  
  2594. public hud_displayer(id)
  2595. {
  2596.     if(is_user_connected(id))
  2597.     {
  2598.         if(is_in_duel[id] == 2 && is_user_connected(his_challenger[id]))
  2599.         {
  2600.             check_is_duelant_to_platform(id);
  2601.             check_is_duelant_to_platform(his_challenger[id]);
  2602.            
  2603.             set_task(1.0,"hud_displayer",id)
  2604.         }
  2605.     }
  2606. }
  2607.  
  2608. stock Set_Entity_Invisible(ent, Invisible = 1)
  2609. {
  2610.     if(!pev_valid(ent))
  2611.         return
  2612.     set_pev(ent, pev_effects, Invisible == 0 ? pev(ent, pev_effects) & ~EF_NODRAW : pev(ent, pev_effects) | EF_NODRAW)
  2613. }
  2614.  
  2615. stock client_print_color(const id, const input[], any:...)  
  2616. {  
  2617.     new count = 1, players[32];  
  2618.     static msg[191];  
  2619.     vformat(msg, 190, input, 3);
  2620.     replace_all(msg, 190, "!g", "^x04"); // Green Color  
  2621.     replace_all(msg, 190, "!y", "^x01"); // Default Color  
  2622.     replace_all(msg, 190, "!t", "^x03"); // Team Color  
  2623.     if (id) players[0] = id; else get_players(players, count, "ch");  
  2624.     {  
  2625.         for (new i = 0; i < count; i++)  
  2626.         {  
  2627.             if (is_user_connected(players[i]))  
  2628.             {  
  2629.                 message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("SayText"), _, players[i]);  
  2630.                 write_byte(players[i]);  
  2631.                 write_string(msg);  
  2632.                 message_end();  
  2633.             }  
  2634.         }  
  2635.     }  
  2636. }
  2637.  
  2638. public check_is_duelant_to_platform(id)
  2639. {
  2640.     new iEnt, iTrace, Float: fOriginStart[3], Float: fOriginEnd[3];
  2641.     new ent_code = arena_number[id]+ARENA_CODE
  2642.    
  2643.     entity_get_vector(id, EV_VEC_origin, fOriginStart);
  2644.     fOriginEnd = fOriginStart; fOriginEnd[2] -= 500;
  2645.     iTrace = create_tr2();
  2646.     engfunc(EngFunc_TraceLine, fOriginStart, fOriginEnd, 0, id, iTrace);
  2647.     iEnt = get_tr2(iTrace, TR_pHit);
  2648.    
  2649.     if(!pev_valid(iEnt) || entity_get_int(iEnt, EV_INT_iuser1) != ent_code)
  2650.     {
  2651.              prevent_bad_spawn[id] +=1;
  2652.              spawn_back(id)
  2653.              client_print(id,print_center,"Stay On The Area [%d / 10]",prevent_bad_spawn[id])
  2654.            
  2655.              if(prevent_bad_spawn[id] == 10)
  2656.              {
  2657.                  end_his_duel(id)
  2658.              }
  2659.     }
  2660. }
  2661.  
  2662. ////////////////////////////////////////////////////////////////////////////////////////////////////
  2663. ///////////////////////////////// Invsible Arena & Players  ///////////////////////////////////////
  2664.  
  2665. public OnCBasePlayer_Spawn_Post(id)
  2666. {
  2667.     if( is_user_alive(id) )
  2668.     {
  2669.         set_pev(id, pev_groupinfo, GROUP_ENTITY | GROUP_PLAYER);
  2670.     }
  2671.     if(is_user_alive(id) && his_arena[id] == 2)
  2672.     {
  2673.         his_arena[his_challenger[id]] = 2;
  2674.         set_user_health(id,100)
  2675.         set_user_health(his_challenger[id],100)
  2676.     }
  2677. }
  2678.  
  2679. public ForwardAddToFullPack(ES,e,Ent,Host,HostFlags,Player,pSet)
  2680. {
  2681.     static arenas_ent = -1
  2682.  
  2683.     while((arenas_ent=engfunc(EngFunc_FindEntityByString,arenas_ent,"classname",ARENA_ENT_NAME)))  
  2684.     {          
  2685.     if(Player && is_user_alive(Host) && is_user_alive(Ent) && ((is_in_duel[Ent] != is_in_duel[Host]) || (!is_in_duel[Host] && is_in_duel[Ent])))
  2686.     {
  2687.         set_es(ES,ES_Solid,SOLID_NOT)
  2688.         set_es(ES,ES_RenderMode,kRenderTransAlpha)
  2689.         set_es(ES,ES_RenderAmt,clamp(get_pcvar_num(p_Transparency),0,255))
  2690.     }
  2691.    }
  2692. }
  2693.  
  2694. public ForwardPlayerPreThink(id)
  2695. {
  2696.     for(new Count = 1;Count <= MAXPLAYERS;Count++)
  2697.     {
  2698.         if(!is_user_connected(Count) || Count == id || (!his_challenger[id] && !his_challenger[Count]) || his_challenger[id] == Count)
  2699.             continue
  2700.        
  2701.         g_PlayerSolid[Count] = pev(Count,pev_solid)
  2702.         set_pev(Count,pev_solid,SOLID_NOT)
  2703.        
  2704.         set_user_footsteps ( Count, 0 )
  2705.     }
  2706.    
  2707.     return FMRES_IGNORED
  2708. }
  2709.  
  2710. public ForwardPlayerPostThink(id)
  2711. {
  2712.     for(new Count;Count < MAXPLAYERS;Count++)
  2713.     {
  2714.         if(!is_user_connected(Count) || Count == id || (!his_challenger[id] && !his_challenger[Count]) || his_challenger[id] == Count)
  2715.             continue
  2716.        
  2717.         set_pev(Count,pev_solid,g_PlayerSolid[Count])
  2718.     }
  2719.    
  2720.     return FMRES_IGNORED
  2721. }
  2722.  
  2723. public ForwardTraceLine(Float:v1[3],Float:v2[3],NoMonsters,SkipEnt,Ptr)
  2724. {
  2725.     if(!is_user_alive(SkipEnt))
  2726.         return FMRES_IGNORED
  2727.    
  2728.     new Ptr2
  2729.     engfunc(EngFunc_TraceLine,v1,v2,NoMonsters,SkipEnt,Ptr2)
  2730.     new Hit = get_tr2(0,TR_pHit)
  2731.     if(is_user_alive(Hit) && ((Hit != his_challenger[SkipEnt] && his_challenger[SkipEnt]) || (!his_challenger[SkipEnt] && his_challenger[Hit])))
  2732.         set_tr(TR_flFraction,1.0)
  2733.    
  2734.     return FMRES_IGNORED
  2735. }
  2736.  
  2737. public ForwardTraceHull(Float:v1[3],Float:v2[3],NoMonsters,Hull,SkipEnt,Ptr)
  2738. {
  2739.     if(!is_user_alive(SkipEnt))
  2740.         return FMRES_IGNORED
  2741.    
  2742.     new Ptr2
  2743.     engfunc(EngFunc_TraceHull,v1,v2,NoMonsters,Hull,SkipEnt,Ptr2)
  2744.     new Hit = get_tr2(0,TR_pHit)
  2745.     if(is_user_alive(Hit) && ((Hit != his_challenger[SkipEnt] && his_challenger[SkipEnt]) || (!his_challenger[SkipEnt] && his_challenger[Hit])))
  2746.         set_tr(TR_flFraction,1.0)
  2747.    
  2748.     return FMRES_IGNORED   
  2749. }
  2750.  
  2751. public ForwardAddToFullPackPost( es_handle, e, ent, host, hostflags, player, pset )
  2752. {
  2753.     if( his_arena_entity[ent] )
  2754.     {
  2755.         if(is_in_duel[host] == 2)
  2756.         {
  2757.                 set_pev(host, pev_groupinfo, GROUP_ENTITY)
  2758.         }
  2759.         else if(arena_selected == 1)
  2760.         {
  2761.             //set_es( es_handle, ES_Effects, EF_NODRAW );
  2762.             set_pev(host, pev_groupinfo, GROUP_PLAYER)
  2763.         }
  2764.     }
  2765. }
  2766. public client_PreThink(id)
  2767. {
  2768.     if(is_user_bot(id))
  2769.     {
  2770.         set_pev(id, pev_groupinfo, GROUP_PLAYER)
  2771.     }
  2772.    
  2773.     if(his_player_arena_entity[id])
  2774.     {
  2775.         new ent = engfunc( EngFunc_FindEntityByString, -1, "classname", "entity_arena" );
  2776.         while( ent )
  2777.         {
  2778.             his_arena_entity[ent] = true;
  2779.  
  2780.             ent = engfunc( EngFunc_FindEntityByString, ent, "classname", "entity_arena" );
  2781.        
  2782.             his_player_arena_entity[id] = false;
  2783.         }
  2784.     }
  2785. }
  2786.  
  2787. ///////////////////////////////////  bttale types  /////////////////////////////////////////////////
  2788.  
  2789. public fw_PlayerPreThink( id )
  2790. {
  2791.     static btn
  2792.    
  2793.     if(is_in_duel[id] == 2)
  2794.     {
  2795.  
  2796.         if(his_types[id] == 2)
  2797.         {
  2798.             btn = pev(id, pev_button)
  2799.            
  2800.             if(btn & IN_ATTACK)
  2801.             {
  2802.                 set_pev(id,pev_button,(btn & ~IN_ATTACK) | IN_ATTACK2)
  2803.             }
  2804.         }
  2805.         else if(his_types[id] == 1)
  2806.         {
  2807.             btn = pev(id, pev_button)
  2808.            
  2809.             if(btn & IN_ATTACK2)
  2810.             {
  2811.                 set_pev(id,pev_button,(btn & ~IN_ATTACK2) | IN_ATTACK)
  2812.             }
  2813.         }
  2814.     }
  2815.     return FMRES_IGNORED
  2816. }
  2817.  
  2818.  
  2819. public Forward_TraceAttack(id, attacker, Float:dmg, Float:dir[3], tr, dmgbit)
  2820. {
  2821.     if(id != attacker && get_tr2(tr, TR_iHitgroup) != HIT_HEAD && get_pcvar_num(display_hud))
  2822.     {
  2823.         if(1 <= attacker <= MAXPLAYERS)
  2824.         {
  2825.             if(is_in_duel[id] == 2 && his_types[id] == 3)
  2826.             {
  2827.                 if(!get_pcvar_num(display_hud) && get_user_weapon(attacker) == CSW_KNIFE)
  2828.                 {
  2829.                     return HAM_IGNORED;
  2830.                 }
  2831.                
  2832.                 return HAM_SUPERCEDE;
  2833.             }
  2834.         }
  2835.     }
  2836.    
  2837.     return HAM_IGNORED;
  2838. }
  2839.  
  2840. public Rush_Non_Stop(id)
  2841. {
  2842.     if(is_in_duel[id] == 2 && his_types[id] == 4)
  2843.     {
  2844.         if(get_user_team(id) == 1)
  2845.         {
  2846.             fVelocity[0] = 250.0;
  2847.             fVelocity[1] = 0.0;
  2848.             fVelocity[2] = 0.0;
  2849.            
  2850.             set_pev( id, pev_velocity, fVelocity )
  2851.         }
  2852.         if(get_user_team(id) == 2)
  2853.         {
  2854.             fVelocity[0] = -250.0;
  2855.             fVelocity[1] = 0.0;
  2856.             fVelocity[2] = 0.0;
  2857.            
  2858.             set_pev( id, pev_velocity, fVelocity )
  2859.         }
  2860.     }
  2861. }
  2862.  
  2863. ///////////////////////////////  Block Player Menu  ////////////////////////////////////////////////
  2864.  
  2865. public GetName( id )
  2866. {
  2867.     new name[32]
  2868.    
  2869.     get_user_name(id, name, charsmax(name))
  2870.     return name
  2871. }
  2872.  
  2873. public BlockMenu( id )
  2874. {
  2875.     new pl[32], num
  2876.     get_players(pl, num,"ch")
  2877.     static menuid, menu[128], buffer[2]
  2878.    
  2879.     if(!available_duelers(id))
  2880.     {
  2881.         client_print_color(id, "%sThere's ^4nobody^1 to block.",CHAT_TAG)
  2882.         return PLUGIN_HANDLED
  2883.     }
  2884.    
  2885.    
  2886.     menuid = menu_create("Block Players Menu", "BlockMenuHandler")
  2887.     buffer[1] = 0
  2888.    
  2889.     for(new i = 0; i < num; i++)
  2890.     {
  2891.         if(id == pl[i]) continue
  2892.         formatex(menu, charsmax(menu), "%s %s", GetName(pl[i]), isBlocked[id][pl[i]]? "\r[BLOCKED]":"")
  2893.         buffer[0] = pl[i]
  2894.         menu_additem(menuid, menu, buffer)
  2895.     }
  2896.     menu_display(id, menuid, 0)
  2897.     return PLUGIN_HANDLED
  2898. }
  2899. public BlockMenuHandler( id, menuid, item )
  2900. {
  2901.     if(!is_user_connected(id) || item == MENU_EXIT)
  2902.     {
  2903.         menu_destroy(menuid)
  2904.         return PLUGIN_HANDLED
  2905.     }
  2906.     new dummy, buffer[2], playerid
  2907.     menu_item_getinfo(menuid, item, dummy, buffer, charsmax(buffer), _, _, dummy )
  2908.     playerid = buffer[0]
  2909.     isBlocked[id][playerid] = !isBlocked[id][playerid]
  2910.     client_print_color(id, "%s Player '%s' %sblocked from sending you requests", CHAT_TAG, GetName(playerid), isBlocked[id][playerid]? "":"un")
  2911.     BlockMenu( id )
  2912.     return PLUGIN_HANDLED
  2913. }
  2914.  
  2915.  
  2916.  
  2917. public CopyWeaponSettings(id)
  2918. {
  2919.     if(Weapons_Settings[id] == 0)
  2920.     {
  2921.         Weapons_Settings[his_challenger[id]] = 0
  2922.     }
  2923.     if(Weapons_Settings[id] == 1)
  2924.     {
  2925.         Weapons_Settings[his_challenger[id]] = 1
  2926.     }
  2927.     if(Weapons_Settings[id] == 2)
  2928.     {                                                                                
  2929.         Weapons_Settings[his_challenger[id]] = 2
  2930.     }
  2931.     if(Weapons_Settings[id] == 3)
  2932.     {
  2933.         Weapons_Settings[his_challenger[id]] = 3
  2934.     }
  2935.     if(Weapons_Settings[id] == 4)
  2936.     {
  2937.         Weapons_Settings[his_challenger[id]] = 4
  2938.     }
  2939.     if(Weapons_Settings[id] == 5)
  2940.     {
  2941.         Weapons_Settings[his_challenger[id]] = 5
  2942.     }
  2943.     if(Weapons_Settings[id] == 6)
  2944.     {
  2945.         Weapons_Settings[his_challenger[id]] = 6
  2946.     }
  2947.     if(Weapons_Settings[id] == 7)
  2948.     {
  2949.         Weapons_Settings[his_challenger[id]] = 7
  2950.     }
  2951.     if(Weapons_Settings[id] == 8)
  2952.     {
  2953.         Weapons_Settings[his_challenger[id]] = 8
  2954.     }
  2955.     if(Weapons_Settings[id] == 9)
  2956.     {
  2957.         Weapons_Settings[his_challenger[id]] = 9
  2958.     }
  2959.     if(Weapons_Settings[id] == 10)
  2960.     {
  2961.         Weapons_Settings[his_challenger[id]] = 10
  2962.     }
  2963.     if(Weapons_Settings[id] == 11)
  2964.     {
  2965.         Weapons_Settings[his_challenger[id]] = 11
  2966.     }
  2967.     if(Weapons_Settings[id] == 12)
  2968.     {
  2969.         Weapons_Settings[his_challenger[id]] = 12
  2970.     }
  2971.     if(Weapons_Settings[id] == 13)
  2972.     {
  2973.         Weapons_Settings[his_challenger[id]] = 13
  2974.     }
  2975.     if(Weapons_Settings[id] == 14)
  2976.     {
  2977.         Weapons_Settings[his_challenger[id]] = 14
  2978.     }
  2979.     if(Weapons_Settings[id] == 15)
  2980.     {
  2981.         Weapons_Settings[his_challenger[id]] = 15
  2982.     }
  2983.     if(Weapons_Settings[id] == 16)
  2984.     {
  2985.         Weapons_Settings[his_challenger[id]] = 16
  2986.     }
  2987.     if(Weapons_Settings[id] == 17)
  2988.     {
  2989.         Weapons_Settings[his_challenger[id]] = 17
  2990.     }
  2991.     if(Weapons_Settings[id] == 18)
  2992.     {
  2993.         Weapons_Settings[his_challenger[id]] = 18
  2994.     }
  2995. }
  2996.  
  2997. public HAM_Touch_Weapon(ent, id)
  2998. {
  2999.     if(is_user_alive(id) && !(get_pdata_cbase(ent, 39, 4) > 0))
  3000.         return HAM_SUPERCEDE
  3001.     return HAM_IGNORED
  3002. }
  3003.  
  3004. public Fw_SetModel(entity, const model[])
  3005. {
  3006.         set_task(1.0, "RemoveItems", entity)
  3007.             return;
  3008. }
  3009.  
  3010. public RemoveItems(entity)
  3011. {
  3012.     static Class[10]
  3013.    
  3014.     if(!pev_valid(entity))
  3015.         return;
  3016.    
  3017.     pev(entity, pev_classname, Class, sizeof Class - 1)
  3018.        
  3019.     if (equal(Class, "weaponbox"))
  3020.     {
  3021.         set_pev(entity, pev_nextthink, get_gametime() + 1.0)
  3022.         return;
  3023.     }
  3024. }
  3025.  
  3026. public block_moving(id, weapons, cd)
  3027. {
  3028.     if(his_types[id] == 4)
  3029.     {
  3030.         set_cd(cd, CD_flNextAttack, 0.1)
  3031.    
  3032.         if((entity_get_int(id, EV_INT_button) & (IN_MOVELEFT | IN_MOVERIGHT | IN_BACK )))
  3033.             set_cd(cd, CD_MaxSpeed, 0.1)
  3034.     }
  3035. }
  3036.  
  3037. public fwd_Player_PreThink(id)
  3038. {
  3039.     if(his_types[id] == 4)
  3040.     {
  3041.         set_pev(id, pev_oldbuttons, pev(id, pev_oldbuttons)|IN_JUMP|IN_DUCK);
  3042.     }
  3043. }
  3044.  
  3045. public event_curweapon(id)
  3046. {
  3047.     if(his_arena[id] == 2)
  3048.     {
  3049.     new weaponID= read_data(2)
  3050.     if(weaponID==CSW_C4 || weaponID==CSW_KNIFE || weaponID==CSW_HEGRENADE || weaponID==CSW_SMOKEGRENADE || weaponID==CSW_FLASHBANG)
  3051.         return PLUGIN_CONTINUE;
  3052.    
  3053.     if(cs_get_user_bpammo(id, weaponID)!=CSW_MAXAMMO[weaponID])
  3054.         cs_set_user_bpammo(id, weaponID, CSW_MAXAMMO[weaponID])
  3055.    }
  3056.    return PLUGIN_CONTINUE;
  3057.  
  3058. }
  3059. ///////////////////////////////////////  RANK  /////////////////////////////////////////////////////
  3060.  
  3061. ////////////////////////////////////////////  MENU  ////////////////////////////////////////////////
  3062. public Rank_Menu(id)
  3063. {
  3064.     new menu = menu_create("\r[\y Rank & Top Menu \r]\w By raizo","Rank_Menu_Handled")
  3065.  
  3066.     formatex(szTmp,charsmax(szTmp),"Rank");
  3067.     menu_additem(menu,szTmp,"1")
  3068.  
  3069.     formatex(szTmp,charsmax(szTmp),"Top");
  3070.     menu_additem(menu,szTmp,"2")
  3071.    
  3072.     menu_display(id,menu)
  3073.  
  3074.     return PLUGIN_HANDLED;
  3075. }
  3076.  
  3077. public Rank_Menu_Handled(id,menu,item)
  3078. {
  3079.     if(item == MENU_EXIT)
  3080.     {
  3081.         menu_destroy(menu);
  3082.  
  3083.         return PLUGIN_HANDLED;
  3084.     }
  3085.  
  3086.     new data[3], iName[64]
  3087.     new access, callback;
  3088.     menu_item_getinfo(menu, item, access, data,2, iName, 63, callback);
  3089.     new key = str_to_num(data)
  3090.  
  3091.     switch(key)
  3092.     {
  3093.         case 1:
  3094.         {
  3095.             CmdRank(id)
  3096.             return PLUGIN_HANDLED;
  3097.         }
  3098.         case 2:
  3099.         {
  3100.             CmdTop(id)
  3101.             return PLUGIN_HANDLED;
  3102.         }
  3103.     }
  3104.     menu_destroy(menu);
  3105.  
  3106.     return PLUGIN_HANDLED;
  3107. }
  3108.  
  3109.  
  3110. public CmdReset( )
  3111. {
  3112.     fvault_clear( g_szVaultName );
  3113.  
  3114.     server_print( "[Knife Duel] Rank have been reset !" );
  3115.  
  3116.     log_amx( "[Knife Duel] Rank have been reset !" );
  3117.  
  3118.     return PLUGIN_HANDLED;
  3119. }
  3120.  
  3121. public CmdRank( iPlayer )
  3122. {
  3123.     new Array:aRankData;
  3124.     new iTotal = GetPlayerRanks( aRankData );
  3125.  
  3126.     new iRank;
  3127.     new eRankData[ RankData ];
  3128.  
  3129.     if( iTotal )
  3130.     {
  3131.     new szPlayerSteamID[ 35 ];
  3132.     get_user_authid( iPlayer, szPlayerSteamID, charsmax( szPlayerSteamID ) );
  3133.    
  3134.     for( new i = 0; i < iTotal; i++ )
  3135.     {
  3136.         ArrayGetArray( aRankData, i, eRankData );
  3137.        
  3138.         if( equal( szPlayerSteamID, eRankData[ Rank_SteamID ] ) )
  3139.         {
  3140.             iRank = i + 1;
  3141.             break;
  3142.         }
  3143.     }
  3144.     }
  3145.  
  3146.     if( iRank )
  3147.     {
  3148.     client_print( iPlayer, print_chat, "[Knife Duel] You are ranked %i of %i with %i kill%s!", iRank, iTotal, eRankData[ Rank_Kills ], ( eRankData[ Rank_Kills ] == 1 ) ? "" : "s" );
  3149.     }
  3150.     else
  3151.     {
  3152.     client_print( iPlayer, print_chat, "[Knife Duel] You are not ranked because you have not killed anyone!" );
  3153.     }
  3154.  
  3155.     ArrayDestroy( aRankData );
  3156.    
  3157.     Principal_Menu(iPlayer)
  3158. }
  3159.  
  3160. public CmdTop( iPlayer )
  3161. {
  3162.     new Array:aRankData;
  3163.     new iTotal = max( 0, min( GetPlayerRanks( aRankData ), get_pcvar_num( pCvar_Top ) ) );
  3164.  
  3165.     if( iTotal )
  3166.     {
  3167.     static szMOTD[ 2500 ], iDefaultLen;
  3168.     if( !iDefaultLen )
  3169.     {
  3170.         iDefaultLen = add( szMOTD, charsmax( szMOTD ),
  3171.         "<html><style>\
  3172.         body{background:#040404;font-family:Verdana, Arial, Sans-Serif;font-size:7pt;}\
  3173.         .t{color:#808080;text-align:left; }\
  3174.         #h{background: #222 url('http://limmudny.org/wp-content/uploads/2014/09/PageTitleBackground2-900x100.jpg') repeat-x;color:#000;font-weight:bold;}\
  3175.             #p{color:#D41313;}\
  3176.             #n{color:#fff;}\
  3177.             </style><body>\
  3178.             <table cellspacing=0 width=100% class=t>")
  3179.            
  3180.             add(szMOTD, charsmax(szMOTD),
  3181.             "<tr><td id=h width=7%>Nr:</td>\
  3182.             <td id=h>Nick</td>\
  3183.             <td id=h>Kills</td></tr>")
  3184.            
  3185.             iDefaultLen = strlen(szMOTD)
  3186.         }
  3187.        
  3188.         new iLen = iDefaultLen;
  3189.        
  3190.         new eRankData[ RankData ];
  3191.        
  3192.         new szFixedName[ 128 ];
  3193.        
  3194.         for( new i = 0; i < iTotal; i++ )
  3195.         {
  3196.             ArrayGetArray( aRankData, i, eRankData );
  3197.            
  3198.             copy( szFixedName, charsmax( szFixedName ), eRankData[ Rank_Name ] );
  3199.            
  3200.             MakeNameMOTDSafe( szFixedName, 31 );
  3201.            
  3202.             iLen += formatex( szMOTD[ iLen ], charsmax( szMOTD ) - iLen, "<tr><td>%i</td><td>%s</td><td>%i</td></tr>", ( i + 1 ), szFixedName, eRankData[ Rank_Kills ] );
  3203.         }
  3204.        
  3205.         copy( szMOTD[ iLen ], charsmax( szMOTD ) - iLen, "</tbody></table></body>" );
  3206.        
  3207.         show_motd( iPlayer, szMOTD, "Knife Duel Top" );
  3208.     }
  3209.     else
  3210.     {
  3211.         client_print( iPlayer, print_chat, "* No players have been put on the top!" );
  3212.     }
  3213.    
  3214.     ArrayDestroy( aRankData );
  3215.     Principal_Menu(iPlayer)
  3216. }
  3217.  
  3218.  
  3219. public fw_PlayerKilled(iVictim, iKiller)  
  3220. {
  3221.     if (iVictim == iKiller || !is_user_alive(iKiller))
  3222.         return
  3223.        
  3224.         new szName[ 32 ], szSteamID[ 35 ];
  3225.         get_user_authid( iKiller, szSteamID, charsmax( szSteamID ) );
  3226.        
  3227.         new szKills[ 48 ], iKills;
  3228.        
  3229.         if( fvault_get_data( g_szVaultName, szSteamID, szKills, charsmax( szKills ) ) )
  3230.         {
  3231.             strbreak( szKills, szKills, charsmax( szKills ), szName, charsmax( szName ) );
  3232.            
  3233.             iKills = str_to_num( szKills );
  3234.         }
  3235.         if(is_in_duel[iKiller] == 2)
  3236.         {
  3237.             iKills++;
  3238.            
  3239.             get_user_name( iKiller, szName ,charsmax( szName ) );
  3240.            
  3241.             formatex( szKills, charsmax( szKills ), "%i %s", iKills, szName );
  3242.            
  3243.             fvault_set_data( g_szVaultName, szSteamID, szKills );
  3244.         }
  3245.        
  3246.     }
  3247.    
  3248.     GetPlayerRanks( &Array:aRankData )
  3249. {
  3250.     aRankData = ArrayCreate( RankData );
  3251.     new iTotal;
  3252.    
  3253.     new eRankData[ RankData ];
  3254.    
  3255.     new szFileName[ 128 ];
  3256.     _FormatVaultName( g_szVaultName, szFileName, charsmax( szFileName ) );
  3257.    
  3258.     new iFile = fopen( szFileName, "rt" );
  3259.    
  3260.     if( !iFile )
  3261.     {
  3262.         return iTotal;
  3263.     }
  3264.    
  3265.     new szFileData[ 128 ];
  3266.     new szKills[ 48 ];
  3267.    
  3268.     while( !feof( iFile ) )
  3269.     {
  3270.         fgets( iFile, szFileData, charsmax( szFileData ) );
  3271.         trim( szFileData );
  3272.        
  3273.         if( !szFileData[ 0 ] )
  3274.         {
  3275.             continue;
  3276.         }
  3277.        
  3278.         parse( szFileData, eRankData[ Rank_SteamID ], charsmax( eRankData[ Rank_SteamID ] ), szKills, charsmax( szKills ) );
  3279.         strbreak( szKills, szKills, charsmax( szKills ), eRankData[ Rank_Name ], charsmax( eRankData[ Rank_Name ] ) );
  3280.         eRankData[ Rank_Kills ] = str_to_num( szKills );
  3281.        
  3282.         ArrayPushArray( aRankData, eRankData );
  3283.        
  3284.         iTotal++;
  3285.     }
  3286.    
  3287.     fclose( iFile );
  3288.    
  3289.     ArraySort( aRankData, "SortData" );
  3290.    
  3291.     return iTotal;
  3292. }
  3293.  
  3294. public SortData( Array:aData, iIndex1, iIndex2, const iSortData[ ], iSortDataSize )
  3295. {
  3296.     new eData1[ RankData ], eData2[ RankData ];
  3297.     ArrayGetArray( aData, iIndex1, eData1 );
  3298.     ArrayGetArray( aData, iIndex2, eData2 );
  3299.    
  3300.     return clamp( ( eData2[ Rank_Kills ] - eData1[ Rank_Kills ] ), -1, 1 );
  3301. }
  3302.  
  3303. stock MakeNameMOTDSafe( szName[ 128 ], iMaxChars )
  3304. {
  3305.     szName[ 32 ] = 0;
  3306.    
  3307.     replace_all( szName, 127, "&", "&amp;" );
  3308.     replace_all( szName, 127, "<", "&lt;" );
  3309.     replace_all( szName, 127, ">", "&gt;" );
  3310.     replace_all( szName, 127, "^"", "&quot;" );
  3311.    
  3312.     if( iMaxChars > 128 ) return;
  3313.    
  3314.     new iLast;
  3315.     for( new i = 0; i < 128 && szName[ i ]; )
  3316.     {
  3317.         if( szName[ i ] == '&' )
  3318.         {
  3319.             if( equal( szName[ i ], "&amp;", 5 ) )
  3320.             {
  3321.                 i += 4;
  3322.             }
  3323.             else if( equal( szName[ i ], "&quot;", 6 ) )
  3324.             {
  3325.                 i += 5;
  3326.             }
  3327.             else if( equal( szName[ i ], "&lt;", 4 ) || equal( szName[ i ], "&gt;", 4 ) )
  3328.             {
  3329.                 i += 3;
  3330.             }
  3331.         }
  3332.        
  3333.         if( ++i > iMaxChars )
  3334.         {
  3335.             break;
  3336.         }
  3337.        
  3338.         iLast = i;
  3339.     }
  3340.    
  3341.     szName[ iLast ] = 0;
  3342. }
  3343.  
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement