Script activates event in front of actor for some reason

J_C

Veteran
Veteran
Joined
Jan 21, 2015
Messages
192
Reaction score
45
First Language
Hungarian
Primarily Uses
N/A
So, I've been using a HUD script, which shows three icons on the map screen as buttons. I can use them to open the Items menu, the Combine Items menu and there is a close button. It works like this: when I click on the button, it actives a common event, which has a scenemanager call in it (open item, combine item etc). The script does what it has to done, but it has a strange problem.

If I stand facing to an event, and I click a button (for opening the inventory for example), the script triggers the event in front of the character for whatever reason first before it executes the scenemanager.call.

I think the problem must be with the HUD script, because if I change the common event so it doesn't make a scenemanager.call, but instead just writes out a text, the button still launches the event in front of it, before writing out the text. I have no idea why does it do this.

This is the script:

#===============================================================================
# ** Mouse Hud **
#
# Author:   Evgenij
# Version:  1.0
# Date:     24.07.2014
#
# Required: SUPER SIMPLE MOUSE SCRIPT V. 1.10 by Shaz
#           http://forums.rpgmakerweb.com/index.php?/topic/17829-amaranths-super-simple-mouse-system-for-ace/
#
# Thanks To: Shaz for the Script
#            kevin25081998 for requesting this script
#
# My Terms of Use: http://evgenij-scripts.org/?page_id=34
#===============================================================================
#
# Description:
#
#  With this script you can make map icon commands which will call an common
#  event if you press it.
#  Look below at the examples to understand how it works.
#
#===============================================================================
module EVG
  module MouseHud
    #--------------------------------------------------------------------------
    Huds = { # Dont touch this line
    #--------------------------------------------------------------------------
    
      #------------------------------------------------------------------------
      :test1 => {
      
        pos_x:        Graphics.width - 2,
        pos_y:        Graphics.height - 72,
        icon:         261,
        hower_text:   "Open backpack",
        
        
        # take the right corner as reference for the x placing.
        # set this true if you want to place commands at the right site
        invert_x:     true,
        
        # Position of the hower text
        # :right or :left
        hower_pos:    :left,
        
        # Common Event which will be started when you press this Command
        ce_on_click:  19,
      },
      
      #------------------------------------------------------------------------
      :test2 => {
      
        pos_x:        Graphics.width - 0,
        pos_y:        Graphics.height - 48,
        icon:         245,
        hower_text:   "Combine items",
        
        
        # take the right corner as reference for the x placing.
        # set this true if you want to place commands at the right site
        invert_x:     true,
        
        # Position of the hower text
        # :right or :left
        hower_pos:    :left,
        
        # Common Event which will be started when you press this Command
        ce_on_click:  20,
      },
      
      #------------------------------------------------------------------------
      :test3 => {
      
        pos_x:        Graphics.width - 0,
        pos_y:        Graphics.height - 24,
        icon:         368,
        hower_text:   "Put item away",
        
        
        # take the right corner as reference for the x placing.
        # set this true if you want to place commands at the right site
        invert_x:     true,
        
        # Position of the hower text
        # :right or :left
        hower_pos:    :left,
        
        # Common Event which will be started when you press this Command
        ce_on_click:  21,
      },
    
      #------------------------------------------------------------------------
      
    #--------------------------------------------------------------------------
    } # Dont touch this line !
    #--------------------------------------------------------------------------
  end
end
#===============================================================================
class Spriteset_Map
  #--------------------------------------------------------------------------
  alias :evg_sm_cp_mhuds        :create_pictures
  #--------------------------------------------------------------------------
  def create_pictures
    evg_sm_cp_mhuds
    @mouse_huds = {}
    EVG::MouseHud::Huds.each do |sym, properties|
      @mouse_huds[sym] = HudSpriteMouse.new(properties, @viewport3)
    end
  end
  #--------------------------------------------------------------------------
  alias :evg_sm_up_mhuds        :update_pictures
  #--------------------------------------------------------------------------
  def update_pictures
    evg_sm_up_mhuds
    @mouse_huds.values.compact.each(&:update) if @mouse_huds
  end
  #--------------------------------------------------------------------------
end
#===============================================================================
class HudSpriteMouse < Sprite
  #--------------------------------------------------------------------------
  def initialize(command, viewport = nil)
    super(viewport)
    self.x = command[:pos_x]
    self.y = command[:pos_y]
    @icon_index = command[:icon]
    @hower_text = command[:hower_text]
    @common_event_id = command[:ce_on_click]
    @pos    = command[:hower_pos]
    @need_clean = true
    create_bitmap
    adjust_position if command[:invert_x]
    refresh
  end
  def adjust_position
    self.x -= self.bitmap.width
  end
  #--------------------------------------------------------------------------
  def create_bitmap
    self.bitmap = Bitmap.new(24, 24)
    width_plus = self.bitmap.text_size(@hower_text).width
    self.bitmap.dispose
    self.bitmap = Bitmap.new(24 + width_plus + 4, 24)
  end
  #--------------------------------------------------------------------------
  def refresh
    self.bitmap.clear
    draw_icon(@icon_index, icon_x, 0)
  end
  #--------------------------------------------------------------------------
  def update
    if mouse_hower?
      proccess_common_event if Mouse.trigger?(0)
      return if @need_clean
      $mouse.ignored = true
      refresh
      self.bitmap.draw_text(text_x, 0, self.bitmap.width - 26, 24, @hower_text)
      @need_clean = true
    elsif @need_clean
      $mouse.ignored = false
      refresh
      @need_clean = false
    end
  end
  #--------------------------------------------------------------------------
  def icon_x
    @pos == :right ? 0 : self.bitmap.width - 24
  end
  #--------------------------------------------------------------------------
  def text_x
    @pos == :right ? 26 : 0
  end
  #--------------------------------------------------------------------------
  def proccess_common_event
    $game_temp.reserve_common_event(@common_event_id)
  end
  #--------------------------------------------------------------------------
  def mouse_hower?
    return false if $game_message.visible
    (hower_x..(hower_x + 24)).include?(Mouse.pos[0]) &&
    (self.y..(self.y + 24)).include?(Mouse.pos[1])
  end
  #--------------------------------------------------------------------------
  def hower_x
    @pos == :right ? self.x : self.x + self.bitmap.width - 24
  end
  #--------------------------------------------------------------------------
  def draw_icon(icon_index, x, y)
    bitmap = Cache.system("Iconset")
    rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
    self.bitmap.blt(x, y, bitmap, rect)
  end
  #--------------------------------------------------------------------------
end
#===============================================================================
# SCRIPT END
#===============================================================================
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
32,526
Reaction score
8,150
First Language
German
Primarily Uses
RMMV
Please do not post the same thing multiple times in the wrong forums - the script forum is for presenting scripts you wrote.


I'm locking and deleting the other topic (which is also in a wrong forum)


I've moved this thread to Script Support. Please be sure to post your threads in the correct forum next time. Thank you.
 

J_C

Veteran
Veteran
Joined
Jan 21, 2015
Messages
192
Reaction score
45
First Language
Hungarian
Primarily Uses
N/A
Please do not post the same thing multiple times in the wrong forums - the script forum is for presenting scripts you wrote.

I'm locking and deleting the other topic (which is also in a wrong forum)

I've moved this thread to Script Support. Please be sure to post your threads in the correct forum next time. Thank you.
Sorry, will be more careful in the future.
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
42,165
Reaction score
14,655
First Language
English
Primarily Uses
RMMV
Can you show a screenshot of your hud?


And please don't post other people's scripts. Just provide a link to them, as that will give more information than the script alone (and the script will be formatted correctly as well).
 

J_C

Veteran
Veteran
Joined
Jan 21, 2015
Messages
192
Reaction score
45
First Language
Hungarian
Primarily Uses
N/A
Can you show a screenshot of your hud?

And please don't post other people's scripts. Just provide a link to them, as that will give more information than the script alone (and the script will be formatted correctly as well).
Sure. The first one is the common even which is called by one of the buttons. Nothing special really, just a scene call.

35l91g7.jpg


And here is my HUD in the game in the lower right corner:

2hdbg3d.jpg


And just to repeat myself, if my character stand facing an event, like on the picture, then if I press the backpack icon on the HUD, it would trigger the event (which is a monster in this case).
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
32,526
Reaction score
8,150
First Language
German
Primarily Uses
RMMV
Here's a tip: make your screenshots with [alt]-[prtscrn], that will limit them to the current window instead the entire desktop.


One other thing that I just thought of: Could it be that the key you're using as a trigger for the use item is also one of the keys that are assigned as action buttons?


If that is the case, there is no problem with the script itself but with the key assignments.


You can check the default key assignments with F1, but they are difficult to change in the engine - if there is a double assignment, it's easier to move the key or button for the use item.


Which key is that by the way? can you give us a screenshot where that has been set or checked?
 

J_C

Veteran
Veteran
Joined
Jan 21, 2015
Messages
192
Reaction score
45
First Language
Hungarian
Primarily Uses
N/A
Here's a tip: make your screenshots with [alt]-[prtscrn], that will limit them to the current window instead the entire desktop.

One other thing that I just thought of: Could it be that the key you're using as a trigger for the use item is also one of the keys that are assigned as action buttons?

If that is the case, there is no problem with the script itself but with the key assignments.

You can check the default key assignments with F1, but they are difficult to change in the engine - if there is a double assignment, it's easier to move the key or button for the use item.

Which key is that by the way? can you give us a screenshot where that has been set or checked?
Ah, you are probably right. I'm using Shaz' Super Simple Mouse script, so I'm not pushing a button, but clicking on the icon with the mouse. But on an engine level, clicking on the button is the same as pushing the action button (space or enter). So if I click with the mouse facing an event, this is like pressing space in front of the event. At least that's what I think.

There is a line in the mouse script which specifies which button is pressed if I click with the mouse:

Mouse_to_Input_Triggers = {0 => Input::C, 1 => Input::B, 2 => Input::A}

But if I change that (C for L for example), all I achieve is that the game doesn't recognise my click in the game.

Shaz told me that he will look at the HUD implementation when he has some time before. I guess I can't do anything else about this until then.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
32,526
Reaction score
8,150
First Language
German
Primarily Uses
RMMV
yes, button :C is the action button - but if the mousescript uses the same as interface with the engine, then a simple change of the buttons will not solve the problem.


You would need to identify the mouse position on click and redirect the signal only if the mouse is on one of the button-icons - and that isn't done by a simple line, it'll need a specific script change.
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
42,165
Reaction score
14,655
First Language
English
Primarily Uses
RMMV
The mouse script treats the mouse button like the action button/key, so yes, it will register the click as a space/enter press, and the default code will pick it up as interacting with the event.


Also, I'm not a guy ;)
 

J_C

Veteran
Veteran
Joined
Jan 21, 2015
Messages
192
Reaction score
45
First Language
Hungarian
Primarily Uses
N/A
The mouse script treats the mouse button like the action button/key, so yes, it will register the click as a space/enter press, and the default code will pick it up as interacting with the event.

Also, I'm not a guy ;)
Hehe, I knew I mess this up. I'm not kidding when I say that the time I wrote my previous post, I was thinking whether you are a he or a she. Of course I've chosen the wrong one. Sorry. :p
 
Last edited by a moderator:

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
42,165
Reaction score
14,655
First Language
English
Primarily Uses
RMMV
Actually, I know what's going on.

In the Game_Player class, find the move_by_input method. On the following lines (starting at 899 in the pastebin version):

Code:
      if !$game_message.busy? && !$game_message.visible && !@move_route_forcing &&        !@vehicle_getting_on && !@vehicle_getting_off &&        Mouse.trigger?(0) && !Mouse.grid.nil? && !$mouse.ignored?
add a check to make sure the mouse is not over the hud:
Code:
      if !$game_message.busy? && !$game_message.visible && !@move_route_forcing &&        !@vehicle_getting_on && !@vehicle_getting_off &&        Mouse.trigger?(0) && !Mouse.grid.nil? && !$mouse.ignored? && (Mouse.pos[0] < x || Mouse.pos[1] < y)
replace x and y in that added bit with the correct values to ignore clicks on the tiles containing the hud icons. So x will be whatever tile they're both on, and y will be the y coordinate of the top icon's tile.
 

J_C

Veteran
Veteran
Joined
Jan 21, 2015
Messages
192
Reaction score
45
First Language
Hungarian
Primarily Uses
N/A
Thanks, I will check it out.
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
42,165
Reaction score
14,655
First Language
English
Primarily Uses
RMMV
that's in the mouse script, not in the default Game_Player class.
 

J_C

Veteran
Veteran
Joined
Jan 21, 2015
Messages
192
Reaction score
45
First Language
Hungarian
Primarily Uses
N/A
that's in the mouse script, not in the default Game_Player class.

Well I did what you told me and it stopped recognising mouse movement in the specified area. So that part of the script works as it should. Unfortunately it didn't stop the events from activating when I face them and click on a button.
 
Last edited by a moderator:

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
42,165
Reaction score
14,655
First Language
English
Primarily Uses
RMMV
events always activate when you face them and press space or enter.  That is not the mouse script.  I'm not sure what the problem is - don't you WANT events to activate when you face them and press a button?
 

J_C

Veteran
Veteran
Joined
Jan 21, 2015
Messages
192
Reaction score
45
First Language
Hungarian
Primarily Uses
N/A
events always activate when you face them and press space or enter.  That is not the mouse script.  I'm not sure what the problem is - don't you WANT events to activate when you face them and press a button?

The way this works is that I have the mouse script, so I only use the mouse to contol the game. If I want to activate an event I click on it, whether or not my character is facing it. And it works as it should.


But since I also installed the HUD script, the events I'm facing activate even if I don't click on the event itself, just on the HUD buttons. The thing I wanted is that the click on a HUD button should not be recognised as a space or enter key push. The Hud button click and the event key (space-enter) press should be two seperate things, so the game doesn't confuse the two.
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
42,165
Reaction score
14,655
First Language
English
Primarily Uses
RMMV
I thought the bit of script I gave you should fix that?
 

J_C

Veteran
Veteran
Joined
Jan 21, 2015
Messages
192
Reaction score
45
First Language
Hungarian
Primarily Uses
N/A
I thought the bit of script I gave you should fix that?

Well your bit helped in a sense that I can set up an area around the HUD buttons which doesn't recognise the mouse clicks. I can even set half the screen if I want. BUT when I click on the HUD icons, it still recognises the action and triggers the event in front of my character.
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
42,165
Reaction score
14,655
First Language
English
Primarily Uses
RMMV
try this, in a new slot

Code:
class Game_Player < Game_Character
  alias mouse_check_action_event check_action_event
  def check_action_event
    result = (Mouse.pos[0] < x && Mouse.pos[1] < y) ? mouse_check_action_event : false
    return result
  end
end

Again, change the x and y in that result = line to the same values you set in the other snippet.
 
Last edited by a moderator:

J_C

Veteran
Veteran
Joined
Jan 21, 2015
Messages
192
Reaction score
45
First Language
Hungarian
Primarily Uses
N/A
try this, in a new slot

Code:
class Game_Player < Game_Character
  alias mouse_check_action_event check_action_event
  def check_action_event
    result = (Mouse.pos[0] < x && Mouse.pos[1] < y) ? mouse_check_action_event : false
    return result
  end
end

Again, change the x and y in that result = line to the same values you set in the other snippet.

Shaz, you are a genius. :D It works perfectly. Clicking on the HUD buttons only activate the specific HUD window, not the events on the map.


Thank you very, very much.
 
Last edited by a moderator:

Latest Threads

Latest Profile Posts

Two NPCs blinking animations in VNMaker and two to go. Some progress!
Fun Fact: My last two projects (Fursona and A Postmortem Nation) were released before I could do post-completion playtesting because I got so excited and happy I released them on the spot. Sometimes I have rubbish impulse control. smh
Circle, circle, dot, dot... I got my first COVID shot! And I barely felt it, which shocked me. Usually having Autism causes my sense of touch to be amplified! I go for my second dose in June.
Another update, this time on moving. I got the keys to my apartment today, but it was poorly cleaned/repaired. They're working on it, don't worry!
:kaojoy:I just saw 2 players reached 10 hours.
The game is totally not for cult recruitment. As of yet, we have not summoned Cthulhu.
Unfortunately, besides that, many issues still need to be fixed for more common fellows.
To at least pretend everything is normal here. :kaoswt2:

Forum statistics

Threads
111,308
Messages
1,060,084
Members
144,629
Latest member
petebooh
Top