A$K Posted May 28, 2015 Share Posted May 28, 2015 I am creating a ped, I wish he shoots, but in this role he does not react after the player shooting I'm new, I registered in search of a solution for this, I thank you local function setPedAttackPlayer(thePed) if(attacking[thePed] == true) then return end attacking[thePed] = true attackTimer[thePed] = setTimer(function() if(getElementHealth(thePed) < 1) then killTimer(attackTimer[thePed]) else local x1, y1, z1 = getElementPosition(thePed) local x2, y2, z2 = getElementPosition(localPlayer) local rot = math.atan2(y2 - y1, x2 - x1) * 180 / math.pi rot = rot-90 end end, 500, -1) end Link to comment
SpoC^ Posted May 28, 2015 Share Posted May 28, 2015 I believe you stole it from someone !? try this local function setPedAttackPlayer(thePed) if(attacking[thePed] == true) then return end attacking[thePed] = true attackTimer[thePed] = setTimer(function() if(getElementHealth(thePed) < 1) then killTimer(attackTimer[thePed]) else local x1, y1, z1 = getElementPosition(thePed) local x2, y2, z2 = getElementPosition(localPlayer) local rot = math.atan2(y2 - y1, x2 - x1) * 180 / math.pi rot = rot-90 if(isLineOfSightClear(x1, y1, z1, x2, y2, z2, true, false, false, false, false, false, false)) then setPedRotation(thePed, rot) setPedAimTarget(thePed, getElementPosition(localPlayer)) setPedControlState(thePed, "aim_weapon", true) setPedControlState(thePed, "fire", true) setTimer(setPedControlState, 100, 1, thePed, "fire", false) else setPedControlState(thePed, "aim_weapon", false) setPedControlState(thePed, "fire", false) end end end, 500, -1) end 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