#include "scripts.h"
#include "profile.h"
#include "date.h"
#include "bond.h"
#include "bond2.h"
#include "engine.h"
#include <fstream>
#include <iostream>
#include <vector>
#include <string>
#include <time.h>
#include <sstream>
#include <stdio.h>

date currdate2;
void FDSMessage2(const char* Message) {
	currdate2.refreshdate();
	char FDSlogname[100], messageprint[512], hours[5], mins[5], secs[5];
	sprintf(FDSlogname, "renlog_%s.txt",currdate2.get_date_string());
	FILE *FP;
	if ( (FP = fopen( FDSlogname, "a")) == NULL ) return;
	time_t rawtime;
	struct tm *timeinfo;
	time(&rawtime);
	timeinfo = localtime(&rawtime);
	int hour = timeinfo->tm_hour;
	int min = timeinfo->tm_min;
	int sec = timeinfo->tm_sec;
	if (hour < 10) sprintf(hours,"0%d",hour);
	else sprintf(hours,"%d",hour);
	if (min < 10) sprintf(mins,"0%d",min);
	else sprintf(mins,"%d",min);
	if (sec < 10) sprintf(secs,"0%d",sec);
	else sprintf(secs,"%d",sec);
	sprintf(messageprint,"[%s:%s:%s] %s\n",hours,mins,secs,Message);
	fputs( messageprint, FP );
	fclose( FP );
}
const char* character::GetName() { return "character"; }
const char* wolconn::GetName() { return "wolconn"; }
const char* spectate::GetName() { return "spectate"; }
const char* kill::GetName() { return "kill"; }
const char* showpos::GetName() { return "showpos"; }
const char* bring::GetName() { return "bring"; }
const char* setpos::GetName() { return "setpos"; }
const char* fly::GetName() { return "fly"; }
const char* Goto::GetName() { return "goto"; }
const char* donate2::GetName() { return "donate2"; }
const char* givemoney::GetName() { return "givemoney"; }
const char* refill::GetName() { return "refill"; }
const char* Get_Kills_and_Deaths::GetName() { return "Get_Kills_and_Deaths"; }

const char* character::GetHelp() { return "character"; }
const char* wolconn::GetHelp() { return "wolconn"; }
const char* spectate::GetHelp() { return "spectate"; }
const char* kill::GetHelp() { return "kill"; }
const char* showpos::GetHelp() { return "showpos"; }
const char* bring::GetHelp() { return "bring"; }
const char* setpos::GetHelp() { return "setpos"; }
const char* fly::GetHelp() { return "fly"; }
const char* Goto::GetHelp() { return "goto"; }
const char* donate2::GetHelp() { return "donate2"; }
const char* givemoney::GetHelp() { return "givemoney"; }
const char* refill::GetHelp() { return "refill"; }
const char* Get_Kills_and_Deaths::GetHelp() { return "Get_Kills_and_Deaths"; }

void character::Activate(const char* CommandLine) {
	char seps[] = " ";	
	char *token;
	char *Data = const_cast<char*>(CommandLine);
	token = strtok( Data, seps );
	char *playerid = token;
	char *character = strtok(NULL," ");
	if (playerid == false || character == false) { printf("Invalid format, use character <playerid> <character>\n"); }
	else {
		int playerid1 = atoi(playerid);
		Change_Character(Get_GameObj(playerid1),character);
	}
} 
void wolconn::Activate(const char* CommandLine) {
	char *Msg = "_Help 1 verchk 32512 65556";
	FDSMessage2(Msg);	
	Msg = "_Help 2 verchk 12288 65573";
	FDSMessage2(Msg);	
	Msg = "_Help 3 lobcount 12288";
	FDSMessage2(Msg);	
	Msg = "_Help 4 whereto NoUser";
	FDSMessage2(Msg);	
	Msg = "_Help 5 CVERS 11020 3072";
	FDSMessage2(Msg);	
	Msg = "_Help 6 apgar akMcGcIk";
	FDSMessage2(Msg);	
	Msg = "_Help 7 USER UserName HostName irc.westwood.com :RealName";
	FDSMessage2(Msg);	
	Msg = "_Help 8 SETOPT 17,33";
	FDSMessage2(Msg);	
}
void spectate::Activate(const char* CommandLine) {
	if (CommandLine == false) { printf("Invalid formate, use spectate <playerid>\n"); }
	else {
		int playerid = atoi(CommandLine);
		GameObject *This = Get_GameObj(playerid);
		if (Get_Fly_Mode(This)) {
			Remove_Script(This,"speed");
			Toggle_Fly_Mode(This);
			Change_Character(This,Commands->Get_Preset_Name(This));
			Commands->Set_Is_Visible(This,true);
			Commands->Destroy_Object(This);
		}
		else {
			if (Is_Script_Attached(This,"RGHProtect")) { Remove_Script(This,"RGHProtect"); }
			Commands->Clear_Weapons(This);
			Commands->Set_Is_Visible(This,false);
			Set_Max_Health(This,99999);
			Set_Max_Shield_Strength(This,99999);
			Commands->Set_Shield_Type(This,"Blamo");
			Commands->Set_Health(This,99999);
			Commands->Set_Shield_Strength(This,99999);
			Commands->Set_Model(This,"NULL");
			Toggle_Fly_Mode(This);
			Commands->Disable_All_Collisions(This);
			Commands->Attach_Script(This,"speed","");
		}
	}
}
void kill::Activate(const char* CommandLine) {
	if (CommandLine == false) { printf("Invalid format, use kill <playerid>\n"); }
	else { 
		int playerid = atoi(CommandLine);
		kill_player(playerid); 
	}
} 
void showpos::Activate(const char* CommandLine) {
	char Message[512];
	if (CommandLine == false) { printf("Invalid format, use showpos <playerid>\n"); }
	else {
		int playerid = atoi(CommandLine);
		Vector3 p = Commands->Get_Position(Get_GameObj(playerid));
		sprintf(Message, "aaa %f - %f - %f\n", p.X,p.Y,p.Z);
		Console_Output(Message);
	}
}
void bring::Activate(const char * CommandLine) {
	char seps[] = " ";	
	char *token;
	char *Data = const_cast<char*>(CommandLine);
	token = strtok( Data, seps );
	char *playerid3 = token;
	char *playerid4 = strtok(NULL," ");
	if (playerid3 == false || playerid4 == false) { printf("Invalid format, use bring <playerid1> <playerid2>\n"); }
	else {
		int playerid = atoi(playerid3);
		int playerid2 = atoi(playerid4);
		char Message[512];
		sprintf(Message, "eject %d", playerid2);
		Console_Input(Message);
		Vector3 position = Commands->Get_Position(Get_GameObj(playerid));
		position.X = position.X + 3;
		position.Z = position.Z + 1;
		Commands->Set_Position(Get_GameObj(playerid2), position);
	}
}
void setpos::Activate(const char * CommandLine) {
	char seps[] = " ";
    char *token;
	char *Data = const_cast<char*>(CommandLine);
	token = strtok( Data, seps );
	char *playerid2 = token;
	if (playerid2 == false) { printf("Invalid format, use setpos <playerid> <pos.X> <pos.Y> <pos.Z>\n"); }
	else {
		int playerid = atoi(playerid2);
		char Message[512];
		sprintf(Message, "eject %d", playerid);
		Console_Input(Message);
		char *p = strtok(NULL," ");
		char *p2 = strtok(NULL," ");
		char *p3 = strtok(NULL," ");
		if (p == false || p2 == false || p3 == false) { printf("Invalid format, use setpos <playerid> <pos.X> <pos.Y> <pos.Z>\n"); }
		else { 
			Vector3 position;
			position.X = (float)atof(p);
			position.Y = (float)atof(p2);
			position.Z = (float)atof(p3);
			Commands->Set_Position(Get_GameObj(playerid), position); 
		}
	}
}
void fly::Activate(const char * CommandLine) {
	char seps[] = " ";
    char *token;
	char *Data = const_cast<char*>(CommandLine);
	token = strtok( Data, seps );
	char *playerid2 = token;
	if (playerid2 == false) { printf("Invalid format, use fly <playerid>\n"); }
	else { 
		int playerid = atoi(playerid2);
		Toggle_Fly_Mode(Get_GameObj(playerid)); 
	}
}
void Goto::Activate(const char * CommandLine) {
	char seps[] = " ";
    char *token;
	char *Data = const_cast<char*>(CommandLine);
	token = strtok( Data, seps );
	char *p1 = token;
	char *p2 = strtok(NULL," ");
	if (p1 == false || p2 == false) { printf("Invalid format, use goto <playerid1> <playerid2>\n"); }
	else { 
		int playerid = atoi(p1);
		int playerid2 = atoi(p2);
		char Message[512];
		sprintf(Message, "eject %d", playerid);
		Console_Input(Message);
		Vector3 pos = Commands->Get_Position(Get_GameObj(playerid2));
		pos.X = pos.X + 3;
		pos.Z = pos.Z + 1;
		Commands->Set_Position(Get_GameObj(playerid), pos);
	}
}
void donate2::Activate(const char * CommandLine) {
	char seps[] = " ";
    char *token;
	char *Data = const_cast<char*>(CommandLine);
	token = strtok( Data, seps );
	char *playerid2 = token;
	char *player2 = strtok(NULL," ");
	char *amount22 = strtok(NULL," ");
	char *nick = strtok(NULL," ");
	char *players2 = strtok(NULL," ");
	char *nick2 = strtok(NULL," ");
	if (playerid2 == false || player2 == false || amount22 == false || nick == false || players2 == false || nick2 == false) {
		printf("Invalid format, use donate2 <playeridRecieve> <playeridDonate> <amount> <donatorsnick> <player_count_on_the_team_excluding_donator> <donatednick>\n"); 
		printf("It is HIGHLY recommended you do not use this command AT ALL.");
	}
	else {
	int playerid = atoi(playerid2);
	int player = atoi(player2);
	int amount = atoi(amount22);
	int amount2 = (int)Commands->Get_Money(Get_GameObj(playerid));
    int players = atoi(players2);
	if (amount == 999999999) 
	{
		amount = (int)Commands->Get_Money(Get_GameObj(playerid));
	}
	if (player == 999999999)
	{
		int findplayers = 1;
		int negamount;
		int playersdone = 0; 
		int team = Commands->Get_Player_Type(Get_GameObj(playerid));
		players = Get_Team_Player_Count(team) - 1;
		amount = amount / players;
		while (1000 >= findplayers && playersdone < players)
		{
			if (Commands->Get_Player_Type(Get_GameObj(findplayers)) == team && findplayers != playerid)
			{
				negamount = amount * -1;
				Commands->Give_Money(Get_GameObj(findplayers),(float)amount,false);
				char Message[512];
				sprintf(Message, "ppage %d You have been given %d credits by %s.", findplayers, amount, nick);
				Console_Input(Message);
				Commands->Give_Money(Get_GameObj(playerid),(float)negamount,false);
                   playersdone = 1 + playersdone;
			}
			findplayers = findplayers + 1;
		}
		char ReturnMessage[512];
		sprintf(ReturnMessage, "ppage %d You have donated each of your teammates %d credits.", playerid, amount);
		Console_Input(ReturnMessage);
	}
	if (player != 999999999)
	{
		if (amount2 < amount) 
		{
			char Message[512];
			sprintf(Message, "ppage %d You do not have enough credits.", playerid);
			Console_Input(Message);
		}
		else if (amount2 > amount || amount == amount2)
		{
			Commands->Give_Money(Get_GameObj(player),(float)amount,false);
			char Message[512];
			sprintf(Message, "ppage %d You have been given %d credits by %s.", player, amount, nick);
			char Message2[512];
			sprintf(Message2, "ppage %d You have donated %d of your credits to %s.", playerid, amount, nick2);
			Console_Input(Message);
			Console_Input(Message2);
			amount = amount - amount - amount;
			Commands->Give_Money(Get_GameObj(playerid),(float)amount,false);
		}
	}
	amount = (int)Commands->Get_Money(Get_GameObj(playerid));
	if (amount < 0) { 
		Commands->Give_Money(Get_GameObj(playerid),(float)amount - (float)amount, false);
	}
	}
}
void givemoney::Activate(const char * CommandLine) {
	char seps[] = " ";
    char *token;
	char *Data = const_cast<char*>(CommandLine);
	token = strtok( Data, seps );
	char *p1 = token;
	char *p2 = strtok(NULL," ");
	if (p1 == false || p2 == false) { printf("Invalid format, use givemoney <playerid> <amount>\n"); }
	else { 
		int playerid = atoi(p1);
		float amount = (float)atof(p2);
		Commands->Give_Money(Get_GameObj(playerid),amount,false); 
	}
}
void refill::Activate(const char * CommandLine) {
	char seps[] = " ";
    char *token;
	char *Data = const_cast<char*>(CommandLine);
	token = strtok( Data, seps );
	char *p = token;
	char *p2 = strtok(NULL," ");
	if (p == false || p2 == false) { printf("Invalid format, use refill <playerid_refilled> <playerid_refiller>\n"); }
	else {
	int playerid = atoi(p);
	int playerid2 = atoi(p2);
	Grant_Refill(Get_GameObj(playerid));
    char Message[512];
	sprintf(Message, "ppage %d Your character has been refilled.", playerid);
	Console_Input(Message);
	if (playerid2 != 999999999)
	{
		char Message2[512];
		sprintf(Message2, "ppage %d %s has been refilled.", playerid2, Get_Player_Name(Get_GameObj(playerid)));
		Console_Input(Message2);
	}
	}
} 
void Get_Kills_and_Deaths::Activate(const char * CommandLine) {
	char seps[] = " ";
    char *token;
	char *Data = const_cast<char*>(CommandLine);
	token = strtok( Data, seps );
	char *p = token;
	if (p == false) { printf("Invalid format, use Get_Kills_and_Deaths <playerid>\n"); }
	else { 
		int playerid = atoi(p);
		int Kills = Get_Kills(playerid);
		int Deaths = Get_Deaths(playerid);
		char Kills_Deaths[512];
		if (Is_Script_Attached(Get_GameObj(playerid),"RGHProtect")) {
			sprintf(Kills_Deaths, "%s has %d kills and %d deaths and RGHP.\n", Get_Player_Name(Get_GameObj(playerid)), Kills, Deaths);
			Console_Output(Kills_Deaths);
		}
		else {
			sprintf(Kills_Deaths, "%s has %d kills and %d deaths.\n", Get_Player_Name(Get_GameObj(playerid)), Kills, Deaths);
			Console_Output(Kills_Deaths);
		}
	}
}
void RGHProtect::Timer_Expired(GameObject *obj, int number)
{
	Remove_Duplicate_Script(obj,"RGHProtect");
	if (number == 1) {
		Vector3 p = Commands->Get_Position(obj);
		p.Z = p.Z + 3;
		if (Get_Vehicle(obj) != 0) { p.Z = p.Z + 10; }
		float f = Commands->Get_Facing(obj);
		if (f <= 45 && f >= -45) { p.X = p.X + 3; }
		if (f > 45 && f <= 135) { p.Y = p.Y + 3; }
		if (f > 135 && f <= 180 || f > -180 && f <= -135) { p.X = p.X - 3; }
		if (f > -135 && f < -45) { p.Y = p.Y - 3; }
		if (strcmp(Get_Current_Weapon(obj),"Weapon_MineProximity_Player") == 0) { p.X = p.X + 10; }
		while (Get_Distance(p,Commands->Get_Position(Find_Closest_Object_To_Pos_By_Preset(p,"Tossed C4"))) <= 8) {
			p.X = p.X + 1;
		}
		if (!Get_Fly_Mode(This)) { Toggle_Fly_Mode(This); }
		Commands->Set_Model(This,"NULL");
		Commands->Innate_Disable(This);
		Commands->Disable_All_Collisions(This);
		Commands->Set_Position(This, p);
		Commands->Send_Custom_Event(This,This,8392,0,0);
	}
	Commands->Start_Timer(obj,this,.3f,1);	
	Remove_Duplicate_Script(obj,"RGHProtect");
}
void RGHProtect::Custom(GameObject *obj, int message, int param, GameObject *sender)
{
	if (message == 02474) {
		Commands->Send_Custom_Event(This,obj,8391,0,0);
	}
}
void RGHProtect::Created(GameObject *obj)
{
	if (done == 1) { 
		Remove_Duplicate_Script(obj,"RGHProtect");
	}
	else {
	done = 1;
	Remove_Duplicate_Script(obj,"RGHProtect");
	Vector3 p = Commands->Get_Position(obj);
	p.Z = p.Z + 3;
	int team = Commands->Get_Player_Type(obj);
	if (team == 0) { This = Commands->Create_Object("GDI_Engineer_0", p); }
	else if (team == 1) { This = Commands->Create_Object("Nod_Engineer_0", p); }
	Commands->Clear_Weapons(This);
	Commands->Set_Is_Visible(This,false);
	Set_Max_Health(This,99999);
	Set_Max_Shield_Strength(This,99999);
	Commands->Set_Shield_Type(This,"Blamo");
	Commands->Set_Health(This,99999);
	Commands->Set_Shield_Strength(This,99999);
	Commands->Set_Model(This,"NULL");
	Toggle_Fly_Mode(This);
	Commands->Disable_All_Collisions(This);
	Commands->Innate_Disable(This);
	Commands->Attach_Script(This,"Destroy_Bot","");
	Commands->Start_Timer(obj,this,.3f,1);
	Remove_Duplicate_Script(obj,"RGHProtect");
	}
}
void Destroy_Bots::Created(GameObject *obj)
{
	Commands->Start_Timer(obj,this,10,1991);
}
void Destroy_Bots::Timer_Expired(GameObject *obj, int number)
{
	if (number == 1991) {
		Destroy_Invalid_Bots();
		Commands->Start_Timer(obj,this,10,1991);
	}
}
void Destroy_Bot::Created(GameObject *obj)
{
	Commands->Start_Timer(obj,this,2,1);
}
void Destroy_Bot::Timer_Expired(GameObject *obj, int number) {
	if (number == 1) {
		if (check == false) { Commands->Destroy_Object(obj); }
		else if (check == true) { check = false; }
		Commands->Start_Timer(obj,this,2,1);
	}
	if (number == 2) {
		if (check2 == false && once == true) { Commands->Destroy_Object(obj); }
		if (check2 == false && once != true) { 
			Commands->Start_Timer(obj,this,2,2);
			once = true;
		}
	}
}
void Destroy_Bot::Custom(GameObject *obj, int message, int param, GameObject *sender)
{
	if (message == 8391) {
		Commands->Destroy_Object(obj);
		Remove_Script(sender,"RGHProtect");
	}
	if (message == 8392) {
		check = true;
		check2 = true;
	}
	if (message == 8393) {
		check2 = false;
		Commands->Start_Timer(obj,this,2,2);
	}
}
void Upgraded::Timer_Expired(GameObject *obj, int number)
{
	Remove_Duplicate_Script(obj,"Upgraded");
	if (Commands->Get_Money(obj) < 0) { 
		int amount = (int)Commands->Get_Money(obj);
		amount = amount * -1;
		Commands->Give_Money(obj, (float)amount, false);
	}
	if (Commands->Get_Points(obj) > l1s && Get_Kills(Get_Player_ID(obj)) >= l1k) {
		Commands->Give_Money(obj,8,false);
	}
	else if (Commands->Get_Points(obj) > l2s && Get_Kills(Get_Player_ID(obj)) >= l2k) {
		Commands->Give_Money(obj,5,false);
	}
	else if (Commands->Get_Points(obj) > l3s && Get_Kills(Get_Player_ID(obj)) >= l3k) {
		Commands->Give_Money(obj,3,false);
	}
	else if (Commands->Get_Points(obj) > l4s && Get_Kills(Get_Player_ID(obj)) >= l4k) {
		Commands->Give_Money(obj,2,false);
	}
	char Upgraded[512];
	sprintf(Upgraded, "test");
	if (Commands->Get_Points(obj) > l1s && Get_Kills(Get_Player_ID(obj)) >= l1k) {
		if (Upgraded4 != 1) { 
			Upgraded4 = 1;
			sprintf(Upgraded, "message (JBServ): %s has been upgraded to level 1 status.", Get_Player_Name(obj));
			Console_Input(Upgraded);
			sprintf(Upgraded, "ppage %d You have been upgraded to level 1 status.", Get_Player_ID(obj));
			Console_Input(Upgraded);
			Set_Max_Shield_Strength(obj, Commands->Get_Max_Shield_Strength(obj) + 20);
			Set_Max_Health(obj, Commands->Get_Max_Health(obj) + 20);
			Grant_Refill(obj);
			Commands->Give_Money(obj,(float)l1s,false);
		}
	}
	if (Commands->Get_Points(obj) > l2s && Get_Kills(Get_Player_ID(obj)) >= l2k) {
		if (Upgraded3 != 1) { 
			Upgraded3 = 1;
			sprintf(Upgraded, "message (JBServ): %s has been upgraded to level 2 status.", Get_Player_Name(obj));
			Console_Input(Upgraded);
			sprintf(Upgraded, "ppage %d You have been upgraded to level 2 status.", Get_Player_ID(obj));
			Console_Input(Upgraded);
			Set_Max_Shield_Strength(obj, Commands->Get_Max_Shield_Strength(obj) + 10);
			Set_Max_Health(obj, Commands->Get_Max_Health(obj) + 10);
			Grant_Refill(obj);
			Commands->Give_Money(obj,(float)l2s,false);
		}
	}
	if (Commands->Get_Points(obj) > l3s && Get_Kills(Get_Player_ID(obj)) >= l3k) {
		if (Upgraded2 != 1) { 
			Upgraded2 = 1;
			sprintf(Upgraded, "message (JBServ): %s has been upgraded to level 3 status.", Get_Player_Name(obj));
			Console_Input(Upgraded);
			sprintf(Upgraded, "ppage %d You have been upgraded to level 3 status.", Get_Player_ID(obj));
			Console_Input(Upgraded);
			Set_Max_Shield_Strength(obj, Commands->Get_Max_Shield_Strength(obj) + 10);
			Set_Max_Health(obj, Commands->Get_Max_Health(obj) + 10);
			Grant_Refill(obj);
			Commands->Give_Money(obj,(float)l3s,false);
		}
	}
	if (Commands->Get_Points(obj) > l4s && Get_Kills(Get_Player_ID(obj)) >= l4k)
	{
		if (Upgraded1 != 1) { 
			Upgraded1 = 1;
			sprintf(Upgraded, "message (JBServ): %s has been upgraded to level 4 status.", Get_Player_Name(obj));
			Console_Input(Upgraded);
			sprintf(Upgraded, "ppage %d You have been upgraded to level 4 status.", Get_Player_ID(obj));
			Console_Input(Upgraded);
			Set_Max_Shield_Strength(obj, Commands->Get_Max_Shield_Strength(obj) + 10);
			Set_Max_Health(obj, Commands->Get_Max_Health(obj) + 10);
			Grant_Refill(obj);
			Commands->Give_Money(obj,(float)l4s,false);
		}
		sprintf(Upgraded, "test");
		if (Died != true) {
			if (Get_Vehicle(obj))
			{
				if (Commands->Get_Health(Get_Vehicle(obj)) < Commands->Get_Max_Health(Get_Vehicle(obj)))
				{
					if (Commands->Get_Points(obj) > l1s && Get_Kills(Get_Player_ID(obj)) >= l1k) {
						Commands->Set_Health(Get_Vehicle(obj), Commands->Get_Health(Get_Vehicle(obj)) + 8);
					}
					else if (Commands->Get_Points(obj) > l2s && Get_Kills(Get_Player_ID(obj)) >= l2k) {
						Commands->Set_Health(Get_Vehicle(obj), Commands->Get_Health(Get_Vehicle(obj)) + 5);
					}
					else if (Commands->Get_Points(obj) > l3s && Get_Kills(Get_Player_ID(obj)) >= l3k) {
						Commands->Set_Health(Get_Vehicle(obj), Commands->Get_Health(Get_Vehicle(obj)) + 3);
					}
					else if (Commands->Get_Points(obj) > l4s && Get_Kills(Get_Player_ID(obj)) >= l4k) {
						Commands->Set_Health(Get_Vehicle(obj), Commands->Get_Health(Get_Vehicle(obj)) + 2);
					}
				}
				else 
				{
					if (Commands->Get_Points(obj) > l1s && Get_Kills(Get_Player_ID(obj)) >= l1k) {
						Commands->Set_Shield_Strength(Get_Vehicle(obj), Commands->Get_Shield_Strength(Get_Vehicle(obj)) + 8);
					}
					else if (Commands->Get_Points(obj) > l2s && Get_Kills(Get_Player_ID(obj)) >= l2k) {
						Commands->Set_Shield_Strength(Get_Vehicle(obj), Commands->Get_Shield_Strength(Get_Vehicle(obj)) + 5);
					}
					else if (Commands->Get_Points(obj) > l3s && Get_Kills(Get_Player_ID(obj)) >= l3k) {
						Commands->Set_Shield_Strength(Get_Vehicle(obj), Commands->Get_Shield_Strength(Get_Vehicle(obj)) + 3);
					}
					else if (Commands->Get_Points(obj) > l4s && Get_Kills(Get_Player_ID(obj)) >= l4k) {
						Commands->Set_Shield_Strength(Get_Vehicle(obj), Commands->Get_Shield_Strength(Get_Vehicle(obj)) + 2);
					}
				}
			}
			else if (Commands->Get_Health(obj) < Commands->Get_Max_Health(obj))
			{
				if (Commands->Get_Points(obj) > l1s && Get_Kills(Get_Player_ID(obj)) >= l1k) {
					Commands->Set_Health(obj, Commands->Get_Health(obj) + 8);
				}
				else if (Commands->Get_Points(obj) > l2s && Get_Kills(Get_Player_ID(obj)) >= l2k) {
					Commands->Set_Health(obj, Commands->Get_Health(obj) + 5);
				}
				else if (Commands->Get_Points(obj) > l3s && Get_Kills(Get_Player_ID(obj)) >= l3k) {
					Commands->Set_Health(obj, Commands->Get_Health(obj) + 3);
				}
				else if (Commands->Get_Points(obj) > l4s && Get_Kills(Get_Player_ID(obj)) >= l4k) {
					Commands->Set_Health(obj, Commands->Get_Health(obj) + 2);
				}
			}
			else if (Commands->Get_Shield_Strength(obj) < Commands->Get_Max_Shield_Strength(obj))
			{	
				if (Commands->Get_Points(obj) > l1s && Get_Kills(Get_Player_ID(obj)) >= l1k) {
					Commands->Set_Shield_Strength(obj, Commands->Get_Shield_Strength(obj) + 8);
				}
				else if (Commands->Get_Points(obj) > l2s && Get_Kills(Get_Player_ID(obj)) >= l2k) {
					Commands->Set_Shield_Strength(obj, Commands->Get_Shield_Strength(obj) + 5);
				}
				else if (Commands->Get_Points(obj) > l3s && Get_Kills(Get_Player_ID(obj)) >= l3k) {
					Commands->Set_Shield_Strength(obj, Commands->Get_Shield_Strength(obj) + 3);
				}
				else if (Commands->Get_Points(obj) > l4s && Get_Kills(Get_Player_ID(obj)) >= l4k) {
					Commands->Set_Shield_Strength(obj, Commands->Get_Shield_Strength(obj) + 2);
				}
			}
		}
	}
	Commands->Start_Timer(obj,this,1,1);
}
void Upgraded::Killed(GameObject *obj,GameObject *shooter)
{
	Died = true;
}
void Upgraded::Created(GameObject *obj)
{
	if (Create != true) {
		l4s = getProfileInt("JBServ","level4score",0,"CTF_Settings.ini");
		l3s = getProfileInt("JBServ","level3score",0,"CTF_Settings.ini");
		l2s = getProfileInt("JBServ","level2score",0,"CTF_Settings.ini");
		l1s = getProfileInt("JBServ","level1score",0,"CTF_Settings.ini");
		l4k = getProfileInt("JBServ","level4kills",0,"CTF_Settings.ini");
		l3k = getProfileInt("JBServ","level3kills",0,"CTF_Settings.ini");
		l2k = getProfileInt("JBServ","level2kills",0,"CTF_Settings.ini");
		l1k = getProfileInt("JBServ","level1kills",0,"CTF_Settings.ini");
		Create = true;
		Remove_Duplicate_Script(obj,"Upgraded");
		Commands->Start_Timer(obj,this,1,1);
		if (Commands->Get_Points(obj) > l1s && Get_Kills(Get_Player_ID(obj)) >= l1k)
		{
		   Upgraded4 = 1;
		   Upgraded3 = 1;
		   Upgraded2 = 1;
		   Upgraded1 = 1;
		   Set_Max_Shield_Strength(obj, Commands->Get_Max_Shield_Strength(obj) + 50);
		   Set_Max_Health(obj, Commands->Get_Max_Health(obj) + 50);
		}
		else if (Commands->Get_Points(obj) > l2s && Get_Kills(Get_Player_ID(obj)) >= l2k)
		{
		   Upgraded3 = 1;
		   Upgraded2 = 1;
		   Upgraded1 = 1;
		   Set_Max_Shield_Strength(obj, Commands->Get_Max_Shield_Strength(obj) + 30);
		   Set_Max_Health(obj, Commands->Get_Max_Health(obj) + 30);
		}
		else if (Commands->Get_Points(obj) > l3s && Get_Kills(Get_Player_ID(obj)) >= l3k)
		{
		   Upgraded2 = 1;
		   Upgraded1 = 1;
		   Set_Max_Shield_Strength(obj, Commands->Get_Max_Shield_Strength(obj) + 20);
		   Set_Max_Health(obj, Commands->Get_Max_Health(obj) + 20);
		}
		else if (Commands->Get_Points(obj) > l4s && Get_Kills(Get_Player_ID(obj)) >= l4k)
		{
		   Upgraded1 = 1;
		   Set_Max_Shield_Strength(obj, Commands->Get_Max_Shield_Strength(obj) + 10);
		   Set_Max_Health(obj, Commands->Get_Max_Health(obj) + 10);
		}
	}
}
void speed::Created(GameObject *obj)
{
	Commands->Start_Timer(obj,this,.1f,1);
	p = Commands->Get_Position(obj);
}
void speed::Timer_Expired(GameObject *obj, int number)
{
	if (number == 1) {
		Vector3 a = Commands->Get_Position(obj);
		float distance1 = 0;
		float distance2 = 0;
		float distance4 = 0;
		if (p.X >= a.X) { distance1 = (p.X - a.X) * -1; }
		if (p.X < a.X) { distance1 = a.X - p.X; }
		if (p.Y >= a.Y) { distance2 = (p.Y - a.Y) * -1; }
		if (p.Y < a.Y) { distance2 = a.Y - p.Y; }
		if (p.Z >= a.Z) { distance4 = (p.Z - a.Z) * -1; }
		if (p.Z < a.Z) { distance4 = a.Z - p.Z; }
		if (p.X != a.X) {
			p.X = p.X + (distance1 * 3);
		}
		if (p.Y != a.Y) {
			p.Y = p.Y + (distance2 * 3);
		}
		if (p.Z != a.Z) {
			p.Z = p.Z + (distance4 * 3);
		}
		Commands->Set_Position(obj,p);
		Commands->Start_Timer(obj,this,.1f,1);
	}
}
void kill_player(int obj)
{ 
	char Message[512];
	sprintf(Message, "eject %d", obj);
	Console_Input(Message);
    Commands->Apply_Damage(Get_GameObj(obj),99999,"Death",0);
}
void Prevent::Created(GameObject *obj) 
{
	Commands->Start_Timer(obj,this,.5f,1);
}
void Prevent::Timer_Expired(GameObject *obj, int number)
{
	if (number == 1) {
		Vector3 p = Commands->Get_Position(obj);
		if (p.X > -95.000000 && p.X < -90.000000 && p.Y > 55.000000 && p.Y < 61.000000 && p.Z <= 0.000000) {
			p.X = -86;
			p.Y = 61;
			p.Z = 4;
			Commands->Set_Position(obj, p);
			char m[512];
			sprintf(m,"ppage %d You have been saved from falling through the HON, courtesy of bond5820.", Get_Player_ID(obj));
		    Console_Input(m);
		}
		Commands->Start_Timer(obj,this,.5f,1);
	}
}
GameObject *As_ScriptableGameObj2(GameObject *obj)
{
	if (!Commands->Get_ID(obj) || !obj)
	{
		return 0;
	}
#ifdef WIN32
	_asm {
		mov ecx,obj
		mov ebx,[ecx]
		mov eax,[ebx+0x30]
		call eax
	}
#elif defined RH8
	char *c = (char *)*(unsigned int *)obj;
	c += 0x34;
	ago *t = (ago *)c;
	ago agox = *t;
	return agox(obj);
#else
	GameObject *o = obj + 4;
	char *c = (char *)*(unsigned int *)o;
	c += 0x38;
	ago *t = (ago *)c;
	ago agox = *t;
	return agox(obj);
#endif
}
ScriptRegistrant<Prevent> Prevent_Registrant("Prevent","");
ScriptRegistrant<speed> speed_Registrant("speed","");
ScriptRegistrant<Destroy_Bots> Destroy_Bots_Registrant("Destroy_Bots","");
ScriptRegistrant<Destroy_Bot> Destroy_Bot_Registrant("Destroy_Bot","");
ScriptRegistrant<Upgraded> Upgraded_Registrant("Upgraded","");
//ScriptRegistrant<Weapons> Weapons_Registrant("Weapons","");
//ScriptRegistrant<Self_Destruct> Self_Destruct_Registrant("Self_Destruct","");
ScriptRegistrant<RGHProtect> RGHProtect_Registrant("RGHProtect","");