Advertisement
Guest User

Untitled

a guest
Oct 10th, 2018
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.72 KB | None | 0 0
  1. #include <amxmodx>
  2. #include <fakemeta>
  3. #include <engine>
  4. #include <fun>
  5. #include <colorchat>
  6. #include <dhudmessage>
  7. #include <xs>
  8.  
  9. #define TASK_TELEPORT 12345
  10.  
  11. #define VERSION "1.0"
  12.  
  13. new bool: pronadji_orig = false
  14.  
  15. new bool: hoce_duel, bool: hoce_duel_i[ 33 ], d_started, bool: teleporting_p[ 33 ]
  16.  
  17. new broj_igraca = 0, g_broj = 0
  18.  
  19. new Float:spremi_duel, Float: time_cup
  20.  
  21. new startovao_name[ 32 ]
  22.  
  23. new ime_brt[ 33 ][ 32 ]
  24.  
  25. new Float:origins[ 33 ][ 3 ]
  26. new vreme_cupa = 1;
  27. new bool: naziv_CUPa = false
  28.  
  29. new r = 50, g = 35, b = 170
  30.    
  31. new playerNum, players[ 32 ]
  32.  
  33. new forbiden_say[][] = { "say /cp", "say /tp", "say /gc", "+hook", "say /nc", "say /pause", "say /noclip",
  34.             "say /savepos", "say /checkpoint", "say /spec" }
  35. new saycmd[ 12 ]
  36.  
  37. new p_inDuel[ 33 ]
  38. new currentPlayer[ 33 ]
  39.  
  40. new kz_cup_message
  41.  
  42.  
  43. public plugin_init()
  44. {
  45.     register_plugin( "CUP Plugin", VERSION, "JocA" )
  46.  
  47.     kz_cup_message = register_cvar( "kz_cup_message", "1" ) //should be say commands be visible?
  48.  
  49.     register_clcmd( "say /startcup", "duel_open_pre" )
  50.     register_clcmd( "say /joincup", "join_duel" )
  51.     register_clcmd( "cupname", "duel_open" )
  52.     register_clcmd( "say /tcup", "timeOfcup" )
  53.    
  54.     register_clcmd( "say /exit", "exitCup" )
  55.    
  56.     for( new i = 0; i < sizeof( forbiden_say ); i++ )
  57.     {
  58.         formatex( saycmd, charsmax( saycmd ), "%s", forbiden_say[ i ] )
  59.         register_clcmd( saycmd, "forbiden" )
  60.     }
  61.    
  62. }
  63. public forbiden( id )
  64. {
  65.     if( d_started && hoce_duel_i[ id ] )
  66.     {
  67.         ColorChat( id, RED, "^1[CUP] Sorry,^3 not possible^1 while in Cup." )
  68.         return PLUGIN_HANDLED
  69.     }
  70.     return PLUGIN_CONTINUE
  71. }
  72. public client_disconnect( id )
  73. {
  74.     remove_task( id )
  75.     if( hoce_duel_i[ id ] )
  76.     {
  77.         ColorChat( 0, BLUE, "Player from cup left the server :/" )
  78.         hoce_duel_i[ id ] = false
  79.         broj_igraca -= 1
  80.     }
  81. }
  82. public duel_open_pre( id )
  83. {
  84.     if( hoce_duel )
  85.     {
  86.         ColorChat( id, GREY, "^1[CUP] It's already started, wait some moments." )
  87.         return PLUGIN_HANDLED
  88.     }
  89.     new vreme_cupa_text[ 50 ]; formatex( vreme_cupa_text, 49, "Time of the battle:\y %d minutes^n", vreme_cupa )
  90.     new menu = menu_create( "Start the cup!^n\dVersion: 1.0", "cupHandled" )
  91.    
  92.     menu_additem( menu, vreme_cupa_text )
  93.  
  94.     menu_additem( menu, "\wAdd custom name for the battle^n" )
  95.     menu_additem( menu, "\ySTART IT BOIII" )
  96.    
  97.     menu_display( id, menu, 0 )
  98.    
  99.     return get_pcvar_num( kz_cup_message ) == 0 ? PLUGIN_HANDLED:PLUGIN_CONTINUE
  100. }
  101. public cupHandled( id, menu, item )
  102. {
  103.     switch( item )
  104.     {
  105.         case 0:
  106.         {
  107.             switch( vreme_cupa )
  108.             {
  109.                 case 1:
  110.                 {
  111.                     vreme_cupa += 1
  112.                     duel_open_pre( id )
  113.                 }
  114.                 case 2:
  115.                 {
  116.                     vreme_cupa += 1
  117.                     duel_open_pre( id )
  118.                 }
  119.                 case 3:
  120.                 {
  121.                     vreme_cupa = 5
  122.                     duel_open_pre( id )
  123.                 }
  124.                 case 5:
  125.                 {
  126.                     vreme_cupa = 7
  127.                     duel_open_pre( id )
  128.                 }
  129.                 case 7:
  130.                 {
  131.                     vreme_cupa = 1
  132.                     duel_open_pre( id )
  133.                 }
  134.             }
  135.         }
  136.  
  137.         case 1:
  138.         {
  139.             client_cmd( id, "messagemode cupname" )
  140.             naziv_CUPa = true
  141.         }
  142.         case 2:
  143.         {
  144.             duel_open( id )
  145.         }
  146.     }
  147.     menu_destroy( menu )
  148. }
  149. public duel_open( id )
  150. {
  151.     if( !naziv_CUPa )
  152.         get_user_name( id, startovao_name, charsmax( startovao_name ) )
  153.     else
  154.         read_args( startovao_name, charsmax( startovao_name ) )
  155.        
  156.     hoce_duel_i[ id ] = true
  157.     broj_igraca++
  158.    
  159.     hoce_duel = true
  160.     spremi_duel = get_gametime()
  161.    
  162.     ColorChat( 0, BLUE, "^1[CUP] Cup started^4 %s ^1%d mins. Waiting^4 10 sec^1 for players...", startovao_name, vreme_cupa )
  163.     set_task( 10.0, "kraj_open", id )
  164. }
  165. public join_duel( id )
  166. {
  167.     new name[ 32 ], Float: get_timing, Float: pred_polazak
  168.     get_user_name( id, name, charsmax( name ) )
  169.    
  170.     get_timing = get_gametime() - spremi_duel
  171.     if( get_timing >= 10.0 && d_started)
  172.     {
  173.         ColorChat( id, GREY, "^1[CUP] Someone is already playing,^3 wait or go /spec ;)" )
  174.         return PLUGIN_HANDLED
  175.     }
  176.     else
  177.     {
  178.         pred_polazak = 10.0 - get_timing
  179.         set_task( pred_polazak, "pocetak_CUPa", id )
  180.     }
  181.    
  182.     if( hoce_duel && !d_started )
  183.     {
  184.         hoce_duel_i[ id ] = true
  185.         broj_igraca++
  186.         ColorChat( 0, BLUE, "^1[CUP]^3 %s^1 joined! Cup name:^4 %s", name, startovao_name )
  187.     }
  188.     if( !hoce_duel )
  189.     {
  190.         ColorChat( id, BLUE, "^1[CUP] No one started, go /startcup." )
  191.         return PLUGIN_HANDLED
  192.     }
  193.     return get_pcvar_num( kz_cup_message ) == 0 ? PLUGIN_HANDLED:PLUGIN_CONTINUE
  194. }
  195. public kraj_open( id )
  196. {
  197.     if( broj_igraca <= 1 )
  198.     {
  199.         ColorChat( id, BLUE, "^1[CUP] No enought players, sorry." )
  200.     }
  201.     else
  202.     {
  203.         set_dhudmessage( 255, 85, 0, -1.0, 0.4, 0, 2.5, 2.5 )  
  204.         show_dhudmessage( id, "It's starting BOIIIZ ! GL !^nPlayers: %d", broj_igraca  )
  205.         pocetak_CUPa( id )
  206.     }
  207. }
  208. public pocetak_CUPa( id )
  209. {
  210.     if( hoce_duel_i[ id ] )
  211.     {
  212.         SendCmd_1( id, "say /start" )
  213.        
  214.         set_task( 0.1, "frozen", id )
  215.         ColorChat( id, BLUE, "^1[CUP] Starts in 5....4....3....." )
  216.        
  217.         set_user_rendering(id, kRenderFxGlowShell, r, g, b, kRenderNormal, 15)
  218.         d_started = true
  219.         set_task( 5.0, "start_CUP", id )
  220.         pronadji_orig=false
  221.     }
  222. }
  223. public timeOfcup( id )
  224. {
  225.     if( d_started && hoce_duel_i[ id ] )
  226.         client_print( id, print_center, "^r[ CUP Time Remaining ]^r^r^r%.00f seconds", 60.0*vreme_cupa - ( get_gametime() - time_cup ) )
  227. }
  228. public frozen( id )
  229. {
  230.     fm_set_user_frozen( id, 1 )
  231.    
  232.     ScreenFade( id )
  233. }
  234.  
  235. public start_CUP( id )
  236. {
  237.     time_cup = get_gametime()
  238.     fm_set_user_frozen( id, 0 )
  239.     ColorChat( id, BLUE, "^1[CUP]^1 Started ! GL & HF !^4 %dmin^1 remainig", vreme_cupa )
  240.     set_task( vreme*60, "zavrsen_CUP", id )
  241. }
  242. public exitCup( id )
  243. {
  244.     if( hoce_duel_i[ id ] )
  245.     {
  246.         new name[ 32 ]; get_user_name( id, name, charsmax( name ) )
  247.         if( d_started )
  248.         {
  249.             broj_igraca -= 1
  250.             hoce_duel_i[ id ] = false
  251.            
  252.             remove_task( id )
  253.         }
  254.         else
  255.         {
  256.             hoce_duel_i[ id ] = false
  257.             remove_task( id )
  258.         }
  259.         ColorChat( id, RED, "^1[CUP]^1 One player left the cup:^3 %s", name )
  260.     }
  261.     else
  262.     {
  263.         client_print( id, print_chat, "^1[CUP] From where to exit lol ?" )
  264.     }
  265.     return PLUGIN_HANDLED
  266. }
  267.    
  268. public zavrsen_CUP( id )
  269. {
  270.     g_broj = broj_igraca
  271.     teleporting_p[ id ] = true
  272.     naziv_CUPa = false
  273.     fm_set_user_frozen( id, 1 )
  274.     ScreenFade( id )
  275.     remove_task( id )
  276.    
  277.     ColorChat( id, BLUE, ".....one sec...finding (%d plrs) origins....", broj_igraca )
  278.     if( !pronadji_orig )
  279.     {
  280.         pronadji_origine()
  281.        
  282.         pronadji_orig=true
  283.     }  
  284.     SendCmd_1( id, "say /start" )
  285.  
  286.     set_task( 4.0, "teleport_origin", id + TASK_TELEPORT)
  287.  
  288.     set_task( 4.0*g_broj+4.0, "pravi_kraj", id ) //real finish
  289. }  
  290. public pronadji_origine()
  291. {
  292.     new id, x=0
  293.     get_players( players, playerNum, "a" )
  294.    
  295.     for( new i = 0; i < playerNum; i++ )
  296.     {
  297.         id = players[ i ]
  298.         if( hoce_duel_i[ id ] )
  299.         {
  300.             entity_get_vector( id, EV_VEC_origin, origins[ id ] )
  301.             get_user_name( id, ime_brt[ id ], 31 )
  302.            
  303.             p_inDuel[ x++ ] = id //thanks kushfield
  304.  
  305.         }
  306.     }
  307. }
  308.  
  309. public teleport_origin( id )
  310. {
  311.     id = id - TASK_TELEPORT;
  312.    
  313.     //entity_set_vector( id, EV_VEC_origin, origins[ p_inDuel[ currentPlayer[ id ]]] )
  314.     engfunc( EngFunc_SetOrigin, id, origins[ p_inDuel[ currentPlayer[ id ]]] )
  315.     set_dhudmessage( 255, 85, 0, -1.0, 0.4, 0, 2.5, 2.5 )
  316.     show_dhudmessage( id, "Teleported to: %s", ime_brt[ p_inDuel[ currentPlayer[ id ]]] )
  317.     currentPlayer[id]++
  318.    
  319.     if( broj_igraca > currentPlayer[id] )
  320.         set_task( 4.0, "teleport_origin", id+ TASK_TELEPORT )
  321. }
  322.    
  323.  
  324. public pravi_kraj( id )
  325. {
  326.     set_dhudmessage( 255, 85, 0, -1.0, 0.4, 0, 3.0, 3.0)  
  327.     show_dhudmessage( id, "THE END! Be fair and tell who won!^nPlayers: %d", g_broj )
  328.     ColorChat( id, BLUE, "^1[CUP] It's finished^1 GG ! For another one, go ^4/startcup^1 !" )
  329.     d_started = false
  330.     broj_igraca = 0
  331.     g_broj = 0
  332.     hoce_duel_i[ id ] = false
  333.     hoce_duel = false
  334.     startovao_name = ""
  335.     fm_set_user_frozen( id, 0 )
  336.     set_user_rendering( id )
  337.     remove_task( id )
  338.     teleporting_p[ id ] = false
  339.     client_cmd( id, "say /start" )
  340.     teleporting_p[ id ] = false
  341.     vreme_cupa = 1
  342.     pronadji_orig = false
  343.     currentPlayer[ id ] = 0
  344. }
  345. stock fm_set_user_frozen(client, frozen)
  346. {
  347.     if( !is_user_alive(client) ) return 0;
  348.        
  349.     new flags = pev(client, pev_flags);
  350.     if( frozen && !(flags & FL_FROZEN) )
  351.     {
  352.         set_pev(client, pev_flags, (flags | FL_FROZEN))
  353.        
  354.     }
  355.     else if( !frozen && (flags & FL_FROZEN) )
  356.     {
  357.         set_pev(client, pev_flags, (flags & ~FL_FROZEN));
  358.     }  
  359.        
  360.     return 1;
  361. }  
  362.  
  363. public ScreenFade(id )
  364. {
  365.     message_begin(MSG_ONE, get_user_msgid("ScreenFade"), {0,0,0}, id)
  366.     write_short((1<<10)*4)
  367.     write_short((1<<10)*15)
  368.     write_short(0x0000)
  369.     write_byte(150)
  370.     write_byte(100)
  371.     write_byte(5)
  372.     write_byte(80)
  373.     message_end()
  374. }      
  375. stock SendCmd_1( id , text[] ) //cuz filtercmd 1
  376. {
  377.     message_begin( MSG_ONE, 51, _, id )
  378.     write_byte( strlen(text) + 2 )
  379.     write_byte( 10 )
  380.     write_string( text )
  381.     message_end()
  382. }
  383. stock fm_set_user_origin(index,  origin[3]) {
  384.     new Float:orig[3];
  385.     IVecFVec(origin, orig);
  386.    
  387.     return fm_entity_set_origin(index, orig);
  388. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement