- 听众
- 收听
- 积分
- 3894
- 主题
- 回帖
- 0
- 精华
注册时间2008-4-22
最后登录1970-1-1
该用户从未签到
|
发表于 2010-6-16 20:24:37
|
显示全部楼层
本帖最后由 SiMen.K. 于 2010-6-16 22:01 编辑
- #include <amxmodx>
- #include <engine>
- #include <fakemeta>
- #include <xs>
- #pragma semicolon 1
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * SETTINGS
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
- #define MIN_BLOCK 210 // minimum block for which stats appear
- #define MAX_BLOCK 280 // maximum block for which stats appear
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * SETTINGS
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
- #define MIN_BLOCK 210 // minimum block for which stats appear
- #define MAX_BLOCK 280 // maximum block for which stats appear
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * DO NOT MODIFY BELOW HERE
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
- #define FL_ONGROUND2 ( FL_ONGROUND | FL_PARTIALGROUND | FL_INWATER | FL_CONVEYOR | FL_FLOAT )
- #define HLBSP_EXTRA 0.03125 // hlbsp adds an aditional hull around entites with this size, unfortunately players cannot land on it
- new bool:edgeDistanceEnabled[33];
- new bool:resetJump[33];
- new sv_gravity;
- new cvarHudColor;
- new cvarHudColorFail;
- new cvarHudCoords;
- new cvarHudHoldtime;
- new cvarHudChannel;
- public plugin_init( )
- {
- register_plugin( "Edge Distances", "0.23", "SchlumPF" );
- register_forward( FM_PlayerPreThink, "FM_PlayerPreThink_Pre", 0 );
- register_clcmd( "say /ed", "Cmd_EdgeDistance" );
- register_clcmd( "say /edge", "Cmd_EdgeDistance" );
- register_clcmd( "say /edgedistance", "Cmd_EdgeDistance" );
- cvarHudColor = register_cvar( "ed_hud_color", "0 255 0" );
- cvarHudColorFail = register_cvar( "ed_hud_failcolor", "255 0 127" );
- cvarHudCoords = register_cvar( "ed_hud_coords", "-1.0 -0.875" );
- cvarHudHoldtime = register_cvar( "ed_hud_holdtime", "1.6" );
- cvarHudChannel = register_cvar( "ed_hud_channel", "5" );
- register_touch( "func_train", "player", "Fwd_ResetJump" );
- register_touch( "func_door", "player", "Fwd_ResetJump" );
- register_touch( "func_door_rotating", "player", "Fwd_ResetJump" );
- register_touch( "func_conveyor", "player", "Fwd_ResetJump" );
- register_touch( "func_rotating", "player", "Fwd_ResetJump" );
- register_touch( "trigger_push", "player", "Fwd_ResetJump" );
- register_touch( "trigger_teleport", "player", "Fwd_ResetJump" );
- sv_gravity = get_cvar_pointer( "sv_gravity" );
- }
- public plugin_cfg( )
- {
- new const commands[][] =
- {
- "tele", "tp", "gocheck", "gc",
- "stuck", "unstuck",
- "start", "reset", "spawn", "restart"
- };
- new const prefixes[][] =
- {
- "", ".", "/"
- };
- new cmd[32];
- for( new s; s < 2; s++ )
- {
- for( new i; i < sizeof( commands ); i++ )
- {
- for( new j; j < sizeof( prefixes ); j++ )
- {
- formatex( cmd, 31, "%s%s%s", (s == 0) ? "" : "say ", prefixes[j], commands );
- register_clcmd( cmd, "Cmd_ResetJump" );
- }
- }
- }
- register_clcmd( "+hook", "Cmd_ResetJump" );
- register_clcmd( "-hook", "Cmd_ResetJump" );
- register_clcmd( "+rope", "Cmd_ResetJump" );
- register_clcmd( "-rope", "Cmd_ResetJump" );
- }
- public ResetJump( plr )
- {
- resetJump[plr] = true;
- }
- public Fwd_ResetJump( ent, plr )
- {
- ResetJump( plr );
- }
- public Cmd_ResetJump( plr )
- {
- ResetJump( plr );
- }
- public Cmd_EdgeDistance( plr )
- {
- edgeDistanceEnabled[plr] = !edgeDistanceEnabled[plr];
- static saytext;
- if( !saytext )
- {
- saytext = get_user_msgid( "SayText" );
- }
- static msg[64];
- formatex( msg, 63, "^x04[ED]^x01 Edge Distances %s be shown now.", edgeDistanceEnabled[plr] ? "will" : "won't" );
- message_begin( MSG_ONE_UNRELIABLE, saytext, { 0, 0, 0 }, plr );
- write_byte( plr );
- write_string( msg );
- message_end( );
- return PLUGIN_HANDLED;
- }
- public client_connect( plr )
- {
- edgeDistanceEnabled[plr] = true;
- }
- public FM_PlayerPreThink_Pre( plr )
- {
- static bool:inAir[33], bool:firstFrame[33], bool:failStats[33];
- static Float:jumpoff_footheight[33];
- static Float:jumpoff_origin[33][3], Float:fail_origin[33][3];
- static Float:frame_origin[33][2][3], Float:frame_velocity[33][2][3];
- static Floatrigin[3];
- if( !edgeDistanceEnabled[plr] )
- {
- return FMRES_IGNORED;
- }
- if( resetJump[plr] || pev( plr, pev_movetype ) == MOVETYPE_FLY )
- {
- resetJump[plr] = false;
- inAir[plr] = false;
- }
- static button;
- button = pev( plr, pev_button );
- static oldButtons;
- oldButtons = pev( plr, pev_oldbuttons );
- static flags;
- flags = pev( plr, pev_flags );
- if( inAir[plr] )
- {
- if( flags & FL_ONGROUND2 && !failStats[plr] )
- {
- pev( plr, pev_origin, origin );
-
- static Float:mins[3];
- pev( plr, pev_mins, mins );
-
- if( jumpoff_footheight[plr] == origin[2] + mins[2] )
- {
- static Float:gravity;
- gravity = get_pcvar_float( sv_gravity ) * pev( plr, pev_gravity );
-
- static Float:temp;
- 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 );
-
- static Float:landing_origin[3];
- if( frame_origin[plr][1][0] < origin[0] ) landing_origin[0] = frame_origin[plr][1][0] + temp * floatabs( frame_velocity[plr][1][0] );
- else landing_origin[0] = frame_origin[plr][1][0] - temp * floatabs( frame_velocity[plr][1][0] );
-
- if( frame_origin[plr][1][1] < origin[1] ) landing_origin[1] = frame_origin[plr][1][1] + temp * floatabs( frame_velocity[plr][1][1] );
- else landing_origin[1] = frame_origin[plr][1][1] - temp * floatabs( frame_velocity[plr][1][1] );
-
- static Float:distance_1;
- distance_1 = floatsqroot( floatpower( origin[0] - jumpoff_origin[plr][0], 2.0 ) + floatpower( origin[1] - jumpoff_origin[plr][1], 2.0 ) ) + 32.0;
-
- static Float:distance_2;
- 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;
-
- if( distance_1 > distance_2 ) CalculateDistances( plr, jumpoff_origin[plr], landing_origin, jumpoff_footheight[plr], flags, distance_2 );
- else CalculateDistances( plr, jumpoff_origin[plr], origin, jumpoff_footheight[plr], flags, distance_1 );
- }
-
- resetJump[plr] = true;
- }
- else if( failStats[plr] )
- {
- resetJump[plr] = true;
- failStats[plr] = false;
- CalculateDistances( plr, jumpoff_origin[plr], fail_origin[plr], jumpoff_footheight[plr], flags, -1.0 );
- }
- else
- {
- pev( plr, pev_origin, origin );
-
- failStats[plr] = ( ( origin[2] + 18 ) < jumpoff_origin[plr][2] );
-
- if( ( is_user_ducking( plr ) ? ( origin[2] + 18 ) : origin[2] ) >= jumpoff_origin[plr][2] )
- {
- static Float:temp;
- temp = ( jumpoff_origin[plr][2] - frame_origin[plr][1][2] ) / ( origin[2] - frame_origin[plr][1][2] );
- fail_origin[plr][0] = temp * ( origin[0] - frame_origin[plr][1][0] ) + frame_origin[plr][1][0];
- fail_origin[plr][1] = temp * ( origin[1] - frame_origin[plr][1][1] ) + frame_origin[plr][1][1];
- fail_origin[plr][2] = jumpoff_footheight[plr];
- }
-
- if( firstFrame[plr] )
- {
- firstFrame[plr] = false;
-
- xs_vec_copy( origin, frame_origin[plr][0] );
- pev( plr, pev_velocity, frame_velocity[plr][0] );
- }
- else
- {
- xs_vec_copy( origin, frame_origin[plr][1] );
- pev( plr, pev_velocity, frame_velocity[plr][1] );
- }
- }
- }
- if( button & IN_JUMP && !( oldButtons & IN_JUMP ) )
- {
- inAir[plr] = true;
- firstFrame[plr] = true;
-
- if( flags & FL_ONGROUND2 )
- {
- pev( plr, pev_origin, jumpoff_origin[plr] );
-
- static Float:mins[3];
- pev( plr, pev_mins, mins );
-
- jumpoff_footheight[plr] = jumpoff_origin[plr][2] + mins[2];
- }
- else
- {
- static Float:velocity[3];
- pev( plr, pev_velocity, velocity );
-
- if( !velocity[2] )
- {
- pev( plr, pev_origin, origin );
-
- jumpoff_origin[plr][0] = origin[0];
- jumpoff_origin[plr][1] = origin[1];
- }
- }
- }
- return FMRES_IGNORED;
- }
- public CalculateDistances( plr, Float:start[3], Float:stop[3], Float:jumpoff_footheight, flags, Float:distance )
- {
- // use some delay to avoid bugs
- static Float:lastCalc[33];
- static Float:gametime;
- gametime = get_gametime( );
- if( gametime - lastCalc[plr] < 0.5 )
- {
- return 0;
- }
- lastCalc[plr] = gametime;
- // calculate the center origin of jumpoff and landing and set it to the height of the player's feet
- // we need to lower stop[2] so that the hull with which we are tracing can hit the block
- static Float:vertex_origin[3];
- vertex_origin[0] = ( start[0] + stop[0] ) * 0.5;
- vertex_origin[1] = ( start[1] + stop[1] ) * 0.5;
- vertex_origin[2] = stop[2] - 1.0;
- // check whether it was in free space by which we can find out whether the player jumped over a gap
- if( engfunc( EngFunc_PointContents, vertex_origin ) != CONTENTS_EMPTY )
- {
- return 0;
- }
- // set the hull with which we will need to trace for a valid result
- static hull;
- hull = flags & FL_DUCKING || ( distance < 0 ) ? HULL_HEAD : HULL_HUMAN;
- start[2] = vertex_origin[2];
- stop[2] = vertex_origin[2];
- static block;
- static Float:jumpoff_edge;
- static Float:landing_edge;
- static Float:jumpoff_edge_origin[3];
- static Float:landing_edge_origin[3];
- static Float:vecPlaneNormal[3];
- // do a trace from the center to jumpoff
- engfunc( EngFunc_TraceHull, vertex_origin, start, IGNORE_MONSTERS, hull, -1, 0 );
- get_tr2( 0, TR_vecPlaneNormal, vecPlaneNormal );
- // if vecPlaneNormal is 0.0, the player hit some ramp or something
- if( vecPlaneNormal[2] != 0.0 )
- {
- return 0;
- }
- // retrieve the edge origin
- get_tr2( 0, TR_vecEndPos, jumpoff_edge_origin );
- // calculate the smallest distance from jumpoff to the edge using vecPlaneNormal to see in which direction the player jumped
- if( floatabs( vecPlaneNormal[0] ) == 1.0 && !vecPlaneNormal[1] ) jumpoff_edge = floatabs( jumpoff_edge_origin[0] - start[0] ) - HLBSP_EXTRA;
- else if( !vecPlaneNormal[0] && floatabs( vecPlaneNormal[1] ) == 1.0 ) jumpoff_edge = floatabs( jumpoff_edge_origin[1] - start[1] ) - HLBSP_EXTRA;
- else return 0;
- // distance < 0 means the player failed failed the jump
- if( distance < 0 )
- {
- static Float:end[3];
-
- // extend the coords so the traces can hit the block
- if( floatabs( vecPlaneNormal[0] ) == 1.0 && !vecPlaneNormal[1] )
- {
- end[0] = stop[0] + vecPlaneNormal[0] * 300;
- end[1] = stop[1];
- end[2] = stop[2];
- }
- else if( !vecPlaneNormal[0] && floatabs( vecPlaneNormal[1] ) == 1.0 )
- {
- end[0] = stop[0];
- end[1] = stop[1] + vecPlaneNormal[1] * 300;
- end[2] = stop[2];
- }
- else return 0;
-
- engfunc( EngFunc_TraceHull, vertex_origin, end, IGNORE_MONSTERS, hull, -1, 0 );
- get_tr2( 0, TR_vecPlaneNormal, vecPlaneNormal );
- if( vecPlaneNormal[2] != 0.0 ) return 0;
- get_tr2( 0, TR_vecEndPos, landing_edge_origin );
-
- if( floatabs( vecPlaneNormal[0] ) == 1.0 && !vecPlaneNormal[1] )
- {
- end[0] = landing_edge_origin[0] - vecPlaneNormal[0] * 16.1;
- end[1] = landing_edge_origin[1];
- end[2] = landing_edge_origin[2] + 37.0;
- }
- else if( !vecPlaneNormal[0] && floatabs( vecPlaneNormal[1] ) == 1.0 )
- {
- end[0] = landing_edge_origin[0];
- end[1] = landing_edge_origin[1] - vecPlaneNormal[1] * 16.1;
- end[2] = landing_edge_origin[2] + 37.0;
- }
- else return 0;
-
- vertex_origin[2] += 37.0;
- engfunc( EngFunc_TraceHull, vertex_origin, end, IGNORE_MONSTERS, hull, -1, 0 );
-
- static Float:fraction;
- get_tr2( 0, TR_flFraction, fraction );
-
- // the player jumped against a wall
- if( fraction < 1.0 ) return 0;
- }
- else
- {
- engfunc( EngFunc_TraceHull, vertex_origin, stop, IGNORE_MONSTERS, hull, -1, 0 );
- get_tr2( 0, TR_vecPlaneNormal, vecPlaneNormal );
- if( vecPlaneNormal[2] != 0.0 ) return 0;
-
- get_tr2( 0, TR_vecEndPos, landing_edge_origin );
- }
- if( floatabs( vecPlaneNormal[0] ) == 1.0 && !vecPlaneNormal[1] )
- {
- landing_edge = floatabs( landing_edge_origin[0] - stop[0] ) - HLBSP_EXTRA;
- block = floatround( floatabs( landing_edge_origin[0] - jumpoff_edge_origin[0] ) ) + 32;
- }
- else if( !vecPlaneNormal[0] && floatabs( vecPlaneNormal[1] ) == 1.0 )
- {
- landing_edge = floatabs( landing_edge_origin[1] - stop[1] ) - HLBSP_EXTRA;
- block = floatround( floatabs( landing_edge_origin[1] - jumpoff_edge_origin[1] ) ) + 32;
- }
- else return 0;
- if( MAX_BLOCK < block || block < MIN_BLOCK ) return 0;
- static Float:x, Float:y;
- GetHudCoords( cvarHudCoords, x, y );
- static r, g, b;
- if( distance < 0 )
- {
- GetHudColor( cvarHudColorFail, r, g, b );
-
- client_print( plr, print_console, "Fail --- Block: %i - Jumpoff: %f", block, jumpoff_edge );
-
- set_hudmessage( r, g, b, x, y, 0, 0.0, get_pcvar_float( cvarHudHoldtime ), 0.1, 0.1, get_pcvar_num( cvarHudChannel ) );
- show_hudmessage( plr, "Block: %i^nJumpoff: %f", block, jumpoff_edge );
-
- return 1;
- }
- GetHudColor( cvarHudColor, r, g, b );
- client_print( plr, print_console, "Gj! --- Block: %i - Jumpoff: %f - Landing: %f", block, jumpoff_edge, landing_edge );
- set_hudmessage( r, g, b, x, y, 0, 0.0, get_pcvar_float( cvarHudHoldtime ), 0.0, 0.0, get_pcvar_num( cvarHudChannel ) );
- show_hudmessage( plr, "Block: %i^nJumpoff: %f^nLanding: %f", block, jumpoff_edge, landing_edge );
- return 1;
- }
- public GetHudColor( cvar, &r, &g, &b )
- {
- static color[16], piece[5];
- get_pcvar_string( cvar, color, 15 );
- strbreak( color, piece, 4, color, 15 );
- r = str_to_num( piece );
- strbreak( color, piece, 4, color, 15 );
- g = str_to_num( piece );
- b = str_to_num( color );
- }
- public GetHudCoords( cvar, &Float:x, &Float:y )
- {
- static coords[16], piece[10];
- get_pcvar_string( cvar, coords, 15 );
- strbreak( coords, piece, 9, coords, 15 );
- x = str_to_float( piece );
- y = str_to_float( coords );
- }
- stock bool:is_user_ducking( plr )
- {
- static Float:absmin[3];
- pev( plr, pev_absmin, absmin );
- static Float:absmax[3];
- pev( plr, pev_absmax, absmax );
- return !( ( absmin[2] + 64.0 ) < absmax[2] );
- }
复制代码
给交给你个艰巨的任务 看看我改了那些代码 |
|