找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 969|回复: 9

【以解决】 求起边缘的插件。

[复制链接]

该用户从未签到

发表于 2010-8-25 19:47:31 | 显示全部楼层 |阅读模式
本帖最后由 SiMen.K. 于 2010-8-26 17:25 编辑

起跳的时候显示离扳子边缘有多少单位的显示。..

谁知道怎么弄教我下..


QQ108873249

该用户从未签到

发表于 2010-8-25 20:25:13 | 显示全部楼层
本帖最后由 1937 于 2010-8-25 20:26 编辑

该用户从未签到

发表于 2010-8-25 20:35:38 | 显示全部楼层

该用户从未签到

发表于 2010-8-25 21:09:11 | 显示全部楼层
我上回也发了个帖求这个,你怎么不说啊...

该用户从未签到

发表于 2010-8-26 17:25:25 | 显示全部楼层
  1. #include <amxmodx>
  2. #include <engine>
  3. #include <fakemeta>
  4. #include <xs>

  5. #pragma semicolon 1

  6. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  7. * SETTINGS
  8. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

  9. #define MIN_BLOCK 210         // minimum block for which stats appear
  10. #define MAX_BLOCK 280         // maximum block for which stats appear

  11. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  12. * DO NOT MODIFY BELOW HERE
  13. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

  14. #define FL_ONGROUND2         ( FL_ONGROUND | FL_PARTIALGROUND | FL_INWATER | FL_CONVEYOR | FL_FLOAT )
  15. #define HLBSP_EXTRA         0.03125         // hlbsp adds an aditional hull around entites with this size, unfortunately players cannot land on it

  16. new bool:edgeDistanceEnabled[33];
  17. new bool:resetJump[33];
  18. new sv_gravity;

  19. new cvarHudColor;
  20. new cvarHudColorFail;
  21. new cvarHudCoords;
  22. new cvarHudHoldtime;
  23. new cvarHudChannel;

  24. public plugin_init( )
  25. {
  26.         register_plugin( "Edge Distances", "0.23", "SchlumPF" );
  27.         register_forward( FM_PlayerPreThink, "FM_PlayerPreThink_Pre", 0 );
  28.        
  29.         register_clcmd( "say /ed", "Cmd_EdgeDistance" );
  30.         register_clcmd( "say /edge", "Cmd_EdgeDistance" );
  31.         register_clcmd( "say /edgedistance", "Cmd_EdgeDistance" );
  32.        
  33.         cvarHudColor = register_cvar( "ed_hud_color", "0 0 255" );
  34.         cvarHudColorFail = register_cvar( "ed_hud_failcolor", "255 0 127" );
  35.         cvarHudCoords = register_cvar( "ed_hud_coords", "0.43 0.83" );
  36.         cvarHudHoldtime = register_cvar( "ed_hud_holdtime", "1.6" );
  37.         cvarHudChannel = register_cvar( "ed_hud_channel", "8" );
  38.        
  39.         register_touch( "func_train", "player", "Fwd_ResetJump" );
  40.         register_touch( "func_door", "player", "Fwd_ResetJump" );
  41.         register_touch( "func_door_rotating", "player", "Fwd_ResetJump" );
  42.         register_touch( "func_conveyor", "player", "Fwd_ResetJump" );
  43.         register_touch( "func_rotating", "player", "Fwd_ResetJump" );
  44.         register_touch( "trigger_push", "player", "Fwd_ResetJump" );
  45.         register_touch( "trigger_teleport", "player", "Fwd_ResetJump" );
  46.        
  47.         sv_gravity = get_cvar_pointer( "sv_gravity" );
  48. }

  49. public plugin_cfg( )
  50. {
  51.         new const commands[][] =
  52.         {
  53.                 "tele", "tp", "gocheck", "gc",
  54.                 "stuck", "unstuck",
  55.                 "start", "reset", "spawn", "restart"
  56.         };
  57.        
  58.         new const prefixes[][] =
  59.         {
  60.                 "", ".", "/"
  61.         };
  62.        
  63.         new cmd[32];
  64.         for( new s; s < 2; s++ )
  65.         {
  66.                 for( new i; i < sizeof( commands ); i++ )
  67.                 {
  68.                         for( new j; j < sizeof( prefixes ); j++ )
  69.                         {
  70.                                 formatex( cmd, 31, "%s%s%s", (s == 0) ? "" : "say ", prefixes[j], commands[i] );
  71.                                 register_clcmd( cmd, "Cmd_ResetJump" );
  72.                         }
  73.                 }
  74.         }
  75.        
  76.         register_clcmd( "+hook", "Cmd_ResetJump" );
  77.         register_clcmd( "-hook", "Cmd_ResetJump" );
  78.         register_clcmd( "+rope", "Cmd_ResetJump" );
  79.         register_clcmd( "-rope", "Cmd_ResetJump" );
  80. }

  81. public ResetJump( plr )
  82. {
  83.         resetJump[plr] = true;
  84. }

  85. public Fwd_ResetJump( ent, plr )
  86. {
  87.         ResetJump( plr );
  88. }

  89. public Cmd_ResetJump( plr )
  90. {
  91.         ResetJump( plr );
  92. }

  93. public Cmd_EdgeDistance( plr )
  94. {
  95.         edgeDistanceEnabled[plr] = !edgeDistanceEnabled[plr];
  96.        
  97.         static saytext;
  98.        
  99.         if( !saytext )
  100.         {
  101.                 saytext = get_user_msgid( "SayText" );
  102.         }
  103.        
  104.         static msg[64];
  105.         formatex( msg, 63, "^x04[ED]^x01 Edge Distances %s be shown now.", edgeDistanceEnabled[plr] ? "will" : "won't" );
  106.        
  107.         message_begin( MSG_ONE_UNRELIABLE, saytext, { 0, 0, 0 }, plr );
  108.         write_byte( plr );
  109.         write_string( msg );
  110.         message_end( );
  111.        
  112.         return PLUGIN_HANDLED;
  113. }

  114. public client_connect( plr )
  115. {
  116.         edgeDistanceEnabled[plr] = true;
  117. }

  118. public FM_PlayerPreThink_Pre( plr )
  119. {
  120.         static bool:inAir[33], bool:firstFrame[33], bool:failStats[33];
  121.         static Float:jumpoff_footheight[33];
  122.         static Float:jumpoff_origin[33][3], Float:fail_origin[33][3];
  123.         static Float:frame_origin[33][2][3], Float:frame_velocity[33][2][3];
  124.        
  125.         static Float:origin[3];
  126.        
  127.         if( !edgeDistanceEnabled[plr] )
  128.         {
  129.                 return FMRES_IGNORED;
  130.         }
  131.        
  132.         if( resetJump[plr] || pev( plr, pev_movetype ) == MOVETYPE_FLY )
  133.         {
  134.                 resetJump[plr] = false;
  135.                 inAir[plr] = false;
  136.         }
  137.        
  138.         static button;
  139.         button = pev( plr, pev_button );
  140.        
  141.         static oldButtons;
  142.         oldButtons = pev( plr, pev_oldbuttons );
  143.        
  144.         static flags;
  145.         flags = pev( plr, pev_flags );
  146.        
  147.         if( inAir[plr] )
  148.         {       
  149.                 if( flags & FL_ONGROUND2 && !failStats[plr] )
  150.                 {
  151.                         pev( plr, pev_origin, origin );
  152.                
  153.                         static Float:mins[3];
  154.                         pev( plr, pev_mins, mins );
  155.                        
  156.                         if( jumpoff_footheight[plr] == origin[2] + mins[2] )
  157.                         {
  158.                                 static Float:gravity;
  159.                                 gravity = get_pcvar_float( sv_gravity ) * pev( plr, pev_gravity );
  160.                                
  161.                                 static Float:temp;
  162.                                 temp = floatdiv( -floatsqroot( frame_velocity[plr][0][2] * frame_velocity[plr][0][2] + ( 2 * gravity * ( frame_origin[plr][0][2] - origin[2] + 0.1 ) ) ) - frame_velocity[plr][1][2], -gravity );
  163.                                
  164.                                 static Float:landing_origin[3];
  165.                                 if( frame_origin[plr][1][0] < origin[0] )        landing_origin[0] = frame_origin[plr][1][0] + temp * floatabs( frame_velocity[plr][1][0] );
  166.                                 else                                                landing_origin[0] = frame_origin[plr][1][0] - temp * floatabs( frame_velocity[plr][1][0] );
  167.                                
  168.                                 if( frame_origin[plr][1][1] < origin[1] )        landing_origin[1] = frame_origin[plr][1][1] + temp * floatabs( frame_velocity[plr][1][1] );
  169.                                 else                                                landing_origin[1] = frame_origin[plr][1][1] - temp * floatabs( frame_velocity[plr][1][1] );
  170.                                
  171.                                 static Float:distance_1;
  172.                                 distance_1 = floatsqroot( floatpower( origin[0] - jumpoff_origin[plr][0], 2.0 ) + floatpower( origin[1] - jumpoff_origin[plr][1], 2.0 ) ) + 32.0;
  173.                                
  174.                                 static Float:distance_2;
  175.                                 distance_2 = floatsqroot( floatpower( landing_origin[0] - jumpoff_origin[plr][0], 2.0 ) + floatpower( landing_origin[1] - jumpoff_origin[plr][1], 2.0 ) ) + 32.0;
  176.                                
  177.                                 if( distance_1 > distance_2 )         CalculateDistances( plr, jumpoff_origin[plr], landing_origin, jumpoff_footheight[plr], flags, distance_2 );
  178.                                 else                                 CalculateDistances( plr, jumpoff_origin[plr], origin, jumpoff_footheight[plr], flags, distance_1 );
  179.                         }
  180.                        
  181.                         resetJump[plr] = true;
  182.                 }
  183.                 else if( failStats[plr] )
  184.                 {
  185.                         resetJump[plr] = true;
  186.                         failStats[plr] = false;

  187.                         CalculateDistances( plr, jumpoff_origin[plr], fail_origin[plr], jumpoff_footheight[plr], flags, -1.0 );
  188.                 }
  189.                 else
  190.                 {
  191.                         pev( plr, pev_origin, origin );
  192.                
  193.                         failStats[plr] = ( ( origin[2] + 18 ) < jumpoff_origin[plr][2] );
  194.                        
  195.                         if( ( is_user_ducking( plr ) ? ( origin[2] + 18 ) : origin[2] ) >= jumpoff_origin[plr][2] )
  196.                         {
  197.                                 static Float:temp;
  198.                                 temp = ( jumpoff_origin[plr][2] - frame_origin[plr][1][2] ) / ( origin[2] - frame_origin[plr][1][2] );

  199.                                 fail_origin[plr][0] = temp * ( origin[0] - frame_origin[plr][1][0] ) + frame_origin[plr][1][0];
  200.                                 fail_origin[plr][1] = temp * ( origin[1] - frame_origin[plr][1][1] ) + frame_origin[plr][1][1];
  201.                                 fail_origin[plr][2] = jumpoff_footheight[plr];
  202.                         }
  203.                        
  204.                         if( firstFrame[plr] )
  205.                         {
  206.                                 firstFrame[plr] = false;
  207.                                
  208.                                 xs_vec_copy( origin, frame_origin[plr][0] );
  209.                                 pev( plr, pev_velocity, frame_velocity[plr][0] );
  210.                         }
  211.                         else
  212.                         {
  213.                                 xs_vec_copy( origin, frame_origin[plr][1] );
  214.                                 pev( plr, pev_velocity, frame_velocity[plr][1] );
  215.                         }
  216.                 }
  217.         }
  218.        
  219.         if( button & IN_JUMP && !( oldButtons & IN_JUMP ) )
  220.         {
  221.                 inAir[plr] = true;
  222.                 firstFrame[plr] = true;
  223.                
  224.                 if( flags & FL_ONGROUND2 )
  225.                 {
  226.                         pev( plr, pev_origin, jumpoff_origin[plr] );
  227.                        
  228.                         static Float:mins[3];
  229.                         pev( plr, pev_mins, mins );
  230.                        
  231.                         jumpoff_footheight[plr] = jumpoff_origin[plr][2] + mins[2];
  232.                 }
  233.                 else
  234.                 {
  235.                         static Float:velocity[3];
  236.                         pev( plr, pev_velocity, velocity );
  237.                                
  238.                         if( !velocity[2] )
  239.                         {
  240.                                 pev( plr, pev_origin, origin );
  241.                                
  242.                                 jumpoff_origin[plr][0] = origin[0];
  243.                                 jumpoff_origin[plr][1] = origin[1];
  244.                         }
  245.                 }
  246.         }
  247.        
  248.         return FMRES_IGNORED;
  249. }

  250. public CalculateDistances( plr, Float:start[3], Float:stop[3], Float:jumpoff_footheight, flags, Float:distance )
  251. {
  252.         // use some delay to avoid bugs
  253.         static Float:lastCalc[33];
  254.        
  255.         static Float:gametime;
  256.         gametime = get_gametime( );
  257.        
  258.         if( gametime - lastCalc[plr] < 0.5 )
  259.         {
  260.                 return 0;
  261.         }
  262.        
  263.         lastCalc[plr] = gametime;
  264.        
  265.         // calculate the center origin of jumpoff and landing and set it to the height of the player's feet
  266.         // we need to lower stop[2] so that the hull with which we are tracing can hit the block
  267.         static Float:vertex_origin[3];
  268.         vertex_origin[0] = ( start[0] + stop[0] ) * 0.5;
  269.         vertex_origin[1] = ( start[1] + stop[1] ) * 0.5;
  270.         vertex_origin[2] = stop[2] - 1.0;
  271.        
  272.         // check whether it was in free space by which we can find out whether the player jumped over a gap
  273.         if( engfunc( EngFunc_PointContents, vertex_origin ) != CONTENTS_EMPTY )
  274.         {       
  275.                 return 0;
  276.         }
  277.        
  278.         // set the hull with which we will need to trace for a valid result
  279.         static hull;
  280.         hull = flags & FL_DUCKING || ( distance < 0 ) ? HULL_HEAD : HULL_HUMAN;
  281.        
  282.         start[2] = vertex_origin[2];
  283.         stop[2] = vertex_origin[2];
  284.        
  285.         static block;
  286.         static Float:jumpoff_edge;
  287.         static Float:landing_edge;
  288.        
  289.         static Float:jumpoff_edge_origin[3];
  290.         static Float:landing_edge_origin[3];
  291.        
  292.         static Float:vecPlaneNormal[3];
  293.        
  294.         // do a trace from the center to jumpoff
  295.         engfunc( EngFunc_TraceHull, vertex_origin, start, IGNORE_MONSTERS, hull, -1, 0 );
  296.         get_tr2( 0, TR_vecPlaneNormal, vecPlaneNormal );
  297.        
  298.         // if vecPlaneNormal is 0.0, the player hit some ramp or something
  299.         if( vecPlaneNormal[2] != 0.0 )
  300.         {
  301.                 return 0;
  302.         }
  303.        
  304.         // retrieve the edge origin
  305.         get_tr2( 0, TR_vecEndPos, jumpoff_edge_origin );
  306.        
  307.         // calculate the smallest distance from jumpoff to the edge using vecPlaneNormal to see in which direction the player jumped
  308.         if( floatabs( vecPlaneNormal[0] ) == 1.0 && !vecPlaneNormal[1] )                jumpoff_edge = floatabs( jumpoff_edge_origin[0] - start[0] ) - HLBSP_EXTRA;
  309.         else if( !vecPlaneNormal[0] && floatabs( vecPlaneNormal[1] ) == 1.0 )        jumpoff_edge = floatabs( jumpoff_edge_origin[1] - start[1] ) - HLBSP_EXTRA;
  310.         else return 0;
  311.        
  312.         // distance < 0 means the player failed failed the jump
  313.         if( distance < 0 )
  314.         {
  315.                 static Float:end[3];
  316.                
  317.                 // extend the coords so the traces can hit the block
  318.                 if( floatabs( vecPlaneNormal[0] ) == 1.0 && !vecPlaneNormal[1] )
  319.                 {
  320.                         end[0] = stop[0] + vecPlaneNormal[0] * 300;
  321.                         end[1] = stop[1];
  322.                         end[2] = stop[2];
  323.                 }
  324.                 else if( !vecPlaneNormal[0] && floatabs( vecPlaneNormal[1] ) == 1.0 )
  325.                 {
  326.                         end[0] = stop[0];
  327.                         end[1] = stop[1] + vecPlaneNormal[1] * 300;
  328.                         end[2] = stop[2];
  329.                 }
  330.                 else return 0;
  331.                
  332.                 engfunc( EngFunc_TraceHull, vertex_origin, end, IGNORE_MONSTERS, hull, -1, 0 );
  333.                 get_tr2( 0, TR_vecPlaneNormal, vecPlaneNormal );
  334.        
  335.                 if( vecPlaneNormal[2] != 0.0 ) return 0;

  336.                 get_tr2( 0, TR_vecEndPos, landing_edge_origin );
  337.                
  338.                 if( floatabs( vecPlaneNormal[0] ) == 1.0 && !vecPlaneNormal[1] )
  339.                 {
  340.                         end[0] = landing_edge_origin[0] - vecPlaneNormal[0] * 16.1;
  341.                         end[1] = landing_edge_origin[1];
  342.                         end[2] = landing_edge_origin[2] + 37.0;
  343.                 }
  344.                 else if( !vecPlaneNormal[0] && floatabs( vecPlaneNormal[1] ) == 1.0 )
  345.                 {
  346.                         end[0] = landing_edge_origin[0];
  347.                         end[1] = landing_edge_origin[1] - vecPlaneNormal[1] * 16.1;
  348.                         end[2] = landing_edge_origin[2] + 37.0;
  349.                 }
  350.                 else return 0;
  351.                
  352.                 vertex_origin[2] += 37.0;
  353.        
  354.                 engfunc( EngFunc_TraceHull, vertex_origin, end, IGNORE_MONSTERS, hull, -1, 0 );
  355.                
  356.                 static Float:fraction;
  357.                 get_tr2( 0, TR_flFraction, fraction );
  358.                
  359.                 // the player jumped against a wall
  360.                 if( fraction < 1.0 ) return 0;
  361.         }
  362.         else
  363.         {
  364.                 engfunc( EngFunc_TraceHull, vertex_origin, stop, IGNORE_MONSTERS, hull, -1, 0 );
  365.                 get_tr2( 0, TR_vecPlaneNormal, vecPlaneNormal );
  366.        
  367.                 if( vecPlaneNormal[2] != 0.0 ) return 0;
  368.                
  369.                 get_tr2( 0, TR_vecEndPos, landing_edge_origin );
  370.         }
  371.        
  372.         if( floatabs( vecPlaneNormal[0] ) == 1.0 && !vecPlaneNormal[1] )
  373.         {
  374.                 landing_edge = floatabs( landing_edge_origin[0] - stop[0] ) - HLBSP_EXTRA;
  375.                 block = floatround( floatabs( landing_edge_origin[0] - jumpoff_edge_origin[0] ) ) + 32;
  376.         }
  377.         else if( !vecPlaneNormal[0] && floatabs( vecPlaneNormal[1] ) == 1.0 )
  378.         {
  379.                 landing_edge = floatabs( landing_edge_origin[1] - stop[1] ) - HLBSP_EXTRA;
  380.                 block = floatround( floatabs( landing_edge_origin[1] - jumpoff_edge_origin[1] ) ) + 32;
  381.         }
  382.         else return 0;
  383.        
  384.         if( MAX_BLOCK < block || block < MIN_BLOCK ) return 0;

  385.         static Float:x, Float:y;
  386.         GetHudCoords( cvarHudCoords, x, y );

  387.         static r, g, b;
  388.        
  389.         if( distance < 0 )
  390.         {
  391.                 GetHudColor( cvarHudColorFail, r, g, b );
  392.                
  393.                 client_print( plr, print_console, "Fail --- Block: %i - Jumpoff: %f", block, jumpoff_edge );
  394.                
  395.                 set_hudmessage( r, g, b, x, y, 0, 0.0, get_pcvar_float( cvarHudHoldtime ), 0.1, 0.1, get_pcvar_num( cvarHudChannel ) );
  396.                 show_hudmessage( plr, "^t^t^t^t Block: %i^nJumpoff: %f", block, jumpoff_edge );
  397.                
  398.                 return 1;
  399.         }
  400.        
  401.         GetHudColor( cvarHudColor, r, g, b );
  402.        
  403.         client_print( plr, print_console, "Gj! --- Block: %i - Jumpoff: %f - Landing: %f", block, jumpoff_edge, landing_edge );
  404.        
  405.         set_hudmessage( r, g, b, x, y, 0, 0.0, get_pcvar_float( cvarHudHoldtime ), 0.0, 0.0, get_pcvar_num( cvarHudChannel ) );
  406.         show_hudmessage( plr, "^t^t^t^t Block: %i^nJumpoff: %f^nLanding: %f", block, jumpoff_edge, landing_edge );       
  407.        
  408.         return 1;
  409. }

  410. public GetHudColor( cvar, &r, &g, &b )
  411. {
  412.         static color[16], piece[5];
  413.         get_pcvar_string( cvar, color, 15 );
  414.        
  415.         strbreak( color, piece, 4, color, 15 );
  416.         r = str_to_num( piece );
  417.        
  418.         strbreak( color, piece, 4, color, 15 );
  419.         g = str_to_num( piece );
  420.         b = str_to_num( color );
  421. }

  422. public GetHudCoords( cvar, &Float:x, &Float:y )
  423. {
  424.         static coords[16], piece[10];
  425.         get_pcvar_string( cvar, coords, 15 );
  426.        
  427.         strbreak( coords, piece, 9, coords, 15 );
  428.         x = str_to_float( piece );
  429.         y = str_to_float( coords );
  430. }

  431. stock bool:is_user_ducking( plr )
  432. {
  433.         static Float:absmin[3];
  434.         pev( plr, pev_absmin, absmin );
  435.        
  436.         static Float:absmax[3];
  437.         pev( plr, pev_absmax, absmax );

  438.         return !( ( absmin[2] + 64.0 ) < absmax[2] );
  439. }
复制代码

该用户从未签到

发表于 2010-8-26 21:25:14 | 显示全部楼层
回复 5# SiMen.K.


    发了一些代码,然后方法都没教?这对新手不是约等于没回复?

该用户从未签到

发表于 2010-8-26 21:37:19 | 显示全部楼层
回复 6# 8891888


    源码都发出来了,我总不能喂你一口一口的吃吧!
复制上面的代码另存为文件名.sma 然后拖到compile.exe生成的文件即为所需插件!

该用户从未签到

发表于 2010-8-26 21:45:27 | 显示全部楼层
回复 7# SiMen.K.


    对啊,教一个新手的确是很累的事情,他们很菜都不懂,况且我又是插件区的版主,很忙的,给你些源码自己琢磨去。。。。。。。

该用户从未签到

发表于 2010-8-27 11:38:09 | 显示全部楼层
回复 8# 8891888


像安装amxx平台、编译sma源码之类简单的问题网上都有教程,不自己去google一下,总问些低级问题,至少我没闲得蛋疼喜欢浪费时间解释这些东西。

该用户从未签到

 楼主| 发表于 2010-8-27 14:36:43 | 显示全部楼层
回复 9# fantasist


    Just like waste your time

   哈哈哈哈后
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表