• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

Easy mouse functionality for Essentials

Luka S.J.

Jealous Croatian
1,270
Posts
15
Years
  • Easy Mouse System

    Notice: Please ignore this thread if you have no coding experience or knowledge. In such cases, this script will be of no use to you. I will not spend my time answering basic coding questions/problems.

    I am not too sure how everybody feels about this anymore, but back in the day, when I used to be more active, there was a lot of fuss about adding mouse usability into Essentials. Over the years there have been many scripts which implement the mouse, but for my taste they were unnecessarily complicated. I'm not sure how many of you know this, but Essentials does have a module for the mouse. The only thing it lacks is interpretations of this module.

    Personally I feel, if you're developing a game for the PC, why deprive it of the biggest input device on said platform. The mouse is used in virtually all PC games, as it is an essential input device - much like an Xbox controller is for the Xbox. Some people will disagree with me on this, but both as a developer and a gamer - the mouse adds to a game. So without further ado, here is the code.

    Download Script from here

    Read documentation here

    So I hope most of you find this useful. I've tried to make it as user friendly as possible, and as functional as possible. If any of you come up with other ideas, other features/functionalities for the mouse, just leave a comment in the thread, and I'll see what I can do about it. I'd just like to ask you to please give credit when using the code.
     
    Last edited:
    423
    Posts
    13
    Years
    • Seen Aug 31, 2023
    looks intresting i'll have a go with this
    thank you

    Edit

    keep getting the following errors:
    undefined method 'over?' for nil:NilClass
    undefined method 'leftClick?' for nil:NilClass
    undefined method 'rightClick?' for nil:NilClass
    when using
    $mouse.over?(object)
    $mouse.leftClick?(object)
    $mouse.rightClick?(object)

    Code:
    @button1=Sprite.new
    @button1.x = 10# Change the # to the value of the displayed graphic's verticle appearance
    @button1.y = 390# Change the # to the value of the displayed graphic's horizontal appearance
    @button1.z = 100 # This sets the priority of the button over other graphics
    @button1.bitmap = RPG::Cache.picture("MenuHGSS2dex") # defines the graphic
    if $mouse.leftClick?(@button1)
    if Input.triggerex?(Input::Mouse_Left)
                pbFadeOutIn(99999) {
                   scene=PokemonPokedexScene.new
                   screen=PokemonPokedex.new(scene)
                   screen.pbStartScreen
                   @scene.pbRefresh
                }
              end
              end
     
    Last edited:
    41
    Posts
    10
    Years
  • You can send a template for leftclick(script base) Im noob in script, more if you send a Exemple I can make a menu for me. thanks
    ps: I test playdon script and no work
     

    Luka S.J.

    Jealous Croatian
    1,270
    Posts
    15
    Years
  • looks intresting i'll have a go with this
    thank you

    Edit

    keep getting the following errors:
    undefined method 'over?' for nil:NilClass

    Now to make use of the mouse, you need to do two things: initialize the mouse, and update the mouse. Initialization is easy, you have to declare a global variable and assign Game_Mouse.new to it. The best place to do this would be in the Main script, right before the whole begin block, and just declare it as
    Code:
      [B]$mouse = Game_Mouse.new[/B]

    I really don't want to be answering questions like that, as they are already answered here. You have clearly not declared your $mouse variable as stated in the instructions, which is why it is a nil value. And nil values do not have class functions. Had you defined it as
    Code:
      $something_else = Game_Mouse.new
    Then you would have used $something_else.over? This is coding basics. You should not be using any parts of this script if you do not know how to assign classes to variables, and use their functions. Also, you do not use both
    Code:
    if $mouse.leftClick?(@button1)
    if Input.triggerex?(Input::Mouse_Left)
    The reason it's called leftClick? is because it checks whether or not the object is being left-clicked (as stated in the opening post). If you want to use a left-mouse button trigger check, you use .leftTrigger?(object), also stated in the opening post.

    You can send a template for leftclick(script base) Im noob in script, more if you send a Exemple I can make a menu for me. thanks
    ps: I test playdon script and no work

    Same as the above, this is coding basics. If you don't know what to do in scripts, this script is not for you. All this script does (as stated in the opening post) is allowing you to interface with the Mouse module, in a simple manner. A sample code would be (once you initialized your mouse, and defined it as $mouse)
    Code:
    if $mouse.leftClick?(whateveryouwanttoclick)
      dosomethinghere
    end
     
    Last edited:

    Worldslayer608

    ಥдಥ
    894
    Posts
    16
    Years
  • Wow, I just saw this Luka! Sweet, thanks for the share. I am not sure if a mouse input is what I am looking for in Pillars, but this is still handy for anyone who wants it and pretty overdue for a decent one if I may say so.

    I remember the fuss about the mouse was also with the dual screen addition, which is primarily what you see with the scripts that have mouse input. Definitely nice to see one without the dual screen.
     
    41
    Posts
    10
    Years
  • @Buton01["Buton01"] = Sprite.new
    @Buton01["Buton01"].bitmap=BitmapCache.load_bitmap("Graphics/Pictures/buton01")
    @Buton01["Buton01"].x=459
    @Buton01["Buton01"].y=1
    @Buton01["Buton01"].z=0
    if $mouse.leftClick?(Buton01)
    scene=PokemonOptionScene.new
    screen=PokemonOption.new(scene)
    pbFadeOutIn(99999) {
    screen.pbStartScreen
    pbUpdateSceneMap
    @scene.pbRefresh
    }
    end


    what I did wrong?
    error
    Message: undefined method `[]=' for nil:NilClass
    HUD:83:in `createHud'
    HUD:36:in `initialize'
    Scene_Map:29:in `new'
    Scene_Map:29:in `createSpritesets'
    Scene_Map:28:in `each'
    Scene_Map:28:in `createSpritesets'
    Scene_Map:63:in `main'
    Main:38:in `mainFunctionDebug'
    Main:16:in `mainFunction'
    Main:16:in `pbCriticalCode'
     

    Luka S.J.

    Jealous Croatian
    1,270
    Posts
    15
    Years
  • what I did wrong?

    There is so much wrong with that, and none of it has to do with my script. You really should learn the fundamentals of coding, of Ruby before you can do anything else. Your first mistake was the way you declare variables. You obviously don't know what you're doing, and just tried copying some other code. I'm not going to go step by step through what you did wrong. Here is an amended version of what you wrote, and look at the stuff I've fixed and figure out where you went wrong:
    Code:
    @sprites = {}
    @sprites["button01"] = Sprite.new
    @sprites["button01"].bitmap=BitmapCache.load_bitmap("Graphics/Pictures/button01") 
    @sprites["button01"].x=459 
    @sprites["button01"].y=1
    @sprites["button01"].z=0
    Then there is your whole mouse usage. You need to use the $mouse functions in an update loop. There is no point in using mouse checks right after the initialization of the actual sprites, as the player will not start to trigger the sprites before they can actually see the sprite. In your code, where you have the Graphics.update and Input.update, in some loop, this is where you use the
    Code:
    if $mouse.leftClick?(@sprites["button01"])
    My mouse system, will not help you if you're a complete beginner at coding. There is no point in trying to use this without having proper knowledge of the structure of codes, and the types of objects you use (and how to properly declare them). I will not be giving you any assistance on how to code, as it is not the point of this thread.

    For everyone else: this is not the place to ask such questions. I will be ignoring any further posts/comments like this. Unless it is constructive critique or bug reporting (for this particular script), please do not post here. Find the appropriate thread, or forum for that.
     

    Luka S.J.

    Jealous Croatian
    1,270
    Posts
    15
    Years
  • Easy mouse functionality for Essentials
    I decided to overhaul the script a bit, to make it more compatible with other things. The mouse now accepts pretty much any and all objects (where it only used to be sprites before). You can now use the mouse.over? methods with
    • Sprites
    • Viewports
    • Rects
    • Windows
    and possibly a few other things as well. Another thing is that the individual checks for object or area triggers do not separately check whether or not the mouse is in a certain rectangle.

    But probably the most exciting part is the new .overPixel? method. This checks for the individual pixels of a sprite's bitmap, which essentially means that you can have triangular or circular buttons for your menu, and that the mouse will only return true it it's over a non transparent pixel of the bitmap.

    I have updated the first post, and also have a link to the script on my site.

    [S-HIGHLIGHT][The system is now fully plug-n-play][/S-HIGHLIGHT]
     
    Last edited:

    Luka S.J.

    Jealous Croatian
    1,270
    Posts
    15
    Years
  • I have revamped much of the Mouse system. Functions such as $mouse.leftClick? can omit their object parameters to only check whether a certain mouse button is being clicked. I've also added support for those of you that want to use custom cursor sprites (see the script itself). I've also cleaned and tweaked some portions of the script to work better. It's definitely an improvement over the previous iteration, so make sure you get it (if you are already using it).
     
    1,224
    Posts
    10
    Years
  • I'd recommend doing something like this to accommodate for objects using src_rects, since currently over? and similar methods will return true if you are over a portion outside or the src_rect

    Code:
    def getObjectParams(object)
        params=[0,0,0,0]
        if object.is_a?(Sprite)
          params[0]=(object.x)
          params[1]=(object.y)
          if defined?(object.viewport) && object.viewport
            params[0]+=object.viewport.rect.x
            params[1]+=object.viewport.rect.y
          end
          params[2]=(object.bitmap.width*object.zoom_x) if object.bitmap
          params[3]=(object.bitmap.height*object.zoom_y) if object.bitmap
         [COLOR=Red] if object.respond_to?(:src_rect)
            params[2]=(object.src_rect.width*object.zoom_x) if object.bitmap
            params[3]=(object.src_rect.height*object.zoom_y) if object.bitmap
          end[/COLOR]
        elsif object.is_a?(Viewport)
          params=[object.rect.x,object.rect.y,object.rect.width,object.rect.height]
        else
          params[0]=(object.x) if object.x
          params[1]=(object.y) if object.y
          if defined?(object.viewport) && object.viewport
            params[0]+=object.viewport.rect.x
            params[1]+=object.viewport.rect.y
          end
          params[2]=(object.width) if object.width
          params[3]=(object.height) if object.height
        end
        return params
      end
     

    Starlight Minun

    LoveEletric
    21
    Posts
    9
    Years
    • Seen Jul 15, 2016
    i have done everything working well but just a one question. what index is mouse left click?
    example
    when Input:C
    return (xx,xx,xx)
     

    Luka S.J.

    Jealous Croatian
    1,270
    Posts
    15
    Years
  • i have done everything working well but just a one question. what index is mouse left click?
    example
    when Input:C
    return (xx,xx,xx)
    $mouse.leftClick?(object)
    This checks if you've left-clicked the specified object. The method checks for Input triggers, meaning that it will not register continuous key holding. If you want to check if the mouse is pressing an object, use $mouse.leftPress?(object). The object parameter can be omitted if you just want to check whether or not the left mouse button is being clicked alone.
     
    Last edited:
    1,224
    Posts
    10
    Years
  • Wanted to point out a slight mistake in the check for rightClick?
    Code:
    def rightClick?(object=nil,width=-1,height=-1)
        if object.nil?
          return Input.triggerex?(Input::[COLOR="Red"]Mouse_Left[/COLOR])
        else
          return (self.over?(object,width,height) && Input.triggerex?(Input::Mouse_Right))
        end
      end
    Red part should say Mouse_Right
     

    FoxySeta

    (Trainer)
    11
    Posts
    9
    Years
  • Hi all! I hope noone asked this, but... I use the screen border option, so the mouse is not calibrate. Wich line(s) should I edit to fix this?
     

    Luka S.J.

    Jealous Croatian
    1,270
    Posts
    15
    Years
  • Hi all! I hope noone asked this, but... I use the screen border option, so the mouse is not calibrate. Wich line(s) should I edit to fix this?

    You can try changing lines 52 and 53 to
    Code:
          @x = @position[0] - $ResizeOffsetX
          @y = @position[1] - $ResizeOffsetY
    but to be completely honest, I don't really know. And since the latest version of Essentials doesn't utilize borders, I don't know how to properly use or test them out.
     
    Last edited:

    FoxySeta

    (Trainer)
    11
    Posts
    9
    Years
  • You can try changing lines 52 and 53 to
    Code:
          @x = @position[0] - $ResizeOffsetX
          @y = @position[1] - $ResizeOffsetY
    but to be completely honest, I don't really know. And since the latest version of Essentials doesn't utilize borders, I don't know how to properly use or test them out.
    TU! I'll test when I clear some glitch/bug.
     

    Luka S.J.

    Jealous Croatian
    1,270
    Posts
    15
    Years
  • Update!

    Overhauled and tidied up the script a fair bit, but also added new features:
    • Mouse scrolling is now in the script. Requires RPG.Net.dll
    • Smart detecting for dragging vs clicking. Disables leftClicks when you're dragging the mouse.
    • New method for dragging objects
    • New method to check if the mouse is being dragged
     
    Last edited:
    Back
    Top