Chat Text

Can someone tell me why the hook isnt running when i say something?

[lua]
Msg(“Running”)
function chatText( playerindex, playername, text, messagetype )
Msg(playername)
Msg(text)
if( playername == LocalPlayer():Nick() ) then
Msg("You said: “…text)
local ChatExplode = string.Explode(” ", text)
Msg("ChatExplode: "…tostring(ChatExplode))
if string.find(text, “!Player”) == 1 then
Msg(“string.find found !Player at the first part”)
local player = ChatExplode:string(2)
Msg("Player: "…player)

	end
end

end
hook.Add( “ChatText” , “chatText”, chatText )
[/lua]
Thanks in advance!

Says this on the wiki.

Then is there a client side way to tell if the localplayer chatted, and if so, what is it?

You mean like this?
[lua]if ( player == LocalPlayer() ) then[/lua]

Ok, so i have

[lua]
Msg("Running
“)
function chatText(playername, text, teamchat, alive )
if(playername == LocalPlayer()) then
Etext = string.Explode(” ", text)
if Etext[1] == “!Player” then
if type(Etext[2]) == “string” then // change string to player when the time is right
aim(Etext[2])
end
end
end
end
hook.Add( “OnPlayerChat”, “plychat”, chatText);

function aim( Etext2 )

end
[/lua]

How would i, in aim(), change Etext2 from a string, into a player’s entity?

[editline]02:38PM[/editline]

I need something like wire E2’s findPlayerByName()

First of all, the OnPlayerChat hook returns the player entity, not a name.


Msg("Running
")
function chatText(player, text, teamchat, alive )
	if(player == LocalPlayer()) then
		Etext = string.Explode(" ", text)
		if Etext[1] == "!Player" then
			for k , v in ipairs(player.GetAll()) do
				if string.lower(string.sub(v:Nick() , 0 , string.len(Etext[2]))) == string.lower(Etext[2]) then
					aim(v:EntIndex())
				end
			end
		end
	end
end
hook.Add( "OnPlayerChat", "plychat", chatText);

function aim( Etext2 )
	// Now you have the player's entity index, which won't change unless they rejoin. Better than using name.
end

Just send the player as the argument:

[lua]Msg("Running
")

function chatText(ply, text, teamchat, alive )

if ( ply == LocalPlayer() ) then

	Etext = string.Explode(" ", text)
	if Etext[1] == "!Player" then
	
		for k , v in ipairs( player.GetAll( ) ) do
		
			if string.lower(string.sub(v:Nick() , 0 , string.len(Etext[2]))) == string.lower(Etext[2]) then
			
				aim( v );
				
			end
			
		end
		
	end
	
end

end
hook.Add( “OnPlayerChat”, “plychat”, chatText);

function aim( ply )

//code here ( ply is the player entity )

end[/lua]

Thank you very much MakeR, even though i dont know what your doing, it works!

You’re welcome

Hi, I am Andres Kramack from http://www.cathybarryadultstore.com/.

It’s a ‘pleasure’ serving the public if you know what I mean and this message is

Here at Cathy Barry Adult Store, we offer a wide variety of dildos that come in all sizes from goblin-sized dicks to black-man draconic dicks. I know at Facepunch everyone loves good old dicks which is why I personally offer anyone with an association with Facepunch Forums a 50% discount code “DIL4FACEPUNCH”. Don’t forget, this offer lasts until the next Garry’s Mod update which we so much love.

Here are pictures of our products just for you!

Sponsored Images:

http://static.fjcdn.com/pictures/Gym+leaders+hate+him_ab471d_5017861.jpg

https://static.fjcdn.com/comments/That+one+with+the+lamp+got+me+_e68beb19422eea14289caa5f4d6dffb7.jpg

Got any questions? Visit my Steam Profile!