[nexuiz-commits] r7546 - in trunk/data: qcsrc/server scripts
DONOTREPLY at icculus.org
DONOTREPLY at icculus.org
Fri Aug 28 01:49:35 EDT 2009
Author: div0
Date: 2009-08-28 01:49:35 -0400 (Fri, 28 Aug 2009)
New Revision: 7546
Modified:
trunk/data/qcsrc/server/clientcommands.qc
trunk/data/qcsrc/server/g_triggers.qc
trunk/data/qcsrc/server/miscfunctions.qc
trunk/data/scripts/entities.def
Log:
{
"classname" "trigger_magicear"
"spawnflags" "64"
"message" "*fuck*"
"netname" "duck"
"target" "duck_yourself"
}
{
"classname" "target_items"
"targetname" "duck_yourself"
"health" "-10"
}
Modified: trunk/data/qcsrc/server/clientcommands.qc
===================================================================
--- trunk/data/qcsrc/server/clientcommands.qc 2009-08-27 14:53:56 UTC (rev 7545)
+++ trunk/data/qcsrc/server/clientcommands.qc 2009-08-28 05:49:35 UTC (rev 7546)
@@ -315,9 +315,15 @@
} else if(argv(0) == "tell") {
e = GetCommandPlayerSlotTargetFromTokenizedCommand(tokens, 1);
if(e && tokens > ParseCommandPlayerSlotTarget_firsttoken)
- Say(self, FALSE, e, substring(s, argv_start_index(ParseCommandPlayerSlotTarget_firsttoken), argv_end_index(-1) - argv_start_index(ParseCommandPlayerSlotTarget_firsttoken)), 1);
+ {
+ Say(self, FALSE, e, substring(s, argv_start_index(ParseCommandPlayerSlotTarget_firsttoken), argv_end_index(-1) - argv_start_index(ParseCommandPlayerSlotTarget_firsttoken)), TRUE);
+ }
else
+ {
+ if(tokens > ParseCommandPlayerSlotTarget_firsttoken)
+ trigger_magicear_processmessage_forallears(self, -1, world, substring(s, argv_start_index(ParseCommandPlayerSlotTarget_firsttoken), argv_end_index(-1) - argv_start_index(ParseCommandPlayerSlotTarget_firsttoken)));
sprint(self, "ERROR: usage: tell # playerid text...\n");
+ }
//clientcommand(self, formatmessage(s));
} else if(argv(0) == "info") {
cmd = cvar_string(strcat("sv_info_", argv(1)));
Modified: trunk/data/qcsrc/server/g_triggers.qc
===================================================================
--- trunk/data/qcsrc/server/g_triggers.qc 2009-08-27 14:53:56 UTC (rev 7545)
+++ trunk/data/qcsrc/server/g_triggers.qc 2009-08-28 05:49:35 UTC (rev 7546)
@@ -1644,3 +1644,155 @@
{
self.use = trigger_disablerelay_use;
}
+
+float magicear_matched;
+string trigger_magicear_processmessage(entity ear, entity source, float teamsay, entity privatesay, string msgin)
+{
+ float domatch, dotrigger, matchstart, l;
+ string s;
+ entity oldself;
+
+ magicear_matched = FALSE;
+
+ dotrigger = ((self.classname == "player") && ((ear.radius == 0) || (vlen(source.origin - ear.origin) <= ear.radius)));
+ domatch = ((ear.spawnflags & 32) || dotrigger);
+ if not(domatch)
+ return msgin;
+
+ if(privatesay)
+ {
+ if(ear.spawnflags & 4)
+ return msgin;
+ }
+ else
+ {
+ if(!teamsay)
+ if(ear.spawnflags & 1)
+ return msgin;
+ if(teamsay > 0)
+ if(ear.spawnflags & 2)
+ return msgin;
+ if(teamsay < 0)
+ if(ear.spawnflags & 8)
+ return msgin;
+ }
+
+ matchstart = -1;
+ l = strlen(ear.message);
+
+ if(substring(ear.message, 0, 1) == "*")
+ {
+ if(substring(ear.message, -1, 1) == "*")
+ {
+ // two wildcards
+ // as we need multi-replacement here...
+ s = substring(ear.message, 1, -2);
+ l -= 2;
+ if(strstrofs(msgin, s, 0) >= 0)
+ matchstart = -2; // we use strreplace on s
+ }
+ else
+ {
+ // match at start
+ s = substring(ear.message, 1, -1);
+ l -= 1;
+ if(substring(msgin, -l, l) == s)
+ matchstart = strlen(msgin) - l;
+ }
+ }
+ else
+ {
+ if(substring(ear.message, -1, 1) == "*")
+ {
+ // match at end
+ s = substring(ear.message, 0, -2);
+ l -= 1;
+ if(substring(msgin, 0, l) == s)
+ matchstart = 0;
+ }
+ else
+ {
+ // full match
+ s = ear.message;
+ if(msgin == ear.message)
+ matchstart = 0;
+ }
+ }
+
+ if(matchstart == -1) // no match
+ return msgin;
+
+ magicear_matched = TRUE;
+
+ if(dotrigger)
+ {
+ oldself = activator = self;
+ self = ear;
+ SUB_UseTargets();
+ self = oldself;
+ }
+
+ if(ear.spawnflags & 16)
+ {
+ return ear.netname;
+ }
+ else if(ear.netname != "")
+ {
+ if(matchstart < 0)
+ return strreplace(s, ear.netname, msgin);
+ else
+ return strcat(
+ substring(msgin, 0, matchstart),
+ ear.netname,
+ substring(msgin, matchstart + l, -1)
+ );
+ }
+ else
+ return msgin;
+}
+
+entity magicears;
+string trigger_magicear_processmessage_forallears(entity source, float teamsay, entity privatesay, string msgin)
+{
+ entity ear;
+ string msgout;
+ for(ear = magicears; ear; ear = ear.enemy)
+ {
+ msgout = trigger_magicear_processmessage(ear, source, teamsay, privatesay, msgin);
+ if not(ear.spawnflags & 64)
+ if(magicear_matched)
+ return msgout;
+ msgin = msgout;
+ }
+ return msgin;
+}
+
+void spawnfunc_trigger_magicear()
+{
+ self.enemy = magicears;
+ magicears = self;
+
+ // actually handled in "say" processing
+ // spawnflags:
+ // 1 = ignore say
+ // 2 = ignore teamsay
+ // 4 = ignore tell
+ // 8 = ignore tell to unknown player
+ // 16 = let netname replace the whole message (otherwise, netname is a word replacement if set)
+ // 32 = perform the replacement even if outside the radius
+ // 64 = continue replacing/triggering even if this one matched
+ // message: either
+ // *pattern*
+ // or
+ // *pattern
+ // or
+ // pattern*
+ // or
+ // pattern
+ // netname:
+ // if set, replacement for the matched text
+ // radius:
+ // "hearing distance"
+ // target:
+ // what to trigger
+}
Modified: trunk/data/qcsrc/server/miscfunctions.qc
===================================================================
--- trunk/data/qcsrc/server/miscfunctions.qc 2009-08-27 14:53:56 UTC (rev 7545)
+++ trunk/data/qcsrc/server/miscfunctions.qc 2009-08-28 05:49:35 UTC (rev 7546)
@@ -2421,14 +2421,12 @@
s = argv(idx);
++idx;
}
+ ParseCommandPlayerSlotTarget_firsttoken = idx;
if (s == ftos(stof(s)))
{
e = edict_num(stof(s));
if (e.flags & FL_CLIENT)
- {
- ParseCommandPlayerSlotTarget_firsttoken = idx;
return e;
- }
}
}
else
@@ -2436,6 +2434,7 @@
// it must be a nick name
s = argv(idx);
++idx;
+ ParseCommandPlayerSlotTarget_firsttoken = idx;
n = 0;
FOR_EACH_CLIENT(head)
@@ -2445,10 +2444,7 @@
++n;
}
if (n == 1)
- {
- ParseCommandPlayerSlotTarget_firsttoken = idx;
return e;
- }
s = strdecolorize(s);
n = 0;
@@ -2459,10 +2455,7 @@
++n;
}
if (n == 1)
- {
- ParseCommandPlayerSlotTarget_firsttoken = idx;
return e;
- }
}
}
Modified: trunk/data/scripts/entities.def
===================================================================
--- trunk/data/scripts/entities.def 2009-08-27 14:53:56 UTC (rev 7545)
+++ trunk/data/scripts/entities.def 2009-08-28 05:49:35 UTC (rev 7546)
@@ -1709,3 +1709,23 @@
-------- MODEL FOR RADIANT ONLY - DO NOT SET THIS AS A KEY --------
model="models/items/g_jetpack.md3"
*/
+
+/*QUAKED trigger_magicear (0 0 1) (-8 -8 -8) (8 8 8) IGNORE_SAY IGNORE_TEAMSAY IGNORE_TELL IGNORE_INVALIDTELL REPLACE_WHOLE_MESSAGE REPLACE_OUTSIDE CONTINUE
+Triggers targets when a given magic word has been said
+-------- KEYS --------
+message: message to wait for (can start or end with * for wildcards)
+netname: replacement text (by default, no replacement is performed if empty)
+radius: radius in which the player has to be for this to match
+target: all entities with a matching targetname will be triggered.
+target2: all entities with a matching targetname will be triggered.
+target3: all entities with a matching targetname will be triggered.
+target4: all entities with a matching targetname will be triggered.
+-------- SPAWNFLAGS --------
+IGNORE_SAY: do not respond to "say" messages
+IGNORE_TEAMSAY: do not respond to "say_team" messages
+IGNORE_TELL: do not respond to "tell" messages
+IGNORE_INVALIDTELL: do not respond to "tell" messages of invalid syntax
+REPLACE_WHOLE_MESSAGE: replace the whole message by netname, or drop the message if netname is empty
+REPLACE_OUTSIDE: also perform the replacement when outside the radius (to hide the "secret word")
+CONTINUE: even if this magic ear matched, continue looking for further matches/replacements (useful for swear word filters)
+*/
More information about the nexuiz-commits
mailing list