News: Welcome back to Bullworth! If you haven't already, you will need to reset your password..


Author Topic: [Help] Why my mix fighting style script is not working properly?  (Read 874 times)

0 Members and 1 Guest are viewing this topic.

Offline feliiperh

  • Jr. Member
  • **
  • Posts: 13
    • View Profile
Hey guys!
I found a youtube tutorial of how to script a basic attack mod, and the code is the following:

Code: [Select]
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:

Code: [Select]
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?

Offline RBS ID

  • Jr. Member
  • **
  • Posts: 67
  • Gender: Male
  • I don't know.
    • View Profile
    • This is website title.
Re: [Help] Why my mix fighting style script is not working properly?
« Reply #1 on: August 01, 2022, 11:30:26 PM »
You need to randomize the  'i'  variable again everytime you want to play the animation.

if blabla then
  blablabla
  ii = math.random(table.getn(array))
  PlayAnim(array[ii][1], array[ii][2])
  blblabla
end
« Last Edit: August 01, 2022, 11:32:35 PM by RBS ID »

Offline feliiperh

  • Jr. Member
  • **
  • Posts: 13
    • View Profile
Re: [Help] Why my mix fighting style script is not working properly?
« Reply #2 on: August 02, 2022, 07:46:28 AM »
Thank you brother!
It works.
But Jimmy still doesn't do some nodes. I think it's because I need to change player act tree, cause I remember reading in daBOSS posts that he heard that some nodes are not able to be executed while player being in Player.act.
So I will have to test one by one to see, unless there's no need and the answer is already out there  :innocent:

Btw, your tutorials in your channel are awesome!
I have a question.
https://www.youtube.com/watch?v=0vcg8K3xGr0
To make those moves work you didn't have to change player AI or Act Tree, and the nodes still worked out without any problems, even tho some of them where boss nodes. Why is that?