Better Controls

Discussion in 'RGSS Script Requests' started by Andrea87Sky, Aug 24, 2019.

  1. Andrea87Sky

    Andrea87Sky Just a random musician/coder. Veteran

    Messages:
    81
    Likes Received:
    1
    Location:
    Sicily
    First Language:
    Italian
    Primarily Uses:
    RMXP
    So umh, I recently tried to edit the game controls by doing the F1 options, but it sadly didn't work how I wanted, I wanted to do for example the select action (that normally is C/ENTER) to be instead only on the Z and Enter button, but it don't work in any way in Z, I tried many times with different systems, but it still don't work. So.. I'm thinking if it's possible to make better controls, making the game to ignore completely the F1 controls. Sorry if I'm not so clear. Maybe it's just me that i'm stupid and I don't understand how F1 controls works.

    Anyway I wanted to make the controls like this:

    Select: Enter, Z
    Cancel: X
    Menu: C, CTRL.
    (RESOLVED)

    Another question: it's possible to make the game understand when your holding a specific button and when not with the system of tons of addons? the game standard game can only detect if you pressed a button, but not if you're pressing it and if not.

    Because I wanna do a system that make a picture appear with the text "Quitting" and instantly close the game when you're pressing the esc button for 2 seconds, and when you release it before the two second it just don't do nothing and make fade the picture.
     
    Last edited: Aug 25, 2019
    #1
  2. bgillisp

    bgillisp Global Moderators Global Mod

    Messages:
    12,304
    Likes Received:
    12,517
    Location:
    USA
    First Language:
    English
    Primarily Uses:
    RMVXA
    F1 is hardwired into the .dll that the engine uses, and as such, is nearly impossible to overwrite due to it using the hidden classes of the engine which no scripter can access. If you don't want F1 to be an option you'll probably have to use MV instead.
     
    #2
  3. KK20

    KK20 Just some XP Scripter Veteran

    Messages:
    101
    Likes Received:
    41
    Location:
    Orange County, California
    First Language:
    English
    Primarily Uses:
    RMXP
    You don't want to mess with the F1 controls because that's global for every user (i.e. the controls set in one game will carry over to another game). You're looking for a script that allows full keyboard access and hard-coding the various Input buttons to a key.

    Blizzard's Tons of Add-ons has a script in it that does just that called Custom Game Controls (it's in Part 2 of the scripts).
    https://forum.chaos-project.com/index.php/topic,105.0.html
    You'll see a configuration section within:
    Code:
    #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    # START Configuration
    #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
      UP = [Key['Arrow Up']]
      LEFT = [Key['Arrow Left']]
      DOWN = [Key['Arrow Down']]
      RIGHT = [Key['Arrow Right']]
      A = [Key['Shift']]
      B = [Key['Esc'], Key['NumberPad 0'], Key['X']]
      C = [Key['Space'], Key['Enter'], Key['C']]
      X = [Key['A']]
      Y = [Key['S']]
      Z = [Key['D']]
      L = [Key['Q'], Key['Page Down']]
      R = [Key['W'], Key['Page Up']]
      F5 = [Key['F5']]
      F6 = [Key['F6']]
      F7 = [Key['F7']]
      F8 = [Key['F8']]
      F9 = [Key['F9']]
      SHIFT = [Key['Shift']]
      CTRL = [Key['Ctrl']]
      ALT = [Key['Alt']]
    
    For Select and Delete (do you mean Cancel?), that would be
    Code:
    B = [Key['X']]
    C = [Key['Z'], Key['Enter']]
    
    I'm not sure what your Menu is since that's normally opened with Input::B.
     
    #3
    bblizzard likes this.
  4. Andrea87Sky

    Andrea87Sky Just a random musician/coder. Veteran

    Messages:
    81
    Likes Received:
    1
    Location:
    Sicily
    First Language:
    Italian
    Primarily Uses:
    RMXP
    Umh, the standard rpg maker xp's menu that you open with esc? Anyway I don't know if Tons Of Addons scripts are compatible with my other scripts, but thanks.

    A question: Is possible to reset then the F1 controls? 'cause I messed with them and I wanna them to return to the standard controls.
     
    #4
  5. Andrea87Sky

    Andrea87Sky Just a random musician/coder. Veteran

    Messages:
    81
    Likes Received:
    1
    Location:
    Sicily
    First Language:
    Italian
    Primarily Uses:
    RMXP
    Nevermind I resetted them, but I tried to do what you did but the controls Z and X still don't wanna work
     
    #5
  6. KK20

    KK20 Just some XP Scripter Veteran

    Messages:
    101
    Likes Received:
    41
    Location:
    Orange County, California
    First Language:
    English
    Primarily Uses:
    RMXP
    Okay so that would be the same as the Cancel/Delete button then. So just add Key['Esc'] to Input::B.

    Did you insert all three scripts? Did you put them in your project correctly? Did you enable the script (in Part 2, there's a list of CONSTANTS set equal to false. You need to enable the script by setting the one for custom controls to true.)

    Please read the instructions
     
    #6
  7. Andrea87Sky

    Andrea87Sky Just a random musician/coder. Veteran

    Messages:
    81
    Likes Received:
    1
    Location:
    Sicily
    First Language:
    Italian
    Primarily Uses:
    RMXP
    It's all right, except I didn't know I had to enable it xd I just followed ur instructions. Anyway I enabled it and now it works, thanks!
     
    #7
  8. Andrea87Sky

    Andrea87Sky Just a random musician/coder. Veteran

    Messages:
    81
    Likes Received:
    1
    Location:
    Sicily
    First Language:
    Italian
    Primarily Uses:
    RMXP
    Another question: it's possible to make the game understand when your holding a specific button and when not with the system of tons of addons? the game standard game can only detect if you pressed a button, but not if you're pressing it and if not.

    Because I wanna do a system that make a picture appear with the text "Quitting" and instantly close the game when you're pressing the esc button for 2 seconds, and when you release it before the two second it just don't do nothing and make fade the picture.
     
    #8
  9. KK20

    KK20 Just some XP Scripter Veteran

    Messages:
    101
    Likes Received:
    41
    Location:
    Orange County, California
    First Language:
    English
    Primarily Uses:
    RMXP
    Parallel Process Common Event, assuming 40FPS game:
    Code:
    Conditional Branch: Script: Input.press?(Input::Key['Esc'])
      Show Picture #or whatever you use to show it, maybe throw in another conditional branch for ExitTimer equaling 0
      Control Variables: [ExitTimer] += 1
      Conditional Branch: Variable[ExitTimer] == 80
        Script: exit
      Branch End
    Else
      Erase Picture #or whatever you use to remove it
      Control Variables: [ExitTimer] = 0
    Branch End
    
     
    #9
  10. Andrea87Sky

    Andrea87Sky Just a random musician/coder. Veteran

    Messages:
    81
    Likes Received:
    1
    Location:
    Sicily
    First Language:
    Italian
    Primarily Uses:
    RMXP
    The game says there's a syntax error on "Input.press?(Input::Key['Esc'])", idk why. Anyway the weird thing is that I tried to put from the tons of add-ons Esc as Y, I tried with the conditional branch to put the button Y, but it don't work.
     
    #10
  11. KK20

    KK20 Just some XP Scripter Veteran

    Messages:
    101
    Likes Received:
    41
    Location:
    Orange County, California
    First Language:
    English
    Primarily Uses:
    RMXP
    It's fine on my end. You need to share more details as to what you did, like a screenshot.

    That's a kind-of bug with the script actually. You should only try to use the script-call method since you're working with the full keyboard now.
    Code:
    Input.press?(Input::Y)
    EDIT:
    Nevertheless, here's a fix for it. Place this below the Tons of Add-ons in your script list.
    Code:
    module Input
      def self.int_to_button(n)
        case n
        when 2 then DOWN
        when 4 then LEFT
        when 6 then RIGHT
        when 8 then UP
        when 11 then A
        when 12 then B
        when 13 then C
        when 14 then X
        when 15 then Y
        when 16 then Z
        when 17 then L
        when 18 then R
        when 21 then SHIFT
        when 22 then CTRL
        when 23 then ALT
        when 25 then F5
        when 26 then F6
        when 27 then F7
        when 28 then F8
        when 29 then F9
        end
      end
     
      def self.press?(keys)
        keys = Input.int_to_button(keys) if keys.is_a?(Integer)
        keys = [keys] unless keys.is_a?(Array)
        return keys.any? {|key| @pressed[key]}
      end
    end
    
     
    Last edited: Aug 26, 2019
    #11
  12. Andrea87Sky

    Andrea87Sky Just a random musician/coder. Veteran

    Messages:
    81
    Likes Received:
    1
    Location:
    Sicily
    First Language:
    Italian
    Primarily Uses:
    RMXP
    Here's a screen of what I did. (And anyway yes, I know that I forgot to add a wait of 5 frames for the picture fade in "else", ignore it xd.)
     

    Attached Files:

    #12
  13. KK20

    KK20 Just some XP Scripter Veteran

    Messages:
    101
    Likes Received:
    41
    Location:
    Orange County, California
    First Language:
    English
    Primarily Uses:
    RMXP
    Other than forgetting to reset EscTimer back to 0, I don't see anything wrong with the event list. However, I'd think you'd want to move this to a Common Event and not a map event.

    So you're sure that the error pop-up specifically says "SyntaxError occurred while running script"? Try putting this rewrite of Main above your current Main:
    Code:
    def traceback_report
      backtrace = $!.backtrace.clone
      backtrace.each{ |bt|
        bt.sub!(/Section(\d+)/) {"[#{$1}]#{$RGSS_SCRIPTS[$1.to_i][1]}"}
      }
      return $!.message + "\n\n" + backtrace.join("\n")
    end
    
    def raise_traceback_error
      File.open('traceback.log', 'w') { |f| f.write($!) }
      raise 'SyntaxError occurred. Created file traceback.log'
    end
    
    begin
      # Prepare for transition
      Graphics.freeze
      # Make scene object (title screen)
      $scene = Scene_Title.new
      # Call main method as long as $scene is effective
      while $scene != nil
        $scene.main
      end
      # Fade out
      Graphics.transition(20)
    rescue SyntaxError
      $!.message.sub!($!.message, traceback_report)
      raise_traceback_error
    rescue Errno::ENOENT
      # Supplement Errno::ENOENT exception
      # If unable to open file, display message and end
      filename = $!.message.sub("No such file or directory - ", "")
      print("Unable to find file #{filename}.")
    end
    
    It will output a LOG file in your game directory. Share its results back here.
     
    #13
  14. Andrea87Sky

    Andrea87Sky Just a random musician/coder. Veteran

    Messages:
    81
    Likes Received:
    1
    Location:
    Sicily
    First Language:
    Italian
    Primarily Uses:
    RMXP
    What do you mean? I already put EscTimer back to zero on "else". I did everything you told me to do.

    For the log thing, I have already a log system, but that's not important anymore because i don't have the syntax error anymore, idk why.

    Anyway it works but the image don't show.
     
    #14
  15. KK20

    KK20 Just some XP Scripter Veteran

    Messages:
    101
    Likes Received:
    41
    Location:
    Orange County, California
    First Language:
    English
    Primarily Uses:
    RMXP
    Your screenshot says otherwise. I see LettersExtTimer being set to 0, not EscTimer.
    Does the game still close after a few seconds?
    If so, make sure your picture event is properly set up. You have to figure that one on your own.
    If not, your parallel process is not running obviously.
     
    #15
  16. Andrea87Sky

    Andrea87Sky Just a random musician/coder. Veteran

    Messages:
    81
    Likes Received:
    1
    Location:
    Sicily
    First Language:
    Italian
    Primarily Uses:
    RMXP
    Wait you're right, why the hell I made another variable for? My bad I didn't noticed it, anyway yes the game still close after a few seconds but the image shows only like on 1 opacity only, can you tell me how to fix it please?
     
    #16
  17. KK20

    KK20 Just some XP Scripter Veteran

    Messages:
    101
    Likes Received:
    41
    Location:
    Orange County, California
    First Language:
    English
    Primarily Uses:
    RMXP
    Going back to my post with how to setup the event:
    Code:
    Show Picture #or whatever you use to show it, maybe throw in another conditional branch for ExitTimer equaling 0
    
    In your current event, you're showing the picture EVERY FRAME the button is being held down; you're constantly resetting its opacity back to 0. This is what I meant by throwing in another conditional branch. You only want to show/move the picture once.

    While we're at it, you should remove the Erase Picture command since the fade-out effect will not be noticeable--it'll just instantly disappear.
     
    #17

Share This Page