I was using this in a plugin of mine until I realized it was causing my l4d2 server to crash.
After investigating, I saw that the traceray was using up handles until all of them were filled up and weird things would happen.
It seems you need to CloseHandle all tracerays period. Doesn't even matter if its a global handle or not, it will even happen if you try to assign the same handle to another traceray and will use up addresses in memory.
This fixed it for me:
Code:
new Float:pos[3];
new Float:floor[3];
new Float:ceiling[3];
new Float:direction[3];
new Handle:trace;
new Float:totalHeight;
for(new i = 0; i < 11; ++i)
{
pos[0] = GetRandomFloat(MapX[0],MapX[1]);
pos[1] = GetRandomFloat(MapY[0],MapY[1]);
pos[2] = GetRandomFloat(MapZ[0],MapZ[1]);
direction[0] = 89.0;//thats right you'd think its a z value - this will point you down
trace = TR_TraceRayEx(pos, direction,MASK_PLAYERSOLID_BRUSHONLY, RayType_Infinite);
if(TR_DidHit(trace))
{
TR_GetEndPosition(floor, trace);
}
CloseHandle(trace);
direction[0] = -89.0;//this will point you up
trace = TR_TraceRayEx(pos, direction,MASK_PLAYERSOLID_BRUSHONLY, RayType_Infinite);
if(TR_DidHit(trace))
{
TR_GetEndPosition(ceiling, trace);
}
CloseHandle(trace);
//I find the height below to prevent players from becoming stuck
if (ceiling[2] < 0 && floor[2] < 0)
{
totalHeight = FloatAbs(ceiling[2]) - FloatAbs(floor[2]);
}
else if (ceiling[2] > 0 && floor[2] > 0)
{
totalHeight = ceiling[2] - floor[2];
}
else
{
totalHeight = FloatAbs(ceiling[2]) + FloatAbs(floor[2]);
}
if (FloatAbs(totalHeight) > 75.0)
{
pos[2] = floor[2] + 20;//once again keep those players out of the dirt
i = 11;
}
}