I made this script for mouse support, but it acts funny.
It lets the user click npcs to activate them, and that's about it.
I thought it would allow menu use, but the mouse freezes when a menu is opened.
It also seems to activate an npc when nothing is under the mouse.
I would like it if right click closed any open textboxes, or something like that.
init mouse
variable(mouse)
IF(mouse==false)THEN(mouse:=create rect (3,3,-1))
WHILE(mouse==true)
DO(
wait,put slice (mouse, mouse pixel x, mouse pixel y)
IF(mouse click (left button)==true)
THEN
(use NPC (NPC at pixel (mouse pixel x, mouse pixel y, 0))))
IF(mouse click (left button)==true)
THEN
(use menu item(menu item at pixel(mouse pixel x, mouse pixel y)))
IF(mouse click (right button)==true)
THEN(
advance text box
close menu(top menu)
)
Mouse scripting
Moderators: marionline, SDHawk
- SwordPlay
- Chemical Slime
- Posts: 966
- Joined: Sun Jan 22, 2017 9:32 am
- Location: London, England
- Contact:
Mouse scripting
"Imagination. Life is your creation."
NPC at pixel returns 0 (false) if there's no NPC, but 0 is also a valid NPC ID, so you need to check for that.
And you want to avoid passing invalid arguments to script commands anyway, as that will result in error messages if errors are enabled.
Also, you need to check for an NPC at (camera pixel x + mouse pixel x, camera pixel y + mouse pixel y) not (mouse pixel x, mouse pixel y). Adding the camera position turns screen coordinates into map coordinates.
And you want to avoid passing invalid arguments to script commands anyway, as that will result in error messages if errors are enabled.
Also, you need to check for an NPC at (camera pixel x + mouse pixel x, camera pixel y + mouse pixel y) not (mouse pixel x, mouse pixel y). Adding the camera position turns screen coordinates into map coordinates.
Code: Select all
init mouse
variable(mouse)
IF(mouse==false)THEN(mouse:=create rect (3,3,-1))
WHILE(mouse==true)
DO(
wait
put slice (mouse, mouse pixel x, mouse pixel y)
IF(mouse click (left button)==true)
THEN (
variable(which)
which := NPC at pixel (camera pixel x + mouse pixel x, camera pixel y + mouse pixel y, 0)
IF(which) THEN (use NPC (which))
ELSE (
which := menu item at pixel(mouse pixel x, mouse pixel y)
IF(which) THEN (use menu item(which))
)
)
IF(mouse click (right button)==true)
THEN(
IF(current textbox) THEN (advance text box)
IF(top menu) THEN (close menu(top menu))
)
Last edited by TMC on Fri Apr 14, 2017 8:36 pm, edited 2 times in total.