Hey guys!
I found a youtube tutorial of how to script a basic attack mod, and the code is the following:
function main()
-- Waiting for the game's appearing:
while not SystemIsReady() or AreaIsLoading() do
Wait(0)
end
LoadAnim()
CreateThread("Basic_Attack")
while true do
Wait(0)
end
end
function Basic_Attack()
while true do
Wait(0)
if PedIsPlaying(gPlayer, "/Global/Player/Attacks/Strikes/LightAttacks", "act/anim/Player.act") and PedHasWeapon(gPlayer, -1) then
PedLockTarget(gPlayer, -1)
PedSetAITree(gPlayer, "/Global/DarbyAI", "Act/AI/AI_DARBY_2_B.act")
PedSetActionNode(gPlayer, "/Global/G_Johnny/Offense/Short/Strikes/LightAttacks", "Act/Anim/G_Johnny.act")
repeat
Wait(0)
until not PedIsPlaying(gPlayer, "/Global/G_Johnny", true)
PedSetAITree(gPlayer, "/Global/PlayerAI", "Act/PlayerAI.act")
end
end
end
Ok, good. So, I wanted to make a mix style so, i adapted the script to apply random nodes from a table I created using daBOSS tutorial on a post about how to spawn peds random locations, and so my script is as follows:
function main()
-- Waiting for the game's appearing:
while not SystemIsReady() or AreaIsLoading() do
Wait(0)
end
LoadAnim()
CreateThread("Basic_Attack")
while true do
Wait(0)
end
end
function Basic_Attack()
local basicnodes = {
{"/Global/G_Johnny/Offense/Short/Strikes/LightAttacks", "Act/Anim/G_Johnny.act", "/Global/G_Johnny"}, --1 and 2 for pedsetaction, 3 for pedmeplaying
{"/Global/Nemesis/Offense/Short/Strikes/LightAttacks/LeftHook/RightCross/HeavyAttacks/HeavyPunch2", "act/anim/Nemesis.act", "/Global/Nemesis"},
{"/Global/P_Striker_B/Offense/Short/Strikes/HeavyAttacks/Hook2", "act/anim/P_Striker_B.act", "/Global/P_Striker_B"},
{"/Global/P_Grappler_A/Offense/Short/Strikes/HeavyAttacks/RightCross/LeftDown", "act/anim/P_Grappler_A.act", "/Global/P_Grappler_A"},
{"/Global/P_Bif/Offense/Short/HeavyAttacks/RightHook", "act/anim/P_Bif.act", "/Global/P_Bif"},
{"/Global/G_Melee_A/Offense/Short/Strikes/LightAttacks/RightHook/LeftHook/RightStomach", "act/anim/G_Melee_A.act", "/Global/G_Melee_A"},
{"/Global/G_Grappler_A/Offense/Short/Strikes/HeavyAttacks/RightHook/Uppercut", "act/anim/G_Grappler_A.act", "/Global/G_Grappler_A"},
{"/Global/G_Melee_A/Offense/Short/Strikes/HeavyAttacks", "act/anim/G_Melee_A.act", "/Global/G_Melee_A"}
}
local tableSize = table.getn(basicnodes)
local i = math.random(1,tableSize)
local node = basicnodes[i]
while true do
Wait(0)
if PedIsPlaying(gPlayer, "/Global/Player/Attacks/Strikes/LightAttacks", "act/anim/Player.act") and PedHasWeapon(gPlayer, -1) then
PedLockTarget(gPlayer, -1)
PedSetAITree(gPlayer, "/Global/DarbyAI", "Act/AI/AI_DARBY_2_B.act")
PedSetActionNode(gPlayer, node[1], node[2])
repeat
Wait(0)
until not PedIsPlaying(gPlayer, node[3], true)
PedSetAITree(gPlayer, "/Global/PlayerAI", "Act/PlayerAI.act")
end
end
end
But my player only does the regular jimmy punch and Sloppy kick (G_Melee_A).
Why is that happening??? I don't understand why it happens.
Anybody can help me?