LUA:Mouse Out Tutorial

From GMod Wiki

Revision as of 03:08, 17 August 2011 by Alan (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Lua: Mouse Out Tutorial
Page white text.png Description:How to get the mouse out, like DarkRP.
link=User:KillerLUA Original Author:KillerLUA
Calendar.png Created:March 12, 2010

Contents


Introduction

In this tutorial, I will be showing you how to make the mouse go out of the screen using the F3 key. Like Dark Roleplaying.

Code

I'm relying on the fact that you have a pre-coded gamemode ready.

We are going to send a usermessage to the client that presses F3. Although we could send entites, floats and strings too, we won't be doing that in this tutorial.

Add the following code to the files:

init.lua

 
function OutOfGUI(ply)
	umsg.Start("ToggleClicker", ply)
	umsg.End()
end
hook.Add("ShowSpare1", "OutOfGUIHook", OutOfGUI)
 

Now, we create a simple function that is hooked to whenever the ToggleClicker usermessage is sent to the client. We are not being sent data so just carry on with the ToggleClicker function.

Usermessages require that you start the user message, piece in the data, then end it. When you end it, it is then added to the sending queue. When it arrives at the client, microseconds later (ping), it is then added to a processing queue.

cl_init.lua

 
function ToggleClicker()
	GUIToggled = not GUIToggled --Get's the opposite of what the current state is, IE: The new state we're going to set
	gui.EnableScreenClicker(GUIToggled)
end
usermessage.Hook("ToggleClicker", ToggleClicker)
 

Once our user message has been processed, the game will determine it's required by LUA and not the source engine, thus your data is here,

Now wasn't that easy?

Yarin Kaul Icon ArrowSquare32.png Back to KillerLUA Tutorials


Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox