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


Author Topic: Help bully lua  (Read 3194 times)

0 Members and 1 Guest are viewing this topic.

Offline bullymodder74

  • Jr. Member
  • **
  • Posts: 51
  • Gender: Male
  • Bully Mods
    • View Profile
Help bully lua
« on: September 02, 2015, 03:06:34 PM »
 :( ayudaa script lua
scriptname.lua:25: "end" expected )to close "if" at line 9) near  (eof)"



ImportScript("Library/LibTable.lua")
ImportScript("Library/LibTrigger.lua")
ImportScript("Library/LibSchool.lua")
ImportScript("SGlFunc.lua")
ImportScript("SZone.lua")
local l_0_0 = false

 if IsButtonPressed(10,0) and IsMoving() and not isStrafing and not PedIsValid(PedGetGrappleTargetPed(gPlayer)) then
    PedSetActionNode(gPlayer,"/Global/P_Striker_A/Default_KEY/ExecuteNodes/LocomotionOverride/Combat/CombatBasic","Act/Anim/P_Striker_A.act")
 isStrafing = true
  elseif (not IsButtonPressed(10,0) or not IsMoving()) and isStrafing and not PedIsValid(PedGetGrappleTargetPed(gPlayer)) then
 PedSetActionTree(gPlayer,"/Global/P_Striker_A", "")
 isStrafing = false
  elseif isStrafing then
 local x,y,z = PedGetPosXYZ(PedGetTargetPed())
 PedFaceXYZ(gPlayer,x,y,z)

IsMoving = function()
  local s = 0.08
  return GetStickValue(16,0) > s or GetStickValue(16,0) < -s or GetStickValue(17,0) > s or GetStickValue(17,0) < -s
end

Offline bullymodder74

  • Jr. Member
  • **
  • Posts: 51
  • Gender: Male
  • Bully Mods
    • View Profile
Re: Help bully lua
« Reply #1 on: September 02, 2015, 03:50:20 PM »
:( ayudaa script lua
scriptname.lua:25: "end" expected )to close "if" at line 9) near  (eof)"



ImportScript("Library/LibTable.lua")
ImportScript("Library/LibTrigger.lua")
ImportScript("Library/LibSchool.lua")
ImportScript("SGlFunc.lua")
ImportScript("SZone.lua")
local l_0_0 = false

 if IsButtonPressed(10,0) and IsMoving() and not isStrafing and not PedIsValid(PedGetGrappleTargetPed(gPlayer)) then
    PedSetActionNode(gPlayer,"/Global/P_Striker_A/Default_KEY/ExecuteNodes/LocomotionOverride/Combat/CombatBasic","Act/Anim/P_Striker_A.act")
 isStrafing = true
  elseif (not IsButtonPressed(10,0) or not IsMoving()) and isStrafing and not PedIsValid(PedGetGrappleTargetPed(gPlayer)) then
 PedSetActionTree(gPlayer,"/Global/P_Striker_A", "")
 isStrafing = false
  elseif isStrafing then
 local x,y,z = PedGetPosXYZ(PedGetTargetPed())
 PedFaceXYZ(gPlayer,x,y,z)

IsMoving = function()
  local s = 0.08
  return GetStickValue(16,0) > s or GetStickValue(16,0) < -s or GetStickValue(17,0) > s or GetStickValue(17,0) < -s
end
please help me

Offline Shrimp

  • Sr. Member
  • ***
  • Posts: 514
  • Gender: Male
  • your official b-b's chav. wag wan.
    • View Profile
Re: Help bully lua
« Reply #2 on: September 02, 2015, 03:57:18 PM »
You're just demanding help instantly and showing it by commenting that you need help after 40 minutes, be patience, geez.

Offline DaBOSS54320

  • Hero Member
  • ****
  • Posts: 3,398
  • Gender: Female
    • View Profile
Re: Help bully lua
« Reply #3 on: September 02, 2015, 04:49:50 PM »
That post was very helpful of you Shrimp, the board appreciates it.



ImportScript("Library/LibTable.lua")
ImportScript("Library/LibTrigger.lua")
ImportScript("Library/LibSchool.lua")
ImportScript("SGlFunc.lua")
ImportScript("SZone.lua")
local l_0_0 = false

if IsButtonPressed(10,0) and IsMoving() and not isStrafing and not PedIsValid(PedGetGrappleTargetPed(gPlayer)) then
    PedSetActionNode(gPlayer,"/Global/P_Striker_A/Default_KEY/ExecuteNodes/LocomotionOverride/Combat/CombatBasic","Act/Anim/P_Striker_A.act")
 isStrafing = true
  elseif (not IsButtonPressed(10,0) or not IsMoving()) and isStrafing and not PedIsValid(PedGetGrappleTargetPed(gPlayer)) then
 PedSetActionTree(gPlayer,"/Global/P_Striker_A", "")
 isStrafing = false
  elseif isStrafing then
 local x,y,z = PedGetPosXYZ(PedGetTargetPed())
 PedFaceXYZ(gPlayer,x,y,z)

IsMoving = function()
  local s = 0.08
  return GetStickValue(16,0) > s or GetStickValue(16,0) < -s or GetStickValue(17,0) > s or GetStickValue(17,0) < -s
end



The if statement you started (highlighted in yellow) doesn't have an end, you probably meant to have one right after PedFaceXYZ(gPlayer,x,y,z). If you fix that you should be able to compile the script but it still won't work how you probably want it to. See what a script will do when it runs is it will first read through the entire script and run all code that is outside of any functions, then Bully will call a few functions in your script depending on what kind of script it is. If it's a mission script (like ArcRace1.lur) then the function MissionSetup will be called first, then after that main, then when the script terminates MissionCleanup. If it's STimeCycle.lur Bully will only call the main function at first. There is also other scripts in STimeCycle.lur that Bully will call which you can find a template of STimeCycle.lur with all those needed functions here. If Bully doesn't call a function and you don't either, then that function won't run until it is called.

So with all that in mind... basically your script will run one single time and it'll check one single time if this evaluates to true: IsButtonPressed(10,0) and IsMoving() and not isStrafing and not PedIsValid(PedGetGrappleTargetPed(gPlayer)). If it does then all the code between the then and end belonging to that then will run, just once. After that the script will end. So what should you do? You should make it so it checks if that if statement is true more than just one single time, perhaps once every frame. So how to do that? Well we'll need something called loops (there is a link to a detailed tutorial about how they work and also some stuff on the if statement). Basically what you need to know is a loop will run a certain bit of code repeatedly while a certain condition is met. Here's an example:

while true do
  -- code here
end

The true, similar to the if statement, is what will tell it that it is meant to run the code between do and end. If it was [i[false[/i] the code would not run, not even once. What is different about this loop though compared to an if statement, is that while that condition between while and do evaluates to true, the code in between do and end will keep running, repeatedly, until it does not evaluate to true anymore. You can put variables and function calls and other things there instead of just true or false too, just like with the if statement. But since we want our script to just keep running and running we can just use true so it never stops. Remember our goal: to check if that if statement evaluates to true each frame and if so, run that strafe code you have there. So here's how we'll do that.

Code: [Select]
while true do
  if IsButtonPressed(10,0) and IsMoving() and not isStrafing and not PedIsValid(PedGetGrappleTargetPed(gPlayer)) then
    PedSetActionNode(gPlayer,"/Global/P_Striker_A/Default_KEY/ExecuteNodes/LocomotionOverride/Combat/CombatBasic","Act/Anim/P_Striker_A.act")
    isStrafing = true
  elseif (not IsButtonPressed(10,0) or not IsMoving()) and isStrafing and not PedIsValid(PedGetGrappleTargetPed(gPlayer)) then
    PedSetActionTree(gPlayer,"/Global/P_Striker_A", "")
    isStrafing = false
  elseif isStrafing then
    local x,y,z = PedGetPosXYZ(PedGetTargetPed())
    PedFaceXYZ(gPlayer,x,y,z)
  end
  Wait(0)
end

Notice I also added a call to a function called Wait. This function basically makes the script wait for a certain amount of time (specified in milliseconds). While our script is waiting, Bully will be able to run other scripts and also run the game itself. If our script never waits the game will be frozen until our script ends or we do finally wait. Since we put 0 though the script only waits for 1 frame, which is perfect because that is exactly what we wanted. Now thanks to the while loo we created, the script will repeatedly check if that if statement is true, and if so run the strafe code there, and then after that wait 1 frame so the rest of the game can run giving the player another chance to press the button needed and lock onto a target (since that is what the if statement there requires him to do).

However our script isn't just ready yet... if we're replacing ArcRace1.lur with this script (which I suggest you do instead of any other script right now because it's probably the easiest) then we need to move the player somewhere out of the dorm. For some reason when you don't do this in ArcRace1.lur the game will crash... so basically we'll need to call the function AreaTransitionXYZ (provided by Bully we don't need to make it ourselves) to move the player somewhere else, and we should do this before the while loop runs. On top of that the script and game will crash because we don't have a MissionSetup or main function which Bully expects ArcRace1.lur to have. So to fix this we'll have to make those 2 functions. In MissionSetup since that runs first, we'll call our AreaTransitionXYZ that we need to move the player somewhere else. Then in main we'll put our while loop. The script now becomes this:

Code: [Select]
ImportScript("Library/LibTable.lua")
ImportScript("Library/LibTrigger.lua")
ImportScript("Library/LibSchool.lua")
ImportScript("SGlFunc.lua")
ImportScript("SZone.lua")
local l_0_0 = false

MissionSetup = function()
  AreaTransitionXYZ(0,270,-110,6)
end

main = function()
  while true do
    if IsButtonPressed(10,0) and IsMoving() and not isStrafing and not PedIsValid(PedGetGrappleTargetPed(gPlayer)) then
      PedSetActionNode(gPlayer,"/Global/P_Striker_A/Default_KEY/ExecuteNodes/LocomotionOverride/Combat/CombatBasic","Act/Anim/P_Striker_A.act")
      isStrafing = true
    elseif (not IsButtonPressed(10,0) or not IsMoving()) and isStrafing and not PedIsValid(PedGetGrappleTargetPed(gPlayer)) then
      PedSetActionTree(gPlayer,"/Global/P_Striker_A", "")
      isStrafing = false
    elseif isStrafing then
      local x,y,z = PedGetPosXYZ(PedGetTargetPed())
      PedFaceXYZ(gPlayer,x,y,z)
    end
    Wait(0)
  end
end

IsMoving = function()
  local s = 0.08
  return GetStickValue(16,0) > s or GetStickValue(16,0) < -s or GetStickValue(17,0) > s or GetStickValue(17,0) < -s
end

One last thing... this little snippet of code you have at the top:
  ImportScript("Library/LibTable.lua")
  ImportScript("Library/LibTrigger.lua")
  ImportScript("Library/LibSchool.lua")
  ImportScript("SGlFunc.lua")
  ImportScript("SZone.lua")
  local l_0_0 = false
This isn't needed, none of those library scripts are used in our script and that variable l_0_0 you made is not used or needed either. So we can just remove all of that from the top of the script, it's optional though... but there really is no good reason to keep them either.



So there you have it, good luck and happy modding.



Edit: One more thing and this is important... don't know how I missed it but I guess I did.
PedSetActionTree(gPlayer,"/Global/P_Striker_A", "") | This, this code will not work because you did not specify an action file. Use this instead: PedSetActionTree(gPlayer,"/Global/P_Striker_A", "Act/Anim/P_Striker_A.act")

Also if you're using a different action tree (fighting style) you should probably load the animation groups for it. Loading "Boxing" and "P_Striker" should work. You can load them in MissionSetup. So now the final script becomes this:

Code: [Select]
MissionSetup = function()
  AreaTransitionXYZ(0,270,-110,6)
  LoadAnimationGroup("Boxing")
  LoadAnimationGroup("P_Striker")
end

main = function()
  while true do
    if IsButtonPressed(10,0) and IsMoving() and not isStrafing and not PedIsValid(PedGetGrappleTargetPed(gPlayer)) then
      PedSetActionNode(gPlayer,"/Global/P_Striker_A/Default_KEY/ExecuteNodes/LocomotionOverride/Combat/CombatBasic","Act/Anim/P_Striker_A.act")
      isStrafing = true
    elseif (not IsButtonPressed(10,0) or not IsMoving()) and isStrafing and not PedIsValid(PedGetGrappleTargetPed(gPlayer)) then
      PedSetActionTree(gPlayer,"/Global/P_Striker_A", "Act/Anim/P_Striker_A.act")
      isStrafing = false
    elseif isStrafing then
      local x,y,z = PedGetPosXYZ(PedGetTargetPed())
      PedFaceXYZ(gPlayer,x,y,z)
    end
    Wait(0)
  end
end

IsMoving = function()
  local s = 0.08
  return GetStickValue(16,0) > s or GetStickValue(16,0) < -s or GetStickValue(17,0) > s or GetStickValue(17,0) < -s
end
« Last Edit: September 02, 2015, 04:54:59 PM by DaBOSS54320 »

Offline bullymodder74

  • Jr. Member
  • **
  • Posts: 51
  • Gender: Male
  • Bully Mods
    • View Profile
Re: Help bully lua
« Reply #4 on: September 02, 2015, 04:56:56 PM »
Thanks Dabbos

Offline Unknownsoldier

  • Hero Member
  • ****
  • Posts: 2,773
    • View Profile
Re: Help bully lua
« Reply #5 on: September 02, 2015, 05:09:08 PM »
That post was very helpful of you Shrimp, the board appreciates it.
looooooool

( ͡° ͜ʖ ͡°)

Offline Shrimp

  • Sr. Member
  • ***
  • Posts: 514
  • Gender: Male
  • your official b-b's chav. wag wan.
    • View Profile
Re: Help bully lua
« Reply #6 on: September 02, 2015, 05:40:02 PM »
That post was very helpful of you Shrimp, the board appreciates it.

Maybe if you weren't shitting on what I said you'd realize I was being helpful :^)
Also, you've done it before, am sure I'm not the only one friend :)

Offline Unknownsoldier

  • Hero Member
  • ****
  • Posts: 2,773
    • View Profile
Re: Help bully lua
« Reply #7 on: September 03, 2015, 05:29:32 PM »
Also, you've done it before, am sure I'm not the only one friend :)