Scripting Posted June 19, 2012 Share Posted June 19, 2012 Hi all I m maked this code ,but onChat function don t work,fix and thx people. server-side: number1 = "test" function onChat ( message,type,number1 ) if message == number1 then outputChatBox("good") end end addEventHandler ( "onPlayerChat", root,onChat) Link to comment
mjau Posted June 19, 2012 Share Posted June 19, 2012 number1 = "test" function onChat ( message,type) if message == number1 then outputChatBox("good") end end addEventHandler ( "onPlayerChat", root,onChat) try that Link to comment
BinSlayer1 Posted June 19, 2012 Share Posted June 19, 2012 This is the kind of problem that can be solved very easily by debugging the code like this outside the IF statement. outputChatBox(type(number1)) outputChatBox(tostring(number1)) This will tell you that the type of number1 variable is BOOLEAN and will also output "nil" in the console meaning nothing is stored in that variable. This happens because once you declare number1 as being a PARAMETER in the header of the function, it won't recognize the global value "test" that you set it to in the beginning of the script. The problem occurs because onPlayerChat will not send any 3rd parameter to that function, simply because that's how MTA works. Thus sending "nil". You can find the list of parameters for onPlayerChat here: https://wiki.multitheftauto.com/wiki/OnPlayerChat edit: I know that the problem has been solved by the previous poster but he simply gave the correct code with no explanation. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now