/* Classes */
//{
public class Rcp{
	public WeaponItem WI;
	public bool IsResource = false;
	public int Woods = 0;
	public int Metals = 0;
	public int Components = 0;
	public int Gas = 0;
	public int Propane = 0;
	public string ID = "";
	public string Cost(){
		return (Woods > 0 ? "Woods: "+Woods.ToString() : "")+(Metals > 0 ? "Metals: "+Metals.ToString() : "")+(Components > 0 ? "Components: "+Components.ToString() : "")+(Gas > 0 ? "Gas: "+Gas.ToString() : "")+(Propane > 0 ? "Propane: "+Propane.ToString() : "");
	}
	public Rcp(string ID_, WeaponItem WI_, int Woods_, int Metals_, int Components_, int Gas_, int Propane_){
		WI = WI_;
		Woods = Woods_;
		Metals = Metals_;
		Components = Components_;
		Gas = Gas_;
		Propane = Propane_;
		ID = ID_;
		Rcps.Add(this);
	}
	public void Craft(Inventory inv){
		if(inv.Woods >= Woods && inv.Metals >= Metals && inv.Components >= Components && inv.Gas >= Gas && inv.Propane >= Propane){
			if(ID == "Components"){
				inv.Components += 2;
				Game.PlayEffect("CFTXT", inv.cply.GetWorldPosition() + new Vector2(0, 10), "Crafted components");
			}
			else{
				inv.cply.GiveWeaponItem(WI);
			}
			Game.ShowChatMessage("You crafted sucessfull '"+ID+"'", Color.Green, inv.cply.GetUser().UserIdentifier);
			inv.Remove(Woods, Metals, Components, Gas, Propane);
		}
		else{
			Game.PlayEffect("CFTXT", inv.cply.GetWorldPosition() + new Vector2(0, 10), string.Format("It's missing {0}{1}{2}{3}{4}", 
				Woods > 0 ? " Woods: "+(Woods - inv.Woods).ToString()+" /" : "",
				Metals > 0 ? " Metals: "+(Metals - inv.Metals).ToString()+" /" : "",
				Components > 0 ? " Components: "+(Components - inv.Components).ToString()+" /" : "",
				Gas > 0 ? " Gas: "+(Gas - inv.Gas).ToString()+" /" : "",
				Propane > 0 ? " Propane: "+(Propane - inv.Propane).ToString()+" /" : ""
			));
			Game.ShowChatMessage(string.Format("It's missing {0}{1}{2}{3}{4}", 
				Woods > 0 ? " Woods: "+(Woods - inv.Woods).ToString()+" /" : "",
				Metals > 0 ? " Metals: "+(Metals - inv.Metals).ToString()+" /" : "",
				Components > 0 ? " Components: "+(Components - inv.Components).ToString()+" /" : "",
				Gas > 0 ? " Gas: "+(Gas - inv.Gas).ToString()+" /" : "",
				Propane > 0 ? " Propane: "+(Propane - inv.Propane).ToString()+" /" : ""
			), Color.Yellow, inv.cply.GetUser().UserIdentifier);
		}
	}
}

public class Inventory{
	public int Woods = 0;
	public int Metals = 0;
	public int Components = 0;
	public int Propane = 0;
	public int CannedFood = 0;
	public int Gas = 0;
	public IPlayer cply;
	public bool GuiOn = false;
	public GUI Gui = null;
	public Inventory(IPlayer ply){
		cply = ply;
	}
	public void Remove(int Woods_, int Metals_, int Components_, int Gas_, int Propane_){
		Woods -= Woods_;
		Metals -= Metals_;
		Components -= Components_;
		Gas -= Gas_;
		Propane -= Propane_;
	}
	public void Drop(int Woods_, int Metals_, int Components_, int Gas_, int Propane_, int CannedFood_){
		if((Woods_ + Metals_) + ((Components_ + Gas_) + Propane_) < 7){
			string[] strs0 = new string[] {"A","B","C","D","E"};
			for(int i = 0; i < Woods_;i++){
				Game.CreateObject("WoodDebris00"+strs0[rnd.Next(0,6)], cply.GetWorldPosition() + new Vector2(rnd.Next(-2, 2), rnd.Next(1, 5)));
			}
			for(int i = 0; i < Metals_;i++){
				Game.CreateObject("MetalDebris00"+strs0[rnd.Next(0,6)], cply.GetWorldPosition() + new Vector2(rnd.Next(-2, 2), rnd.Next(1, 5)));
			}
			for(int i = 0; i < Components_;i++){
				string[] strs1 = {"ItemDebrisDark01","ItemDebrisDark00","ItemDebrisFlamethrower00","ItemDebrisShiny00","ItemDebrisShiny01"};
				Game.CreateObject(strs1[rnd.Next(0,4)], cply.GetWorldPosition() + new Vector2(rnd.Next(-2, 2), rnd.Next(1, 5)));
			}
			for(int i = 0; i < ((int)Gas_ / 3);i++){
				Game.CreateObject("Gascan00", cply.GetWorldPosition() + new Vector2(rnd.Next(-2, 2), rnd.Next(1, 5)));
			}
			for(int i = 0; i < ((int)Propane_ / 3);i++){
				Game.CreateObject("PropaneTank", cply.GetWorldPosition() + new Vector2(rnd.Next(-2, 2), rnd.Next(1, 5)));
			}
			for(int i = 0; i < CannedFood_;i++){
				Game.CreateObject("CrabCan00", cply.GetWorldPosition() + new Vector2(rnd.Next(-2, 2), rnd.Next(1, 5)));
			}
		}
		else{
			IObject box = (IObject)Game.CreateObject("CardboardBox00", cply.GetWorldPosition() + new Vector2(rnd.Next(-2, 2), rnd.Next(1, 5)));
			cbBoxItems.Add(box, new int[] {Woods_, Metals_, Components_, Gas_, Propane_, CannedFood_});
		}
	}
	/*
	foreach(item i in array){
		if(inv.count[i] >= count[i]){
			inv.count[i]-=count[i]
		}
		else{
			--fail--
		}
	}
	
	string[] x;
	int y;
	foreach(item i in array){
		if(count[i] > 0){
			y++;
			x[y] == i.id + count[i];
		}
	}
	showchatmessage(x);
	*/
}
//}
/* Recipes */
//{

/* Melees */
Rcp Bat = new Rcp("Bat", WeaponItem.BAT, 3, 0, 0, 0, 0);
Rcp BatAmmo = new Rcp("Bat Ammo", WeaponItem.BAT, 1, 0, 0, 0, 0);

Rcp LeadPipe = new Rcp("Pipe", WeaponItem.LEAD_PIPE, 0, 3, 0, 0, 0);
Rcp LeadPipeAmmo = new Rcp("Pipe Ammo", WeaponItem.LEAD_PIPE, 0, 3, 0, 0, 0);

Rcp Hammer = new Rcp("Hammer", WeaponItem.HAMMER, 1, 2, 0, 0, 0);
Rcp HammerAmmo = new Rcp("Hammer Ammo", WeaponItem.HAMMER, 0, 1, 0, 0, 0);

Rcp Axe = new Rcp("Axe", WeaponItem.AXE, 2, 2, 0, 0, 0);
Rcp AxeAmmo = new Rcp("AxeAmmo", WeaponItem.AXE, 1, 1, 0, 0, 0);

Rcp Machete = new Rcp("Machete", WeaponItem.MACHETE, 2, 3, 0, 0, 0);
Rcp MacheteAmmo = new Rcp("Machete Ammo", WeaponItem.MACHETE, 1, 1, 0, 0, 0);

Rcp Knife = new Rcp("Knife", WeaponItem.KNIFE, 1, 1, 0, 0, 0);
Rcp KnifeAmmo = new Rcp("Knife Ammo", WeaponItem.KNIFE, 0, 1, 0, 0, 0);

Rcp Katana = new Rcp("Katana", WeaponItem.KATANA, 2, 4, 0, 0, 0);
Rcp KatanaAmmo = new Rcp("Katana Ammo", WeaponItem.KATANA, 1, 2, 0, 0, 0);

Rcp ShockBaton = new Rcp("Shock Baton", WeaponItem.SHOCK_BATON, 1, 3, 2, 0, 0);
Rcp ShockBatonAmmo = new Rcp("Shock Baton Ammo", WeaponItem.SHOCK_BATON, 1, 1, 1, 0, 0);

/* Guns */

Rcp Pistol = new Rcp("Pistol", WeaponItem.PISTOL, 0, 5, 1, 0, 0);
Rcp PistolAmmo = new Rcp("Pistol Ammo", WeaponItem.PISTOL, 0, 3, 0, 0, 0);

Rcp Pistol45 = new Rcp("Pistol45", WeaponItem.PISTOL45, 0, 6, 2, 0, 0);
Rcp Pistol45Ammo = new Rcp("Pistol45 Ammo", WeaponItem.PISTOL45, 0, 4, 0, 0, 0);

Rcp MachinePistol = new Rcp("Machine Pistol", WeaponItem.MACHINE_PISTOL, 0, 7, 2, 0, 0);
Rcp MachinePistolAmmo = new Rcp("Machine Pistol Ammo", WeaponItem.MACHINE_PISTOL, 0, 5, 0, 0, 0);

Rcp Bow = new Rcp("Bow", WeaponItem.BOW, 7, 0, 0, 0, 0);
Rcp BowAmmo = new Rcp("Bow Ammo", WeaponItem.BOW, 4, 0, 0, 0, 0);

Rcp Magnum = new Rcp("Magnum", WeaponItem.MAGNUM, 0, 8, 3, 0, 0);
Rcp MagnumAmmo = new Rcp("Magnum Ammo", WeaponItem.MAGNUM, 0, 5, 0, 0, 0);

Rcp Revolver = new Rcp("Revolver", WeaponItem.REVOLVER, 0, 6, 2, 0, 0);
Rcp RevolverAmmo = new Rcp("Revolver Ammo", WeaponItem.REVOLVER, 0, 4, 0, 0, 0);

Rcp Carbine = new Rcp("Carbine", WeaponItem.CARBINE, 0, 8, 3, 0, 0);
Rcp CarbineAmmo = new Rcp("Carbine Ammo", WeaponItem.CARBINE, 0, 5, 0, 0, 0);

/* Others */

Rcp Grenades = new Rcp("Grenades", WeaponItem.GRENADES, 0, 3, 1, 0, 3);
Rcp ComponentsR = new Rcp("Components", WeaponItem.MEDKIT, 0, 3, 0, 0, 0);

//}
/* Variables */
//{

static Random rnd = new Random();

Events.UserMessageCallback m_userMessageCallback = null;
Events.PlayerKeyInputCallback m_playerKeyInputEvent = null;
Events.ObjectTerminatedCallback m_objectTerminatedEvent = null;

static List <Rcp> Rcps = new List<Rcp>();

static Dictionary<IObject, int[]> cbBoxItems = new Dictionary<IObject, int[]>(0);
static Dictionary<IPlayer, Inventory> plyInv = new Dictionary<IPlayer, Inventory>(0);

//}
/* Main */
//{
public void AddClass(IPlayer ply){
	Inventory inv = new Inventory(ply);
	plyInv.Add(ply, inv);
}
public void OnStartup(){
	m_userMessageCallback = Events.UserMessageCallback.Start(OnUserMessage);
	m_playerKeyInputEvent = Events.PlayerKeyInputCallback.Start(OnPlayerKeyInput);
	m_objectTerminatedEvent = Events.ObjectTerminatedCallback.Start(OnObjectTerminated);
	
	foreach(IObject cb in Game.GetObjectsByArea(Game.GetCameraMaxArea())){
		if(cb.Name == "CardboardBox00")cbBoxItems.Add(cb, new int[]{rnd.Next(2,5), rnd.Next(1,5), rnd.Next(5), rnd.Next(1), rnd.Next(1), rnd.Next(1)});
	}
	foreach(IPlayer ply in Game.GetPlayers()){
		AddClass(ply);
	}
	CreateTimer(100,0,"PickUpItems","");
}

public void OnObjectTerminated(IObject[] objs){
	foreach(IObject obj in objs){
		if(obj.Name == "CardboardBox00"){
			Vector2 pos = obj.GetWorldPosition();
			int[] cbit = new int[6];
			try{cbit = cbBoxItems[obj];}
			catch(Exception){cbBoxItems.Add(obj, new int[]{rnd.Next(2,5), rnd.Next(1,5), rnd.Next(5), rnd.Next(1), rnd.Next(1), rnd.Next(1)}); cbit = cbBoxItems[obj];}
			string[] strs0 = new string[] {"A","B","C","D","E"};
/*			Game.ShowChatMessage(cbit[0].ToString());
			Game.ShowChatMessage(cbit[1].ToString());
			Game.ShowChatMessage(cbit[2].ToString());
			Game.ShowChatMessage(cbit[3].ToString());
			Game.ShowChatMessage(cbit[4].ToString());
			Game.ShowChatMessage(cbit[5].ToString());*/
			for(int i = 0; i < cbit[0];i++){
				Game.CreateObject("WoodDebris00"+strs0[rnd.Next(0,5)], pos + new Vector2(rnd.Next(-4, 4), rnd.Next(1, 5)));
			}
			for(int i = 0; i < cbit[1];i++){
				Game.CreateObject("MetalDebris00"+strs0[rnd.Next(0,5)], pos + new Vector2(rnd.Next(-4, 4), rnd.Next(1, 5)));
			}
			for(int i = 0; i < cbit[2];i++){
				string[] strs1 = {"ItemDebrisDark01","ItemDebrisDark00","ItemDebrisFlamethrower00","ItemDebrisShiny00","ItemDebrisShiny01"};
				Game.CreateObject(strs1[rnd.Next(0,5)], pos + new Vector2(rnd.Next(-4, 4), rnd.Next(1, 5)));
			}
			for(int i = 0; i < cbit[3];i++){
				Game.CreateObject("Gascan00", pos + new Vector2(rnd.Next(-4, 4), rnd.Next(1, 5)));
			}
			for(int i = 0; i < cbit[4];i++){
				Game.CreateObject("PropaneTank", pos + new Vector2(rnd.Next(-4, 4), rnd.Next(1, 5)));
			}
			for(int i = 0; i < cbit[5];i++){
				Game.CreateObject("CrabCan00", pos + new Vector2(rnd.Next(-4, 4), rnd.Next(1, 5)));
			}
		}
	}
}

public void PickUpItems(TriggerArgs args){
	foreach(IPlayer ply in Game.GetPlayers()){
		if(ply.IsUser && !ply.IsDead && (ply.IsCrouching && ply.IsBlocking && ply.IsWalking) ){
			Inventory inv = plyInv[ply];
			Vector2 EffectPos = ply.GetWorldPosition() + new Vector2(0, 6);
			Area PickUpArea = new Area (ply.GetWorldPosition() + new Vector2 (-8,-8) , ply.GetWorldPosition() + new Vector2 (8,8));
			bool WoodsH = false;
			bool MetalsH = false;
			bool ComponentsH = false;
			bool GasH = false;
			bool PropaneH = false;
			bool CannedFoodH = false;
			foreach(IObject obj in Game.GetObjectsByArea(PickUpArea)){
				bool Destroy = false;
				if(obj.Name.Contains("WoodDebris")||obj.Name.Contains("ItemDebrisWood")||obj.Name.Contains("WoodBarrelDebris")){ inv.Woods += 1;WoodsH = true;Destroy = true; }
				if(obj.Name.Contains("MetalDebris")){ inv.Metals += 1;MetalsH = true;Destroy = true; }
				if(obj.Name.Contains("ChairLeg")){ inv.Woods += 2;WoodsH = true;Destroy = true; }
				if(obj.Name.Contains("WoodDebrisTable")){ inv.Woods += 3;WoodsH = true;Destroy = true; }
				if(obj.Name.Contains("Gascan")){ inv.Gas += 3;GasH = true;Destroy = true; }
				if(obj.Name.Contains("CrabCan")){ inv.CannedFood += 1;CannedFoodH = true;Destroy = true; }
				if(obj.Name.Contains("Propane")){ inv.Propane += 3;PropaneH = true;Destroy = true; }
				if(obj.Name.Contains("ItemDebrisShiny")||obj.Name.Contains("ItemDebrisDark")||obj.Name.Contains("ItemDebrisStock")||obj.Name.Contains("ItemDebrisBazooka")||obj.Name.Contains("ItemDebrisFlamethrower")){ inv.Components += 2;ComponentsH = true;Destroy = true; }
				if(obj.Name == "Computer00" || obj.Name == "Monitor00"){ inv.Components += 5;ComponentsH = true;Destroy = true; }
				if(obj.Name == "MetalBucket00"||obj.Name == "Helmet00"||obj.Name == "GasMask00"||obj.Name == "CashRegister00"||obj.Name == "Computer00"||obj.Name.Contains("Monitor00")){ inv.Metals += 3;MetalsH = true;Destroy = true; }
				if(obj.Name == "CardboardBox00"){
					int[] cbit = new int[6];
					try{cbit = cbBoxItems[obj];}
					catch(Exception){cbBoxItems.Add(obj, new int[]{rnd.Next(2,5), rnd.Next(1,5), rnd.Next(5), rnd.Next(5), rnd.Next(3), rnd.Next(2)}); cbit = cbBoxItems[obj];}
					inv.Woods += cbit[0];
					inv.Metals += cbit[1];
					inv.Components += cbit[2];
					inv.Gas += cbit[3];
					inv.Propane += cbit[4];
					inv.CannedFood += cbit[5];
					if(cbit[0] > 0)WoodsH = true;
					if(cbit[1] > 0)MetalsH = true;
					if(cbit[2] > 0)ComponentsH = true;
					if(cbit[3] > 0)GasH = true;
					if(cbit[4] > 0)PropaneH = true;
					if(cbit[5] > 0)CannedFoodH = true;
					cbit = new int[6] {0,0,0,0,0,0};
					cbBoxItems[obj] = cbit;
				}
				if(Destroy)obj.Remove();
			}
			if(WoodsH || MetalsH || ComponentsH || GasH || PropaneH || CannedFoodH)
			Game.PlayEffect("CFTXT", EffectPos, string.Format("{0}{1}{2}{3}{4}{5}", 
				WoodsH ? "/ Woods: "+inv.Woods.ToString()+" /" : "",
				MetalsH ? "/ Metals: "+inv.Metals.ToString()+" /" : "",
				ComponentsH ? "/ Components: "+inv.Components.ToString()+" /" : "",
				GasH ? "/ Gas: "+inv.Gas.ToString()+" /" : "",
				PropaneH ? "/ Propane: "+inv.Propane.ToString()+" /" : "",
				CannedFoodH ? "/ CannedFood: "+inv.CannedFood.ToString()+" /" : ""
			));
			if(inv.GuiOn)inv.Gui.organize();
		}
	}
}
//}
/* Craft System */
//{
public void OnUserMessage(UserMessageCallbackArgs args){
	if(args.IsCommand){
		string cmd = args.Command.ToUpper();
		string arg = args.CommandArguments.ToUpper();
		//Game.ShowChatMessage(cmd);
		//Game.ShowChatMessage(arg);
		if(args.User.GetPlayer() != null){
			IPlayer ply = args.User.GetPlayer();
			Inventory inv = null;
			try{ inv = plyInv[ply]; }catch(Exception){AddClass(ply);inv = plyInv[ply];}
			if((cmd == "C" && arg == "M") || cmd == "CM" || cmd == "CRAFT_MELEE" || (cmd == "CRAFT" && arg == "MELEE")){
				GUI g = new GUI(new Vector2(0), new string[]{"Bat", "Pipe", "Hammer", "Axe", "Machete", "Knife", "Katana", "Shock Baton"}, ply);
				return;
			}
			else if((cmd == "C" && arg == "G") || cmd == "CG" || cmd == "CRAFT_GUN" || (cmd == "CRAFT" && arg == "GUN")){
			GUI g = new GUI(new Vector2(0), new string[]{"Pistol", "Pistol45", "Machine Pistol", "Bow", "Magnum", "Revolver", "Carbine"}, ply);
			return;
			}
			else if((cmd == "C" && arg == "O") || cmd == "CO" || cmd == "CRAFT_OTHER" || (cmd == "CRAFT" && arg == "OTHER")){
				GUI g = new GUI(new Vector2(0), new string[]{"Grenades", "Components"}, ply);
				return;
			}
			if(cmd == "EAT_CANNEDFOOD" || cmd == "EATCANNEDFOOD" || cmd == "ECF" || (cmd == "EAT" && arg == "CANNEDFOOD")){
				if(inv.CannedFood >= 1 && ply.GetHealth() < 80){
					ply.SetHealth(ply.GetHealth()+20);
					Game.PlayEffect("CFTXT",ply.GetWorldPosition() + new Vector2(0,10),"Hmmm delicius! :D");
					inv.CannedFood -= 1;
					Game.CreateObject("CrabCan00", ply.GetWorldPosition() + new Vector2(rnd.Next(-1,1),10));
				}
				else if(inv.CannedFood >= 1 && ply.GetHealth() >99)
				Game.PlayEffect("CFTXT",ply.GetWorldPosition() + new Vector2(0,10),"I do not need this... :/");
				return;
			}
			foreach(Rcp r in Rcps){
				if(cmd == "CRAFT_"+r.ID.ToUpper() || (cmd == "CRAFT" && arg == r.ID.ToUpper()) || cmd == "C"+r.ID.ToUpper()){
					r.Craft(inv);
				}
			}
		}
		if(cmd == "LISTOFWEAPONS" || cmd == "LIST" || (cmd == "LIST" && arg == "OF WEAPONS")){
			Game.ShowChatMessage(" ----Melee----", Color.Red, args.User.UserIdentifier);
			Game.ShowChatMessage(" Bat: "+Bat.Cost(),Color.Yellow, args.User.UserIdentifier);
			Game.ShowChatMessage(" Pipe: "+LeadPipe.Cost(),Color.Yellow, args.User.UserIdentifier);
			Game.ShowChatMessage(" Hammer: "+Hammer.Cost(),Color.Yellow, args.User.UserIdentifier);
			Game.ShowChatMessage(" Axe: "+Axe.Cost(),Color.Yellow, args.User.UserIdentifier);
			Game.ShowChatMessage(" Knife: "+Knife.Cost(),Color.Yellow, args.User.UserIdentifier);
			Game.ShowChatMessage(" Katana: "+Katana.Cost(),Color.Yellow, args.User.UserIdentifier);
			Game.ShowChatMessage(" Machete: "+Machete.Cost(),Color.Yellow, args.User.UserIdentifier);
			Game.ShowChatMessage(" ShockBaton: "+ShockBaton.Cost(),Color.Yellow, args.User.UserIdentifier);
			Game.ShowChatMessage(" -----GUNS-----", Color.Red, args.User.UserIdentifier);
			Game.ShowChatMessage(" Bow: "+Bow.Cost(), Color.Yellow, args.User.UserIdentifier);
			Game.ShowChatMessage(" Pistol: "+Pistol.Cost(),Color.Yellow, args.User.UserIdentifier);
			Game.ShowChatMessage(" Pistol.45: "+Pistol45.Cost(),Color.Yellow, args.User.UserIdentifier);
			Game.ShowChatMessage(" MachinePistol: "+MachinePistol.Cost(),Color.Yellow, args.User.UserIdentifier);
			Game.ShowChatMessage(" Revolver: "+Revolver.Cost(),Color.Yellow, args.User.UserIdentifier);
			Game.ShowChatMessage(" Magnum: "+Magnum.Cost(),Color.Yellow, args.User.UserIdentifier);
			Game.ShowChatMessage(" Carbine: "+Carbine.Cost(),Color.Yellow, args.User.UserIdentifier);
			Game.ShowChatMessage(" ----OTHERS----", Color.Red, args.User.UserIdentifier);
			Game.ShowChatMessage(" Grenades: "+Grenades.Cost(),Color.Yellow, args.User.UserIdentifier);
			Game.ShowChatMessage(" Components: "+ComponentsR.Cost(), Color.Yellow, args.User.UserIdentifier);
			return;
		}
		if(cmd == "CMDS" || cmd == "COMMANDS" || cmd == "CD_HELP"){
			Game.ShowChatMessage("'/Info' to show more information about the script.", Color.Yellow, args.User.UserIdentifier);
			Game.ShowChatMessage("'/Show items' to show the amount of resources in your inventory.", Color.Yellow, args.User.UserIdentifier);
			Game.ShowChatMessage("'/List of weapons (or '/List')' to show the list of weapons available for crafting.", Color.Yellow, args.User.UserIdentifier);
			Game.ShowChatMessage("'/Eat Cannedfood (or '/EAT')' to show more information about the script.", Color.Yellow, args.User.UserIdentifier);
			Game.ShowChatMessage("'/Craft [Weapon Id] (Id of '/List of weapons')' for crafting a weapon.", Color.Yellow, args.User.UserIdentifier);
			Game.ShowChatMessage("- Crafting - (UP - To scroll up the list) (DOWN - To scroll down the list)", Color.Red, args.User.UserIdentifier);
			Game.ShowChatMessage("'/Craft Melee (or '/CM')' to choose a melee weapon for crafting.", Color.Yellow, args.User.UserIdentifier);
			Game.ShowChatMessage("'/Craft Gun (or '/CG')' to choose a gun for crafting.", Color.Yellow, args.User.UserIdentifier);
			Game.ShowChatMessage("'/Craft Other (or '/CO')' to choose a gun for crafting.", Color.Yellow, args.User.UserIdentifier);
		}
		if(cmd == "INFO"){
			Game.ShowChatMessage("------------------------", Color.Red, args.User.UserIdentifier);
			Game.ShowChatMessage("Script by Lozango", Color.Yellow, args.User.UserIdentifier);
			Game.ShowChatMessage("------------------------", Color.Red, args.User.UserIdentifier);
			Game.ShowChatMessage("To pick up items press Down, Defense and Walk.", Color.Yellow, args.User.UserIdentifier);
			Game.ShowChatMessage("To find out how many items you have in your inventory, type '/Show items'.", Color.Yellow, args.User.UserIdentifier);
			Game.ShowChatMessage("To see the list of weapons that can be crafting and the recipe for all weapons type '/List of weapons'.", Color.Yellow, args.User.UserIdentifier);            Game.ShowChatMessage("To drop an debris, type /Drop (Debris name)", Color.Yellow, args.User.UserIdentifier);
			Game.ShowChatMessage("You can see all script commands here '/CMDS'.", Color.Yellow, args.User.UserIdentifier);			Game.ShowChatMessage("You can break mailboxes to gain resources.", Color.Yellow, args.User.UserIdentifier);
			Game.ShowChatMessage("Important!, The script is still under development by Lozango, If you find any error, call me on Discord (Lozango com z#7177)", Color.Magenta, args.User.UserIdentifier);
			Game.ShowChatMessage("------------------------", Color.Red, args.User.UserIdentifier);		
		}
		if(cmd == "SHOWITEMS" || cmd == "SHOW" && arg == "ITEMS"){
			if(args.User.GetPlayer() != null){
				IPlayer ply = args.User.GetPlayer();
				Inventory inv = null;
				try{ inv = plyInv[ply]; }catch(Exception){AddClass(ply);inv = plyInv[ply];}
				Game.ShowChatMessage(
				string.Format("You have {0}{1}{2}{3}{4}{5}", 
					inv.Woods > 0 ? " Woods: "+inv.Woods.ToString()+" /" : "",
					inv.Metals > 0 ? " Metals: "+inv.Metals.ToString()+" /" : "",
					inv.Components > 0 ? " Components: "+inv.Components.ToString()+" /" : "",
					inv.Gas > 0 ? " Gas: "+inv.Gas.ToString()+" /" : "",
					inv.Propane > 0 ? " Propane: "+inv.Propane.ToString()+" /" : "",
					inv.CannedFood > 0 ? " Gas: "+inv.CannedFood.ToString()+" /" : ""), Color.Yellow, args.User.UserIdentifier);
			}else Game.ShowChatMessage("Your character is dead.", Color.Yellow, args.User.UserIdentifier);
		}
	}
}

public class GUI{
	public button[] buttons;
	public int Selected = 0;
	public bool On = true;
	IPlayer cply;
	public void adjust(){
		foreach(button bt in buttons){
			bt.obj.SetWorldPosition(cply.GetWorldPosition() + new Vector2(0, 20));
		}
		Events.UpdateCallback.Start((float r) => {
			if(On == true){
				if(cply.IsDead || !cply.IsIdle)destroy();
				adjust();
			}
		}, 30, 1);
	}
	public void destroy(){
		On = false;
			
		foreach(button bt in buttons){
			bt.obj.Remove();
		}
		plyInv[cply].Gui = null;
		plyInv[cply].GuiOn = false;
	}
	public void active(){
		button bt = buttons[Selected];
		foreach(Rcp r in Rcps){
			if(((r.ID == bt.id && cply.CurrentMeleeWeapon.WeaponItem != r.WI) || (r.ID == bt.id + " Ammo" && cply.CurrentMeleeWeapon.WeaponItem == r.WI)) && On == true){
				r.Craft(plyInv[cply]);
				destroy();
			}
		}
	}
	public void organize(){
		for(int i = 0; i < buttons.Length; i++){
			buttons[i].obj.SetText("");
		}
		buttons[Selected].obj.SetText(buttons[Selected].id);
		foreach(Rcp r in Rcps){
			if((r.ID == buttons[Selected].id && cply.CurrentMeleeWeapon.WeaponItem != r.WI) || (r.ID == buttons[Selected].id + " Ammo" && cply.CurrentMeleeWeapon.WeaponItem == r.WI)){
				Inventory inv  = plyInv[cply];
				if(inv.Woods >= r.Woods && inv.Metals >= r.Metals && inv.Components >= r.Components && inv.Gas >= r.Gas && inv.Propane >= r.Propane)
					buttons[Selected].obj.SetTextColor(Color.Green);
				else
					buttons[Selected].obj.SetTextColor(Color.Red);
			}
		}
	}
	public void interact(VirtualKey key){
		if(key == VirtualKey.AIM_CLIMB_DOWN || key == VirtualKey.WALKING){
			Selected--;
			if(Selected < 0)Selected = buttons.Length - 1;
			organize();
		}
		if(key == VirtualKey.AIM_CLIMB_UP || key == VirtualKey.SPRINT){
			Selected++;
			if(Selected > buttons.Length - 1)Selected = 0;
			organize();
		}
		if(key == VirtualKey.ACTIVATE /*|| key == VirtualKey.ATTACK*/){
			active();
		}
		
	}
	public class button{
		public string id = "";
		public IObjectText obj = (IObjectText)Game.CreateObject("Text");
		public button(Vector2 local, string id_){
			obj.SetText(id_);
			obj.SetWorldPosition(local);
			obj.SetTextAlignment(TextAlignment.Middle);
			id = id_;
		}
	}
	public GUI(Vector2 local, string[] strings, IPlayer ply){
		buttons = new button[strings.Length];
		cply = ply;
		Inventory inv = plyInv[ply];
		inv.Gui = this;
		inv.GuiOn = true;
		for(int i = 0; i < strings.Length; i++){
			buttons[i] = new button(new Vector2(0f), strings[i]);
		}
		organize();
		adjust();
	}
}

public void OnPlayerKeyInput(IPlayer ply, VirtualKeyInfo[] keyEvents){
	Inventory inv = null;
	try{ inv = plyInv[ply]; }catch(Exception){AddClass(ply);inv = plyInv[ply];}
	if(inv.GuiOn == true && inv.Gui != null){
		GUI g = inv.Gui;
		VirtualKeyInfo keyInfo = keyEvents[0];
		VirtualKey key = keyInfo.Key;
		if(keyInfo.Event == VirtualKeyEvent.Pressed){
			g.interact(key);
		}
	}
}
//}

public void CreateTimer(int interval, int repeat, string script, string customid){IObjectTimerTrigger obj = (IObjectTimerTrigger)Game.CreateObject("TimerTrigger");obj.SetIntervalTime(interval);obj.SetRepeatCount(repeat);obj.SetScriptMethod(script);obj.CustomId = customid;obj.StartTimer();}