Garipso
System Logging Specialist
2
MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1
100 XP
Today i wanted to share my very first old prediction code.
pretty similar to Elobuddy / L# prediction this code is more like a pseudo code and i think that it will be useful for this community.
pretty similar to Elobuddy / L# prediction this code is more like a pseudo code and i think that it will be useful for this community.
Loading…
i.ibb.co
Code:
//vars: obj_target_ptr, radius, spell_range, spell_missile_speed, spell_cast_delay
//CVector3D is inherited from D3DXVECTOR3
//CVector3D.DistanceTo = sqrtf(powf(v1.x - v2.x, 2) + powf(v1.y - v2.y, 2) + powf(v1.z - v2.z, 2));
//CVector3D.To2D swaps z to y
int ping = CGameClient::GetPing(); //if u cant get ur ping just do "; //+ ping / xxxx.f;"
float flytime_max = (missile_speed != 0) ? spell_range / spell_missile_speed : 0.f;
float t_min = spell_cast_delay + ping / 2000.f;
float t_max = flytime_max + spell_cast_delay + ping / 1000.f;
float path_time = 0.f;
CVector3D** path_bounds[2] = { nullptr, nullptr };
//CVector3D* NAVBEGIN 0x1BC
//CVector3D* NAVEND 0x1C0
CVector3D** ppNavStart = target->AIManager()->GetNavigationBegin();
CVector3D** ppNavEnd = target->AIManager()->GetNavigationEnd();
//find the limits
for (auto ppNavPtr = ppNavStart; ppNavPtr != ppNavEnd; ppNavPtr++)
{
CVector3D cur = (*ppNavPtr)->To2D(); //skills hit calculating in 2d space
CVector3D next = (*(ppNavPtr + 1))->To2D(); //because height is not neccessary but when calculating the distance in 3d
float t = next.DistanceTo(cur); //that causes a little difference in calculating so it will likely miss the target
if (path_time <= t_min && path_time + t >= t_min)
{
path_bounds[0] = ppNavPtr;
}
if (path_time <= t_max && path_time + t >= t_max)
{
path_bounds[1] = ppNavPtr;
}
if (path_bounds[0] != nullptr && path_bounds[1] != nullptr)
{
break;
}
path_time += t;
}
//if skill will hit to the target within the boundaries
if (path_bounds[0] != nullptr && path_bounds[1] != nullptr)
{
CVector3D** ppNavPtr = path_bounds[0];
while (true)
{
CVector3D cur = (*ppNavPtr)->To2D();
CVector3D next = (*(ppNavPtr + 1))->To2D();
CVector3D direction = CVector3D{ (next - cur) }.ToNormalized();
float extender = target->GetBoundingRadius();
float distance = radius;
int steps = (int)floor(cur.DistanceTo(next) / distance);
if (steps > 0 && steps < 1000)
{
for (int i = 1; i < steps - 1; i++)
{
CVector3D center = CVector3D{ cur + direction * distance * i };
CVector3D pt_a = CVector3D{ center - direction * extender };
CVector3D pt_b = CVector3D{ center + direction * extender };
float flytime = (missile_speed != 0) ? player->GetPosition()->DistanceTo(target->GetPosition()) / missile_speed : 0.f;
float t = flytime + spell_cast_delay + ping / 2000.f;
float arrive_time_a = target->GetPosition()->DistanceTo(pt_a) / *target->GetMovementSpeed();
float arrive_time_b = target->GetPosition()->DistanceTo(pt_b) / *target->GetMovementSpeed();
CVector3D predicted_pos = CVector3D{ center.x, center.y };
CVector2D enemy_position_w2s = CRiot3DRenderer::WorldToScreen(target->GetPosition());
CVector2D predicted_position_w2s = CRiot3DRenderer::WorldToScreen(&predicted_pos);
if (min(arrive_time_a, arrive_time_b) <= t && max(arrive_time_a, arrive_time_b) >= t)
{
CDrawing::DrawLine(enemy_position_w2s.x, enemy_position_w2s.y, predicted_position_w2s.x, predicted_position_w2s.y, 2, COLOR_GREEN);
CDrawing::DrawFontText(predicted_position_w2s.x, predicted_position_w2s.y, COLOR_GREEN, "predicted pos");
return predicted_pos;
}
else
{
CDrawing::DrawLine(enemy_position_w2s.x, enemy_position_w2s.y, predicted_position_w2s.x, predicted_position_w2s.y, 2, COLOR_RED);
CDrawing::DrawFontText(predicted_position_w2s.x, predicted_position_w2s.y, COLOR_RED, "predicted pos");
}
}
}
if (ppNavPtr == path_bounds[1])
{
break;
}
ppNavPtr++;
}
}