Hi,

Sorry if this is not the right list for the patch.

The idea was to implement a small script to highlight chat messages in which 
the multiplayer-callsign is mentioned. This should make multiplayer 
communication with many pilots easier.

The message is highlighted in red.

scosu
diff --git a/Nasal/screen.nas b/Nasal/screen.nas
index 2d572aa..bfebdeb 100644
--- a/Nasal/screen.nas
+++ b/Nasal/screen.nas
@@ -458,6 +458,47 @@ _setlistener("/sim/signals/fdm-initialized", func {
 # functions that make use of the window class (and don't belong anywhere else)
 ##############################################################################
 
+# translates a string to lower case
+var tolower = func (str) {
+	for (var i = 0; i < size(str); i = i+1) {
+		if (str[i] >= `A` and str[i] <= `Z`)
+			str[i] = str[i] - `A` + `a`;
+	}
+	return str;
+}
+
+# highlights messages with the multiplayer callsign in the text
+var msg_mp = func (n) {
+	if (!getprop("/sim/multiplay/chat-display"))
+		return;
+	var msg = tolower(n.getValue());
+	var call = tolower(getprop("/sim/multiplay/callsign"));
+	var matching = 0;
+	var found = 0;
+	for(var i = 0; i < size(msg); i = i + 1) {
+		if (msg[i] == ` ` or msg[i] == `,` or msg[i] == `.` or msg[i] == `;` or msg[i] == `:` or msg[i] == `>`) {
+			if (matching == size(call)) {
+				found = 1;
+				break;
+			}
+			matching = 0;
+			continue;
+		}
+		if (matching >= size(call)) {
+			matching = matching + 1;
+			continue;
+		}
+		if (call[matching] == msg[i]) {
+			matching = matching + 1;
+		} else {
+			matching = 0;
+		}
+	}
+	if (found == 1 or matching == size(call))
+		screen.log.write(n.getValue(), 1.0, 0.5, 0.5);
+	else
+		screen.log.write(n.getValue(), 0.5, 0.0, 0.8);
+}
 
 var msg_repeat = func {
 	if (getprop("/sim/tutorials/running")) {
@@ -557,9 +598,7 @@ _setlistener("/sim/signals/nasal-dir-initialized", func {
 			func(n) map("copilot",  n.getValue(), 1.0, 1.0, 1.0));
 	listener.ai_plane = setlistener(m ~ "ai-plane",
 			func(n) map("ai-plane", n.getValue(), 0.9, 0.4, 0.2));
-	listener.mp_plane = setlistener(m ~ "mp-plane",
-			func(n) map("ai-plane", n.getValue(), 0.5, 0.0, 0.8,
-					func getprop("/sim/multiplay/chat-display")));
+	listener.mp_plane = setlistener(m ~ "mp-plane", msg_mp);
 });
 
 

------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel

Reply via email to