Guest User

Nexie's Single Block Hammer On Controller

a guest
Oct 10th, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.72 KB | None | 0 0
  1. # THIS SCRIPT SHOULD BE USED WITH FREEPIE
  2. # http://andersmalmgren.github.io/FreePIE/
  3. #--------------------------------------------------------------------------------------
  4. # CONTROLLER-CONFIG:
  5. #--------------------------------------------------------------------------------------
  6. # Unfortunately, when plugging Xbox/Playstation/Wii Guitar Hero Controllers into your
  7. # PC, chances are, that they don't really behave as they should.
  8. # To make it work with this script, some configuring needed.
  9. # The default config is for a GH X-plorer
  10. # (the one they sold for Xbox/PC with Guitar Hero [4] World Tour)
  11. # with no other controller plugged in.
  12. # So if you got one of those you're in luck.
  13. #
  14. # Let's go: Assuming you successfully installed the controller
  15. # (3rd party software may be needed), you need to get an overview.
  16. # Type "joy.cpl" in the Windows search bar and press enter to open your game controller
  17. # control panel.
  18. # If you have multiple controllers, you need to count down the list from the top
  19. # (1,2,3..) and use the number the GH controller is placed at in
  20. # "JoystickNumber = X"
  21. #
  22. # Go into the "properties", press your controller buttons and note which number is
  23. # flashing for each fret button.
  24. # If you're unlucky, from green to orange, this wont be 1,2,3,4,5 but 2,4,5,3,1 etc.
  25. # Enter the exact consecutive green to orange numbering you oberserved in
  26. # "Button1_Green = X" to "Button5_Orange = Z"
  27. #
  28. # At last we need to configure the strum bar.
  29. # Technically this is implemented as a "POV-hat". If it's not on your Controller
  30. # (and some axis is used instead) unfortunatelly you need to rewrite the
  31. # "joystick[x].pov[y] parts of the script and adept it for an axis but you can use
  32. # the same principle.
  33. #
  34. # The script needs the default (not pressed) value of the POV-hat to differenciate it
  35. # from the non-default value when it's pressed.
  36. # Start the script and observe the "Watch" tab.
  37. # Write the value you get when not pressing the bar into "DefaultBarValue = X".
  38. #
  39. # That's it! You configured your GH controller for this script!
  40. #------------------------------------------------------------------------------------
  41. JoystickNumber = 1
  42.  
  43. Button1_Green = 1
  44. Button2_Red = 2
  45. Button3_Yellow = 4
  46. Button4_Blue = 3
  47. Button5_Orange = 5
  48.  
  49. DefaultBarValue = -1
  50.  
  51. # !!!script code starts from here!!!
  52. #---------------
  53. # POV-Diagnostics
  54. #---------------
  55. diagnostics.watch(joystick[0].pov[0])
  56.  
  57. if starting:
  58. #------------------------------------------------
  59. # config-value-transformation
  60. #------------------------------------------------
  61.     j = JoystickNumber - 1
  62.     b1 = Button1_Green - 1
  63.     b2 = Button2_Red - 1
  64.     b3 = Button3_Yellow - 1
  65.     b4 = Button4_Blue - 1
  66.     b5 = Button5_Orange -1
  67.     p = DefaultBarValue
  68. #-------------------------------------------------
  69. # declare some cycle-persisting variables at start:
  70. #-------------------------------------------------
  71.     BarIsPressed = 0
  72.     ButtonIsPressed=[0,0,0,0,0]
  73.     LastHOPOButton = 5
  74. # If LastHOPOButton equals 5, no button has been pressed in a HOPO-mode Session
  75.  
  76. #----------------------------------------------------------------------
  77. # check for not pressed, pressed and recently pressed stuff
  78. #----------------------------------------------------------------------
  79. #check for not pressed buttons
  80. if joystick[j].getDown(b1) == 0:
  81.     ButtonIsPressed[0] = 0
  82. if joystick[j].getDown(b2) == 0:
  83.     ButtonIsPressed[1] = 0
  84. if joystick[j].getDown(b3) == 0:
  85.     ButtonIsPressed[2] = 0
  86. if joystick[j].getDown(b4) == 0:
  87.     ButtonIsPressed[3] = 0
  88. if joystick[j].getDown(b5) == 0:
  89.     ButtonIsPressed[4] = 0
  90.    
  91. #ButtonJustDown variable
  92. ButtonJustDown=[0,0,0,0,0]
  93.  
  94. #check for currently pressed and possibly just pressed buttons
  95. if joystick[j].getDown(b1):
  96.     if ButtonIsPressed[0] == 0:
  97.         ButtonJustDown[0] = 1
  98.     ButtonIsPressed[0] = 1
  99. if joystick[j].getDown(b2):
  100.     if ButtonIsPressed[1] == 0:
  101.         ButtonJustDown[1] = 1
  102.     ButtonIsPressed[1] = 1
  103. if joystick[j].getDown(b3):
  104.     if ButtonIsPressed[2] == 0:
  105.         ButtonJustDown[2] = 1
  106.     ButtonIsPressed[2] = 1
  107. if joystick[j].getDown(b4):
  108.     if ButtonIsPressed[3] == 0:
  109.         ButtonJustDown[3] = 1
  110.     ButtonIsPressed[3] = 1
  111. if joystick[j].getDown(b5):
  112.     if ButtonIsPressed[4] == 0:
  113.         ButtonJustDown[4] = 1
  114.     ButtonIsPressed[4] = 1
  115.    
  116. # check for not pressed strum bar and reset HOPO Session if true
  117. if joystick[j].pov[0] == p:
  118.     BarIsPressed = 0
  119.     LastHOPOButton = 5
  120.  
  121. #----------------------------------------------------------------------------------
  122. # HOPO-mode: If the strum bar is pressed, check if a hammered button is different to
  123. # the last one and, if true, do the thing
  124. # No repeated same button Hammer-Ons allowed in this script, because of TRVENESS
  125. # (unless you press 1-5 Number Keys :-D)!
  126. #----------------------------------------------------------------------------------
  127. elif ButtonJustDown[4] and LastHOPOButton != 4:
  128.     keyboard.setPressed(Key.D5)
  129.     LastHOPOButton = 4
  130. elif ButtonJustDown[3] and LastHOPOButton != 3:
  131.     keyboard.setPressed(Key.D4)
  132.     LastHOPOButton = 3
  133. elif ButtonJustDown[2] and LastHOPOButton != 2:
  134.     keyboard.setPressed(Key.D3)
  135.     LastHOPOButton = 2
  136. elif ButtonJustDown[1] and LastHOPOButton != 1:
  137.     keyboard.setPressed(Key.D2)
  138.     LastHOPOButton = 1
  139. elif ButtonJustDown[0] and LastHOPOButton != 0:
  140.     keyboard.setPressed(Key.D1)
  141.     LastHOPOButton = 0
  142.  
  143. #-------------------------------------------
  144. # button handover in case of actual strumming
  145. #-------------------------------------------
  146. if BarIsPressed == 0 and joystick[j].pov[0] != p:
  147.     BarIsPressed = 1
  148.     if ButtonIsPressed[4]:
  149.         keyboard.setPressed(Key.D5)
  150.     elif ButtonIsPressed[3]:
  151.         keyboard.setPressed(Key.D4)
  152.     elif ButtonIsPressed[2]:
  153.         keyboard.setPressed(Key.D3)
  154.     elif ButtonIsPressed[1]:
  155.         keyboard.setPressed(Key.D2)
  156.     elif ButtonIsPressed[0]:
  157.         keyboard.setPressed(Key.D1)
Advertisement
Add Comment
Please, Sign In to add comment