Because users (non-logged in) cannot chat. I will show you how to make it by using custom inputs.
Step 1. Keybind
To make a keybind for user chat, you need to make this script, like: user chat key. Add this script:
NOTE: This is in JSON format. To import it, you need to switch script from Tree View to JSON View (there is a dropdown at the top right corner). Paste the code in and switch back to Tree View
JSON code #1
{ "triggers": [], "conditions": [ { "operator": "==", "operandType": "boolean" }, true, true ], "actions": [ { "type": "showDismissibleInputModalToPlayer", "player": { "function": "getOwner", "entity": { "function": "getLastCastingUnit" } }, "inputLabel": "Type any message to chat.", "runMode": 0 } ], "name": "user chat key", "parent": null, "key": "DUFmvDCwpW", "order": 5 }
After you made the script, you will also need to add a hotkey for the unit itself. To do so, you will need to go to controls of the player and go to Keybindings. Click on the empty slot and click “Add new keybinding”. Mount the keybind as “C” or another letter you like.
Once you did that, you need to go to “On key pressed” section and click the dropdown of Run script. Choose your keybind of the user chat.
Step 2. Chatting
To implement the chatting script, you need to make a new script and paste the JSON code to.
NOTE: This is in JSON format. To import it, you need to switch script from Tree View to JSON View (there is a dropdown at the top right corner). Paste the code in and switch back to Tree View
Chatting code
{ "triggers": [ { "type": "playerCustomInput" } ], "conditions": [ { "operator": "==", "operandType": "boolean" }, true, true ], "actions": [ { "type": "forAllUnits", "unitGroup": { "function": "allUnitsOwnedByPlayer", "player": { "function": "getTriggeringPlayer" } }, "actions": [ { "type": "condition", "conditions": [ { "operandType": "string", "operator": "==" }, { "function": "getValueOfEntityVariable", "variable": { "function": "getEntityVariable", "variable": { "text": "lastCustomInput", "dataType": "string", "entity": "homie", "key": "lastCustomInput" } }, "entity": { "function": "selectedUnit" } }, "userChat" ], "then": [ { "type": "sendChatMessage", "message": { "function": "concat", "textA": { "function": "getPlayerName", "entity": { "function": "getTriggeringPlayer" } }, "textB": { "function": "concat", "textA": " says: ", "textB": { "function": "substringOf", "string": { "function": "playerCustomInput", "player": { "function": "getTriggeringPlayer" } }, "fromIndex": 0, "toIndex": 24 } } }, "runMode": 0 } ], "else": [], "runMode": 0 } ], "runMode": 0 } ], "name": "chat input", "parent": null, "key": "iCXKdte6L6", "order": 25 }
Important!
When you are managing multiple custom inputs, it’s strongly recommended to make an entity variable that checks the last custom input type, like userChat. You can make this in the keybind script and also add a string check.