Click.lua

From Moondust Wiki
Revision as of 20:35, 4 January 2017 by Yoshi021 (talk | contribs)
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.

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.

Examples

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

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.
local click = API.load("click")
click.setCursor()

function onTick()
  Text.print(click.sqrFind("AmountHeld"),0,0)
  if click.sqrScene(click.hold(), player.x-100, player.y-100,player.x+100, player.y+100,"AmountHeld") then
      NPC.spawn(1,click.sceneX(),click.sceneY(),player.section)
  end
end

This example will:

 1) Spawn a goomba when holding the mouse in a box near the player
 2) Show a counter of the amount of frames 'click.sqrScene' returned true

Documentation

click() hold() released()
Returns true for the first frame the mouse was clicked. Returns true if the mouse is being held. 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. NOTE: the API uses 'Misc.resolveFile', so use that to your advantage. Default: SMBX Cursor, "click/example"

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() Delay
Turns on the image for the cursor. Optional, number

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

setCursorOff() Delay
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.