5 #define _SSMAGIX "SUPERSPEC_OPTIONSFILE_V1"
6 #define _ISLOCAL ((edict_num(1) == self) ? true : false)
8 const float ASF_STRENGTH = 1;
9 const float ASF_SHIELD = 2;
10 const float ASF_MEGA_AR = 4;
11 const float ASF_MEGA_HP = 8;
12 const float ASF_FLAG_GRAB = 16;
13 const float ASF_OBSERVER_ONLY = 32;
14 const float ASF_SHOWWHAT = 64;
15 const float ASF_SSIM = 128;
16 const float ASF_FOLLOWKILLER = 256;
17 const float ASF_ALL = 0xFFFFFF;
18 .float autospec_flags;
20 const float SSF_SILENT = 1;
21 const float SSF_VERBOSE = 2;
22 const float SSF_ITEMMSG = 4;
23 .float superspec_flags;
25 .string superspec_itemfilter; //"classname1 classname2 ..."
27 float _spectate(entity _player)
29 if(Spectate(_player) == 1)
30 self.classname = "spectator";
35 void superspec_save_client_conf()
37 string fn = "superspec-local.options";
42 if(self.crypto_idfp == "")
45 fn = sprintf("superspec-%s.options", uri_escape(self.crypto_idfp));
48 fh = fopen(fn, FILE_WRITE);
51 dprint("^1ERROR: ^7 superspec can not open ", fn, " for writing.\n");
57 fputs(fh, ftos(self.autospec_flags));
59 fputs(fh, ftos(self.superspec_flags));
61 fputs(fh, self.superspec_itemfilter);
67 void superspec_msg(string _center_title, string _con_title, entity _to, string _msg, float _spamlevel)
69 sprint(_to, strcat(_con_title, _msg));
71 if(_to.superspec_flags & SSF_SILENT)
75 if (!(_to.superspec_flags & SSF_VERBOSE))
78 centerprint(_to, strcat(_center_title, _msg));
81 float superspec_filteritem(entity _for, entity _item)
85 if(_for.superspec_itemfilter == "")
88 if(_for.superspec_itemfilter == "")
91 float l = tokenize_console(_for.superspec_itemfilter);
92 for(i = 0; i < l; ++i)
94 if(argv(i) == _item.classname)
101 MUTATOR_HOOKFUNCTION(superspec_ItemTouch)
103 entity _oldself = self;
108 if(self.superspec_flags & SSF_ITEMMSG)
109 if(superspec_filteritem(self, _item))
111 if(self.superspec_flags & SSF_VERBOSE)
112 superspec_msg("", "", self, sprintf("Player %s^7 just picked up ^3%s\n", other.netname, _item.netname), 1);
114 superspec_msg("", "", self, sprintf("Player %s^7 just picked up ^3%s\n^8(%s^8)\n", other.netname, _item.netname, _item.classname), 1);
115 if((self.autospec_flags & ASF_SSIM) && self.enemy != other)
120 return MUT_ITEMTOUCH_CONTINUE;
124 if((self.autospec_flags & ASF_SHIELD && _item.invincible_finished) ||
125 (self.autospec_flags & ASF_STRENGTH && _item.strength_finished) ||
126 (self.autospec_flags & ASF_MEGA_AR && _item.itemdef == ITEM_ArmorLarge) ||
127 (self.autospec_flags & ASF_MEGA_HP && _item.itemdef == ITEM_HealthMega) ||
128 (self.autospec_flags & ASF_FLAG_GRAB && _item.classname == "item_flag_team"))
131 if((self.enemy != other) || IS_OBSERVER(self))
133 if(self.autospec_flags & ASF_OBSERVER_ONLY && !IS_OBSERVER(self))
135 if(self.superspec_flags & SSF_VERBOSE)
136 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);
140 if(self.autospec_flags & ASF_SHOWWHAT)
141 superspec_msg("", "", self, sprintf("^7Following %s^7 due to picking up %s\n", other.netname, _item.netname), 2);
151 return MUT_ITEMTOUCH_CONTINUE;
154 MUTATOR_HOOKFUNCTION(superspec_SV_ParseClientCommand)
156 #define OPTIONINFO(flag,var,test,text,long,short) \
157 var = strcat(var, ((flag & test) ? "^2[ON] ^7" : "^1[OFF] ^7")); \
158 var = strcat(var, text," ^7(^3 ", long, "^7 | ^3", short, " ^7)\n")
160 if(MUTATOR_RETURNVALUE) // command was already handled?
166 if(cmd_name == "superspec_itemfilter")
168 if(argv(1) == "help")
171 _aspeco = "^7 superspec_itemfilter ^3\"item_classname1 item_classname2\"^7 only show thise items when ^2superspec ^3item_message^7 is on\n";
172 _aspeco = strcat(_aspeco, "^3 clear^7 Remove the filter (show all pickups)\n");
173 _aspeco = strcat(_aspeco, "^3 show ^7 Display current filter\n");
174 superspec_msg("^3superspec_itemfilter help:\n\n\n", "\n^3superspec_itemfilter help:\n", self, _aspeco, 1);
176 else if(argv(1) == "clear")
178 if(self.superspec_itemfilter != "")
179 strunzone(self.superspec_itemfilter);
181 self.superspec_itemfilter = "";
183 else if(argv(1) == "show" || argv(1) == "")
185 if(self.superspec_itemfilter == "")
187 superspec_msg("^3superspec_itemfilter^7 is ^1not^7 set", "\n^3superspec_itemfilter^7 is ^1not^7 set\n", self, "", 1);
191 float l = tokenize_console(self.superspec_itemfilter);
193 for(i = 0; i < l; ++i)
194 _msg = strcat(_msg, "^3#", ftos(i), " ^7", argv(i), "\n");
195 //_msg = sprintf("^3#%d^7 %s\n%s", i, _msg, argv(i));
197 _msg = strcat(_msg,"\n");
199 superspec_msg("^3superspec_itemfilter is:\n\n\n", "\n^3superspec_itemfilter is:\n", self, _msg, 1);
203 if(self.superspec_itemfilter != "")
204 strunzone(self.superspec_itemfilter);
206 self.superspec_itemfilter = strzone(argv(1));
212 if(cmd_name == "superspec")
218 float i, _bits = 0, _start = 1;
219 if(argv(1) == "help")
221 _aspeco = "use cmd superspec [option] [on|off] to set options\n\n";
222 _aspeco = strcat(_aspeco, "^3 silent ^7(short^5 si^7) supresses ALL messages from superspectate.\n");
223 _aspeco = strcat(_aspeco, "^3 verbose ^7(short^5 ve^7) makes superspectate print some additional information.\n");
224 _aspeco = strcat(_aspeco, "^3 item_message ^7(short^5 im^7) makes superspectate print items that were picked up.\n");
225 _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");
226 superspec_msg("^2Available Super Spectate ^3options:\n\n\n", "\n^2Available Super Spectate ^3options:\n", self, _aspeco, 1);
230 if(argv(1) == "clear")
232 self.superspec_flags = 0;
236 for(i = _start; i < cmd_argc; ++i)
238 if(argv(i) == "on" || argv(i) == "1")
240 self.superspec_flags |= _bits;
243 else if(argv(i) == "off" || argv(i) == "0")
246 self.superspec_flags &= ~_bits;
252 if((argv(i) == "silent") || (argv(i) == "si")) _bits |= SSF_SILENT ;
253 if((argv(i) == "verbose") || (argv(i) == "ve")) _bits |= SSF_VERBOSE;
254 if((argv(i) == "item_message") || (argv(i) == "im")) _bits |= SSF_ITEMMSG;
260 OPTIONINFO(self.superspec_flags, _aspeco, SSF_SILENT, "Silent", "silent", "si");
261 OPTIONINFO(self.superspec_flags, _aspeco, SSF_VERBOSE, "Verbose", "verbose", "ve");
262 OPTIONINFO(self.superspec_flags, _aspeco, SSF_ITEMMSG, "Item pickup messages", "item_message", "im");
264 superspec_msg("^3Current Super Spectate options are:\n\n\n\n\n", "\n^3Current Super Spectate options are:\n", self, _aspeco, 1);
269 /////////////////////
271 if(cmd_name == "autospec")
276 if(argv(1) == "help")
278 _aspeco = "use cmd autospec [option] [on|off] to set options\n\n";
279 _aspeco = strcat(_aspeco, "^3 strength ^7(short^5 st^7) for automatic spectate on strength powerup\n");
280 _aspeco = strcat(_aspeco, "^3 shield ^7(short^5 sh^7) for automatic spectate on shield powerup\n");
281 _aspeco = strcat(_aspeco, "^3 mega_health ^7(short^5 mh^7) for automatic spectate on mega health\n");
282 _aspeco = strcat(_aspeco, "^3 mega_armor ^7(short^5 ma^7) for automatic spectate on mega armor\n");
283 _aspeco = strcat(_aspeco, "^3 flag_grab ^7(short^5 fg^7) for automatic spectate on CTF flag grab\n");
284 _aspeco = strcat(_aspeco, "^3 observer_only ^7(short^5 oo^7) for automatic spectate only if in observer mode\n");
285 _aspeco = strcat(_aspeco, "^3 show_what ^7(short^5 sw^7) to display what event triggered autospectate\n");
286 _aspeco = strcat(_aspeco, "^3 item_msg ^7(short^5 im^7) to autospec when item_message in superspectate is triggered\n");
287 _aspeco = strcat(_aspeco, "^3 followkiller ^7(short ^5fk^7) to autospec the killer/off\n");
288 _aspeco = strcat(_aspeco, "^3 all ^7(short ^5aa^7) to turn everything on/off\n");
289 superspec_msg("^2Available Auto Spectate ^3options:\n\n\n", "\n^2Available Auto Spectate ^3options:\n", self, _aspeco, 1);
293 float i, _bits = 0, _start = 1;
294 if(argv(1) == "clear")
296 self.autospec_flags = 0;
300 for(i = _start; i < cmd_argc; ++i)
302 if(argv(i) == "on" || argv(i) == "1")
304 self.autospec_flags |= _bits;
307 else if(argv(i) == "off" || argv(i) == "0")
310 self.autospec_flags &= ~_bits;
316 if((argv(i) == "strength") || (argv(i) == "st")) _bits |= ASF_STRENGTH;
317 if((argv(i) == "shield") || (argv(i) == "sh")) _bits |= ASF_SHIELD;
318 if((argv(i) == "mega_health") || (argv(i) == "mh")) _bits |= ASF_MEGA_HP;
319 if((argv(i) == "mega_armor") || (argv(i) == "ma")) _bits |= ASF_MEGA_AR;
320 if((argv(i) == "flag_grab") || (argv(i) == "fg")) _bits |= ASF_FLAG_GRAB;
321 if((argv(i) == "observer_only") || (argv(i) == "oo")) _bits |= ASF_OBSERVER_ONLY;
322 if((argv(i) == "show_what") || (argv(i) == "sw")) _bits |= ASF_SHOWWHAT;
323 if((argv(i) == "item_msg") || (argv(i) == "im")) _bits |= ASF_SSIM;
324 if((argv(i) == "followkiller") || (argv(i) == "fk")) _bits |= ASF_FOLLOWKILLER;
325 if((argv(i) == "all") || (argv(i) == "aa")) _bits |= ASF_ALL;
331 OPTIONINFO(self.autospec_flags, _aspeco, ASF_STRENGTH, "Strength", "strength", "st");
332 OPTIONINFO(self.autospec_flags, _aspeco, ASF_SHIELD, "Shield", "shield", "sh");
333 OPTIONINFO(self.autospec_flags, _aspeco, ASF_MEGA_HP, "Mega Health", "mega_health", "mh");
334 OPTIONINFO(self.autospec_flags, _aspeco, ASF_MEGA_AR, "Mega Armor", "mega_armor", "ma");
335 OPTIONINFO(self.autospec_flags, _aspeco, ASF_FLAG_GRAB, "Flag grab", "flag_grab","fg");
336 OPTIONINFO(self.autospec_flags, _aspeco, ASF_OBSERVER_ONLY, "Only switch if observer", "observer_only", "oo");
337 OPTIONINFO(self.autospec_flags, _aspeco, ASF_SHOWWHAT, "Show what item triggered spectate", "show_what", "sw");
338 OPTIONINFO(self.autospec_flags, _aspeco, ASF_SSIM, "Switch on superspec item message", "item_msg", "im");
339 OPTIONINFO(self.autospec_flags, _aspeco, ASF_FOLLOWKILLER, "Followkiller", "followkiller", "fk");
341 superspec_msg("^3Current auto spectate options are:\n\n\n\n\n", "\n^3Current auto spectate options are:\n", self, _aspeco, 1);
345 if(cmd_name == "followpowerup")
348 FOR_EACH_PLAYER(_player)
350 if(_player.strength_finished > time || _player.invincible_finished > time)
351 return _spectate(_player);
354 superspec_msg("", "", self, "No active powerup\n", 1);
358 if(cmd_name == "followstrength")
361 FOR_EACH_PLAYER(_player)
363 if(_player.strength_finished > time)
364 return _spectate(_player);
367 superspec_msg("", "", self, "No active Strength\n", 1);
371 if(cmd_name == "followshield")
374 FOR_EACH_PLAYER(_player)
376 if(_player.invincible_finished > time)
377 return _spectate(_player);
380 superspec_msg("", "", self, "No active Shield\n", 1);
384 if(cmd_name == "followfc")
401 FOR_EACH_PLAYER(_player)
403 if(_player.flagcarried && (_player.team == _team || _team == 0))
406 if(_team == 0 && IS_SPEC(self) && self.enemy == _player)
407 continue; // already spectating a fc, try to find the other fc
408 return _spectate(_player);
413 superspec_msg("", "", self, "No active flag carrier\n", 1);
421 MUTATOR_HOOKFUNCTION(superspec_BuildMutatorsString)
423 ret_string = strcat(ret_string, ":SS");
427 MUTATOR_HOOKFUNCTION(superspec_BuildMutatorsPrettyString)
429 ret_string = strcat(ret_string, ", Super Spectators");
433 void superspec_hello()
435 if(self.enemy.crypto_idfp == "")
436 Send_Notification(NOTIF_ONE_ONLY, self.enemy, MSG_INFO, INFO_SUPERSPEC_MISSING_UID);
441 MUTATOR_HOOKFUNCTION(superspec_ClientConnect)
443 if(!IS_REAL_CLIENT(self))
446 string fn = "superspec-local.options";
449 self.superspec_flags = SSF_VERBOSE;
450 self.superspec_itemfilter = "";
452 entity _hello = spawn();
454 _hello.think = superspec_hello;
455 _hello.nextthink = time + 5;
459 if(self.crypto_idfp == "")
462 fn = sprintf("superspec-%s.options", uri_escape(self.crypto_idfp));
465 fh = fopen(fn, FILE_READ);
468 dprint("^1ERROR: ^7 superspec can not open ", fn, " for reading.\n");
472 string _magic = fgets(fh);
473 if(_magic != _SSMAGIX)
475 dprint("^1ERROR^7 While reading superspec options file: unknown magic\n");
479 self.autospec_flags = stof(fgets(fh));
480 self.superspec_flags = stof(fgets(fh));
481 self.superspec_itemfilter = strzone(fgets(fh));
489 MUTATOR_HOOKFUNCTION(superspec_PlayerDies)
491 entity _old_self = self;
495 if(self.autospec_flags & ASF_FOLLOWKILLER && IS_PLAYER(frag_attacker) && self.enemy == _old_self)
497 if(self.autospec_flags & ASF_SHOWWHAT)
498 superspec_msg("", "", self, sprintf("^7Following %s^7 due to followkiller\n", frag_attacker.netname), 2);
500 _spectate(frag_attacker);
508 MUTATOR_HOOKFUNCTION(superspec_ClientDisconnect)
510 superspec_save_client_conf();
514 MUTATOR_DEFINITION(mutator_superspec)
517 MUTATOR_HOOK(BuildMutatorsString, superspec_BuildMutatorsString, CBC_ORDER_ANY);
518 MUTATOR_HOOK(BuildMutatorsPrettyString, superspec_BuildMutatorsPrettyString, CBC_ORDER_ANY);
519 MUTATOR_HOOK(SV_ParseClientCommand, superspec_SV_ParseClientCommand, CBC_ORDER_ANY);
520 MUTATOR_HOOK(ItemTouch, superspec_ItemTouch, CBC_ORDER_ANY);
521 MUTATOR_HOOK(ClientConnect, superspec_ClientConnect, CBC_ORDER_ANY);
522 MUTATOR_HOOK(ClientDisconnect, superspec_ClientDisconnect, CBC_ORDER_ANY);
523 MUTATOR_HOOK(PlayerDies, superspec_PlayerDies, CBC_ORDER_ANY);