Friday, 29 August 2014

Mouse Manipulation

I seem to be fond of the word manipulation. Probably not a good thing, but when put into practise it can be - such as making an awesome mouse icon.

You are able to do certain things with a player's mouse on ROBLOX, and read certain values from it (such as the size of the icon, its position on screen, etc). There are a few different ways of getting the actual mouse to manipulate (there's that word again) it.

The :GetMouse() method, when called on a Player instance, will return said player's mouse. You can then mess around with it at will, but it doesn't let you change the mouse's icon (ROBLOX's API is wierd, don't ask me). If you want to change the mouse's icon you have to use the .Equipped event of a Tool, or the .Selected event of a Hopperbin. The function/event returns the mouse as an argument. This is quite annoying as a character is therefore required to actually use the tool/hopperbin.

The best way is to :Clone() the tool into the player's character. That forces them to fire the .Equipped event, which you can detect and then connect it to a function where you delete the character (and tool) so the player can't reset and ruin your sequence, and then do anything else you want to do with the mouse within the same function.

Assuming that you already have the tool ready somewhere, it looks something like this:


tool.Equipped:connect(function(mouse) --mouse given to us by Equipped
character:Destroy()
mouse.Icon = "" --Mouse icon link here
end)

Below's a picture showing it in use.


Clever use of a tool to manipulate a player's mouse in a GUI gamestate.

No comments:

Post a Comment