xyz Posted August 29, 2016 Share Posted August 29, 2016 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) Link to comment
Gravestone Posted August 30, 2016 Share Posted August 30, 2016 onClientColShapeHit's root resourceRoot? resourceRoot is a predifined variable which gets the current resource's root and should be used with onClientResourceStart/Stop only. Try this, not tested. function cancelUnkillableDamage(p, md) if (isElement(p)) then if (p.type ~= "player") then return end 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 addEventHandler("onClientColShapeHit", root, cancelUnkillableDamage) addEventHandler("onClientColShapeLeave", root, function(p, md) if (isElement(p)) then if (p.type ~= "player") then return end for _, v in ipairs(Element.getAllByType("ped")) do if (v:getData("ms:guard") == true) then if getPedTarget(v) == p then setPedControlState(v, "fire", false) end end end end end ) Link to comment
xyz Posted August 30, 2016 Author Share Posted August 30, 2016 What? I don't want to trigger this on literally every colshape I leave. That colshape is the only colshape in that resource so I can use resourceRoot. I didn't ask for that. resourceRoot works well as it is. Also, When I go behind a wall and come back their aim is off, and they don't hit me. I'm not leaving the colshape, just going behind a wall, how is leaving the colshape going to help in any way? Link to comment
Gravestone Posted August 30, 2016 Share Posted August 30, 2016 Oh my bad, have you tried processLineOfSight? Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now