/* Origional code by yensid, rebuilt and repaired by TheLazyOne */
 
#include <core> 
#include <console> 
#include <string> 
#include <admin> 
#include <adminlib> 
 
#define ACCESS_NOCLIP 8192
#define TELE_INVALID 0
/* 10 */
new STRING_VERSION[MAX_DATA_LENGTH] = "2.50.00";
new NoClippedLast[MAX_PLAYERS] = {0,...};
new X[MAX_PLAYERS] = {TELE_INVALID,...};
new Y[MAX_PLAYERS] = {TELE_INVALID,...};
new Z[MAX_PLAYERS] = {TELE_INVALID,...};
new CanFreeMe = 0;
new CanNoClip = 1;
new Allownoclip = 0;
/* 20 */
public admin_noclipme(HLCommand,HLData,HLUserName,UserIndex) {
	new User[MAX_NAME_LENGTH];
	new Data[MAX_DATA_LENGTH];
	new Text[MAX_TEXT_LENGTH];
	convert_string(HLUserName, User, MAX_NAME_LENGTH);
	convert_string(HLData, Data, MAX_DATA_LENGTH);
 
	if (check_param(Data)==1) {
		snprintf(Text, MAX_TEXT_LENGTH, "%s has enabled the noclipme plugin, say NOCLIPME for temporary noclip - get stuck afterward say FREEME",User);
		say(Text); /* 30 */
		Allownoclip = 1;
	} else {
		snprintf(Text, MAX_TEXT_LENGTH, "%s has disabled the noclipme plugin", User);
		say(Text);
		Allownoclip = 0;
	}
	return PLUGIN_HANDLED;
}
 
public handlesay(HLCommand,HLData,HLUserName,UserIndex) {
	new User[MAX_NAME_LENGTH]; /* 40 */
	new Data[MAX_DATA_LENGTH];
 
	convert_string(HLUserName, User, MAX_NAME_LENGTH);
	convert_string(HLData, Data, MAX_DATA_LENGTH);
 
	strstripquotes(Data);
 
	if (streq(Data, "noclipme")==1) {
		if (Allownoclip==1) {
			if (systemtime() < NoClippedLast[UserIndex]) { /* 50 */
				messageex(User, "You may not noclip at this time.", print_chat);
			} else {
				if (CanNoClip==1) {
					messageex(User, "Noclip will commence in 5 seconds", print_chat);
					get_userorigin(User, X[UserIndex], Y[UserIndex], Z[UserIndex]);
					set_timer("timer1",5,0,"");
				} else {
					messageex(User, "Try harder, you cannot noclip yet", print_chat);
				}
			}
		}
	} else if (streq(Data, "freeme")==1) {
		if (CanFreeMe==1) {
			teleport(User, X[UserIndex], Y[UserIndex], Z[UserIndex]);
			messageex(User, "You have been returned to your last location, be faster next time.", print_chat);
		} else { /* 60 */
			messageex(User, "Teleport is not available to you now", print_chat);
		}
	}
	return PLUGIN_CONTINUE;
}
 
public timer1(HLCommand,HLData,HLUserName,UserIndex) {
	new User[MAX_NAME_LENGTH];
	convert_string(HLUserName, User, MAX_NAME_LENGTH);
	noclip(User, 1); /* 70 */
	execclient(User, "speak fvox/twenty seconds remaining");
	messageex(User, "Twenty seconds of noclip remaining", print_tty);
	set_timer("timer2",5,0,"");
}
 
public timer2(HLCommand,HLData,HLUserName,UserIndex) {
	new User[MAX_NAME_LENGTH];
	convert_string(HLUserName, User, MAX_NAME_LENGTH);
	execclient(User, "speak fvox/fifteen seconds remaining");
	messageex(User, "Fifteen seconds of noclip remaining", print_tty);
	set_timer("timer3",5,0,"");
}
 
public timer3(HLCommand,HLData,HLUserName,UserIndex) {
	new User[MAX_NAME_LENGTH];
	convert_string(HLUserName, User, MAX_NAME_LENGTH);
	execclient(User, "speak fvox/ten seconds remaining");
	messageex(User, "Ten seconds of noclip remaining", print_tty);
	set_timer("timer4",5,0,"");
}
 
public timer4(HLCommand,HLData,HLUserName,UserIndex) {
	new User[MAX_NAME_LENGTH];
	convert_string(HLUserName, User, MAX_NAME_LENGTH);
	execclient(User, "speak fvox/five seconds remaining");
	messageex(User, "Five", print_tty);
 	set_timer("timer5",1,0,"");
}
 
public timer5(HLCommand,HLData,HLUserName,UserIndex) {
	new User[MAX_NAME_LENGTH];
	convert_string(HLUserName, User, MAX_NAME_LENGTH);
	execclient(User, "speak fvox/four");
	messageex(User, "Four", print_tty);
	set_timer("timer6",1,0,"");
}	
 
public timer6(HLCommand,HLData,HLUserName,UserIndex) {
	new User[MAX_NAME_LENGTH];
	convert_string(HLUserName, User, MAX_NAME_LENGTH);
	execclient(User, "speak fvox/three");
	messageex(User, "Three", print_tty);
	set_timer("timer7",1,0,"");
}	
 
public timer7(HLCommand,HLData,HLUserName,UserIndex) {
	new User[MAX_NAME_LENGTH];
	convert_string(HLUserName, User, MAX_NAME_LENGTH);
	execclient(User, "speak fvox/two");
	messageex(User, "Two", print_tty);
	set_timer("timer8",1,0,"");
}	
 
public timer8(HLCommand,HLData,HLUserName,UserIndex) {
	new User[MAX_NAME_LENGTH];
	convert_string(HLUserName, User, MAX_NAME_LENGTH);
	execclient(User, "speak fvox/one");
	messageex(User, "One", print_tty);
	set_timer("timeroff",1,0,"");
}	
 
public timeroff(HLCommand,HLData,HLUserName,UserIndex) {
	new User[MAX_NAME_LENGTH];
	convert_string(HLUserName, User, MAX_NAME_LENGTH);
	messageex(User, "Noclip is now disabled, if you are stuck you have 20 seconds to say freeme to return to your last position", print_chat);
	execclient(User, "speak fvox/twenty seconds remaining");
	noclip(User, 0);
	CanFreeMe = 1;
	CanNoClip = 0;
	set_timer("DisableFreeme", 20, 0, User);
}
 
public DisableFreeme(HLCommand,HLData,HLUserName,UserIndex) {
	new User[MAX_NAME_LENGTH];
	convert_string(HLUserName, User, MAX_NAME_LENGTH);
	/* new UserIndex; */
	get_userindex(User, UserIndex);
	messageex(User, "Times up, you no longer can free yourself.", print_chat);
	CanFreeMe = 0;
	set_timer("NoclipOnceAgain",170,0, User);
}
 
public NoclipOnceAgain(HLCommand,HLData,HLUserName,UserIndex) {
	CanNoClip = 1;
}
 
public plugin_connect(HLUserName, HLIP, UserIndex) {
	if (UserIndex >= 1 && UserIndex <= MAX_PLAYERS) {
		NoClippedLast[UserIndex] = 0;
		CanFreeMe = 0;
		X[UserIndex] = TELE_INVALID;
		Y[UserIndex] = TELE_INVALID;
		Z[UserIndex] = TELE_INVALID;
	}
	return PLUGIN_CONTINUE;
}
 
public plugin_disconnect(HLUserName, UserIndex) {
	if (UserIndex >= 1 && UserIndex <= MAX_PLAYERS) {
		NoClippedLast[UserIndex] = 0;
		CanFreeMe = 0;
		X[UserIndex] = TELE_INVALID;
		Y[UserIndex] = TELE_INVALID;
		Z[UserIndex] = TELE_INVALID;
	}
	return PLUGIN_CONTINUE;
}
 
public plugin_init() {
	plugin_registerinfo("Noclipme Plugin","2002 - TheLazyOne",STRING_VERSION);
	plugin_registercmd("admin_noclipme","admin_noclipme",ACCESS_NOCLIP,"");
	plugin_registercmd("say","handlesay",ACCESS_ALL,"");
	return PLUGIN_CONTINUE;
}