Kevin_Linden Posted February 28, 2010 Share Posted February 28, 2010 How would i make a script like this? You press M and it shows your mouse. This is useful on other servers if i'm multitasking and would like it for my own. Link to comment
Antibird Posted February 28, 2010 Share Posted February 28, 2010 Try this one: bindKey( "m", "down", function() showCursor( not isCursorShowing() ) end ) Link to comment
Kevin_Linden Posted February 28, 2010 Author Share Posted February 28, 2010 Don't you have to close it? I don't really script well in lua but in php i have to. So I have this so far. mousekey.lua bindKey( "m", mouse) function mouse() showCursor( not isCursorShowing() ) end ) meta.xml <meta> <info author='Antibird and Kevin' version='1' name='mousekey' type='script' /> <script src='mousekey.lua' type='client' /> </meta> Link to comment
Dark Dragon Posted February 28, 2010 Share Posted February 28, 2010 it's correct how he has done it bindKey( "m", "down", --bindKey begins here function() --has a whole function as a parameter which is just defined right here showCursor( not isCursorShowing() ) end --end of the defined function ) -- and finally here ends our bindKey Link to comment
Kevin_Linden Posted February 28, 2010 Author Share Posted February 28, 2010 I feel stupid. I should of tried it. Sorry. But what does bindKey( "m", "down" do? I kind was kind of thinking it would make down show the mouse but it does not. So what is the down part? Also, Thanks all. Link to comment
blas95 Posted February 28, 2010 Share Posted February 28, 2010 "m" is key, "down" is the state. You can also have "up" or "both" Link to comment
dzek (varez) Posted February 28, 2010 Share Posted February 28, 2010 (edited) you need more javascript as javascript also has events working like lua (especially in jquery) so bindKey has 3 parameters: 1st - the key 2nd - the state of key that trigger function ("down" mean when you press key down, "up" (not supported yet) when you release it, "both" (not supported yet)) 3rd - the function that handles that keypress you can do function function_showing_cursor(player, key, state) -- something there end bindKey("m", "down", function_showing_cursor) or bindKey("m", "down", function(player, key,state) -- something there end) ) (notice on the 1st example - when typing function that handles your keypress, you dont pass any arguments in (), it should be without () there - it could be your common mistake - im talking from view php programmer ) hope i helped you to understand Edited February 28, 2010 by Guest Link to comment
Dark Dragon Posted February 28, 2010 Share Posted February 28, 2010 bindKey has 3 arguments. the first is the key as a string, so if you want to bind something to the m key you need to write "m" the second argument is the state of the key. if you want something to happen when the user presses the button down then you use "down", but there are cases when you want something to happen when the user releases a key, that would be "up", that's especially essential for displays that should be shown while the user holds a specific key. and the third argument is a function, it doesn't matter if you point to a previously defined function or define that function right there. in thus case the function has been defined directly in there bindKey( "m", "down", function() showCursor( not isCursorShowing() ) end ) but this would work as well: function thisIsOurFunction() showCursor( not isCursorShowing() ) end bindKey( "m", "down", thisIsOurFunction ) just with the difference that we point to a a function, bindKey will then know what function to find then finally showCursor( not isCursorShowing() ) is doing the magic. depending on if the mouse cursor is currently showing or hidden it sets the mouse cursors showing state to the opposite. shows the cursor when it's not showing and hides it if it is already showing. EDIT: NINJAS!!! Link to comment
Antibird Posted February 28, 2010 Share Posted February 28, 2010 ( You three just explained it all well, while I was typing for the same purpose, thanks. ) Link to comment
dzek (varez) Posted February 28, 2010 Share Posted February 28, 2010 ( You three just explained it all well, while I was typing for the same purpose, thanks. ) haha, what a HOT topic Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now