# 2مساعدة كيف اخلي البوت يهاجم اللاعب

## Recommended Posts

-------------------------------------------------------------------

PedBank1 = createPed (0,879.64978, -1028.60767, 31.90541,180)
wep = givePedWeapon(PedBank1,31,10000, true)
setPedArmor (PedBank1,50)

zone = createColCuboid(883.79004, -1038.33118, 30.90541, 7.3719482421875, 6.88134765625, 1.9)

function dimensionChecker (theElement, matchingDimension)

x, y, z = getElementPosition(localPlayer)
setPedControlState(PedBank1, "aim_weapon",true)
setPedControlState(PedBank1, "fire", true)
setPedAimTarget (PedBank1, x, y, z )
setPedCameraRotation (PedBank1, x, y, z , true)
outputChatBox("Fire!",255,0,0)

end

-------------------------------------------------------------------

function dimensionCheckerLev (theElement, matchingDimension)

x, y, z = getElementPosition(localPlayer)
setPedControlState(PedBank1, "aim_weapon",false)
setPedControlState(PedBank1, "fire", false)
setPedCameraRotation (PedBank1, x, y, z , false)
setPedControlState(PedBank1, "aim_weapon",false)
outputChatBox("StopFire",0,200,0)
end

-------------------------------------------------------------------

وعليكم السلام  , جرب هالكود

```function findRotation( x1, y1, x2, y2 )
local t = -math.deg( math.atan2( x2 - x1, y2 - y1 ) )
return t < 0 and t + 360 or t
end

--  المرجع الاصلي
-- https://wiki.multitheftauto.com/wiki/SetPedAttack
-- تم التعديل على الفنكشن ليتناسب مع الكود المطروح

function setPedAttack(theElement, theTarget, thePedSlot)
if theElement then
local x, y, z = getElementPosition(theTarget)
local ex, ey, ez = getElementPosition(theElement)
-- حساب المسافة بين البيد واللاعب
local distance = getDistanceBetweenPoints3D(x, y, z, ex, ey, ez)
local rotation = findRotation(ex, ey, x, y)
setPedRotation(theElement, rotation)
setPedLookAt(theElement, x, y, z + 5)
setPedAimTarget(theElement, x, y, z)
givePedWeapon(theElement, 30, 30, true)
-- إذا كانت المسافة أكبر من 30
if distance > 30 then
setPedControlState(theElement, "forwards", true)
setPedControlState(theElement, "fire", false)
setPedWeaponSlot(theElement, 0)
else
setPedControlState(theElement, "fire", true)
setPedControlState(theElement, "forwards", false)
setPedWeaponSlot(theElement, thePedSlot)
end
setPedControlState(theElement, "fire", true)
setPedWeaponSlot(theElement, thePedSlot)
end
end

_setPedRotation = setPedRotation
function setPedRotation(element, rot)
return _setPedRotation(element, rot)
end

local thePlayer = getLocalPlayer()

local x, y, z = getElementPosition(thePlayer)

-- إنشاء شخصية بالقرب من موقع اللاعب
local thePed = createPed(0, x + 2, y + 2, z) -- يمكنك تحديد موقع دائم للبيد

if (thePed) then
givePedWeapon(thePed, 30, 30, true)

setTimer(function()
if (isElement(thePed) and isElement(thePlayer)) then
setPedAttack(thePed, thePlayer, 30, 30, 2)
end
end, 1000, 0)

if (isElement(thePed)) then
local sx, sy, sz = getPedBonePosition(thePed, 8)
local ex, ey = getScreenFromWorldPosition(sx, sy, sz + 0.5)
local px, py, pz = getElementPosition(thePlayer)
local distance = getDistanceBetweenPoints3D(px, py, pz, sx, sy, sz)
if (ex and ey and distance <= 100) then
local health = getElementHealth(thePed)
dxDrawRectangle(ex - 50, ey, 100, 10, tocolor(0, 0, 0, 128))
dxDrawRectangle(ex - 50, ey, health, 10, tocolor(255 - health * 2.55, health * 2.55, 0, 128))
dxDrawText("خالد: " .. math.floor(health) .. "%", ex - 50, ey, ex + 50, ey + 20, tocolor(255, 255, 255, 255), 1, "default-bold", "center", "center", false, false, false, true)
end
end
end)

-- اعادة البيد عند موته
local function onPedWasted()
local x, y, z = getElementPosition(source)
createEffect("explosion_molotov", x, y, z) -- إنشاء تأثير الانفجار
destroyElement(source)
thePed = createPed(0, x, y, z)
givePedWeapon(thePed, 30, 30, true)
end
end```

صور :

اني اصور وانا اقتله اصعب شي الصدق

Edited by KhaledX

## Create an account

Register a new account