Is there a Function like this?

Hey people of Facepunch, I have a question. Is there a LUA function that like tells when your typing, and then tells when your done? Cause I really want to add it so if you have a Combine model, and you start typing it makes like a combinish beep sound thing, Whatever. But are there Functions like this?

Called when chatbox is opened and closed, respectively.

Made this a while ago, with some documentation. I am not sure it works though.
I am assuming you are making a typing display so yea.

[lua]
local fadeDistance = 128;

                        -- Check if the player is alive.
                        if ( player:Alive() ) then

[/lua]

You made this a while ago, huh?

:v:

Maybe he made it for people who are new to lua?

-snip-

Oh, you don’t get the joke. It’s my code.

[editline]27th June 2011[/editline]

In case you’re thinking “anyone could have wrote that”, nobody else would have wrote that ridiculously stupid and unnecessary comment except me :v:

Haha, Thank you everyone! <3

So would this work?

function GM:FinishChat()
if ply:GetModel() == “models/player/police.mdl” then
player:EmitSound(“npc/overwatch/radiovoice/off4.wav”);
end
end

I don’t know about that, Conna. I’ve written some pretty dumb and unnecessary comments, myself.

For example, for my current project:

[lua]-- Enable custom physics (we do speed and turning right in the physics simulate hook, bitch)[/lua]

:v:

Ok yea this dident work… What does it look like im doing wrong?

function GM:FinishChat()
if ply:GetModel() == “models/player/police.mdl” then
player:EmitSound(“npc/overwatch/radiovoice/off4.wav”);
end
end

Are you actually calling the function at all with a hook?

hook.Add(“FinishChat”, “EmitPoliceSound”, FinishChat)

So it should be this?

function GM:FinishChat()
if ply:GetModel() == “models/player/police.mdl” then
player:EmitSound(“npc/overwatch/radiovoice/off4.wav”);
end
end

hook.Add(“FinishChat”, “EmitPoliceSound”, FinishChat)

I don’t think you need the “GM:” in front of the function name. It should work though.

It dosent work

Found some fixes to your code,

This hook get’s called on the server not the client, emit sound doesn’t work on the client (well, not for every player to hear it), if you want it to work for just the player, use **[Surface.PlaySound

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Surface.PlaySound)**

Since this is on the client, use **[G.LocalPlayer

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=G.LocalPlayer)** instead of ply or player as no player variable is passed along with this hook.

Here’s a fixed version, never use hooks with gamemode functions.
[lua]
local function EmitPoliceSound()
if LocalPlayer():GetModel() == “models/player/police.mdl” then
surface.PlaySound(“npc/overwatch/radiovoice/off4.wav”)
end
end

hook.Add(“FinishChat”, “EmitPoliceSound”, EmitPoliceSound)
[/lua]

Wait, so which one do I use, Cause I want both the Person whos done typing, and people around Them to hear the beep thing

EDIT:

Ok so If I use

local function EmitPoliceSound()
if LocalPlayer():GetModel() == “models/player/police.mdl” then
surface.PlaySound(“npc/overwatch/radiovoice/off4.wav”)
end
end

hook.Add(“FinishChat”, “EmitPoliceSound”, EmitPoliceSound)

Can only the The person typing hear it? Or can he and both everyone around him hear it?

You can do that, but you’d need to use **[Datastream.StreamToServer

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Datastream.StreamToServer)**. When you create the datastream hook, you simply use the player argument and **[Entity.EmitSound

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Entity.EmitSound)**. In my example, only the person who typed it could hear the sound.

[editline]27th June 2011[/editline]

Please use lua tags like this [ lua ] [/ lua ], but without the spaces inside.

[editline]27th June 2011[/editline]

Also, you should post your LUA Questions in the Questions section. You’re more likely to get better answers.

I need to figure out Datastream myself.

I think it’s quite easy to use, just as easy as using usermessage.

Oh, have you finally managed to go one up the redundancy ladder from “check if a statement is true”?


(User was banned for this post ("Trolling" - Overv))