I wrote a warp bot plugin to move bots around and it works great except for the feature that lets me warp a single bot where I am pointing. It works but it allows placing the bot in the walls where they are stuck. I would like to not allow the warp in this case.
It must have something to do with the traceline but I don't have the expirence to know how to change it.
PHP Code:
//-----------------------------------------------------------------------------
public Action Command_warpFarBot(int client, int args)
{
float clientPos[3];
GetEntPropVector(client, Prop_Data, "m_vecOrigin", clientPos);
int farthestBotIndex = getFarthestBot(client);
if (farthestBotIndex < 1)
{
ReplyToCommand(client, "Could not find a bot to teleport.");
return Plugin_Handled;
}
new Float:g_Origin[3];
new Float:g_Angle[3];
GetClientEyePosition(client, g_Origin);
GetClientEyeAngles(client, g_Angle);
TR_TraceRayFilter(g_Origin, g_Angle, MASK_OPAQUE, RayType_Infinite, TraceRayDontHitSelf, client);
if(TR_DidHit(INVALID_HANDLE))
TR_GetEndPosition(g_Origin);
else
PrintToChat(client, "Vector out of world geometry. Spawning on current position instead");
TeleportEntity(farthestBotIndex, g_Origin, g_Angle, NULL_VECTOR);
ReplyToCommand(client, "[SM] Teleported %N to you.", farthestBotIndex);
return Plugin_Handled;
}
//-----------------------------------------------------------------------------
int getFarthestBot(client)
{
int farthestBotIndex = -1;
float maxDist = 1.0;
float otherPos[3], clientPos[3];
GetEntPropVector(client, Prop_Data, "m_vecOrigin", clientPos);
for (int i = 1; i <= MaxClients; i++)
{
if (!IsClientInGame(i)) continue;
if (!IsPlayerAlive(i)) continue;
if (!IsFakeClient(i)) continue;
if (GetClientTeam(i) != GetClientTeam(client)) continue;
GetEntPropVector(i, Prop_Data, "m_vecOrigin", otherPos);
if (GetVectorDistance(clientPos, otherPos, false) > maxDist)
{
maxDist = GetVectorDistance(clientPos, otherPos, false);
farthestBotIndex = i;
}
}
return farthestBotIndex;
}
//-----------------------------------------------------------------------------
public bool:TraceRayDontHitSelf(entity, mask, any:data)
{
if(entity == data) // TraceRay hit the itself?
return false; // Don't let the entity be hit
return true;
}