Jump to content
New account registrations are disabed. This website is now an archive. Read more here.
  • 0
Izyees Fariz

trigger event by another key ?

Question

All of you know ? trigger ?

In rmxp only Action button, Player touch, Event touch, Autorun and parallel.

Is there anyway to make a key trigger like when the player pressing "S" on the event, then it will show message "Name = Amely, Age = 21" and when the player pressing "G" it will show text "Do you want to give flower to Amely ?" then when enter, it's time amely to say like "Hello, Nice to meet you !"

 

I do the player touch event then conditional branch, script 

Input.trigger?(Input::Key['S'])

but it not work. I don't know why ?

Share this post


Link to post
Share on other sites

4 answers to this question

Recommended Posts

  • 0

There's a lot of potential issues with that... So I'll start with the very top. Are you using the script that came with it? The regular key check is "Input.trigger?(Input::[key]), but that's limited to a select few keys. Cybersam made a script a while ago which allows for something similar to what you're after, and it's here:

 

http://www.gdunlimited.net/forums/topic/2079-rgsskey-input-script-by-cybersam/

 

The instructions to what you need to do is in there. From an eventing point of view, though... You're going to have a lot of issues. Player and event touch only occur when you connect for the first time with the event. So if you walk up to the event and then press the key, nothing will happen. Here's what I'd do;

 

Event Page 1: Parallel Process: No Switches:

page1-6762.png

 

Event Page 2: Parallel Process: Self-Switch A:

page2-6762.png

In the enter area, I forgot to turn off self-switch A after the text 'enter' appears. You can delete that text, but you'll need to add "self switch: A = off" to it.

 

There's a lot you could probably do to refine it, but it works properly in its current state. You'll obviously need to screw with where I've left comments on the second page. Also, the second page loops like that to eliminate the chance of missing a key input. I hope that helps.

Share this post


Link to post
Share on other sites
  • 0
Input.trigger?(Input::Key['S'])

but it not work. I don't know why ?

Because you can't reference a key directly in RGSS. You just have buttons A, B, C, X, Y, Z and keys are bound to them.

Share this post


Link to post
Share on other sites
  • 0

sorry, I use this module (This is on my core script http://www.gdunlimited.net/forums/topic/11139-simple-pause-system/) :

 

 

module Input
  Key = {'A' => 65, 'B' => 66, 'C' => 67, 'D' => 68, 'E' => 69, 'F' => 70, 
         'G' => 71, 'H' => 72, 'I' => 73, 'J' => 74, 'K' => 75, 'L' => 76, 
         'M' => 77, 'N' => 78, 'O' => 79, 'P' => 80, 'Q' => 81, 'R' => 82, 
         'S' => 83, 'T' => 84, 'U' => 85, 'V' => 86, 'W' => 87, 'X' => 88, 
         'Y' => 89, 'Z' => 90,
         '0' => 48, '1' => 49, '2' => 50, '3' => 51, '4' => 52, '5' => 53,
         '6' => 54, '7' => 55, '8' => 56, '9' => 57,
         'NumberPad 0' => 45, 'NumberPad 1' => 35, 'NumberPad 2' => 40,
         'NumberPad 3' => 34, 'NumberPad 4' => 37, 'NumberPad 5' => 12,
         'NumberPad 6' => 39, 'NumberPad 7' => 36, 'NumberPad 8' => 38,
         'NumberPad 9' => 33,
         'F1' => 112, 'F2' => 113, 'F3' => 114, 'F4' => 115, 'F5' => 116,
         'F6' => 117, 'F7' => 118, 'F8' => 119, 'F9' => 120, 'F10' => 121,
         'F11' => 122, 'F12' => 123,
         ';' => 186, '=' => 187, ',' => 188, '-' => 189, '.' => 190, '/' => 220,
         '\\' => 191, '\'' => 222, '[' => 219, ']' => 221, '`' => 192,
         'Backspace' => 8, 'Tab' => 9, 'Enter' => 13, 'Shift' => 16,
         'Left Shift' => 160, 'Right Shift' => 161, 'Left Ctrl' => 162,
         'Right Ctrl' => 163, 'Left Alt' => 164, 'Right Alt' => 165, 
         'Ctrl' => 17, 'Alt' => 18, 'Esc' => 27, 'Space' => 32, 'Page Up' => 33,
         'Page Down' => 34, 'End' => 35, 'Home' => 36, 'Insert' => 45,
         'Delete' => 46, 'Arrow Left' => 37, 'Arrow Up' => 38,
         'Arrow Right' => 39, 'Arrow Down' => 40,
         'Mouse Left' => 1, 'Mouse Right' => 2, 'Mouse Middle' => 4,
         'Mouse 4' => 5, 'Mouse 5' => 6}
  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']]
  ALL_KEYS = (0...256).to_a
  GetKeyboardState = Win32API.new('user32','GetKeyboardState', 'P', 'I')
  GetKeyboardLayout = Win32API.new('user32', 'GetKeyboardLayout','L', 'L')
  MapVirtualKeyEx = Win32API.new('user32', 'MapVirtualKeyEx', 'IIL', 'I')
  ToUnicodeEx = Win32API.new('user32', 'ToUnicodeEx', 'LLPPILL', 'L')
  DOWN_STATE_MASK = 0x80
  DEAD_KEY_MASK = 0x80000000
  @state = "\0" * 256
  @triggered = Array.new(256, false)
  @pressed = Array.new(256, false)
  @released = Array.new(256, false)
  @repeated = Array.new(256, 0)
  def self.update
    @language_layout = GetKeyboardLayout.call(0)
    GetKeyboardState.call(@state)
    ALL_KEYS.each {|key|
        if @state[key] & DOWN_STATE_MASK == DOWN_STATE_MASK
          @released[key] = false
          if !@pressed[key]
            @pressed[key] = true
            @triggered[key] = true
          else
            @triggered[key] = false
          end
          @repeated[key] < 17 ? @repeated[key] += 1 : @repeated[key] = 15
        elsif !@released[key]
          if @pressed[key]
            @triggered[key] = false
            @pressed[key] = false
            @repeated[key] = 0
            @released[key] = true
          end
        else
          @released[key] = false
        end}
  end
  def Input.dir4
    return 2 if Input.press?(DOWN)
    return 4 if Input.press?(LEFT)
    return 6 if Input.press?(RIGHT)
    return 8 if Input.press?(UP)
    return 0
  end
  def Input.dir8
    down = Input.press?(DOWN)
    left = Input.press?(LEFT)
    return 1 if down && left
    right = Input.press?(RIGHT)
    return 3 if down && right
    up = Input.press?(UP)
    return 7 if up && left
    return 9 if up && right
    return 2 if down
    return 4 if left
    return 6 if right
    return 8 if up
    return 0
  end
  def Input.trigger?(keys)
    keys = [keys] unless keys.is_a?(Array)
    return keys.any? {|key| @triggered[key]}
  end
  def Input.press?(keys)
    keys = [keys] unless keys.is_a?(Array)
    return keys.any? {|key| @pressed[key]}
  end
  def Input.repeat?(keys)
    keys = [keys] unless keys.is_a?(Array)
    return keys.any? {|key| @repeated[key] == 1 || @repeated[key] == 16}
  end
  def Input.release?(keys)
    keys = [keys] unless keys.is_a?(Array)
    return keys.any? {|key| @released[key]}
  end
  def self.get_character(vk)
    c = MapVirtualKeyEx.call(vk, 2, @language_layout)
    return '' if c < 32 && (c & DEAD_KEY_MASK != DEAD_KEY_MASK)
    vsc = MapVirtualKeyEx.call(vk, 0, @language_layout)
    result = "\0" * 2
    length = ToUnicodeEx.call(vk, vsc, @state, result, 2, 0, @language_layout)
    return (length == 0 ? '' : result)
  end
  def self.get_input_string
    result = ''
    ALL_KEYS.each {|key|
        if self.repeat?(key)
          c = self.get_character(key)
          result += c if c != ''
        end}
    return '' if result == ''
    return self.unicode_to_utf8(result)
  end
  def self.unicode_to_utf8(string)
    result = ''
    string.unpack('S*').each {|c|
        if c < 0x0080
          result += c.chr
        elsif c < 0x0800
          result += (0xC0 | (c >> 6)).chr
          result += (0x80 | (c & 0x3F)).chr
        else
          result += (0xE0 | (c >> 12)).chr
          result += (0x80 | ((c >> 12) & 0x3F)).chr
          result += (0x80 | (c & 0x3F)).chr
        end}
    return result
  end
  
end  

 

 

 

so the,

Input.trigger?(Input::Key['S'])

is not the problem.

Share this post


Link to post
Share on other sites
  • 0

sorry, I use this module (This is on my core script http://www.gdunlimited.net/forums/topic/11139-simple-pause-system/) :

 

 

module Input
  Key = {'A' => 65, 'B' => 66, 'C' => 67, 'D' => 68, 'E' => 69, 'F' => 70, 
         'G' => 71, 'H' => 72, 'I' => 73, 'J' => 74, 'K' => 75, 'L' => 76, 
         'M' => 77, 'N' => 78, 'O' => 79, 'P' => 80, 'Q' => 81, 'R' => 82, 
         'S' => 83, 'T' => 84, 'U' => 85, 'V' => 86, 'W' => 87, 'X' => 88, 
         'Y' => 89, 'Z' => 90,
         '0' => 48, '1' => 49, '2' => 50, '3' => 51, '4' => 52, '5' => 53,
         '6' => 54, '7' => 55, '8' => 56, '9' => 57,
         'NumberPad 0' => 45, 'NumberPad 1' => 35, 'NumberPad 2' => 40,
         'NumberPad 3' => 34, 'NumberPad 4' => 37, 'NumberPad 5' => 12,
         'NumberPad 6' => 39, 'NumberPad 7' => 36, 'NumberPad 8' => 38,
         'NumberPad 9' => 33,
         'F1' => 112, 'F2' => 113, 'F3' => 114, 'F4' => 115, 'F5' => 116,
         'F6' => 117, 'F7' => 118, 'F8' => 119, 'F9' => 120, 'F10' => 121,
         'F11' => 122, 'F12' => 123,
         ';' => 186, '=' => 187, ',' => 188, '-' => 189, '.' => 190, '/' => 220,
         '\\' => 191, '\'' => 222, '[' => 219, ']' => 221, '`' => 192,
         'Backspace' => 8, 'Tab' => 9, 'Enter' => 13, 'Shift' => 16,
         'Left Shift' => 160, 'Right Shift' => 161, 'Left Ctrl' => 162,
         'Right Ctrl' => 163, 'Left Alt' => 164, 'Right Alt' => 165, 
         'Ctrl' => 17, 'Alt' => 18, 'Esc' => 27, 'Space' => 32, 'Page Up' => 33,
         'Page Down' => 34, 'End' => 35, 'Home' => 36, 'Insert' => 45,
         'Delete' => 46, 'Arrow Left' => 37, 'Arrow Up' => 38,
         'Arrow Right' => 39, 'Arrow Down' => 40,
         'Mouse Left' => 1, 'Mouse Right' => 2, 'Mouse Middle' => 4,
         'Mouse 4' => 5, 'Mouse 5' => 6}
  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']]
  ALL_KEYS = (0...256).to_a
  GetKeyboardState = Win32API.new('user32','GetKeyboardState', 'P', 'I')
  GetKeyboardLayout = Win32API.new('user32', 'GetKeyboardLayout','L', 'L')
  MapVirtualKeyEx = Win32API.new('user32', 'MapVirtualKeyEx', 'IIL', 'I')
  ToUnicodeEx = Win32API.new('user32', 'ToUnicodeEx', 'LLPPILL', 'L')
  DOWN_STATE_MASK = 0x80
  DEAD_KEY_MASK = 0x80000000
  @state = "\0" * 256
  @triggered = Array.new(256, false)
  @pressed = Array.new(256, false)
  @released = Array.new(256, false)
  @repeated = Array.new(256, 0)
  def self.update
    @language_layout = GetKeyboardLayout.call(0)
    GetKeyboardState.call(@state)
    ALL_KEYS.each {|key|
        if @state[key] & DOWN_STATE_MASK == DOWN_STATE_MASK
          @released[key] = false
          if !@pressed[key]
            @pressed[key] = true
            @triggered[key] = true
          else
            @triggered[key] = false
          end
          @repeated[key] < 17 ? @repeated[key] += 1 : @repeated[key] = 15
        elsif !@released[key]
          if @pressed[key]
            @triggered[key] = false
            @pressed[key] = false
            @repeated[key] = 0
            @released[key] = true
          end
        else
          @released[key] = false
        end}
  end
  def Input.dir4
    return 2 if Input.press?(DOWN)
    return 4 if Input.press?(LEFT)
    return 6 if Input.press?(RIGHT)
    return 8 if Input.press?(UP)
    return 0
  end
  def Input.dir8
    down = Input.press?(DOWN)
    left = Input.press?(LEFT)
    return 1 if down && left
    right = Input.press?(RIGHT)
    return 3 if down && right
    up = Input.press?(UP)
    return 7 if up && left
    return 9 if up && right
    return 2 if down
    return 4 if left
    return 6 if right
    return 8 if up
    return 0
  end
  def Input.trigger?(keys)
    keys = [keys] unless keys.is_a?(Array)
    return keys.any? {|key| @triggered[key]}
  end
  def Input.press?(keys)
    keys = [keys] unless keys.is_a?(Array)
    return keys.any? {|key| @pressed[key]}
  end
  def Input.repeat?(keys)
    keys = [keys] unless keys.is_a?(Array)
    return keys.any? {|key| @repeated[key] == 1 || @repeated[key] == 16}
  end
  def Input.release?(keys)
    keys = [keys] unless keys.is_a?(Array)
    return keys.any? {|key| @released[key]}
  end
  def self.get_character(vk)
    c = MapVirtualKeyEx.call(vk, 2, @language_layout)
    return '' if c < 32 && (c & DEAD_KEY_MASK != DEAD_KEY_MASK)
    vsc = MapVirtualKeyEx.call(vk, 0, @language_layout)
    result = "\0" * 2
    length = ToUnicodeEx.call(vk, vsc, @state, result, 2, 0, @language_layout)
    return (length == 0 ? '' : result)
  end
  def self.get_input_string
    result = ''
    ALL_KEYS.each {|key|
        if self.repeat?(key)
          c = self.get_character(key)
          result += c if c != ''
        end}
    return '' if result == ''
    return self.unicode_to_utf8(result)
  end
  def self.unicode_to_utf8(string)
    result = ''
    string.unpack('S*').each {|c|
        if c < 0x0080
          result += c.chr
        elsif c < 0x0800
          result += (0xC0 | (c >> 6)).chr
          result += (0x80 | (c & 0x3F)).chr
        else
          result += (0xE0 | (c >> 12)).chr
          result += (0x80 | ((c >> 12) & 0x3F)).chr
          result += (0x80 | (c & 0x3F)).chr
        end}
    return result
  end
  
end  

 

 

 

so the,

Input.trigger?(Input::Key['S'])

is not the problem.

 

I haven't tested the script, but, if you aren't getting a syntax error, no, it wouldn't be the problem. You see, action button only runs the event if you're pressing enter. Even if you put eventing in to check for keys, those events only run when you press enter.

 

Player touch and event touch also only occur as soon as the player and the event touch, and then doesn't run again. What the eventing I did earlier does is check whether the player is beside the event (so the equivalent of player touch, but runs constantly when the player is beside the event), and then checks for the key press.

 

http://www.gdunlimited.net/media/uploads/manager/event-key-press-6762.zip

 

Here's the project with the event on it so you don't have to re-create what I did earlier. You can swap the script to your own version and modify the event to your liking, but that's basically the foundation of it.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...