From 402d3944e12e0a900dc51a2ba483c9d87ce82a63 Mon Sep 17 00:00:00 2001 From: RD42 <42702181+dashr9230@users.noreply.github.com> Date: Mon, 8 Jul 2024 18:03:56 +0800 Subject: [PATCH] [bot] Implement/match `n_GetDistanceFromMeToPoint(...)` * Implement/match `CNetGame::GetDistanceFromMeToPoint(...)` --- bot/net/netgame.cpp | 17 +++++++++++++++++ bot/net/netgame.h | 1 + bot/scrcustom.cpp | 16 ++++++++++++++-- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/bot/net/netgame.cpp b/bot/net/netgame.cpp index b2a0322..af7b019 100644 --- a/bot/net/netgame.cpp +++ b/bot/net/netgame.cpp @@ -250,6 +250,23 @@ BOOL CNetGame::IsVehicleAdded(VEHICLEID VehicleID) } //---------------------------------------------------- +float CNetGame::GetDistanceFromMeToPoint(PVECTOR vecPos) +{ + VECTOR vecMyPos; + + if(GetMyPos(&vecMyPos)) + { + float fX = vecMyPos.X - vecPos->X; + float fY = vecMyPos.Y - vecPos->Y; + float fZ = vecMyPos.Z - vecPos->Z; + + return (float)sqrt(fX * fX + fY * fY + fZ * fZ); + } + else + { + return 0.0f; + } +} //---------------------------------------------------- PVECTOR CNetGame::GetMyPos(PVECTOR Vector) diff --git a/bot/net/netgame.h b/bot/net/netgame.h index 616d686..678e15c 100644 --- a/bot/net/netgame.h +++ b/bot/net/netgame.h @@ -114,6 +114,7 @@ public: BYTE GetPlayerSpecialAction(PLAYERID playerId); BOOL IsPlayerAdded(PLAYERID playerId); BOOL IsVehicleAdded(VEHICLEID VehicleID); + float GetDistanceFromMeToPoint(PVECTOR vecPos); PVECTOR GetMyPos(PVECTOR Vector); void SetMyPos(PVECTOR Vector); float GetMyZAngle(); diff --git a/bot/scrcustom.cpp b/bot/scrcustom.cpp index dd03c83..dbc3bbb 100644 --- a/bot/scrcustom.cpp +++ b/bot/scrcustom.cpp @@ -306,8 +306,20 @@ static cell AMX_NATIVE_CALL n_SetMyFacingAngle(AMX *amx, cell *params) // native GetDistanceFromMeToPoint(Float:X, Float:Y, Float:Z, &Float:Distance) static cell AMX_NATIVE_CALL n_GetDistanceFromMeToPoint(AMX *amx, cell *params) { - // TODO: n_GetDistanceFromMeToPoint - return 0; + if(!pNetGame->GetPlayerPool()) return 0; + + VECTOR vecPos; + vecPos.X = amx_ctof(params[1]); + vecPos.Y = amx_ctof(params[2]); + vecPos.Z = amx_ctof(params[3]); + + float fResult = pNetGame->GetDistanceFromMeToPoint(&vecPos); + + cell* cptr; + amx_GetAddr(amx, params[4], &cptr); + *cptr = amx_ftoc(fResult); + + return 1; } // native IsPlayerInRangeOfPoint(playerid, Float:range, Float:X, Float:Y, Float:Z)