From 61f5b2ffc4dc221388c0d8ff54b2534c9aac361d Mon Sep 17 00:00:00 2001 From: RD42 <42702181+dashr9230@users.noreply.github.com> Date: Mon, 1 Jul 2024 23:04:33 +0800 Subject: [PATCH] [bot] Implement/match `n_IsPlayerInRangeOfPoint(...)` --- bot/scrcustom.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/bot/scrcustom.cpp b/bot/scrcustom.cpp index 53427a0..df1d77d 100644 --- a/bot/scrcustom.cpp +++ b/bot/scrcustom.cpp @@ -264,7 +264,28 @@ static cell AMX_NATIVE_CALL n_GetDistanceFromMeToPoint(AMX *amx, cell *params) // native IsPlayerInRangeOfPoint(playerid, Float:range, Float:X, Float:Y, Float:Z) static cell AMX_NATIVE_CALL n_IsPlayerInRangeOfPoint(AMX *amx, cell *params) { - // TODO: n_IsPlayerInRangeOfPoint + if(!pNetGame->GetPlayerPool()) return 0; + if(!pNetGame->GetPlayerPool()->GetSlotState((PLAYERID)params[1])) return 0; + + VECTOR vecTestPoint; + VECTOR vecThisPlayer; + if(pNetGame->GetPlayerPos((PLAYERID)params[1], &vecThisPlayer)) + { + float fRange = amx_ctof(params[2]); + vecTestPoint.X = amx_ctof(params[3]); + vecTestPoint.Y = amx_ctof(params[4]); + vecTestPoint.Z = amx_ctof(params[5]); + + fRange = fRange * fRange; + + float fSX = (vecThisPlayer.X - vecTestPoint.X) * (vecThisPlayer.X - vecTestPoint.X); + float fSY = (vecThisPlayer.Y - vecTestPoint.Y) * (vecThisPlayer.Y - vecTestPoint.Y); + float fSZ = (vecThisPlayer.Z - vecTestPoint.Z) * (vecThisPlayer.Z - vecTestPoint.Z); + + if((float)(fSX + fSY + fSZ) <= fRange) return 1; + + return 0; + } return 0; }