So I am making a robbery script with guards, but the guards only hit me when I restart the script near them.
When I go behind a wall and come back their aim is off, and they don't hit me. It sometimes looks like the bullet goes into me but no damage.
function cancelUnkillableDamage(p, md)
if (isElement(p)) then
if (p.type ~= "player") then return end
addEventHandler("onClientRender", root, function()
for _, v in ipairs(Element.getAllByType("ped")) do
if (v:getData("ms:guard") == true) then
local x, y, z = getPedBonePosition(p, 3)
local px, py, pz = getElementPosition(v)
local dg = findRotation(px, py, x, y)
setPedAimTarget(v, x, y, z)
setPedControlState(v, "fire", true)
setElementRotation(v, 0, 0, tonumber(dg))
end
end
end)
end
end
addEventHandler("onClientColShapeHit", resourceRoot, cancelUnkillableDamage)