Browse Source

Flush messages on player_say

nosoop 2 years ago
parent
commit
a589c6b996
1 changed files with 17 additions and 3 deletions
  1. 17 3
      scripting/simple-chatprocessor.sp

+ 17 - 3
scripting/simple-chatprocessor.sp

@@ -13,7 +13,7 @@
 
 #pragma newdecls required
 
-#define PLUGIN_VERSION "0.1.4"
+#define PLUGIN_VERSION "0.2.0"
 public Plugin myinfo = {
 	name = "[CSRD] Simple Chat Processor",
 	author = "nosoop (based off of Simple Plugins' implementation)",
@@ -63,6 +63,8 @@ public void OnPluginStart() {
 			OnClientPutInServer(i);
 		}
 	}
+	
+	HookEvent("player_say", OnPlayerSayPost, EventHookMode_Post);
 }
 
 public void OnClientPutInServer(int client) {
@@ -149,11 +151,20 @@ Action OnSayText2(UserMsg id, Handle buffer, const int[] clients, int nClients,
 	return Plugin_Handled;
 }
 
-public void OnClientThinkPost(int author) {
+void OnPlayerSayPost(Event event, const char[] name, bool dontBroadcast) {
+	int client = GetClientOfUserId(event.GetInt("userid"));
+	FlushQueuedMessages(client);
+}
+
+void OnClientThinkPost(int client) {
+	FlushQueuedMessages(client);
+}
+
+void FlushQueuedMessages(int author) {
 	/**
 	 * Iterate through all queued messages from OnSayText2
 	 */
-	if (g_QueuedMessages[author].Size == 0) {
+	if (!g_QueuedMessages[author] || g_QueuedMessages[author].Size == 0) {
 		return;
 	}
 	StringMapSnapshot messages = g_QueuedMessages[author].Snapshot();
@@ -194,6 +205,9 @@ public void OnClientThinkPost(int author) {
 				}
 			}
 			
+			// since it's not commented on in the SDK, we can only speculate on why the
+			// developers decided to send SayText2 messages individually
+			// probably cheat clients?
 			SayText(author, clients, nClients, localizationToken, name, message);
 			
 			ForwardOnChatMessagePost(author, clientList, name, message);