Advertisement
jocasrb

KZ LJ Auto Cup v1.5 (dcj/cj blocking added)

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