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!
[quote="gmod wiki"]This hook doesn't get called when a player talks anymore, but instead you can use Gamemode.OnPlayerChat. However, this does get called on other than player messages.[/quote]
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\n")
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()
[QUOTE=bobthe2lol;15905920]Ok, so i have
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()[/QUOTE]
First of all, the OnPlayerChat hook returns the player entity, not a name.
[code]Msg("Running\n")
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[/code]
Just send the player as the argument:
[lua]Msg("Running\n")
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!
[QUOTE=bobthe2lol;15909830]Thank you very much MakeR, even though i dont know what your doing, it works![/QUOTE]
You're welcome
Hi, I am Andres Kramack from [url]http://www.cathybarryadultstore.com/[/url].
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 [B]I[/B] 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!
[IMG]http://pic.esmatube.com/imgs/a/g/t/x/x/giant_dildo_in_my_ass_part_ii-3_tmb.jpg[/IMG]
[IMG]http://pic.esmatube.com/imgs/a/d/d/h/r/bbw_giant_dildo_squat_25cm_round-3_tmb.jpg[/IMG]
[IMG]http://xxxdessert.com/tube/contents/videos_screenshots/15000/15261/preview.mp4.jpg[/IMG]
[IMG]http://g04.a.alicdn.com/kf/HTB1JlHlIpXXXXaJXVXXq6xXFXXXo/Silicone-Huge-Dildos-Vibrator-for-woman-shake-Horse-Dildos-penis-swith-sucker-african-Dong-dildos.jpg[/IMG]
Sponsored Images:
[IMG]http://45.media.tumblr.com/f81f8d61fa253dc804edb423c8ab149f/tumblr_mfbk96QAug1rvbfkuo1_500.gif[/IMG]
[IMG]http://49.media.tumblr.com/9110819111aa37acf4cd1c9d5341dd97/tumblr_nc4hqkdESo1skwv6ko1_500.gif[/IMG]
[IMG]http://1.bp.blogspot.com/-gueWbSnnsIc/UUtenyLS0oI/AAAAAAAANF4/L4aZnTrMaqs/s1600/dermatologists-hate-her.jpg[/IMG]
[IMG]http://static.fjcdn.com/pictures/Gym+leaders+hate+him_ab471d_5017861.jpg[/IMG]
[IMG]https://static.fjcdn.com/comments/That+one+with+the+lamp+got+me+_e68beb19422eea14289caa5f4d6dffb7.jpg[/IMG]
Got any questions? Visit my Steam Profile!
[url]http://steamcommunity.com/id/Robotboy655[/url]
Sorry, you need to Log In to post a reply to this thread.