Jump to content

What s Wrong


Recommended Posts

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...