/*
************plugin_gather by Thor************
An edited version of Goku's teamswitch plugin
*********Dedicated to Thor's brother*********
 
***Version 1.0 - 11/23/02***
-First release
 
***Version 1.1 - 11/23/02***
-Instead of having more or less a  line of people, now a snowflake is made:
\|/
-o-
/|\
with people going in those eight directions until there are none left to place.
 
***Version 1.2 - 11/23/02***
-Added admin_gatherteam; self-expllanatory
 
***Version 1.3 - 11/24/02***
-Added admin_gatherotherteam; selff-explanatory
-Fixed a few bugs
 
***Version 1.4 - 11/25/02***
-Merged the commands; now admin_gaather 1|2|null will gather terrorists, counter-terrorists, and everybody.
-Fixed some bugs with admin_gatherr
-Fixed MAJOR bug with distances. NNow it should actually be a snowflake people get teleported into.
 
***Version 1.5 - 11/26/02***
-Added admin_gather "person"; I thhink it's wonid, name, or session id.
-Fixed another MAJOR bug with the  distances. Now gatherX and gatherY are actually set to X and Y at the beginning!
-Changed "admin_gather" to "admin__gather 0"
 
***Version 1.6 - 11/27/02***
-Fixed yet ANOTHER bug with the diistances. Now gatherX and gatherY are reset to X and Y after each ring is finished.
-"blah blah blah bug distances fixxed blah blah blah." Now the loop isn't skipped once every eight. Hurray.
-X is not the same as gatherX. Y iis not the same as gatherY. Bah.
 
***Version 1.7 - 11/30/02***
-Made the status changes a seperatte function, so it will only be changed when a valid player is being teleported.
 
Usage: You must have ACCESS_TELEPORT to use this command. Just type admin_gather 0 in the console and the living people of the server will be teleported around you. See the readme for the other commands.
If you want to make sure they don't get stuck, just do it in a wide, open, level space.
*/
 
// **PLUGIN STARTS HERE**
 
#include <core>
#include <console>
#include <string>
#include <admin>
#include <adminlib>
 
#define ACCESS_GATHER 8192
new gatherX;
new gatherY;
new status=1;
new ring=1;
 
new STRING_VERSION[MAX_DATA_LENGTH] = "2.50.26";
 
public admin_gather(HLCommand,HLData,HLUserName,UserIndex) {
	new Command[MAX_DATA_LENGTH];
	new Data[MAX_DATA_LENGTH];
	new Dead;
	new i;
	new maxplayers = maxplayercount();
	new Name[MAX_NAME_LENGTH];
	new Result;
	new User[MAX_NAME_LENGTH];
	new Text[MAX_TEXT_LENGTH];
	new X;
	new Y;
	new Z;
	new theTeam;
	new Team;
	new targetIndex, targetDead;
	new targetName[MAX_NAME_LENGTH];
	new isthereateam;
 
	convert_string(HLCommand,Command,MAX_DATA_LENGTH);
	convert_string(HLData,Data,MAX_DATA_LENGTH);
	convert_string(HLUserName,User,MAX_DATA_LENGTH);
 
	get_userorigin(User,X,Y,Z);
	gatherX=X;
	gatherY=Y;
 
	if (streq(Data, "2")==1) {
		theTeam=2;
		snprintf(Text, MAX_TEXT_LENGTH, "Gathering cts.");
		isthereateam=1;
	}
	if (streq(Data, "1")==1) {
		theTeam=1;
		snprintf(Text, MAX_TEXT_LENGTH, "Gathering ts.");
		isthereateam=1;
	}
	if (streq(Data, "0")==1) {
		theTeam=0;
		snprintf(Text, MAX_TEXT_LENGTH, "Gathering everybody.");
		isthereateam=1;
	}
	if (isthereateam==1) {
		say(Text);
 
		for (i=1; i<=maxplayers; i++) {
 
			Result = playerinfo(i,Name,MAX_NAME_LENGTH,_,_,Team,Dead);
			if(Result==1) {
				if (check_immunity(Name)==0 && i != UserIndex && Dead == 0) {
					if (theTeam==1 || theTeam==2 && theTeam==Team) {
						Gathercoordchange();
						teleport(Name, gatherX, gatherY, Z);
						status += 1;
					}
					if (theTeam==0) {
						Gathercoordchange();
						teleport(Name, gatherX, gatherY, Z);
						status += 1;
					}
				}
			}
			if (status==9) {
				status=1;
				ring+=1;
				gatherY = Y;
				gatherX = X;
			}
		}
		return PLUGIN_HANDLED;
	}
	say_command(User,Command,Data);
	if (check_user(Data) == 1) {
		get_userindex(Data, targetIndex);
		playerinfo(targetIndex, targetName, MAX_NAME_LENGTH, _, _, _, targetDead);
 
		if (targetDead == 0) {
			teleport(targetName, (X+50), Y, Z);			
 
		} else {
			snprintf(Text, MAX_TEXT_LENGTH, "%s is dead. You can't gather them!", targetName);
			selfmessage(Text);
		}
	} else {
		snprintf(Text, MAX_TEXT_LENGTH, "Unrecognized player: %s", Data);
		selfmessage(Text);
	}
 
	return PLUGIN_HANDLED;
}
 
Gathercoordchange()
{
	if (status==1) {
		gatherY += (ring*50);
	}
	if (status==2) {
		gatherY -=(ring*50);
		gatherX += (ring*50);
	}
	if (status==3) {
		gatherX -=(ring*50);
		gatherY -= (ring*50);
	}
	if (status==4) {
		gatherY +=(ring*50);
		gatherX -= (ring*50);
	}
	if (status==5) {
		gatherX += (ring*50);
		gatherY += (ring*50);
		gatherX += (ring*50);
	}
	if (status==6) {
		gatherY -= (ring*50);
		gatherX -= (ring*50);
		gatherY += (ring*50);
		gatherX -= (ring*50);
	}
	if (status==7) {
		gatherY -= (ring*50);
		gatherX += (ring*50);
		gatherY -= (ring*50);
		gatherX += (ring*50);
	}
	if (status==8) {
		gatherY += (ring*50);
		gatherX -= (ring*50);
		gatherY -= (ring*50);
		gatherX -= (ring*50);
	}
}
 
public plugin_init() {
	plugin_registerinfo("Thor's Gatherer","person gathering plugin by Thor",STRING_VERSION);
	plugin_registercmd("admin_gather","admin_gather",ACCESS_GATHER,"admin_gather:  Brings people to you. 1|2 terrorists|counter-terrorists");
 
	return PLUGIN_CONTINUE;
}