Click.lua

From Moondust Wiki
Jump to navigation Jump to search

Download click.lua

A small library for the cursor. You can find its coordinates in the scene, find the speed's cursor, or set an image cursor. NOTE: This is currently not finished and subject to change.

Installation

Place the file click.lua into the LuaScriptsLib folder.

How to Use

To enable the click.lua, add this line to lunadll.lua:

local click = API.load("click");

This will load the API.

Example

local click = API.load("click")
click.setCursor("example.png")

function onTick()
  Text.print(click.cursorTimer("off"),click.x()-32,click.y()-32)
  if click.click() then
    click.setCursorOn()
    click.setCursorOff(15)
    NPC.spawn(1,click.sceneX(),click.sceneY(),player.section)
  end
end

This example will:

1) Spawn a goomba where the cursor is placed when the mouse is clicked.
2) Show the cursor for 15 frames when the mouse is clicked.
3) Have the timer near the cursor showing how long until the cursor disappears.

Documentation

click() hold() released()
Returns true for the first frame the mouse was clicked. Returns true if the mouse is being clicked. Returns true for the first frame the mouse was released.
x() y()
Returns the X-coordinate relative to the screen. Returns the Y-coordinate relative to the screen.
sceneX() sceneY()
Returns the X-coordinate relative to the scene. Returns the Y-coordinate relative to the scene.
speedX() speedY()
Returns the X-speed of the cursor. NOTE: Doesn't work on 'onTickEnd()'. Returns the Y-speed of the cursor. NOTE: Doesn't work on 'onTickEnd()'.
setCursor() Image Path Priority X offset Y Offset Cursor
Sets the cursor with an image. Optional, string

Provide a file path to the image. Default: SMBX Cursor

Optional, number.

Provide the priority for the cursor. Default: 5

Optional, number.

Provide an X-offset for the image. Default: 0

Optional, number.

Provide a Y-offset for the image. Default: 0

Optional, boolean.

Choose if you want the cursor to appear. Default: True

setCursorOn() Time
Turns on the image for the cursor. Optional, number

A delay for when the image should be turned on. Default: 0

setCursorOff() Time
Turns off the image for the cursor. Optional, number

A delay for when the image should be turned off. Default: 0

cursorTimer() Type
Returns the timer until the cursor image is turned on/off Required, string

Have either "on", or "off".

isCursor()
Returns true if the cursor is being displayed
sqr() TYPE X1 Y1 X2 Y2 NAME
Check if the cursor is inside a square relative to the screen, and insert a function to check an action. It will also manage the amount of time it returned true by giving an optional name. Required, function.

Insert a function that will return true or false. The recommended functions are click.click(), click.hold(), or click.released(). You may also input a custom function, make sure the functions returns true or false. You can also put true, and the function will always return true if the cursor is inside the square.

Required, number.

Put the top-left X-coordinate of the square.

Required, number.

Put the top-left Y-coordinate of the square.

Required, number.

Put the bottom-right X-coordinate of the square.

Required, number.

Put the bottom-right Y-coordinate of the square.

Optional, string.

Put a string, and for every frame, this function returns true, it will add one to a stored number. You can get this number using sqrFind().

sqrIn() TYPE X1 Y1 X2 Y2 NAME
Check if the cursor is outside a square relative to the screen, and insert a function to check an action. It will also manage the amount of time it returned true by giving an optional name. Required, function.

Insert a function that will return true or false. The recommended functions are click.click(), click.hold(), or click.released(). You may also input a custom function, make sure the functions returns true or false. You can also put true, and the function will always return true if the cursor is inside the square.

Required, number.

Put the top-left X-coordinate of the square.

Required, number.

Put the top-left Y-coordinate of the square.

Required, number.

Put the bottom-right X-coordinate of the square.

Required, number.

Put the bottom-right Y-coordinate of the square.

Optional, string.

Put a string, and for every frame, this function returns true, it will add one to a stored number. You can get this number using sqrFind().

sqrScene() TYPE X1 Y1 X2 Y2 NAME
Check if the cursor is inside a square relative to the scene, and insert a function to check an action. It will also manage the amount of time it returned true by giving an optional name. Required, function.

Insert a function that will return true or false. The recommended functions are click.click(), click.hold(), or click.released(). You may also input a custom function, make sure the functions returns true or false. You can also put true, and the function will always return true if the cursor is inside the square.

Required, number.

Put the top-left X-coordinate of the square.

Required, number.

Put the top-left Y-coordinate of the square.

Required, number.

Put the bottom-right X-coordinate of the square.

Required, number.

Put the bottom-right Y-coordinate of the square.

Optional, string.

Put a string, and for every frame, this function returns true, it will add one to a stored number. You can get this number using sqrFind().

sqrSceneIn() TYPE X1 Y1 X2 Y2 NAME
Check if the cursor is outide a square relative to the scene, and insert a function to check an action. It will also manage the amount of time it returned true by giving an optional name. Required, function.

Insert a function that will return true or false. The recommended functions are click.click(), click.hold(), or click.released(). You may also input a custom function, make sure the functions returns true or false. You can also put true, and the function will always return true if the cursor is inside the square.

Required, number.

Put the top-left X-coordinate of the square.

Required, number.

Put the top-left Y-coordinate of the square.

Required, number.

Put the bottom-right X-coordinate of the square.

Required, number.

Put the bottom-right Y-coordinate of the square.

Optional, string.

Put a string, and for every frame, this function returns true, it will add one to a stored number. You can get this number using sqrFind().

sqrFind() Name Set
Get the amount of frames a sqr function returned true using a name. Required, string.

Use the name to get the amount of frames using a name.

Optional, number.

Set the number for the name.