I'm trying to make a code that uses something like math.random to generate a random number when a player types in chat. And if a player types that number in chat, it will run a function. Any help?
Well to start you can use the hook
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/PlayerSay]GM/PlayerSay[/url]
with a local var like this
[lua]
local numberToGuess = math.random(1,100)
[/lua]
then make a if statement inside the hook checking if they said the number
[lua]
hook.Add("PlayerSay","Unique hook name", function(ply, text, team)
-- CODE
end)
[/lua]
well this is what I tried to begin with
[lua]
hook.Add( "PlayerSay", "testnumbchat", function( ply, text, public )
local randnumber = math.random(1,2)
if ( text == randnumber ) then
ply:ChatPrint( "Test" )
return ""
end
end ) [/lua]
[editline]13th December 2015[/editline]
just to test it
[editline]13th December 2015[/editline]
So what am I doing wrong?
[QUOTE=covey88;49306363]well this is what I tried to begin with
[lua]
hook.Add( "PlayerSay", "testnumbchat", function( ply, text, public )
local randnumber = math.random(1,2)
if ( text == randnumber ) then
ply:ChatPrint( "Test" )
return ""
end
end ) [/lua]
[editline]13th December 2015[/editline]
just to test it
[editline]13th December 2015[/editline]
So what am I doing wrong?[/QUOTE]
your checking a string against a number
do
[lua]
tonumber(text)
[/lua]
add me on steam for any further questions
[url]https://steamcommunity.com/id/ProfessorSpace/[/url]
Thank you!
Sorry, you need to Log In to post a reply to this thread.