Advertisement
Guest User

statistika

a guest
Nov 26th, 2012
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 13.25 KB | None | 0 0
  1. #include <amxmodx>
  2. #include <fakemeta>
  3. #include <colorchat>
  4.  
  5. #pragma semicolon 1
  6.  
  7. #define MIN_DISTANCE 215.0
  8. #define MAX_DISTANCE 275.0
  9.  
  10. enum JumpType {
  11.     Type_LongJump = 0,
  12.     Type_HighJump = 1,
  13.     Type_CountJump = 2,
  14.     Type_BhopLongJump = 3,
  15.     Type_DuckBhopLongJump = 4,
  16.     Type_StandupBhopLongJump = 5,
  17.    
  18.     Type_WeirdLongJump = 6,
  19.     Type_Drop_BhopLongJump = 7,
  20.     Type_Drop_CountJump = 8,
  21.    
  22.     Type_Multi_CountJump = 9,
  23.     Type_Multi_Bhop = 10
  24. };
  25.  
  26. new Float:old_angle1[33];
  27. new g_lj_stats[33];
  28. new strafe_num[33];
  29. new g_Jumped[33];
  30. new g_reset[33];
  31. new sv_gravity;
  32.  
  33.  
  34. public plugin_init() {
  35.     register_plugin( "KZ Stats", "xPaw", "SchlumPF" );
  36.     register_clcmd( "say beta",     "cmdljStats" );
  37.     register_clcmd( "say /beta",        "cmdljStats" );
  38.    
  39.  
  40.    
  41.     register_forward( FM_PlayerPreThink,    "fwdPlayerPreThink",    0 );
  42.     register_forward( FM_PlayerPostThink,   "fwdPlayerPostThink",   0 );
  43.     sv_gravity = get_cvar_pointer( "sv_gravity" );
  44. }
  45.  
  46.  
  47. public fwdPlayerPreThink(plr) {
  48.     if( !g_lj_stats[plr] ) {
  49.         return FMRES_IGNORED;
  50.     }
  51.     //else if(get_user_team(plr) == 1) {
  52.    
  53.     static JumpType:jump_type[33];
  54.     static frames[33], frames_gained_speed[33];
  55.     static bool:in_air[33], bool:in_duck[33], bool:in_bhop[33];
  56.     static bool:failed_jump[33], bool:failed_ducking[33];
  57.     static bool:first_frame[33], bool:started_cj_pre[33], bool:started_multicj_pre[33];
  58.     static Float:maxspeed[33], Float:prestrafe[33];
  59.     static Float:frame_origin[33][2][3], Float:frame_velocity[33][2][3];
  60.     static Float:duckoff_time[33], Float:jumpoff_time[33], Float:last_land_time[33];
  61.     static Float:duckoff_origin[33][3], Float:jumpoff_origin[33][3], Float:pre_jumpoff_origin[33][3];
  62.     static Float:failed_origin[33][3];
  63.    
  64.    
  65.     if( g_reset[plr] ) {
  66.         g_reset[plr]    = false;
  67.         g_Jumped[plr]   = false;
  68.        
  69.         in_air[plr] = false;
  70.         in_duck[plr]    = false;
  71.         in_bhop[plr]    = false;
  72.        
  73.         failed_jump[plr] = false;
  74.        
  75.         frames_gained_speed[plr] = 0;
  76.         frames[plr] = 0;
  77.         strafe_num[plr] = 0;
  78.        
  79.         started_multicj_pre[plr]    = false;
  80.         started_cj_pre[plr]     = false;
  81.        
  82.         jump_type[plr]  = Type_LongJump;
  83.        
  84.        
  85.     }
  86.  
  87.    
  88.     static button, oldbuttons, flags;
  89.     button = pev( plr, pev_button );
  90.     flags = pev( plr, pev_flags );
  91.     oldbuttons = pev( plr, pev_oldbuttons );
  92.    
  93.     static Float:origin[3];
  94.     pev( plr, pev_origin, origin );
  95.    
  96.     static Float:velocity[3], Float:speed;
  97.     pev( plr, pev_velocity, velocity );
  98.     speed = get_speed( velocity );
  99.    
  100.     if( in_air[plr] && !( flags & FL_ONGROUND ) && !failed_jump[plr] )
  101.     {
  102.        
  103.        
  104.         static Float:old_speed[33];
  105.         if( speed > old_speed[plr] )
  106.         {
  107.             frames_gained_speed[plr]++;
  108.         }
  109.         frames[plr]++;
  110.        
  111.         old_speed[plr] = speed;
  112.        
  113.         if( speed > maxspeed[plr] )
  114.         {
  115.             maxspeed[plr] = speed;
  116.         }
  117.        
  118.         if( in_bhop[plr] ? floatsub( origin[2] + 18.0, pre_jumpoff_origin[plr][2] ) < 0 : floatsub( origin[2] + 18.0, jumpoff_origin[plr][2] ) < 0 )
  119.         {
  120.             failed_jump[plr] = true;
  121.            
  122.             failed_jump[plr] = true;
  123.             failed_ducking[plr] = is_user_ducking( plr );
  124.            
  125.             static Float:jumpoff_z_origin;
  126.             jumpoff_z_origin = jumpoff_origin[plr][2];
  127.             if( failed_ducking[plr] )
  128.             {
  129.                 jumpoff_z_origin -= 18.0;
  130.                 origin[2] -= 18.0;
  131.             }
  132.            
  133.             static Float:temp;
  134.             temp = ( jumpoff_z_origin - frame_origin[plr][1][2] ) / ( origin[2] - frame_origin[plr][1][2] );
  135.  
  136.             failed_origin[plr][0] = temp * ( origin[0] - frame_origin[plr][1][0] ) + frame_origin[plr][1][0];
  137.             failed_origin[plr][1] = temp * ( origin[1] - frame_origin[plr][1][1] ) + frame_origin[plr][1][1];
  138.             failed_origin[plr][2] = jumpoff_z_origin;
  139.            
  140.             return FMRES_IGNORED;
  141.         }
  142.        
  143.         if( first_frame[plr] )
  144.         {
  145.             first_frame[plr] = false;
  146.            
  147.             frame_origin[plr][0] = origin;
  148.             frame_velocity[plr][0] = velocity;
  149.            
  150.             if( in_bhop[plr] )
  151.             {
  152.                 if( velocity[2] < 229.0 )
  153.                 {
  154.                     jump_type[plr] = Type_BhopLongJump;
  155.                 }
  156.                 else if( velocity[2] )
  157.                 {
  158.                     if( button & IN_DUCK && oldbuttons & IN_DUCK )
  159.                     {
  160.                         jump_type[plr] = Type_DuckBhopLongJump;
  161.                     }
  162.                     else
  163.                     {
  164.                         jump_type[plr] = Type_StandupBhopLongJump;
  165.                     }
  166.                 }
  167.                
  168.                 jumpoff_origin[plr][2] = pre_jumpoff_origin[plr][2];
  169.             }
  170.         } else {
  171.             frame_origin[plr][1] = origin;
  172.             frame_velocity[plr][1] = velocity;
  173.         }
  174.     }
  175.  
  176.    
  177.     else if( button & IN_JUMP && !( oldbuttons & IN_JUMP ) && flags & FL_ONGROUND && !in_air[plr] )
  178.     {
  179.         jumpoff_time[plr] = get_gametime( );
  180.         jumpoff_origin[plr] = origin;
  181.        
  182.         if( jump_type[plr] == Type_CountJump || jump_type[plr] == Type_Multi_CountJump ) {
  183.             if( ( button & IN_DUCK && oldbuttons & IN_DUCK ) && ( 0.35 > jumpoff_time[plr] - duckoff_time[plr] > 0.3 ) )
  184.             {
  185.                 // russian walk + bhop after it.
  186.             }
  187.             else if( jumpoff_time[plr] - duckoff_time[plr] >= 0.3 )
  188.             {
  189.                 jump_type[plr] = Type_LongJump;
  190.             }
  191.             else
  192.             {
  193.                 static bool:ducking;
  194.                 ducking = is_user_ducking( plr );
  195.                
  196.                 static classname[32];
  197.                 pev( pev( plr, pev_groundentity ), pev_classname, classname, 31 );
  198.                
  199.                 static Float:height_difference;
  200.                 height_difference = floatabs( ducking ? jumpoff_origin[plr][2] - origin[2] - 18.0 : jumpoff_origin[plr][2] - origin[2] );
  201.                
  202.                 if( equal( classname, "func_door" ) && height_difference >= 1.0 )
  203.                 {
  204.                     g_reset[plr] = true;
  205.                     return FMRES_IGNORED;
  206.                 }
  207.                 else if( !equal( classname, "func_door" ) && height_difference )
  208.                 {
  209.                     g_reset[plr] = true;
  210.                     return FMRES_IGNORED;
  211.                 }
  212.             }
  213.         }
  214.        
  215.         in_air[plr] = true;
  216.         g_Jumped[plr]   = true;
  217.         first_frame[plr] = true;
  218.        
  219.         prestrafe[plr]  = speed;
  220.         maxspeed[plr]   = speed;
  221.     }
  222.     else if( flags & FL_ONGROUND && in_air[plr] ) {
  223.         static bool:ducking;
  224.        
  225.         static type[32];
  226.         type[0] = '^0';
  227.         if( failed_jump[plr] )
  228.         {
  229.             origin = failed_origin[plr];
  230.             ducking = failed_ducking[plr];
  231.         }
  232.         else
  233.             ducking = is_user_ducking( plr );
  234.        
  235.         last_land_time[plr] = get_gametime( );
  236.  
  237.         static Float:distance1;
  238.         distance1 = get_distance_f( jumpoff_origin[plr], origin ) + 32.0625;
  239.        
  240.         static Float:gravity;
  241.         gravity = get_pcvar_float( sv_gravity );
  242.        
  243.         static Float:_time;
  244.         _time = floatdiv( floatsqroot( floatpower( frame_velocity[plr][0][2], 2.0 ) + ( 2 * gravity * ( frame_origin[plr][0][2] - origin[2] ) ) ) * -1.0 - frame_velocity[plr][1][2], gravity * -1.0 );
  245.        
  246.         if( frame_velocity[plr][1][0] < 0.0 ) frame_velocity[plr][1][0] *= -1.0;
  247.         if( frame_velocity[plr][1][1] < 0.0 ) frame_velocity[plr][1][1] *= -1.0;
  248.        
  249.         static Float:x_difference, Float:y_difference;
  250.         x_difference = _time * frame_velocity[plr][1][0];
  251.         y_difference = _time * frame_velocity[plr][1][1];
  252.        
  253.         static Float:land_origin[3];
  254.         land_origin[0] = frame_origin[plr][1][0] < origin[0] ? frame_origin[plr][1][0] + x_difference : frame_origin[plr][1][0] - x_difference;
  255.         land_origin[1] = frame_origin[plr][1][1] < origin[1] ? frame_origin[plr][1][1] + y_difference : frame_origin[plr][1][1] - y_difference;
  256.         land_origin[2] = ducking ? origin[2] + 18.0 : origin[2];
  257.        
  258.         static Float:distance2;
  259.         distance2 = get_distance_f( jumpoff_origin[plr], land_origin ) + 32.0625;
  260.  
  261.         static Float:distance;
  262.         distance = distance1 > distance2 ? distance2 : distance1;
  263.  
  264.         if( distance < MIN_DISTANCE || MAX_DISTANCE < distance ) {
  265.             g_reset[plr] = true;
  266.             return FMRES_IGNORED;
  267.         }
  268.        
  269.         if( jump_type[plr] == Type_LongJump ) {
  270.             static Float:start[3];
  271.            
  272.             start[0] = ( jumpoff_origin[plr][0] + land_origin[0] ) * 0.5;
  273.             start[1] = ( jumpoff_origin[plr][1] + land_origin[1] ) * 0.5;
  274.             start[2] = ducking ? origin[2] - 18.1 : origin[2] - 36.1;
  275.                
  276.             if( engfunc( EngFunc_PointContents, start ) == CONTENTS_EMPTY ) {
  277.                 static Float:stop[3], Float:fraction, Float:max_fraction;
  278.                
  279.                 stop[0] = jumpoff_origin[plr][0];
  280.                 stop[1] = jumpoff_origin[plr][1];
  281.                 if( start[0] < stop[0] )
  282.                     stop[0] += stop[0] - start[0];
  283.                 else
  284.                     stop[0] -= start[0] - stop[0];
  285.                
  286.                 if( start[1] < stop[1] )
  287.                     stop[1] += stop[1] - start[1];
  288.                 else
  289.                     stop[1] -= start[1] - stop[1];
  290.                
  291.                 stop[2] = start[2];
  292.                
  293.                 jumpoff_origin[plr][2] -= 0.1;
  294.                
  295.                 static Float:temp;
  296.                 temp = get_distance_f( jumpoff_origin[plr], start );
  297.                 max_fraction = floatdiv( temp + 16.03125, temp * 2.0 );
  298.                    
  299.                 engfunc( EngFunc_TraceHull, start, stop, IGNORE_MONSTERS, HULL_HUMAN, plr, 0 );
  300.                 get_tr2( 0, TR_flFraction, fraction );
  301.                
  302.                 if( fraction < max_fraction ) {
  303.                     get_tr2( 0, TR_vecEndPos, start );
  304.                    
  305.                     stop[0] = start[0];
  306.                     stop[1] = start[1];
  307.                     stop[2] = start[2] - 69.9;
  308.                    
  309.                     engfunc( EngFunc_TraceLine, start, stop, IGNORE_MONSTERS, plr, 0 );
  310.                     get_tr2( 0, TR_flFraction, fraction );
  311.                    
  312.                     if( fraction == 1.0 )
  313.                         jump_type[plr] = Type_HighJump;
  314.                 }
  315.             }
  316.         }
  317.        
  318.         // Primitive Weird LJ fake :D
  319.         if( jump_type[plr] == Type_LongJump || jump_type[plr] == Type_HighJump )
  320.             if(distance >= 256.0 || prestrafe[plr] >= 278.0)
  321.                 jump_type[plr] = Type_WeirdLongJump;
  322.        
  323.    
  324.        
  325.         static Float:sync, Float:gain;
  326.         sync = floatdiv( float( frames_gained_speed[plr] * 100 ), float( frames[plr] ) );
  327.         gain = floatsub( maxspeed[plr], prestrafe[plr] );
  328.        
  329.         if( !failed_jump[plr] )
  330.             set_hudmessage( 111, 111, 160, -1.0, -0.2, 0, 6.0, 2.5, 0.1, 0.3, 3 );
  331.         else
  332.             set_hudmessage( 255, 0, 109, -1.0, -0.2, 0, 6.0, 2.5, 0.1, 0.3, 3 );
  333.        
  334.        
  335.        
  336.        
  337.        
  338.        
  339.         static Float:max_prestrafe;
  340.         if( jump_type[plr] == Type_LongJump || jump_type[plr] == Type_HighJump )
  341.         {
  342.             max_prestrafe = pev( plr, pev_maxspeed ) * 1.115;
  343.         }
  344.         else
  345.         {
  346.             max_prestrafe = pev( plr, pev_maxspeed ) * 1.2;
  347.         }
  348.         if( distance >= 220.0 ) {
  349.         show_hudmessage( plr, "Distance: %f^nMaxSpeed: %f (%.03f)^nPreStrafe: %f (%.03f)^nStrafes: %d ^nSync: %d%%", distance, maxspeed[plr], gain, prestrafe[plr], max_prestrafe, strafe_num[plr], floatround(sync) );
  350.        
  351.         }
  352.    
  353.        
  354.         client_print( plr, print_console, "Distance: %f MaxSpeed: %f (Gain %f) Prestrafe: %f Strafes: %d Sync: %d", distance, maxspeed[plr], gain, prestrafe[plr], strafe_num[plr], floatround(sync) );
  355.        
  356.        
  357.        
  358.         g_reset[plr] = true;
  359.     }
  360.    
  361.     if( !in_air[plr] && button & IN_DUCK && flags & FL_ONGROUND && !in_duck[plr] )
  362.     {
  363.         if( get_gametime( ) - duckoff_time[plr] < 0.3 )
  364.             started_multicj_pre[plr] = true;
  365.         else
  366.             started_cj_pre[plr] = true;
  367.        
  368.         in_duck[plr] = true;
  369.     }
  370.     else if( !in_air[plr] && oldbuttons & IN_DUCK )
  371.     {
  372.         if( !is_user_ducking( plr ) )
  373.         {
  374.             in_duck[plr] = false;
  375.             if( started_cj_pre[plr] )
  376.             {
  377.                 started_cj_pre[plr] = false;
  378.                
  379.                 duckoff_time[plr] = get_gametime( );
  380.                 duckoff_origin[plr] = origin;
  381.                
  382.                 strafe_num[plr] = 0;
  383.                 jump_type[plr] = Type_CountJump;
  384.             }
  385.             else if( started_multicj_pre[plr] )
  386.             {
  387.            
  388.                 started_multicj_pre[plr] = false;
  389.                
  390.                 duckoff_time[plr] = get_gametime( );
  391.                 duckoff_origin[plr] = origin;
  392.                
  393.                 strafe_num[plr] = 0;
  394.                 jump_type[plr] = Type_Multi_CountJump;
  395.             }
  396.         }
  397.     //}
  398.     }
  399.     return FMRES_IGNORED;
  400. }
  401.  
  402. public fwdPlayerPostThink( id ) {
  403.     // This is only strafecounter added by xPaw!
  404.    
  405.     if( g_Jumped[id] ) {
  406.         static buttons;
  407.         static Float:angle[3];
  408.         static bool:turning_left[33];
  409.         static bool:turning_right[33];
  410.         static bool:straifing_aw[33];
  411.         static bool:straifing_sd[33];
  412.        
  413.         buttons = pev(id, pev_button);
  414.         pev(id, pev_angles, angle);
  415.        
  416.         if( old_angle1[id] > angle[1] ) {
  417.             turning_left[id] = false;
  418.             turning_right[id] = true;
  419.         }
  420.         else if( old_angle1[id] < angle[1] ) {
  421.             turning_left[id] = true;
  422.             turning_right[id] = false;
  423.         } else {
  424.             turning_left[id] = false;
  425.             turning_right[id] = false;
  426.         }
  427.        
  428.         if( !straifing_aw[id]
  429.         && (buttons&IN_MOVELEFT
  430.         || buttons&IN_FORWARD)
  431.         && (turning_left[id]
  432.         || turning_right[id] )
  433.         && !(buttons&IN_MOVERIGHT
  434.         || buttons&IN_BACK) ) {
  435.             straifing_aw[id] = true;
  436.             straifing_sd[id] = false;
  437.             strafe_num[id] += 1;
  438.         }
  439.         else if( !straifing_sd[id]
  440.         && (buttons&IN_MOVERIGHT
  441.         || buttons&IN_BACK)
  442.         && (turning_left[id]
  443.         || turning_right[id] )
  444.         && !(buttons&IN_MOVELEFT
  445.         || buttons&IN_FORWARD) ) {
  446.             straifing_aw[id] = false;
  447.             straifing_sd[id] = true;
  448.             strafe_num[id] += 1;
  449.         }
  450.     }
  451. }
  452.  
  453.  
  454.  
  455. public client_command( plr ) {
  456.     static command[32];
  457.     read_argv( 0, command, 31 );
  458.    
  459.     static const forbidden[][] = {
  460.         "tele", "tp", "gocheck", "gc", "stuck", "unstuck", "start", "reset", "restart",
  461.         "spawn", "respawn"
  462.     };
  463.    
  464.     if( equal( command, "say" ) ) {
  465.         read_args( command, 31 );
  466.         remove_quotes( command );
  467.     }
  468.    
  469.     if( equal( command, "+hook" ) ) {
  470.         g_reset[plr] = true;
  471.     }
  472.     else if( command[0] == '/' || command[0] == '.' ) {
  473.         copy( command, 31, command[1] );
  474.        
  475.         for( new i ; i < sizeof( forbidden ) ; i++ ) {
  476.             if( equal( command, forbidden[i] ) ) {
  477.                 g_reset[plr] = true;
  478.                 break;
  479.             }
  480.         }
  481.     }
  482. }
  483.  
  484. public cmdljStats( plr ) {
  485.     g_lj_stats[plr] = !g_lj_stats[plr];
  486.     ColorChat(plr, GREY, "%s, minimali distancija 220", g_lj_stats[plr] ? "ijungta" : "isjungta");
  487.     client_cmd(plr,"say /ljstats");
  488. }
  489.  
  490.  
  491. public client_connect( plr )
  492.     g_lj_stats[plr] = false;
  493.  
  494. Float:get_speed( Float:velocity[3] )
  495.     return floatsqroot( floatpower( velocity[0], 2.0 ) + floatpower( velocity[1], 2.0 ) );
  496.  
  497. bool:is_user_ducking( plr ) {
  498.     if( !pev_valid( plr )  )
  499.         return false;
  500.    
  501.     new Float:abs_min[3], Float:abs_max[3];
  502.    
  503.     pev( plr, pev_absmin, abs_min );
  504.     pev( plr, pev_absmax, abs_max );
  505.    
  506.     abs_min[2] += 64.0;
  507.    
  508.     if( abs_min[2] < abs_max[2] )
  509.         return false;
  510.    
  511.     return true;
  512. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement