mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-10 06:34:16 +00:00
add "say" command which sends a chat message
This commit is contained in:
parent
5ae8c65727
commit
38449b1a7e
2 changed files with 22 additions and 0 deletions
|
@ -11,6 +11,10 @@ namespace SanAndreasUnity.Chat
|
|||
private void Start()
|
||||
{
|
||||
ChatManager.singleton.RegisterChatPreprocessor(new ChatPreprocessor {processCallback = ProcessChatMessage});
|
||||
CommandManager.Singleton.RegisterCommand(new CommandManager.CommandInfo("say", "send chat message", true, false, 1.5f)
|
||||
{
|
||||
commandHandler = ProcessSayCommand,
|
||||
});
|
||||
}
|
||||
|
||||
private ChatPreprocessorResult ProcessChatMessage(Player player, string chatMessage)
|
||||
|
@ -50,5 +54,11 @@ namespace SanAndreasUnity.Chat
|
|||
// discard chat message
|
||||
return new ChatPreprocessorResult {shouldBeDiscarded = true};
|
||||
}
|
||||
|
||||
CommandManager.ProcessCommandResult ProcessSayCommand(CommandManager.ProcessCommandContext context)
|
||||
{
|
||||
ChatManager.SubmitChatMessage(CommandManager.GetRestOfTheCommand(context.command, 0));
|
||||
return CommandManager.ProcessCommandResult.Success;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -168,6 +168,18 @@ namespace SanAndreasUnity.Chat
|
|||
SendChatMessageToPlayerAsServer (player, msg, useServerNick ? singleton.serverChatNick : "");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Submit chat message. If there is a local player, message will be sent from that player to the server.
|
||||
/// Otherwise, if server is active, message will be sent from server to all players.
|
||||
/// </summary>
|
||||
public static void SubmitChatMessage(string msg)
|
||||
{
|
||||
if (Player.Local != null)
|
||||
SendChatMessageToAllPlayersAsLocalPlayer(msg);
|
||||
else if (NetStatus.IsServer)
|
||||
SendChatMessageToAllPlayersAsServer(msg);
|
||||
}
|
||||
|
||||
private static void SendChatMessageToPlayerAsServer( Player player, string msg, string sender ) {
|
||||
|
||||
NetStatus.ThrowIfNotOnServer();
|
||||
|
|
Loading…
Reference in a new issue