Jump to content
Jet

Mouse System

Recommended Posts

Mouse System


by Jet



Introduction

Yes that's right, another iteration of my mouse. This time around I coded my own pathfinding (which does not freeze up like the previous one) and i completely recoded almost everything. It's highly optimized and works much better than any previous version. It has removed the scrolling with mouse wheel, but added a developers block.

This is add a fully functioning mouse into your game. This can allow the character to move and interact with just a click and navigate menus with ease.

Features

- Quick, flexible pathfinding, via A*
- Many configuration options
- Even more compatible with custom systems with a recoded base
- Just a click to do mostly anything
- And more...

Screenshots

1.png
2.png
3.png



Script

http://pastebin.com/raw.php?i=3KPTNr7z

 

 


Credit

Jet

Note

I have a license, it's in my signature. Use in commercial games, PM me and I'll lay out my very simple terms.

Share this post


Link to post
Share on other sites

It lags pretty bad with pixel movement. I am using victor saint's pixel movement. Any plans on adding compatibility for it?

 

No, doing the pathfinding with the pixel movement script would not only be a huge pain, but would probably lag anyways.

Share this post


Link to post
Share on other sites

No, doing the pathfinding with the pixel movement script would not only be a huge pain, but would probably lag anyways.

 

Right, I understand A* is expensive with pixel movement. I was trying to see if it was possible to make the pathfinding behave like a destination that is unaffected regardless of the movement factor.

Edited by Helladen

Share this post


Link to post
Share on other sites

It stills doesn't work with your SBS, I can't select a specific enemy :(

Sheesh you people are ungrateful. Not everything is going to work with each and every script in the universe. Just take the script by itself as a stand-alone feature and critique on THAT, not something else that "doesn't work" with it. Even if it has compatibility errors with crap, just the script alone, by itself, is worthy of recommendation.

Share this post


Link to post
Share on other sites

When I go to playtest after installing this script I get the following error message:

 

Script "line 488: NoMethodError occured

undefined method '[]' for nil:NilClass

 

The only alteration I have made is to line 101 TURN_MOUSE_OFF_SWITCH = 99 where I have changed the switch number to 199 as switch 99 is already in use; but as I get the error message whether I've changed that line or not, I assume it has nothing to do with that.

 

What do I do?  I am a complete noob at scripting, so would need a full explanation.

 

Thanks

Share this post


Link to post
Share on other sites

NICE SCRIPT!!! this script ALMOST works perfectly with my EST - PHONE MENU ENGINE !!!!.

it will never be IPhone without touch screen function. it will just become some cheap phone.

 

the only problem is that the code inside

def cursor_left

def cursor_right

def cursor_up

def cursor_down

not executing

 

but i manage to do attach that code to update_mouse. also make it update only when index changes.

 

EDIT: I found a BUG in the mouse script....

how to replicate the bug.

1) create event that call save scene

2) create event that script call: SceneManager.call(Scene_Load)

 

start new game (just to ensure)

talk to event 1. save the game to any slot.

immediately talk to event 2. load to that save you made earlier.

Now the MOUSE PathFinding is ERROR. it will NOT go where you clicked. the bug not happening if you load the game from title. so i assuming that we need some code to reset the mouse / player position when loading a game.

 

above bugs ALSO happen when doing this:

1) start new game

2) save

3) select go to title screen either from menu or from event command.

4) load the game.

or

1) start new game

2) save

3) press f12

4) load the game

 

so i think this bug really need to be fixed. some temporary solution might using code from f12 bugfix from acezone.

which create new player instead of using current one.

 

i modify the go to title code to use the code from acezone f12 bugfix instead normal code...

but that don't solve the problem with loading in game... also it will close the player and then open new one which kinda awkward.

Edited by estriole

Share this post


Link to post
Share on other sites

@nordic: I don't quite get what you want to achieve. without comment the event already will activate when your player is next to the event. If you want it activated where the player position don't bother.... You can use comment mouse click. Or if you want it activated only when player entering certain range(ex: player 3 tiles away from event). You can use event sensor range from moghunter. Make the page before entering the range which don't activated when mouse clicked. But when entering the range. Switch to page where can be activated using mouse click.

 

@jet: btw found another bug. If we place an autorun event at [0,0] position of the map. Then we put the player next to it. Then when the autorun event execute. Click anywhere. The player will board vehicle.

 

I already made fixes to all bugs I mentioned. Also made some adjustment to prevent lag when clicking the unpassable terrain. But it won't pathfind either.

 

I will share the fixes later. Since I'm currently outside of town. writing to this forum using my phone :P.

Share this post


Link to post
Share on other sites

temporary bugfix for this mouse script:
 (until jet fix it officially). put this script below jet mouse script.

 

# fix clicking unpassable place will lag.
class Game_CharacterBase
  def mouse_path(target_x, target_y, did_dir = false)
    return if !check_mouse_passable?(target_x,target_y) || !Jet::MouseSystem::CHECK_FOR_MOVES
    return if target_x == self.x && target_y == self.y
    f = $game_map.find_path(target_x.to_i, target_y.to_i, @x.to_i, @y.to_i, self)
    if f.empty? && !did_dir && Jet::MouseSystem::CHECK_FOR_MOVES
      [[0, 1], [0, -1], [1, 0], [-1, 0]].each {|a|
        next if !f.empty?
        f = $game_map.find_path(target_x.to_i + a[0], target_y.to_i + a[1],
          @x.to_i, @y.to_i, self)
      }
    end
    $game_temp.mouse_path = f
  end
  def check_mouse_passable?(target_x,target_y)
      chk = false
      4.times {|i|
        i += 1
        chk = true if passable?(target_x,target_y, i * 2)
      }
      return chk
  end
end

# fix some bugs standing next autorun event that position at (0,0)
# fix entering vehicle when it shouldn't
class Scene_Map < Scene_Base
  def check_mouse_movement
    $game_temp.mouse_character ||= $game_player
    if Mouse.click?(1)
      dont_move = false
      x, y = *Mouse.true_grid_by_pos
      evs = $game_map.events_xy(x, y)
      (evs + $game_map.vehicles).each {|event|
        if event.is_a?(Game_Vehicle)
           if (event.x - mouse_char.x).abs + (event.y - mouse_char.y).abs == 1 && (event.x - x).abs + (event.y - y).abs == 0 && !event.transparent
            mouse_char.turn_toward_character(event)
            mouse_char.get_on_vehicle_mouse(event)
            dont_move = true
          end
        elsif !!!mouse_char.vehicle
          if event.mouse_activated?
            event.start
            dont_move = true
          elsif (event.x - mouse_char.x).abs + (event.y - mouse_char.y).abs == 1
            if !event.mouse_empty? && [0, 1, 2].include?(event.trigger)
              mouse_char.turn_toward_character(event)
              event.start
              dont_move = true
            end
          else
            {UP: [0, -1], DOWN: [0, 1], LEFT: [-1, 0], RIGHT: [1, 0]}.each {|d, a|
              if event.check_for_comment(/MOUSE[ ]*MOVE[ ]*#{d.to_s}/i)
                x += a[0]; y += a[1]
                did_dir = true
              end
            }
          end
        end
      } if $game_system.mouse_movement
      if $game_system.mouse_movement
        mouse_char.mouse_path(x, y, did_dir ||= false) unless dont_move
      else
        evs.each {|event|
          if event.mouse_activated?
            event.start
          end
        }
      end
    end
  end #end check mouse movement
end #end scene_map


# fix f12/return to title then load bugs.
module Mouse
  def self.reinit
    @keys = []
    @press = []
    @pos = Mouse.pos
    @cursor = Sprite_Cursor.new if @cursor && @cursor.disposed?
  end  
end

class Scene_Title < Scene_Base
  alias est_jet_mouse_patch_post_start post_start
  def post_start
    est_jet_mouse_patch_post_start
    Mouse.reinit
  end
end

 

hope this help.

Share this post


Link to post
Share on other sites

Thanks for making this great script. I have a question.

 

I want to create a (common) event that waits for the player to click anywhere on the screen and then returns the map (x,y) to a couple variables.

 

i.e.

 

I have a fog of war script and want to make a 'Sight' spell. When the spell is used, they get to click one spot on the map. Then, the script $game_map.clear_fog(x,y,radius) runs

 

How would I go about this?

Share this post


Link to post
Share on other sites

Hmmm create common event

Set it parallel process. Give switch as activation if necessary.

In the event

Condional branch:script:

Mouse.click?(1)

 

Inside the branch.

Script call the code to reveal the fog. You can get mouse x value using

Mouse.true_grid[0]

And mouse y value using

Mouse.true_grid[1]

It will return the coordinate on the map.

 

Then switch off the switch earlier.

Hope this help.

Edited by estriole

Share this post


Link to post
Share on other sites

how to disable completely ? by the script, there are option to disable mouse by switch, apparently , it only hidden the cursor, but still can click and many more. 

 

For your information, i make my intro a narrating event, where words and words coming out. so i am afraid of this problems that the player may skip it by clicking many times ( this will spoil the good mood of the game) please, Jet and estriole, help me .

Share this post


Link to post
Share on other sites

Hi,

 

I found a different version of this mouse system in this pastebin, through Google: http://pastebin.com/raw.php?i=Eycj4swG

 

Is this more recent than the one in this thread, or less recent?

 

Both have problems. The code in this thread (first post) shows a square for selecting a tile, which is between two tiles. The code in the above pastebin doesn't run (syntax error, although I'm not sure why).

Edited by ashes999

Share this post


Link to post
Share on other sites

Okay, so this seems like the latest version based on the comments.

 

I "fixed" the outline by changing line #335 from:

 

@outline.x = Mouse.grid[0] * 32

 

to:

 

@outline.x = (Mouse.grid[0] * 32) - 16

 

I would like to know if this is really the right fix. I couldn't figure out where you're getting the mouse x/y positioning from.

Share this post


Link to post
Share on other sites

After testing further, it seems like not only is my fix wrong, but the drawing of the outline doesn't take into account the current view coordinates -- the more you move around, the more it goes out of synch. I'm pretty sure it just needs to account for this.

 

Jet, if you're reading this, I wonder if you have any comments.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×