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;
11 magicear_matched = false;
13 dotrigger = ((IS_PLAYER(source)) && (source.deadflag == DEAD_NO) && ((ear.radius == 0) || (vlen(source.origin - ear.origin) <= ear.radius)));
14 domatch = ((ear.spawnflags & 32) || dotrigger);
21 // we are in TUBA mode!
22 if (!(ear.spawnflags & 256))
25 if(!W_Tuba_HasPlayed(source, ear.message, ear.movedir_x, !(ear.spawnflags & 512), ear.movedir_y, ear.movedir_z))
28 magicear_matched = true;
35 savemessage = self.message;
36 self.message = string_null;
38 self.message = savemessage;
48 if(ear.spawnflags & 256) // ENOTUBA
53 if(ear.spawnflags & 4)
59 if(ear.spawnflags & 1)
62 if(ear.spawnflags & 2)
65 if(ear.spawnflags & 8)
70 l = strlen(ear.message);
72 if(ear.spawnflags & 128)
75 msg = strdecolorize(msgin);
77 if(substring(ear.message, 0, 1) == "*")
79 if(substring(ear.message, -1, 1) == "*")
82 // as we need multi-replacement here...
83 s = substring(ear.message, 1, -2);
85 if(strstrofs(msg, s, 0) >= 0)
86 matchstart = -2; // we use strreplace on s
91 s = substring(ear.message, 1, -1);
93 if(substring(msg, -l, l) == s)
94 matchstart = strlen(msg) - l;
99 if(substring(ear.message, -1, 1) == "*")
102 s = substring(ear.message, 0, -2);
104 if(substring(msg, 0, l) == s)
111 if(msg == ear.message)
116 if(matchstart == -1) // no match
119 magicear_matched = true;
126 savemessage = self.message;
127 self.message = string_null;
129 self.message = savemessage;
133 if(ear.spawnflags & 16)
137 else if(ear.netname != "")
140 return strreplace(s, ear.netname, msg);
143 substring(msg, 0, matchstart),
145 substring(msg, matchstart + l, -1)
153 string trigger_magicear_processmessage_forallears(entity source, float teamsay, entity privatesay, string msgin)
157 for(ear = magicears; ear; ear = ear.enemy)
159 msgout = trigger_magicear_processmessage(ear, source, teamsay, privatesay, msgin);
160 if(!(ear.spawnflags & 64))
168 void spawnfunc_trigger_magicear()
170 self.enemy = magicears;
173 // actually handled in "say" processing
176 // 2 = ignore teamsay
178 // 8 = ignore tell to unknown player
179 // 16 = let netname replace the whole message (otherwise, netname is a word replacement if set)
180 // 32 = perform the replacement even if outside the radius or dead
181 // 64 = continue replacing/triggering even if this one matched
182 // 128 = don't decolorize message before matching
183 // 256 = message is a tuba note sequence (pitch.duration pitch.duration ...)
184 // 512 = tuba notes must be exact right pitch, no transposing
194 // if set, replacement for the matched text
196 // "hearing distance"
200 // for spawnflags 256, defines 'instrument+1 mintempo maxtempo' (zero component doesn't matter)
202 self.movedir_x -= 1; // map to tuba instrument numbers