HopperBins: Difference between revisions
>Nate m This more like a tutorial, not an object |
>Mindraker mNo edit summary |
||
Line 1: | Line 1: | ||
{{CatUp|Tutorials}} | |||
__TOC__ | |||
==What is a HopperBin?== | ==What is a HopperBin?== | ||
HopperBins are considered old now. They were the first ways to make a weapon, a utility tool, or anything you could really think of. They're mainly used for getting input from the player, and doing something with that input. | HopperBins are considered old now. They were the first ways to make a weapon, a utility tool, or anything you could really think of. They're mainly used for getting input from the player, and doing something with that input. | ||
== | ==Special Events== | ||
The special events of a HopperBin are as follows: | |||
#Selected | #Selected | ||
#Deselected | #Deselected | ||
== | ==Important events and properties== | ||
The Selected and Deselected events have an argument, called a MOUSE object. Here are its important events and properties. | |||
'''Events''' | '''Events''' | ||
Line 58: | Line 61: | ||
Thats a simple thing to spawn a boulder wherever you click. It also gets rid of the boulder after a set amount of time. | Thats a simple thing to spawn a boulder wherever you click. It also gets rid of the boulder after a set amount of time. | ||
== | ==Simple Toggle Utility== | ||
This tutorial wouldn't be complete without some decent examples. Assuming you have a brick named "Toggle", and it has a BoolValue in it named "On/Off", you can use this. | |||
This tutorial wouldn't be complete without some decent examples. | |||
Assuming you have a brick named "Toggle", and it has a BoolValue in it named "On/Off", you can use this. | |||
<pre> | <pre> | ||
Line 94: | Line 91: | ||
You can easily manipulate this script to work for anything. | You can easily manipulate this script to work for anything. | ||
==Okay, what else?== | |||
There are PLENTY of different weapons and HopperBins to learn off of. | |||
[[Category:Scripting Tutorials]] | [[Category:Scripting Tutorials]] |
Revision as of 16:12, 22 August 2008
What is a HopperBin?
HopperBins are considered old now. They were the first ways to make a weapon, a utility tool, or anything you could really think of. They're mainly used for getting input from the player, and doing something with that input.
Special Events
The special events of a HopperBin are as follows:
- Selected
- Deselected
Important events and properties
The Selected and Deselected events have an argument, called a MOUSE object. Here are its important events and properties.
Events
- Button1Down
- Button1Up
- Button2Down -- currently un-operational
- Button2Up -- also non-working
- WheelForward -- non-working
- WheelBackward -- non-working
Properties
- Hit -- CFrame value
- Target -- object value
- X -- mouse's X position on the screen.
- Y -- mouse's Y position on the screen.
- ViewSizeX -- your screen's X size.
- ViewSizeY -- your screen's Y size.
- Origin -- CFrame value
- Icon -- the cursor image path
What do I do with it?
You can use it to do almost anything! You can spawn a projectile when Button1Down is fired, have it spawn in the direction the mouse is from your head, and move in the direction of the mouse.
Here's an example of a Boulder Summoner.
lifetime = 5 -- how long the boulder stays there. 5 is a good value. function onButton1Down(mouse) local b = Instance.new("Part") b.BrickColor = BrickColor.new(217) b.Position = mouse.Hit.p b.Size = Vector3.new(5, 5, 5) b.Shape = 0 b.Parent = game.Workspace b.Velocity = (script.Parent.Parent.Parent.Character.Head.Position - mouse.Hit.p).unit * -50 + Vector3.new(0, 10, 0) -- pushes it away from you, and pops it up a bit, making it seem to come out of the ground. game:GetService("Debris"):AddItem(b, lifetime) end function onSelected(mouse) mouse.Button1Down:connect(function() onButton1Down(mouse) end) -- Button1Down doesn't come with a mouse, seeing as its -- an event of the mouse itself. We need to give the function the mouse object to work off of. end script.Parent.Selected:connect(onSelected) -- Selected comes with a mouse.
Thats a simple thing to spawn a boulder wherever you click. It also gets rid of the boulder after a set amount of time.
Simple Toggle Utility
This tutorial wouldn't be complete without some decent examples. Assuming you have a brick named "Toggle", and it has a BoolValue in it named "On/Off", you can use this.
brickName = "Toggle" valueName = "On/Off" function onButton1Down(mouse) local targ = mouse.Target if targ~=nil then if targ.Name == brickName then if targ:findFirstChild(valueName)~=nil then if targ[valueName].Value == true then targ[valueName].Value = false else targ[valueName].Value = true end end end end end function onSelected(mouse) mouse.Button1Down:connect(function() onButton1Down(mouse) end) end script.Parent.Selected:connect(onSelected)
You can easily manipulate this script to work for anything.
Okay, what else?
There are PLENTY of different weapons and HopperBins to learn off of.