Advertisement
jocasrb

KZ LongJump Auto Cup

Jul 7th, 2020
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 10.42 KB | None | 0 0
  1. /* Sublime AMXX Editor v2.2 */
  2. /*VIDEO PRESENTATION:
  3.  
  4. https://www.youtube.com/watch?v=Hbvbg_dbiMk
  5.  
  6. */
  7. #include <amxmodx>
  8. #include <engine>
  9. #include <fakemeta>
  10. #include <colorchat>
  11.  
  12. #define PLUGIN  "LJ CUP 240 (kz_lj2)"
  13. #define VERSION "1.0"
  14. #define AUTHOR  "JocA"
  15.  
  16. #define MODEL "models/player.mdl"
  17.  
  18. #define TASK_ALMOST_STARTED 1222
  19. #define TASK_FINISH_CUP     1555
  20.  
  21. new g_szMapName[ 32 ]
  22. new g_iVerticalInvis
  23. new g_iHorizontalJumped
  24.  
  25. new Float: float_origin[ 3 ] = { 848.0, 953.0, -845.0 }
  26. new Float: float_full_tp[ 3 ] = { 2300.0, 953.0, -895.0 }
  27. new Float: float_jumped_block[ 3 ] = { 990.0, 762.0, -873.0 }
  28. new Float: float_jumped_tp[ 3 ] = { 990.0, 1355.0, -825.0 }
  29.  
  30. new g_iPlayerBlock[ 33 ]
  31. new bool: g_bTouching[ 33 ]
  32. new bool: g_bPlaying[ 33 ]
  33. new bool: g_bCup
  34. new bool: g_bPrepareStart
  35. new Float: g_fCupTime
  36.  
  37. new g_entCountDown, Float: g_flFreq, Float: g_flTimeLeft //connor
  38.  
  39. public plugin_init()
  40. {
  41.     register_plugin(PLUGIN, VERSION, AUTHOR)
  42.  
  43.     register_touch( "kz_lj2_horizontal_jumped", "player", "jumped_it" )
  44.     register_touch( "kz_lj2_full_tp", "player", "failed_it" )
  45.  
  46.     register_clcmd( "say /startlj", "lj_starting" )
  47.     register_clcmd( "say /endlj", "quit_lj" )
  48.     register_clcmd( "say /quitlj", "quit_lj" )
  49.     register_clcmd( "say /joinlj", "joining" )
  50.  
  51.     get_mapname( g_szMapName, charsmax( g_szMapName ) )
  52.     if( !equal( g_szMapName, "kz_longjumps2" ) )
  53.         set_fail_state( "LJ-Cup plugin paused, not kz_longjumps2 map" )
  54. }
  55. public client_putinserver( id )
  56. {
  57.     g_iPlayerBlock[ id ] = 0
  58.     g_bTouching[ id ] = false
  59. }
  60. public client_disconnected( id )
  61. {
  62.     g_iPlayerBlock[ id ] = 0
  63.     g_bTouching[ id ] = false
  64.     if( g_bPlaying[ id ] )
  65.         quit_lj( id )
  66. }
  67. public joining( id )
  68. {
  69.     if( g_bPlaying[ id ] )
  70.     {
  71.         ColorChat( id, BLUE, "^4[LJ-Cup]^1 You are already in the LJ Cup!" )
  72.         return PLUGIN_HANDLED
  73.     }
  74.     if( g_bCup )
  75.     {
  76.         ColorChat( id, BLUE, "^4[LJ-Cup]^1 You must wait new LJ Cup to start." )
  77.         return PLUGIN_HANDLED
  78.     }
  79.     if( g_bPrepareStart )
  80.     {
  81.         g_bPlaying[ id ] = true
  82.         ColorChat( id, BLUE, "^4[LJ-Cup]^3 %n^1 joined the^3 LJ Cup^1. Hurry up!" )
  83.         return PLUGIN_HANDLED
  84.     }
  85.     return PLUGIN_HANDLED
  86. }
  87. public quit_lj( id )
  88. {
  89.     if( !g_bPlaying[ id ] )
  90.     {
  91.         ColorChat( 0, RED, "^4[LJ-Cup]^1 You can't leave if you didn't join..." )
  92.         return PLUGIN_HANDLED
  93.     }
  94.     if( g_bPrepareStart || g_bCup )
  95.     {
  96.         ColorChat( 0, RED, "^4[LJ-Cup]^3 %n^1 left the^3 LJ Cup^1. Ask him why...", id )
  97.         g_bPlaying[ id ] = false
  98.         g_iPlayerBlock[ id ] = 0
  99.     }
  100.     new num_of_players
  101.     for( new i = 1; i <= get_maxplayers(); i++ )
  102.     {
  103.         if( !is_user_connected( i ) )
  104.             continue
  105.  
  106.         if( g_bPlaying[ i ] )
  107.             num_of_players++
  108.     }
  109.     if( !num_of_players )
  110.     {
  111.         finish_cup( 0 )
  112.         ColorChat( 0, RED, "^4[LJ-Cup]^1 Cup has Ended, there are no players left." )
  113.     }
  114.     return PLUGIN_HANDLED
  115. }
  116. public lj_starting( id )
  117. {
  118.     if( g_bPrepareStart || g_bCup )
  119.     {
  120.         ColorChat( id, BLUE, "^4[LJ-Cup]^1 Cup is already in progress. Join or wait to start the new one!" )
  121.         return PLUGIN_HANDLED
  122.     }
  123.     ColorChat( 0, BLUE, "^4[LJ-Cup]^3 %n^1 started the race, type^3 /joinlj^1 to join!^4 [Starting in 10 seconds]", id )
  124.     g_bPrepareStart = true
  125.  
  126.     g_bPlaying[ id ] = true
  127.  
  128.     set_task( 10.0, "almost_start_cup", TASK_ALMOST_STARTED )
  129.     return PLUGIN_HANDLED
  130. }
  131. public almost_start_cup()
  132. {
  133.     for( new i = 1; i <= get_maxplayers(); i++ )
  134.     {
  135.         if( !is_user_connected( i ) )
  136.             continue
  137.  
  138.         if( !g_bPlaying[ i ] )
  139.             continue
  140.  
  141.         entity_set_origin( i, float_jumped_tp )
  142.         drop_to_floor( i )
  143.         set_task( 5.0, "start_cup", i )
  144.         fm_set_user_frozen( i, 1 )
  145.  
  146.         message_begin(MSG_ONE, get_user_msgid("ScreenFade"), {0,0,0}, i)
  147.         write_short((1<<10)*5)
  148.         write_short((1<<10)*20)
  149.         write_short(0x0000)
  150.         write_byte(0)
  151.         write_byte(0)
  152.         write_byte(0)
  153.         write_byte(230)
  154.         message_end()
  155.  
  156.         set_dhudmessage( 255, 255, 255, -1.0, 0.35, 0, 4.0, 7.0 )
  157.         show_dhudmessage( i, "Long Jump Cup is starting!^nHave fun and good luck !" )
  158.         set_hudmessage( 15, 255, 55, -1.0, 0.43, 0, 4.0, 7.0, 0.0, 0.0, -1 )
  159.         show_hudmessage( i, "Important rules: don't cheat !" )
  160.     }
  161. }
  162. public start_cup( id )
  163. {
  164.  
  165.     create_function_all( 1 )
  166.     create_small()
  167.     create_tp()
  168.  
  169.     fm_set_user_frozen( id, 0 )
  170.     g_bCup = true
  171.     g_fCupTime = get_gametime()
  172.  
  173.     set_pev( id, pev_basevelocity, NULL_VECTOR) /* thanks to: */
  174.     set_pev( id, pev_fuser2, 0.0 )              /* juice */
  175.  
  176.     MakeCountDown( 60.0, 0.15 )
  177.     set_task( 60.0, "finish_cup", TASK_FINISH_CUP )
  178. }
  179. public finish_cup( type )
  180. {
  181.     remove_task( TASK_FINISH_CUP )
  182.     remove_task( TASK_ALMOST_STARTED )
  183.     g_bCup = false
  184.     g_bPrepareStart = false
  185.     g_fCupTime = 0.0
  186.     if( type )
  187.     {
  188.         for( new id = 1; id <= get_maxplayers(); id++ )
  189.         {
  190.             if( !is_user_connected( id ) )
  191.                 continue
  192.  
  193.             if( g_bPlaying[ id ] )
  194.             {
  195.                 g_iPlayerBlock[ id ] = 0
  196.                 g_bPlaying[ id ] = false
  197.             }
  198.         }
  199.         ColorChat( 0, BLUE, "^4[LJ-Cup]^1 Cup Finished! GJ to everyone!" )
  200.     }
  201.     //reset blocks for next cup
  202.     remove_entity_name( "kz_lj2_full_tp" )
  203.     remove_entity_name( "kz_lj2_horizontal_jumped" )
  204.     remove_entity_name( "kz_lj2_vertical_invis" )
  205.     g_iVerticalInvis = 0
  206.     g_iHorizontalJumped = 0
  207.     float_origin[ 0 ] = 848.0
  208.     float_jumped_block[ 0 ] = 990.0
  209. }
  210. public failed_it( ent, id )
  211. {
  212.     if( 1 <= id <= 32 && !g_bTouching[ id ] && g_bCup && g_bPlaying[ id ] )
  213.     {
  214.         g_bTouching[ id ] = true
  215.         create_jumped( id )
  216.         set_task( 0.3, "uncheck_it", id )
  217.     }
  218. }
  219. public jumped_it( ent, id )
  220. {
  221.     if( 1 <= id <= 32 && !g_bTouching[ id ] && g_bCup && g_bPlaying[ id ] )
  222.     {
  223.         g_bTouching[ id ] = true
  224.         g_iPlayerBlock[ id ]++
  225.         create_jumped( id )
  226.         set_task( 0.3, "uncheck_it", id )
  227.     }
  228. }
  229. public uncheck_it( id )
  230.     g_bTouching[ id ] = false
  231.  
  232.  
  233. public create_jumped( id )
  234. {
  235.     if( g_iPlayerBlock[ id ] >= 10 )
  236.     {
  237.         ColorChat( 0, BLUE, "^4[LJ-Cup]^3 %n^1 won the LJ Cup! With time:^3 %s^1 !", id, StringTimer( get_gametime() - g_fCupTime ) )
  238.         finish_cup( 1 )
  239.         return PLUGIN_HANDLED
  240.     }
  241.     float_jumped_tp[ 0 ] = float_jumped_tp[ 0 ] + ( g_iPlayerBlock[ id ] * 288.2 )
  242.  
  243.     entity_set_origin( id, float_jumped_tp )
  244.     float_jumped_tp[ 0 ] = 990.0
  245.     drop_to_floor( id )
  246.  
  247.     return PLUGIN_HANDLED
  248. }
  249. public create_small( )
  250. {
  251.     if( g_iHorizontalJumped >= 10 )
  252.         return PLUGIN_HANDLED
  253.  
  254.     if( g_iHorizontalJumped )
  255.         float_jumped_block[ 0 ] += 288.2
  256.  
  257.     g_iHorizontalJumped++
  258.     new ent = create_entity("info_target")
  259.     entity_set_string(ent,EV_SZ_classname,"kz_lj2_horizontal_jumped")
  260.     entity_set_model(ent,MODEL)
  261.     entity_set_int(ent,EV_INT_solid,SOLID_BBOX)
  262.     entity_set_size(ent,Float:{-90.0,-50.0,-5.0},Float:{90.0,50.0,5.0})
  263.  
  264.     entity_set_origin(ent,float_jumped_block)
  265.  
  266.     set_pev(ent, pev_rendermode, kRenderTransAlpha)
  267.     set_pev(ent, pev_renderamt, 0)
  268.  
  269.  
  270.     create_small()
  271.  
  272.     return PLUGIN_HANDLED
  273. }
  274. public create_tp()
  275. {
  276.     new ent = create_entity("info_target")
  277.     entity_set_string(ent,EV_SZ_classname,"kz_lj2_full_tp")
  278.     entity_set_model(ent,MODEL)
  279.     entity_set_int(ent,EV_INT_solid,SOLID_BBOX)
  280.     entity_set_size(ent,Float:{-1600.0,-400.0,-5.0},Float:{1600.0,400.0,5.0})
  281.  
  282.     entity_set_origin(ent,float_full_tp)
  283.  
  284.     set_pev(ent, pev_rendermode, kRenderTransAlpha)
  285.     set_pev(ent, pev_renderamt, 0)
  286. }
  287. public create_function_all( type )
  288. {
  289.     if( type )
  290.     {
  291.         g_iVerticalInvis++
  292.     }
  293.     if( type == 2 )
  294.         float_origin[ 0 ] += 288.0
  295.  
  296.     new ent = create_entity("info_target")
  297.     entity_set_string(ent,EV_SZ_classname,"kz_lj2_vertical_invis")
  298.     entity_set_model(ent,MODEL)
  299.     entity_set_int(ent,EV_INT_solid,SOLID_BBOX)
  300.     if( type )
  301.         entity_set_size(ent,Float:{-2.0,-550.0,-50.0},Float:{2.0,550.0,150.0})
  302.     else
  303.         entity_set_size(ent,Float:{-550.0,-2.0,-50.0},Float:{550.0,2.0,150.0})
  304.     entity_set_origin(ent,float_origin)
  305.  
  306.     entity_set_int( ent, EV_INT_rendermode, kRenderTransAdd )
  307.     entity_set_float( ent, EV_FL_renderamt, 255.0 )
  308.     set_pev(ent, pev_rendermode, kRenderTransAlpha)
  309.     set_pev(ent, pev_renderamt, 0)
  310.  
  311.     if( g_iVerticalInvis >= 11 )
  312.         return PLUGIN_HANDLED
  313.     else
  314.     {
  315.         create_function_all( 2 )
  316.     }
  317.  
  318.     return PLUGIN_HANDLED
  319. }
  320. MakeCountDown(Float:flTimeleft, Float:flFrequency = 0.15)  //connor
  321. {
  322.     if( !g_entCountDown )
  323.     {
  324.         g_entCountDown = create_entity( "info_target" );
  325.  
  326.         new const szClass[] = "countdown";
  327.         register_think(szClass, "CountDown" );
  328.  
  329.         entity_set_string(g_entCountDown, EV_SZ_classname, szClass);
  330.     }
  331.     g_flTimeLeft = flTimeleft;
  332.     g_flFreq = flFrequency;
  333.  
  334.     entity_set_float(g_entCountDown, EV_FL_nextthink, get_gametime() + flFrequency);
  335.     call_think(g_entCountDown);
  336. }
  337. public CountDown( iEntity )
  338. {
  339.     if( iEntity != g_entCountDown || !g_bCup )
  340.         return;
  341.  
  342.     if (g_flTimeLeft > 0.0 )
  343.     {
  344.         set_dhudmessage( 255, 255, 255, -1.0, 0.05, 0, 0.0, 0.15, 0.01, 0.01 )
  345.         show_dhudmessage( 0, "Cuptime:^n%s", StringTimer( g_flTimeLeft ) )
  346.  
  347.         entity_set_float(g_entCountDown, EV_FL_nextthink, get_gametime() + g_flFreq)
  348.         g_flTimeLeft -= g_flFreq
  349.     }
  350. }
  351. stock fm_set_user_frozen(client, frozen)
  352. {
  353.     if( !is_user_alive(client) ) return 0;
  354.  
  355.     new flags = pev(client, pev_flags);
  356.     if( frozen && !(flags & FL_FROZEN) )
  357.     {
  358.         set_pev(client, pev_flags, (flags | FL_FROZEN))
  359.  
  360.     }
  361.     else if( !frozen  && (flags & FL_FROZEN) )
  362.     {
  363.         set_pev(client, pev_flags, (flags & ~FL_FROZEN));
  364.     }
  365.  
  366.     return 1;
  367. }
  368. stock StringTimer(const Float:flRealTime )
  369. {
  370.     new szOutPut[ 25 ]
  371.     static iMinutes, iSeconds, iMiliSeconds
  372.  
  373.     iMinutes = floatround(flRealTime / 60, floatround_floor);
  374.     iSeconds = floatround(flRealTime - (iMinutes * 60), floatround_floor);
  375.     iMiliSeconds = floatround((flRealTime - (iMinutes * 60 + iSeconds)) * 100, floatround_floor);
  376.     formatex(szOutPut, charsmax( szOutPut ), "%02d:%02d.%02d", iMinutes, iSeconds, iMiliSeconds);
  377.     return szOutPut
  378. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement