2 float magicear_matched;
3 float W_Tuba_HasPlayed(entity pl, string melody, float instrument, float ignorepitch, float mintempo, float maxtempo);
4 string trigger_magicear_processmessage(entity ear, entity source, float teamsay, entity privatesay, string msgin)
6 float domatch, dotrigger, matchstart, l;
10 magicear_matched = false;
12 dotrigger = ((IS_PLAYER(source)) && (!IS_DEAD(source)) && ((ear.radius == 0) || (vdist(source.origin - ear.origin, <=, ear.radius))));
13 domatch = ((ear.spawnflags & 32) || dotrigger);
20 // we are in TUBA mode!
21 if (!(ear.spawnflags & 256))
24 if(!W_Tuba_HasPlayed(source, ear.message, ear.movedir_x, !(ear.spawnflags & 512), ear.movedir_y, ear.movedir_z))
27 magicear_matched = true;
33 savemessage = self.message;
34 self.message = string_null;
36 self.message = savemessage;
46 if(ear.spawnflags & 256) // ENOTUBA
51 if(ear.spawnflags & 4)
57 if(ear.spawnflags & 1)
60 if(ear.spawnflags & 2)
63 if(ear.spawnflags & 8)
68 l = strlen(ear.message);
70 if(ear.spawnflags & 128)
73 msg = strdecolorize(msgin);
75 if(substring(ear.message, 0, 1) == "*")
77 if(substring(ear.message, -1, 1) == "*")
80 // as we need multi-replacement here...
81 s = substring(ear.message, 1, -2);
83 if(strstrofs(msg, s, 0) >= 0)
84 matchstart = -2; // we use strreplace on s
89 s = substring(ear.message, 1, -1);
91 if(substring(msg, -l, l) == s)
92 matchstart = strlen(msg) - l;
97 if(substring(ear.message, -1, 1) == "*")
100 s = substring(ear.message, 0, -2);
102 if(substring(msg, 0, l) == s)
109 if(msg == ear.message)
114 if(matchstart == -1) // no match
117 magicear_matched = true;
123 savemessage = self.message;
124 self.message = string_null;
126 self.message = savemessage;
130 if(ear.spawnflags & 16)
134 else if(ear.netname != "")
137 return strreplace(s, ear.netname, msg);
140 substring(msg, 0, matchstart),
142 substring(msg, matchstart + l, -1)
150 string trigger_magicear_processmessage_forallears(entity source, float teamsay, entity privatesay, string msgin)
154 for(ear = magicears; ear; ear = ear.enemy)
156 msgout = trigger_magicear_processmessage(ear, source, teamsay, privatesay, msgin);
157 if(!(ear.spawnflags & 64))
165 spawnfunc(trigger_magicear)
167 self.enemy = magicears;
170 // actually handled in "say" processing
173 // 2 = ignore teamsay
175 // 8 = ignore tell to unknown player
176 // 16 = let netname replace the whole message (otherwise, netname is a word replacement if set)
177 // 32 = perform the replacement even if outside the radius or dead
178 // 64 = continue replacing/triggering even if this one matched
179 // 128 = don't decolorize message before matching
180 // 256 = message is a tuba note sequence (pitch.duration pitch.duration ...)
181 // 512 = tuba notes must be exact right pitch, no transposing
191 // if set, replacement for the matched text
193 // "hearing distance"
197 // for spawnflags 256, defines 'instrument+1 mintempo maxtempo' (zero component doesn't matter)
199 self.movedir_x -= 1; // map to tuba instrument numbers