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_ALL 0xFFFFFF
13 .float autospec_flags;
18 .float superspec_flags;
20 .string superspec_itemfilter; //"classname1 classname2 ..."
22 float _spectate(entity _player)
24 if(SpectateNext(_player) == 1)
26 PutObserverInServer();
27 self.classname = "spectator";
33 void superspec_save_client_conf()
35 string fn = "superspec-local.options";
41 if(self.crypto_idfp == "")
44 fn = sprintf("superspec-%s.options", uri_escape(self.crypto_idfp));
47 fh = fopen(fn, FILE_WRITE);
50 dprint("^1ERROR: ^7 superspec can not open ", fn, " for writing.\n");
56 fputs(fh, ftos(self.autospec_flags));
58 fputs(fh, ftos(self.superspec_flags));
60 fputs(fh, self.superspec_itemfilter);
66 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 not(_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)
125 if((self.autospec_flags & ASF_SHIELD && _item.invincible_finished) ||
126 (self.autospec_flags & ASF_STRENGTH && _item.strength_finished) ||
127 (self.autospec_flags& ASF_MEGA_AR && _item.classname == "item_armor_large") ||
128 (self.autospec_flags& ASF_MEGA_HP && _item.classname == "item_health_mega") ||
129 (self.autospec_flags& ASF_FLAG_GRAB && _item.classname == "item_flag_team"))
132 if((self.enemy != other) || self.classname == "observer")
134 if(self.autospec_flags & ASF_OBSERVER_ONLY && self.classname != "observer")
136 if(self.superspec_flags & SSF_VERBOSE)
137 superspec_msg("", "", self, sprintf("^8Ignored that %s^8 grabbed %s^8 since the observer_only option is ON\n", other.netname, _item.netname), 2);
141 if(self.autospec_flags & ASF_SHOWWHAT)
142 superspec_msg("", "", self, sprintf("^7Following %s^7 due to picking up %s\n", other.netname, _item.netname), 2);
155 MUTATOR_HOOKFUNCTION(superspec_SV_ParseClientCommand)
157 #define OPTIONINFO(flag,var,test,text,long,short) \
158 var = strcat(var, ((flag & test) ? "^2[ON] ^7" : "^1[OFF] ^7")); \
159 var = strcat(var, text," ^7(^3 ", long, "^7 | ^3", short, " ^7)\n")
161 if(MUTATOR_RETURNVALUE) // command was already handled?
164 if(self.classname == "player")
167 if(cmd_name == "superspec_itemfilter")
169 if(argv(1) == "help")
172 _aspeco = "^7 superspec_itemfilter ^3\"item_classname1 item_classname2\"^7 only show thise items when ^2superspec ^3item_message^7 is on\n";
173 _aspeco = strcat(_aspeco, "^3 clear^7 Remove the filter (show all pickups)\n");
174 _aspeco = strcat(_aspeco, "^3 show ^7 Display current filter\n");
175 superspec_msg("^3superspec_itemfilter help:\n\n\n", "\n^3superspec_itemfilter help:\n", self, _aspeco, 1);
177 else if(argv(1) == "clear")
179 if(self.superspec_itemfilter != "")
180 strunzone(self.superspec_itemfilter);
182 self.superspec_itemfilter = "";
184 else if(argv(1) == "show" || argv(1) == "")
186 if(self.superspec_itemfilter == "")
188 superspec_msg("^3superspec_itemfilter^7 is ^1not^7 set", "\n^3superspec_itemfilter^7 is ^1not^7 set\n", self, "", 1);
192 float l = tokenize_console(self.superspec_itemfilter);
194 for(i = 0; i < l; ++i)
195 _msg = strcat(_msg, "^3#", ftos(i), " ^7", argv(i), "\n");
196 //_msg = sprintf("^3#%d^7 %s\n%s", i, _msg, argv(i));
198 _msg = strcat(_msg,"\n");
200 superspec_msg("^3superspec_itemfilter is:\n\n\n", "\n^3superspec_itemfilter is:\n", self, _msg, 1);
204 if(self.superspec_itemfilter != "")
205 strunzone(self.superspec_itemfilter);
207 self.superspec_itemfilter = strzone(argv(1));
214 if(cmd_name == "superspec")
220 float i, _bits = 0, _start = 1;
221 if(argv(1) == "help")
223 _aspeco = "use cmd superspec [option] [on|off] to set options\n\n";
224 _aspeco = strcat(_aspeco, "^3 silent ^7(short^5 si^7) supress ALL mesagess from superspectate.\n");
225 _aspeco = strcat(_aspeco, "^3 verrbose ^7(short^5 ve^7) makes superspectate print some additional information.\n");
226 _aspeco = strcat(_aspeco, "^3 item_message ^7(short^5 im^7) makes superspectate print items that was picked up.\n");
227 _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");
228 superspec_msg("^2Available Super Spectate ^3options:\n\n\n", "\n^2Available Super Spectate ^3options:\n", self, _aspeco, 1);
232 if(argv(1) == "clear")
234 self.superspec_flags = 0;
238 for(i = _start; i < cmd_argc; ++i)
240 if(argv(i) == "on" || argv(i) == "1")
242 self.superspec_flags |= _bits;
245 else if(argv(i) == "off" || argv(i) == "0")
248 self.superspec_flags &~= _bits;
254 if((argv(i) == "silent") || (argv(i) == "si")) _bits |= SSF_SILENT ;
255 if((argv(i) == "verbose") || (argv(i) == "ve")) _bits |= SSF_VERBOSE;
256 if((argv(i) == "item_message") || (argv(i) == "im")) _bits |= SSF_ITEMMSG;
263 OPTIONINFO(self.superspec_flags, _aspeco, SSF_SILENT, "Silent", "silent", "si");
264 OPTIONINFO(self.superspec_flags, _aspeco, SSF_VERBOSE, "Verbose", "verbose", "ve");
265 OPTIONINFO(self.superspec_flags, _aspeco, SSF_ITEMMSG, "Item pickup messages", "item_message", "im");
267 superspec_msg("^3Current Super Spectate options are:\n\n\n\n\n", "\n^3Current Super Spectate options are:\n", self, _aspeco, 1);
272 /////////////////////
274 if(cmd_name == "autospec")
279 if(argv(1) == "help")
281 _aspeco = "use cmd autospec [option] [on|off] to set options\n\n";
282 _aspeco = strcat(_aspeco, "^3 strength ^7(short^5 st^7) for automatic spectate on strength powerup\n");
283 _aspeco = strcat(_aspeco, "^3 shield ^7(short^5 sh^7) for automatic spectate on shield powerup\n");
284 _aspeco = strcat(_aspeco, "^3 mega_health ^7(short^5 mh^7) for automatic spectate on mega health\n");
285 _aspeco = strcat(_aspeco, "^3 mega_armor ^7(short^5 ma^7) for automatic spectate on mega armor\n");
286 _aspeco = strcat(_aspeco, "^3 flag_grab ^7(short^5 fg^7) for automatic spectate on CTF flag grab\n");
287 _aspeco = strcat(_aspeco, "^3 observer_only (short^5 oo^7) for automatic spectate only if in observer mode\n");
288 _aspeco = strcat(_aspeco, "^3 show_what (short^5 sw^7) to display what event triggerd autospectate\n");
289 _aspeco = strcat(_aspeco, "^3 item_msg ^7(short^5 im^7) to autospec when item_message in superspectate is triggerd\n");
290 _aspeco = strcat(_aspeco, "^3 all ^7(short ^5aa^7) turn everything on/off\n");
291 superspec_msg("^2Available Auto Spectate ^3options:\n\n\n", "\n^2Available Auto Spectate ^3options:\n", self, _aspeco, 1);
295 float i, _bits = 0, _start = 1;
296 if(argv(1) == "clear")
298 self.autospec_flags = 0;
302 for(i = _start; i < cmd_argc; ++i)
304 if(argv(i) == "on" || argv(i) == "1")
306 self.autospec_flags |= _bits;
309 else if(argv(i) == "off" || argv(i) == "0")
312 self.autospec_flags &~= _bits;
318 if((argv(i) == "strength") || (argv(i) == "st")) _bits |= ASF_STRENGTH;
319 if((argv(i) == "shield") || (argv(i) == "sh")) _bits |= ASF_SHIELD;
320 if((argv(i) == "mega_health") || (argv(i) == "mh")) _bits |= ASF_MEGA_HP;
321 if((argv(i) == "mega_armor") || (argv(i) == "ma")) _bits |= ASF_MEGA_AR;
322 if((argv(i) == "flag_grab") || (argv(i) == "fg")) _bits |= ASF_FLAG_GRAB;
323 if((argv(i) == "observer_only") || (argv(i) == "oo")) _bits |= ASF_OBSERVER_ONLY;
324 if((argv(i) == "show_what") || (argv(i) == "sw")) _bits |= ASF_SHOWWHAT;
325 if((argv(i) == "item_msg") || (argv(i) == "im")) _bits |= ASF_SSIM;
326 if((argv(i) == "all") || (argv(i) == "aa")) _bits |= ASF_ALL;
332 OPTIONINFO(self.autospec_flags, _aspeco, ASF_STRENGTH, "Strength", "strength", "st");
333 OPTIONINFO(self.autospec_flags, _aspeco, ASF_SHIELD, "Shield", "shield", "sh");
334 OPTIONINFO(self.autospec_flags, _aspeco, ASF_MEGA_HP, "Mega Health", "mega_health", "mh");
335 OPTIONINFO(self.autospec_flags, _aspeco, ASF_MEGA_AR, "Mega Armor", "mega_armor", "ma");
336 OPTIONINFO(self.autospec_flags, _aspeco, ASF_FLAG_GRAB, "Flag grab", "flag_grab","fg");
337 OPTIONINFO(self.autospec_flags, _aspeco, ASF_OBSERVER_ONLY, "Only switch if Observer", "observer_only", "oo");
338 OPTIONINFO(self.autospec_flags, _aspeco, ASF_SHOWWHAT, "Show what item triggered spectate", "show_what", "sw");
339 OPTIONINFO(self.autospec_flags, _aspeco, ASF_SSIM, "Switch on superspec item message", "item_msg", "im");
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 powerups\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 == "followstshield")
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")
400 FOR_EACH_PLAYER(_player)
402 if(_player.flagcarried && (_player.team == _team || _team == 0))
403 return _spectate(_player);
406 superspec_msg("", "", self, "No active flag carrier\n", 1);
414 MUTATOR_HOOKFUNCTION(superspec_BuildMutatorsString)
416 ret_string = strcat(ret_string, ":SS");
420 MUTATOR_HOOKFUNCTION(superspec_BuildMutatorsPrettyString)
422 ret_string = strcat(ret_string, ", Super Spectators");
427 MUTATOR_HOOKFUNCTION(superspec_PlayerSpawn)
434 void superspec_hello()
436 if(self.enemy.crypto_idfp == "")
437 centerprint(self.enemy, "Your client have/allow no crypto id, superspec options will not be saved/restored.");
439 centerprint(self.enemy, sprintf("Hello %s\nSince your client has a Crypto ID, your superspec preferenses will be presisted on this server.", self.enemy.netname));
444 MUTATOR_HOOKFUNCTION(superspec_ClientConnect)
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: unkown 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_ClientDisconnect)
491 superspec_save_client_conf();
497 MUTATOR_HOOKFUNCTION(superspec_MakePlayerObserver)
502 MUTATOR_HOOKFUNCTION(superspec_PlayerPreThink)
508 MUTATOR_DEFINITION(mutator_superspec)
511 MUTATOR_HOOK(BuildMutatorsString, superspec_BuildMutatorsString, CBC_ORDER_ANY);
512 MUTATOR_HOOK(BuildMutatorsPrettyString, superspec_BuildMutatorsPrettyString, CBC_ORDER_ANY);
513 MUTATOR_HOOK(SV_ParseClientCommand, superspec_SV_ParseClientCommand, CBC_ORDER_ANY);
514 MUTATOR_HOOK(ItemTouch, superspec_ItemTouch, CBC_ORDER_ANY);
515 MUTATOR_HOOK(ClientConnect, superspec_ClientConnect, CBC_ORDER_ANY);
516 //MUTATOR_HOOK(PlayerSpawn, superspec_PlayerSpawn, CBC_ORDER_ANY);
517 //MUTATOR_HOOK(PlayerPreThink, superspec_PlayerPreThink, CBC_ORDER_ANY);
518 //MUTATOR_HOOK(MakePlayerObserver, superspec_MakePlayerObserver, CBC_ORDER_ANY);
519 MUTATOR_HOOK(ClientDisconnect, superspec_ClientDisconnect, CBC_ORDER_ANY);