I would suggest you start using ChatBar.onAction instead of onPlayerChats, preventing players from chatting commands looks better in the end.
That said, It would look something like this:
PHP Code:
//#CLIENTSIDE
function ChatBar.onAction() {
// Check for sethat command
if (ChatBar.text.starts("sethat")) {
// Get Hat Name
// I use "sethat ".length() to get the position of chat starting
// a space after the actual command and trim the result.
temp.hat_name = ChatBar.text.substring("sethat ".length()).trim();
// Check if Hat Exists in Player Flags
if (clientr.hat.(@temp.hat_name) != "") {
// Set Player's Hat
player.attr[1] = clientr.hat.(@temp.hat_name);
}
// Clear ChatBar Text (Prevents player from chatting sethat)
ChatBar.text = "";
}
}