You can use the code provided by J_Striker_A on this script, you may also change the code to suit your needs.
BTW.. this is only for Johnny:
X, Y, Z = PlayerGetPosXYZ()
if PedIsModel(ped, 23) then
if PedMePlaying(ped, "Default_KEY") then
if not PedIsPlaying(ped, "/Global/G_Johnny", true) then
PedSetActionTree(ped, "/Global/G_Johnny", "Act/Anim/G_Johnny.act")
end
if PedIsValid(PedGetTargetPed(ped)) and PedIsInCombat(ped) then
local PX, PY, PZ = PedGetPosXYZ(ped)
if math.abs(X - PX) + math.abs(Y - PY) + math.abs(Z - PZ) <= 2.0 and math.random(1, 100) < 5 then
PedSetActionNode(ped, node, file) -- replace node and file with J_Striker_A's action nodes or your own ones
end
end
end
end
That is how you can trigger NPC to do a custom attack animation simply and looks naturally. The chance of doing that animation is 5% (
math.random(1, 100) <
5), i personally don't recommend you to set the chance higher than 20. Otherwise, it will be his favorite moves
.
Disclaimer: I did not test the code, but it was modified according to the attached picture.