Senior Member
|
06-30-2018
, 01:51
Re: [req] teleport to crosshair destination
|
#13
|
Quote:
Originally Posted by supertimor
LenHard, everything works totally fine, but if i can ask second time - as i said at beginning, can u make this teleport not for full lenght forigin, but for 300 units f.e. I need this because it will be a class for COD, which will be able to gain more intelligence = raise lenght of teleport.
hope you'll understand me, thanks in advance, you're great
|
Change this
PHP Code:
public Action Cmd_Teleport(int client, int args)
{
if (0 < client <= MaxClients && IsClientInGame(client) && IsPlayerAlive(client))
{
float fPos[3], fBackwards[3];
float fOrigin[3]; GetClientEyePosition(client, fOrigin);
float fAngles[3]; GetClientEyeAngles(client, fAngles);
Handle trace = TR_TraceRayFilterEx(fOrigin, fAngles, MASK_PLAYERSOLID, RayType_Infinite, TraceRayDontHitPlayers, client);
bool failed;
int loopLimit = 100;
GetAngleVectors(fAngles, fBackwards, NULL_VECTOR, NULL_VECTOR);
NormalizeVector(fBackwards, fBackwards);
ScaleVector(fBackwards, 10.0);
if (TR_DidHit(trace))
{
TR_GetEndPosition(fPos, trace);
while (IsPlayerStuck(fPos, client) && !failed)
{
SubtractVectors(fPos, fBackwards, fPos);
if (GetVectorDistance(fPos, fOrigin) < 10 || loopLimit-- < 1)
{
failed = true;
fPos = fOrigin;
}
}
}
delete trace;
TeleportEntity(client, fPos, NULL_VECTOR, NULL_VECTOR);
PrintCenterText(client, "You have teleported!");
}
return Plugin_Handled;
}
To
PHP Code:
#define DISTANCE 500.0
public Action Cmd_Teleport(int client, int args)
{
if (0 < client <= MaxClients && IsClientInGame(client) && IsPlayerAlive(client))
{
float fPos[3], fBackwards[3];
float fOrigin[3]; GetClientEyePosition(client, fOrigin);
float fAngles[3]; GetClientEyeAngles(client, fAngles);
GetAngleVectors(fAngles, fBackwards, NULL_VECTOR, NULL_VECTOR);
for (int i = 0; i < 3; ++i) {
fAngles[i] = fOrigin[i] + (fBackwards[i] * DISTANCE);
}
Handle hTrace = TR_TraceRayFilterEx(fOrigin, fAngles, MASK_PLAYERSOLID, RayType_EndPoint, TraceRayDontHitPlayers);
int loopLimit = 100;
if (TR_DidHit(hTrace))
{
TR_GetEndPosition(fPos, hTrace);
NormalizeVector(fBackwards, fBackwards);
ScaleVector(fBackwards, 10.0);
while (IsPlayerStuck(fPos, client))
{
SubtractVectors(fPos, fBackwards, fPos);
if (GetVectorDistance(fPos, fOrigin) < 10 || loopLimit-- < 1)
{
fPos = fOrigin;
break;
}
}
}
else fPos = fAngles;
delete hTrace;
TeleportEntity(client, fPos, NULL_VECTOR, NULL_VECTOR);
PrintCenterText(client, "You have teleported!");
}
return Plugin_Handled;
}
__________________
|
|