Seems to work fine, could be improved for sure but i suck hard at 3d geometry.
Edit : i hadn't read accurately what you wrote, so this won't work, i have an idea though
PHP Code:
#include <amxmodx>
#include <xs>
#include <engine>
#include <fakemeta_stocks>
#define PLUGIN "Teleport to Aim Point"
#define VERSION "0.0.1"
const Float:MAX_TELEPORT_Z = 125.0 // approximative height from where you can fall without taking any damage.
public plugin_init()
{
register_plugin( PLUGIN, VERSION, "ConnorMcLeod" )
register_clcmd("drop", "ClientCommand_drop")
}
public ClientCommand_drop( id )
{
if( get_user_weapon(id) == CSW_KNIFE )
{
TeleportToAimPoint( id )
return PLUGIN_HANDLED
}
return PLUGIN_CONTINUE
}
TeleportToAimPoint( id )
{
new Float:coordOrigin[3], Float:coordDest[3], Float:flFraction, Float:vecPlaneNormal[3], Float:vecTemp[3]
pev(id, pev_origin, coordOrigin)
coordOrigin[2] += pev(id, pev_flags) & FL_DUCKING ? 12.0 : 18.0
velocity_by_aim(id, 9999, coordDest)
xs_vec_add(coordDest, coordOrigin, coordDest)
trace_normal(id, coordOrigin, coordDest, vecPlaneNormal)
trace_line(id, coordOrigin, coordDest, coordDest)
traceresult(TR_Fraction, flFraction)
if( flFraction >= 1.0 || point_contents( coordDest ) == CONTENTS_SKY )
{
return 0
}
new const Float:maxs[3] = { 16.0, 16.0, 36.0};
new i
for(i=0; i<3; i++)
{
vecTemp[i] = vecPlaneNormal[i] * maxs[i]
}
xs_vec_add(coordDest, vecTemp, coordDest)
vecTemp[0] = coordDest[0]
vecTemp[1] = coordDest[1]
vecTemp[2] = coordDest[2] - maxs[2]
trace_line(id, coordDest, vecTemp, vecTemp)
new Float:flDist = coordDest[2] - vecTemp[2]
if( flDist < maxs[2] )
{
vecTemp[2] += maxs[2]
if( !trace_hull(vecTemp, HULL_HUMAN) )
{
xs_vec_copy(vecTemp, coordDest)
goto CheckHeight
}
return 0
}
if( trace_hull(coordDest, HULL_HUMAN) )
{
return 0
}
CheckHeight:
vecTemp[0] = coordDest[0]
vecTemp[1] = coordDest[1]
vecTemp[2] = coordDest[2] - 9999.0
engfunc(EngFunc_TraceHull, coordDest, vecTemp, DONT_IGNORE_MONSTERS, HULL_HUMAN, FM_NULLENT, 0)
get_tr2(0, TR_flFraction, flFraction)
flFraction *= 9999.0
flFraction -= maxs[2]
if( flFraction > MAX_TELEPORT_Z )
{
return 0
}
Util_TE_TELEPORT(coordOrigin)
Util_TE_TELEPORT(coordDest)
entity_set_origin(id, coordDest)
return 1
}
Util_TE_TELEPORT( const Float:origin[3] )
{
EF_MessageBegin(MSG_PVS, SVC_TEMPENTITY, origin, 0)
write_byte(TE_TELEPORT)
EF_WriteCoord(origin[0])
EF_WriteCoord(origin[1])
EF_WriteCoord(origin[2])
message_end()
}
__________________