1 #define _SSMAGIX "SUPERSPEC_OPTIONSFILE_V1"
2 #define _ISLOCAL ((edict_num(1) == self) ? TRUE : FALSE)
8 #define ASF_FLAG_GRAB 16
9 #define ASF_OBSERVER_ONLY 32
10 #define ASF_SHOWWHAT 64
12 #define ASF_FOLLOWKILLER 256
13 #define ASF_ALL 0xFFFFFF
14 .float autospec_flags;
19 .float superspec_flags;
21 .string superspec_itemfilter; //"classname1 classname2 ..."
23 float _spectate(entity _player)
25 if(Spectate(_player) == 1)
26 self.classname = "spectator";
31 void superspec_save_client_conf()
33 string fn = "superspec-local.options";
38 if(self.crypto_idfp == "")
41 fn = sprintf("superspec-%s.options", uri_escape(self.crypto_idfp));
44 fh = fopen(fn, FILE_WRITE);
47 dprint("^1ERROR: ^7 superspec can not open ", fn, " for writing.\n");
53 fputs(fh, ftos(self.autospec_flags));
55 fputs(fh, ftos(self.superspec_flags));
57 fputs(fh, self.superspec_itemfilter);
63 void superspec_msg(string _center_title, string _con_title, entity _to, string _msg, float _spamlevel)
65 sprint(_to, strcat(_con_title, _msg));
67 if(_to.superspec_flags & SSF_SILENT)
71 if (!(_to.superspec_flags & SSF_VERBOSE))
74 centerprint(_to, strcat(_center_title, _msg));
77 float superspec_filteritem(entity _for, entity _item)
81 if(_for.superspec_itemfilter == "")
84 if(_for.superspec_itemfilter == "")
87 float l = tokenize_console(_for.superspec_itemfilter);
88 for(i = 0; i < l; ++i)
90 if(argv(i) == _item.classname)
97 MUTATOR_HOOKFUNCTION(superspec_ItemTouch)
99 entity _oldself = self;
104 if(self.superspec_flags & SSF_ITEMMSG)
105 if(superspec_filteritem(self, _item))
107 if(self.superspec_flags & SSF_VERBOSE)
108 superspec_msg("", "", self, sprintf("Player %s^7 just picked up ^3%s\n", other.netname, _item.netname), 1);
110 superspec_msg("", "", self, sprintf("Player %s^7 just picked up ^3%s\n^8(%s^8)\n", other.netname, _item.netname, _item.classname), 1);
111 if((self.autospec_flags & ASF_SSIM) && self.enemy != other)
116 return MUT_ITEMTOUCH_CONTINUE;
120 if((self.autospec_flags & ASF_SHIELD && _item.invincible_finished) ||
121 (self.autospec_flags & ASF_STRENGTH && _item.strength_finished) ||
122 (self.autospec_flags & ASF_MEGA_AR && _item.classname == "item_armor_large") ||
123 (self.autospec_flags & ASF_MEGA_HP && _item.classname == "item_health_mega") ||
124 (self.autospec_flags & ASF_FLAG_GRAB && _item.classname == "item_flag_team"))
127 if((self.enemy != other) || IS_OBSERVER(self))
129 if(self.autospec_flags & ASF_OBSERVER_ONLY && !IS_OBSERVER(self))
131 if(self.superspec_flags & SSF_VERBOSE)
132 superspec_msg("", "", self, sprintf("^8Ignored that ^7%s^8 grabbed %s^8 since the observer_only option is ON\n", other.netname, _item.netname), 2);
136 if(self.autospec_flags & ASF_SHOWWHAT)
137 superspec_msg("", "", self, sprintf("^7Following %s^7 due to picking up %s\n", other.netname, _item.netname), 2);
147 return MUT_ITEMTOUCH_CONTINUE;
150 MUTATOR_HOOKFUNCTION(superspec_SV_ParseClientCommand)
152 #define OPTIONINFO(flag,var,test,text,long,short) \
153 var = strcat(var, ((flag & test) ? "^2[ON] ^7" : "^1[OFF] ^7")); \
154 var = strcat(var, text," ^7(^3 ", long, "^7 | ^3", short, " ^7)\n")
156 if(MUTATOR_RETURNVALUE) // command was already handled?
162 if(cmd_name == "superspec_itemfilter")
164 if(argv(1) == "help")
167 _aspeco = "^7 superspec_itemfilter ^3\"item_classname1 item_classname2\"^7 only show thise items when ^2superspec ^3item_message^7 is on\n";
168 _aspeco = strcat(_aspeco, "^3 clear^7 Remove the filter (show all pickups)\n");
169 _aspeco = strcat(_aspeco, "^3 show ^7 Display current filter\n");
170 superspec_msg("^3superspec_itemfilter help:\n\n\n", "\n^3superspec_itemfilter help:\n", self, _aspeco, 1);
172 else if(argv(1) == "clear")
174 if(self.superspec_itemfilter != "")
175 strunzone(self.superspec_itemfilter);
177 self.superspec_itemfilter = "";
179 else if(argv(1) == "show" || argv(1) == "")
181 if(self.superspec_itemfilter == "")
183 superspec_msg("^3superspec_itemfilter^7 is ^1not^7 set", "\n^3superspec_itemfilter^7 is ^1not^7 set\n", self, "", 1);
187 float l = tokenize_console(self.superspec_itemfilter);
189 for(i = 0; i < l; ++i)
190 _msg = strcat(_msg, "^3#", ftos(i), " ^7", argv(i), "\n");
191 //_msg = sprintf("^3#%d^7 %s\n%s", i, _msg, argv(i));
193 _msg = strcat(_msg,"\n");
195 superspec_msg("^3superspec_itemfilter is:\n\n\n", "\n^3superspec_itemfilter is:\n", self, _msg, 1);
199 if(self.superspec_itemfilter != "")
200 strunzone(self.superspec_itemfilter);
202 self.superspec_itemfilter = strzone(argv(1));
208 if(cmd_name == "superspec")
214 float i, _bits = 0, _start = 1;
215 if(argv(1) == "help")
217 _aspeco = "use cmd superspec [option] [on|off] to set options\n\n";
218 _aspeco = strcat(_aspeco, "^3 silent ^7(short^5 si^7) supresses ALL messages from superspectate.\n");
219 _aspeco = strcat(_aspeco, "^3 verbose ^7(short^5 ve^7) makes superspectate print some additional information.\n");
220 _aspeco = strcat(_aspeco, "^3 item_message ^7(short^5 im^7) makes superspectate print items that were picked up.\n");
221 _aspeco = strcat(_aspeco, "^7 Use cmd superspec_itemfilter \"item_class1 item_class2\" to set up a filter of what to show with ^3item_message.\n");
222 superspec_msg("^2Available Super Spectate ^3options:\n\n\n", "\n^2Available Super Spectate ^3options:\n", self, _aspeco, 1);
226 if(argv(1) == "clear")
228 self.superspec_flags = 0;
232 for(i = _start; i < cmd_argc; ++i)
234 if(argv(i) == "on" || argv(i) == "1")
236 self.superspec_flags |= _bits;
239 else if(argv(i) == "off" || argv(i) == "0")
242 self.superspec_flags &= ~_bits;
248 if((argv(i) == "silent") || (argv(i) == "si")) _bits |= SSF_SILENT ;
249 if((argv(i) == "verbose") || (argv(i) == "ve")) _bits |= SSF_VERBOSE;
250 if((argv(i) == "item_message") || (argv(i) == "im")) _bits |= SSF_ITEMMSG;
256 OPTIONINFO(self.superspec_flags, _aspeco, SSF_SILENT, "Silent", "silent", "si");
257 OPTIONINFO(self.superspec_flags, _aspeco, SSF_VERBOSE, "Verbose", "verbose", "ve");
258 OPTIONINFO(self.superspec_flags, _aspeco, SSF_ITEMMSG, "Item pickup messages", "item_message", "im");
260 superspec_msg("^3Current Super Spectate options are:\n\n\n\n\n", "\n^3Current Super Spectate options are:\n", self, _aspeco, 1);
265 /////////////////////
267 if(cmd_name == "autospec")
272 if(argv(1) == "help")
274 _aspeco = "use cmd autospec [option] [on|off] to set options\n\n";
275 _aspeco = strcat(_aspeco, "^3 strength ^7(short^5 st^7) for automatic spectate on strength powerup\n");
276 _aspeco = strcat(_aspeco, "^3 shield ^7(short^5 sh^7) for automatic spectate on shield powerup\n");
277 _aspeco = strcat(_aspeco, "^3 mega_health ^7(short^5 mh^7) for automatic spectate on mega health\n");
278 _aspeco = strcat(_aspeco, "^3 mega_armor ^7(short^5 ma^7) for automatic spectate on mega armor\n");
279 _aspeco = strcat(_aspeco, "^3 flag_grab ^7(short^5 fg^7) for automatic spectate on CTF flag grab\n");
280 _aspeco = strcat(_aspeco, "^3 observer_only ^7(short^5 oo^7) for automatic spectate only if in observer mode\n");
281 _aspeco = strcat(_aspeco, "^3 show_what ^7(short^5 sw^7) to display what event triggered autospectate\n");
282 _aspeco = strcat(_aspeco, "^3 item_msg ^7(short^5 im^7) to autospec when item_message in superspectate is triggered\n");
283 _aspeco = strcat(_aspeco, "^3 followkiller ^7(short ^5fk^7) to autospec the killer/off\n");
284 _aspeco = strcat(_aspeco, "^3 all ^7(short ^5aa^7) to turn everything on/off\n");
285 superspec_msg("^2Available Auto Spectate ^3options:\n\n\n", "\n^2Available Auto Spectate ^3options:\n", self, _aspeco, 1);
289 float i, _bits = 0, _start = 1;
290 if(argv(1) == "clear")
292 self.autospec_flags = 0;
296 for(i = _start; i < cmd_argc; ++i)
298 if(argv(i) == "on" || argv(i) == "1")
300 self.autospec_flags |= _bits;
303 else if(argv(i) == "off" || argv(i) == "0")
306 self.autospec_flags &= ~_bits;
312 if((argv(i) == "strength") || (argv(i) == "st")) _bits |= ASF_STRENGTH;
313 if((argv(i) == "shield") || (argv(i) == "sh")) _bits |= ASF_SHIELD;
314 if((argv(i) == "mega_health") || (argv(i) == "mh")) _bits |= ASF_MEGA_HP;
315 if((argv(i) == "mega_armor") || (argv(i) == "ma")) _bits |= ASF_MEGA_AR;
316 if((argv(i) == "flag_grab") || (argv(i) == "fg")) _bits |= ASF_FLAG_GRAB;
317 if((argv(i) == "observer_only") || (argv(i) == "oo")) _bits |= ASF_OBSERVER_ONLY;
318 if((argv(i) == "show_what") || (argv(i) == "sw")) _bits |= ASF_SHOWWHAT;
319 if((argv(i) == "item_msg") || (argv(i) == "im")) _bits |= ASF_SSIM;
320 if((argv(i) == "followkiller") || (argv(i) == "fk")) _bits |= ASF_FOLLOWKILLER;
321 if((argv(i) == "all") || (argv(i) == "aa")) _bits |= ASF_ALL;
327 OPTIONINFO(self.autospec_flags, _aspeco, ASF_STRENGTH, "Strength", "strength", "st");
328 OPTIONINFO(self.autospec_flags, _aspeco, ASF_SHIELD, "Shield", "shield", "sh");
329 OPTIONINFO(self.autospec_flags, _aspeco, ASF_MEGA_HP, "Mega Health", "mega_health", "mh");
330 OPTIONINFO(self.autospec_flags, _aspeco, ASF_MEGA_AR, "Mega Armor", "mega_armor", "ma");
331 OPTIONINFO(self.autospec_flags, _aspeco, ASF_FLAG_GRAB, "Flag grab", "flag_grab","fg");
332 OPTIONINFO(self.autospec_flags, _aspeco, ASF_OBSERVER_ONLY, "Only switch if observer", "observer_only", "oo");
333 OPTIONINFO(self.autospec_flags, _aspeco, ASF_SHOWWHAT, "Show what item triggered spectate", "show_what", "sw");
334 OPTIONINFO(self.autospec_flags, _aspeco, ASF_SSIM, "Switch on superspec item message", "item_msg", "im");
335 OPTIONINFO(self.autospec_flags, _aspeco, ASF_FOLLOWKILLER, "Followkiller", "followkiller", "fk");
337 superspec_msg("^3Current auto spectate options are:\n\n\n\n\n", "\n^3Current auto spectate options are:\n", self, _aspeco, 1);
341 if(cmd_name == "followpowerup")
344 FOR_EACH_PLAYER(_player)
346 if(_player.strength_finished > time || _player.invincible_finished > time)
347 return _spectate(_player);
350 superspec_msg("", "", self, "No active powerup\n", 1);
354 if(cmd_name == "followstrength")
357 FOR_EACH_PLAYER(_player)
359 if(_player.strength_finished > time)
360 return _spectate(_player);
363 superspec_msg("", "", self, "No active Strength\n", 1);
367 if(cmd_name == "followshield")
370 FOR_EACH_PLAYER(_player)
372 if(_player.invincible_finished > time)
373 return _spectate(_player);
376 superspec_msg("", "", self, "No active Shield\n", 1);
380 if(cmd_name == "followfc")
397 FOR_EACH_PLAYER(_player)
399 if(_player.flagcarried && (_player.team == _team || _team == 0))
402 if(_team == 0 && IS_SPEC(self) && self.enemy == _player)
403 continue; // already spectating a fc, try to find the other fc
404 return _spectate(_player);
409 superspec_msg("", "", self, "No active flag carrier\n", 1);
417 MUTATOR_HOOKFUNCTION(superspec_BuildMutatorsString)
419 ret_string = strcat(ret_string, ":SS");
423 MUTATOR_HOOKFUNCTION(superspec_BuildMutatorsPrettyString)
425 ret_string = strcat(ret_string, ", Super Spectators");
429 void superspec_hello()
431 if(self.enemy.crypto_idfp == "")
432 Send_Notification(NOTIF_ONE_ONLY, self.enemy, MSG_INFO, INFO_SUPERSPEC_MISSING_UID);
437 MUTATOR_HOOKFUNCTION(superspec_ClientConnect)
439 if(!IS_REAL_CLIENT(self))
442 string fn = "superspec-local.options";
445 self.superspec_flags = SSF_VERBOSE;
446 self.superspec_itemfilter = "";
448 entity _hello = spawn();
450 _hello.think = superspec_hello;
451 _hello.nextthink = time + 5;
455 if(self.crypto_idfp == "")
458 fn = sprintf("superspec-%s.options", uri_escape(self.crypto_idfp));
461 fh = fopen(fn, FILE_READ);
464 dprint("^1ERROR: ^7 superspec can not open ", fn, " for reading.\n");
468 string _magic = fgets(fh);
469 if(_magic != _SSMAGIX)
471 dprint("^1ERROR^7 While reading superspec options file: unknown magic\n");
475 self.autospec_flags = stof(fgets(fh));
476 self.superspec_flags = stof(fgets(fh));
477 self.superspec_itemfilter = strzone(fgets(fh));
485 MUTATOR_HOOKFUNCTION(superspec_PlayerDies)
487 entity _old_self = self;
491 if(self.autospec_flags & ASF_FOLLOWKILLER && IS_PLAYER(frag_attacker) && self.enemy == _old_self)
493 if(self.autospec_flags & ASF_SHOWWHAT)
494 superspec_msg("", "", self, sprintf("^7Following %s^7 due to followkiller\n", frag_attacker.netname), 2);
496 _spectate(frag_attacker);
504 MUTATOR_HOOKFUNCTION(superspec_ClientDisconnect)
506 superspec_save_client_conf();
510 MUTATOR_DEFINITION(mutator_superspec)
513 MUTATOR_HOOK(BuildMutatorsString, superspec_BuildMutatorsString, CBC_ORDER_ANY);
514 MUTATOR_HOOK(BuildMutatorsPrettyString, superspec_BuildMutatorsPrettyString, CBC_ORDER_ANY);
515 MUTATOR_HOOK(SV_ParseClientCommand, superspec_SV_ParseClientCommand, CBC_ORDER_ANY);
516 MUTATOR_HOOK(ItemTouch, superspec_ItemTouch, CBC_ORDER_ANY);
517 MUTATOR_HOOK(ClientConnect, superspec_ClientConnect, CBC_ORDER_ANY);
518 MUTATOR_HOOK(ClientDisconnect, superspec_ClientDisconnect, CBC_ORDER_ANY);
519 MUTATOR_HOOK(PlayerDies, superspec_PlayerDies, CBC_ORDER_ANY);