/*
									SA-MP GUI by Thoth A.K.A Seif

» Windows;
» Text Labels;
» Tabs;
» Progress bars;
» Itemlist
» Checkbox/radio buttons
» Buttons
*/

#include <a_samp>

#define function%0(%1) forward %0(%1); public %0(%1)


#define GUI_TYPE_WINDOW         (1)
#define GUI_TYPE_TAB 			(2)
#define GUI_TYPE_LABEL 			(3)
#define GUI_TYPE_BAR 			(4)
#define GUI_TYPE_ITEMLIST 		(5)
#define GUI_TYPE_CHECKBOX 		(6)
#define GUI_TYPE_BUTTON 		(7)


#define UNIT            0.11            // Font size 0.11 ~= 1 unit pixel
#define MAX_GUI     	(50)        	// Maximum GUI per player


new textdrawVisibility[2048];
new p_textdrawVisibility[MAX_PLAYERS][2048];
new p_tab[MAX_PLAYERS];
new p_row[MAX_PLAYERS];
new pcount_i[MAX_PLAYERS];

enum guiinfo_window
{
	gui_win_ID,
	Float:gui_win_X,
	Float:gui_win_Y,
	Float:gui_win_SizeX,
	Float:gui_win_SizeY,
	gui_win_Title[64],
	PlayerText:gui_win_td,
	PlayerText:gui_win_tdtop,
	PlayerText:gui_win_tdtitle,
	gui_win_P,
}
new gui_WindowData[MAX_PLAYERS][MAX_GUI][guiinfo_window];

enum guiinfo_label
{
	gui_label_ID,
	gui_label_Type,
	gui_label_Window,   // 0 for none, or set the window gui ID so it's part of it
	gui_label_Tab,   	// 0 for none, or set the tab gui ID so it's part of it. If the tab is part of a window, set the window id too!
	Float:gui_label_X,  // if Window/Tab is set, this value is relative to the window's/tab's
	Float:gui_label_Y,  // if Window/Tab is set, this value is relative to the window's/tab's
	Float:gui_label_Length,
	gui_label_Text[64],
	gui_label_Color,
	PlayerText:gui_label_td,
	gui_label_Lines,
	gui_label_P,
}
new gui_LabelData[MAX_PLAYERS][MAX_GUI][guiinfo_label];

enum guiinfo_tab
{
	gui_tab_ID,
	gui_tab_Type,
	gui_tab_Window,   // 0 for none, or set the window gui ID so it's part of it
	Float:gui_tab_X,  // if Window is set, this value is relative to the window's
	Float:gui_tab_Y,  // if Window is set, this value is relative to the window's
	Float:gui_tab_plusX,
	Float:gui_tab_Height, // 0.0 will take the rest of the GUI window height IF window gui is set. This value is relative to its window parent.
	Float:gui_tab_Width, // 0.0 will take the rest of the GUI window width IF window gui is set This value is relative to its window parent.
	gui_tab_Text[64],
	PlayerText:gui_tab_td,
	PlayerText:gui_tab_td2, // active
	PlayerText:gui_tab_tdbg,
	PlayerText:gui_tab_tdbox,
	gui_tab_panel,
	Float:gui_tab_panelX,
	Float:gui_tab_panelY,
	gui_tab_P,
}
new gui_TabData[MAX_PLAYERS][MAX_GUI][guiinfo_tab];

enum guiinfo_bar
{
	gui_bar_ID,
	gui_bar_Type,
	gui_bar_Window,   // 0 for none, or set the window gui ID so it's part of it
	gui_bar_Tab,   	// 0 for none, or set the tab gui ID so it's under it, AND set the window id of the tab.
	Float:gui_bar_X,  // if Window is set, this value is relative to the window's/tab's
	Float:gui_bar_Y,  // if Window is set, this value is relative to the window's/tab's
	Float:gui_bar_Height, // Sets the height of the bar.
	Float:gui_bar_Width, // Sets the weidth of the bar.
	Float:gui_bar_Progress, // The progress in percentage
	PlayerText:gui_bar_tdbg,
	PlayerText:gui_bar_tdbox,
	PlayerText:gui_bar_tdbar,
	gui_bar_bgcolor,
	gui_bar_boxcolor,
	gui_bar_barcolor,
	gui_bar_P,
}
new gui_BarData[MAX_PLAYERS][MAX_GUI][guiinfo_bar];

enum guiinfo_list
{
	gui_list_ID,
	gui_list_Type,
	gui_list_Window,   // 0 for none, or set the window gui ID so it's part of it
	gui_list_Tab,   	// 0 for none, or set the tab gui ID so it's under it, AND set the window id of the tab.
	Float:gui_list_X,  // if Window is set, this value is relative to the window's/tab's
	Float:gui_list_Y,  // if Window is set, this value is relative to the window's/tab's
	Float:gui_list_Height, // Sets the height of the bar. Set to 0.0 to take up the whole window or tab panel
	Float:gui_list_Width, // Sets the weidth of the bar. Set to 0.0 to take up the whole window or tab panel
	Float:gui_list_RowX,
	Float:gui_list_RowY,
	gui_list_RowMax,
	gui_list_Title[32],
	PlayerText:gui_list_tdbox,
	PlayerText:gui_list_tdline,
	PlayerText:gui_list_tdtitle,
	gui_list_P,
}
new gui_ItemlistData[MAX_PLAYERS][MAX_GUI][guiinfo_list];
enum guiinfo_row
{
	gui_row_ID,
	gui_row_List,
	gui_row_Order, // The order number in the list. Ex. 0 = first in the list. 1 = second in the list(if there's multiple listitems)
	Float:gui_row_X,
	Float:gui_row_Y,
	Float:gui_row_Height,
	Float:gui_row_Width,
	gui_row_Text[32],
	PlayerText:gui_row_td,
	PlayerText:gui_row_td2, // active
}
new gui_ItemRowData[MAX_PLAYERS][MAX_GUI][guiinfo_row];

enum guiinfo_check
{
	gui_check_ID,
	gui_check_Type,
	gui_check_Window,
	gui_check_Tab,
	Float:gui_check_X,
	Float:gui_check_Y,
	PlayerText:gui_check_td,
	PlayerText:gui_check_td2, // active
	gui_check_P,
}
new gui_CheckboxData[MAX_PLAYERS][MAX_GUI][guiinfo_check];

enum guiinfo_but
{
	gui_but_ID,
	gui_but_Type,
	gui_but_Window,   // 0 for none, or set the window gui ID so it's part of it
	gui_but_Tab,   	// 0 for none, or set the tab gui ID so it's under it, AND set the window id of the tab.
	Float:gui_but_X,  // if Window is set, this value is relative to the window's/tab's
	Float:gui_but_Y,  // if Window is set, this value is relative to the window's/tab's
	Float:gui_but_Height, // Sets the height of the bar.
	Float:gui_but_Width, // Sets the weidth of the bar.
	gui_but_Text[32],
	PlayerText:gui_but_tdbg,
	PlayerText:gui_but_tdout,
	PlayerText:gui_but_tdbox,
	PlayerText:gui_but_tdgl,
	PlayerText:gui_but_tdtxt,
	gui_but_P,
}
new gui_ButtonData[MAX_PLAYERS][MAX_GUI][guiinfo_but];


forward OnPlayerClickTab(playerid, tabid);
forward OnPlayerClickButton(playerid, buttonid);

/*
native guiSetVisible(playerid, type, gui, bool:toggle)
native guiSetVisibleAll(type, gui, bool:toggle)
native guiCreateWindow(playerid, Float:x, Float:y, Float:size_x, Float:size_y, title[])
native guiCreateTab(playerid, windowid, Float:x, Float:y, Float:height, Float:width, text[])
native guiCreateLabel(playerid, windowid, tabid, Float:x, Float:y, Float:length, color, font, text[])
native guiLabelSetText(playerid, labelid, color, font, text[])
native guiCreateProgressBar(playerid, windowid, tabid, Float:x, Float:y, Float:height, Float:width, color_bg, color_box, color_bar)
native guiProgressBarSetProgress(playerid, barid, Float:progress)
native Float:guiProgressBarGetProgress(playerid, barid)
native guiCreateItemList(playerid, windowid, tabid, Float:x, Float:y, Float:height, Float:width, title[])
native guiItemListAddRow(playerid, listid, text[])
native guiItemListRemoveRow(playerid, listid, rowid)
native guiItemListSetRowOrder(playerid, listid, rowid, orderid)
native guiItemListGetSelectedRow(playerid)
native guiItemListGetRowText(playerid, listid, rowid, string[])
native guiItemListGetCount(playerid, listid)
native guiItemListGetRowList(playerid, rowid)
native guiCreateCheckBox(playerid, windowid, tabid, Float:x, Float:y)
native guiCheckBoxGetSelected(playerid, checkboxid)
native guiCheckBoxSetSelected(playerid, checkboxid)
native guiGetCheckBoxPos(playerid, checkboxid, &Float:x, &Float:y)
native guiCreateButton(playerid, windowid, tabid, Float:x, Float:y, Float:height, Float:width, text[])
native Float:guiGetButtonHeight(playerid, buttonid)
native Float:guiGetButtonWidth(playerid, buttonid)
native guiGetButtonPos(playerid, buttonid, &Float:x, &Float:y)
native guiIsVisible(playerid, type, gui)
native guiDestroy(playerid, type, gui)
native guiDestroyAll(playerid, type)
*/
/*x---------------------------------CallBacks-------------------------------------x*/
/*forward gui_OnPlayerConnect(playerid); 
public gui_OnPlayerConnect(playerid)
{
	//CreatePlayerTextDraw(playerid, 0.0, 0.0, "_");
	//p_tab[playerid] = 0;
	//p_row[playerid] = 0;
	//return OnPlayerConnect(playerid);
	return 1;
}
//#define OnPlayerConnect gui_OnPlayerConnect*/

forward gui_OnPlayerConnect(playerid);
public gui_OnPlayerConnect(playerid)
{
	CreatePlayerTextDraw(playerid, 0.0, 0.0, "_");
	p_tab[playerid] = 0;
	p_row[playerid] = 0;
	return OnPlayerConnect(playerid);
}

function PlayerTextDrawShowEx(playerid, PlayerText:textdrawid)
{
	p_textdrawVisibility[playerid][io_PlayerText:textdrawid] = 1;
	return PlayerTextDrawShow(playerid, textdrawid);
}
#define PlayerTextDrawShow(%0,%1) PlayerTextDrawShowEx(%0,%1)
function PlayerTextDrawHideEx(playerid, PlayerText:textdrawid)
{
	p_textdrawVisibility[playerid][io_PlayerText:textdrawid] = 0;
	return PlayerTextDrawHide(playerid, textdrawid);
}
#define PlayerTextDrawHide(%0,%1) PlayerTextDrawHideEx(%0,%1)
function TextDrawDestroyEx(playerid, PlayerText:textdrawid)
{
	for(new p; p < MAX_PLAYERS; p++)
	{
	    if (!IsPlayerConnected(p)) continue;
	    p_textdrawVisibility[p][io_PlayerText:textdrawid] = 0;
	}
	textdrawVisibility[io_PlayerText:textdrawid] = 0;
	return PlayerTextDrawDestroy(playerid, textdrawid);
}
function GetTextDrawVisibilityForPlayer(playerid, PlayerText:textdrawid) return p_textdrawVisibility[playerid][io_PlayerText:textdrawid];
function GetTextDrawVisibilityForAll(PlayerText:textdrawid) return textdrawVisibility[io_PlayerText:textdrawid];

function guiSetVisible(playerid, type, gui, bool:toggle)
{
	new str[32],end = 0;
	new oldw = GetPVarInt(playerid, "guisetvisible_w");

 	if (toggle == true)
 	{
 		format(str, sizeof str, "PlayerTextDrawShowEx");
	}
	else if (toggle == false)
	{
	    format(str, sizeof str, "PlayerTextDrawHideEx");
	}

	new gid = guiGetID(playerid, type, gui);
	if (gid == -1) return 0;

    //printf("ID: %d = %s", playerid, str);
	    
	if (type == GUI_TYPE_WINDOW)
	{
	    CallLocalFunction(str, "dd", playerid, io_PlayerText:gui_WindowData[playerid][gid][gui_win_td]);
	    CallLocalFunction(str, "dd", playerid, io_PlayerText:gui_WindowData[playerid][gid][gui_win_tdtop]);
	    CallLocalFunction(str, "dd", playerid, io_PlayerText:gui_WindowData[playerid][gid][gui_win_tdtitle]);
	}
	else if (type != GUI_TYPE_TAB && type != GUI_TYPE_WINDOW) end = 1;

	new count;
	/*if (p_tab[playerid] > 0)
	{
		type = GUI_TYPE_TAB;
		gui = gui_TabData[p_tab[playerid]][gui_tab_ID];
	}*/
	for(new g; g < MAX_GUI; g++)
	{
	    switch (type)
		{
			case GUI_TYPE_TAB: goto TAB;
			case GUI_TYPE_LABEL: goto LABEL;
			case GUI_TYPE_BAR: goto BAR;
			case GUI_TYPE_ITEMLIST: goto ITEMLIST;
			case GUI_TYPE_CHECKBOX: goto CHECKBOX;
			case GUI_TYPE_BUTTON: goto BUTTON;
		}

		TAB:
	    if (
			gui_TabData[playerid][g][gui_tab_ID] > 0 &&
			(
				(type == GUI_TYPE_WINDOW && gui_TabData[playerid][g][gui_tab_Window] == gui) ||
				(type == gui_TabData[playerid][g][gui_tab_Type])
			) &&
			gui_TabData[playerid][g][gui_tab_P] == playerid
		)
		{
			if (!count && !p_tab[playerid])
			{
				p_tab[playerid] = g;
				CallLocalFunction(str, "dd", playerid, io_PlayerText:gui_TabData[playerid][g][gui_tab_td2]); // first tab
				//type = GUI_TYPE_TAB;
				//gui = gui_TabData[g][gui_tab_ID];
				if (type == GUI_TYPE_WINDOW) // Re-applies the function with the tab option, so it can show its child elements
				{
					SetPVarInt(playerid, "guisetvisible_w", gui);
					guiSetVisible(playerid, GUI_TYPE_TAB, gui_TabData[playerid][g][gui_tab_ID], toggle);
					break;
				}
			}
			else if (p_tab[playerid] == g)
			{
				CallLocalFunction(str, "dd", playerid, io_PlayerText:gui_TabData[playerid][g][gui_tab_td2]); // selected tab
				//type = GUI_TYPE_TAB;
				//gui = gui_TabData[playerid][g][gui_tab_ID];
				if (type == GUI_TYPE_WINDOW)
				{
					guiSetVisible(playerid, GUI_TYPE_TAB, gui_TabData[playerid][g][gui_tab_ID], toggle);
					break;
				}
			}
			else CallLocalFunction(str, "dd", playerid, io_PlayerText:gui_TabData[playerid][g][gui_tab_td]);
		    CallLocalFunction(str, "dd", playerid, io_PlayerText:gui_TabData[playerid][g][gui_tab_tdbg]);
		    CallLocalFunction(str, "dd", playerid, io_PlayerText:gui_TabData[playerid][g][gui_tab_tdbox]);
		    count++;
		}
		if (end) continue;

		LABEL:
		//printf("Type: %d(%d) | GUI: %d(%d) | Window: %d(%d) | Tab: %d(%d)", type, gui_LabelData[playerid][g][gui_label_Type], gui, gui_LabelData[playerid][g][gui_label_ID], gui, gui_LabelData[playerid][g][gui_label_Window], gui, gui_LabelData[playerid][g][gui_label_Tab]);
	    if (
			gui_LabelData[playerid][g][gui_label_ID] > 0 &&                                               	// Valid gui?
			(
				(type == GUI_TYPE_WINDOW && gui_LabelData[playerid][g][gui_label_Window] == gui &&            // If it's being viewed under a window (In case the window has no tab)
					(
						(!gui_LabelData[playerid][g][gui_label_Tab] && toggle) ||
						(gui_LabelData[playerid][g][gui_label_Tab] > 0 && !toggle)
					)
				) ||
				(type == GUI_TYPE_TAB && gui_LabelData[playerid][g][gui_label_Tab] == gui) ||                 // Under a tab?
				(type == gui_LabelData[playerid][g][gui_label_Type] && gui_LabelData[playerid][g][gui_label_ID] == gui) // Maybe it's alone?
			) ||
		 	(                                                                                       // It's under a window, however if the window has a tab, it automatically runs the function under tab. So this checks if it's only under a window
			 	oldw > 0 && oldw == gui_LabelData[playerid][g][gui_label_Window] &&
			 	(type == GUI_TYPE_TAB && !gui_LabelData[playerid][g][gui_label_Tab])
			) &&
			gui_LabelData[playerid][g][gui_label_P] == playerid
		)
		{
			CallLocalFunction(str, "dd", playerid, io_PlayerText:gui_LabelData[playerid][g][gui_label_td]);
		}
		if (end) continue;

		BAR:
	    if (
			gui_BarData[playerid][g][gui_bar_ID] > 0 &&
			(
				(type == GUI_TYPE_WINDOW && gui_BarData[playerid][g][gui_bar_Window] == gui &&
					(
						(!gui_BarData[playerid][g][gui_bar_Tab] && toggle) ||
						(gui_BarData[playerid][g][gui_bar_Tab] > 0 && !toggle)
					)
				) ||
				(type == GUI_TYPE_TAB && gui_BarData[playerid][g][gui_bar_Tab] == gui) ||
				(type == gui_BarData[playerid][g][gui_bar_Type] && gui_BarData[playerid][g][gui_bar_ID] == gui)
			) ||
		 	(
			 	oldw > 0 && oldw == gui_BarData[playerid][g][gui_bar_Window] &&
			 	(type == GUI_TYPE_TAB && !gui_BarData[playerid][g][gui_bar_Tab])
			) &&
			gui_BarData[playerid][g][gui_bar_P] == playerid
		)
		{
            CallLocalFunction(str, "dd", playerid, io_PlayerText:gui_BarData[playerid][g][gui_bar_tdbg]);
            CallLocalFunction(str, "dd", playerid, io_PlayerText:gui_BarData[playerid][g][gui_bar_tdbox]);
            CallLocalFunction(str, "dd", playerid, io_PlayerText:gui_BarData[playerid][g][gui_bar_tdbar]);
		}
		if (end) continue;

		ITEMLIST:
		if (
			gui_ItemlistData[playerid][g][gui_list_ID] > 0 &&
			(
				(type == GUI_TYPE_WINDOW && gui_ItemlistData[playerid][g][gui_list_Window] == gui &&
					(
						(!gui_ItemlistData[playerid][g][gui_list_Tab] && toggle) ||
						(gui_ItemlistData[playerid][g][gui_list_Tab] > 0 && !toggle)
					)
				) ||
				(type == GUI_TYPE_TAB && gui_ItemlistData[playerid][g][gui_list_Tab] == gui) ||
				(type == gui_ItemlistData[playerid][g][gui_list_Type] && gui_ItemlistData[playerid][g][gui_list_ID] == gui)
			) ||
		 	(
			 	oldw > 0 && oldw == gui_ItemlistData[playerid][g][gui_list_Window] &&
			 	(type == GUI_TYPE_TAB && !gui_ItemlistData[playerid][g][gui_list_Tab])
			) &&
			gui_ItemlistData[playerid][g][gui_list_P] == playerid
		)
		{
            CallLocalFunction(str, "dd", playerid, io_PlayerText:gui_ItemlistData[playerid][g][gui_list_tdbox]);
            CallLocalFunction(str, "dd", playerid, io_PlayerText:gui_ItemlistData[playerid][g][gui_list_tdline]);
            CallLocalFunction(str, "dd", playerid, io_PlayerText:gui_ItemlistData[playerid][g][gui_list_tdtitle]);
			pcount_i[playerid] = 0;
			for(new r; r <= gui_ItemlistData[playerid][g][gui_list_RowMax]+1; r++)
			{
			    if (gui_ItemRowData[playerid][r][gui_row_ID] > 0 && gui_ItemRowData[playerid][r][gui_row_List] == gui_ItemlistData[playerid][g][gui_list_ID])
			    {
					if ((!pcount_i[playerid] && !p_row[playerid]) || p_row[playerid] == r)
					{
						CallLocalFunction(str, "dd", playerid, io_PlayerText:gui_ItemRowData[playerid][r][gui_row_td2]);
						p_row[playerid] = g;
					}
					else
					{
						CallLocalFunction(str, "dd", playerid, io_PlayerText:gui_ItemRowData[playerid][r][gui_row_td]);
					}
				}
				pcount_i[playerid]++;
			}
		}
		if (end) continue;

		CHECKBOX:
	    if (
			gui_CheckboxData[playerid][g][gui_check_ID] > 0 &&
			(
				(type == GUI_TYPE_WINDOW && gui_CheckboxData[playerid][g][gui_check_Window] == gui &&
					(
						(!gui_CheckboxData[playerid][g][gui_check_Tab] && toggle) ||
						(gui_CheckboxData[playerid][g][gui_check_Tab] > 0 && !toggle)
					)
				) ||
			 	(type == GUI_TYPE_TAB && gui_CheckboxData[playerid][g][gui_check_Tab] == gui) ||
			 	(type == gui_CheckboxData[playerid][g][gui_check_Type] && gui_CheckboxData[playerid][g][gui_check_ID] == gui)
		 	) ||
		 	(
			 	oldw > 0 && oldw == gui_CheckboxData[playerid][g][gui_check_Window] &&
			 	(type == GUI_TYPE_TAB && !gui_CheckboxData[playerid][g][gui_check_Tab])
			) &&
			gui_CheckboxData[playerid][g][gui_check_P] == playerid
		 )
		{
			CallLocalFunction(str, "dd", playerid, io_PlayerText:gui_CheckboxData[playerid][g][gui_check_td]);
		}
		if (end) continue;

		BUTTON:
	    //printf("Type: %d(%d) | GUI: %d(%d) | Window: %d | Tab: %d", type, gui_ButtonData[playerid][g][gui_but_Type], gui, gui_ButtonData[playerid][g][gui_but_ID], gui_ButtonData[playerid][g][gui_but_Window], gui_ButtonData[playerid][g][gui_but_Tab]);
	    if (
			gui_ButtonData[playerid][g][gui_but_ID] > 0 &&
			(
				(type == GUI_TYPE_WINDOW && gui_ButtonData[playerid][g][gui_but_Window] == gui &&
					(
						(!gui_ButtonData[playerid][g][gui_but_Tab] && toggle) ||
						(gui_ButtonData[playerid][g][gui_but_Tab] > 0 && !toggle)
					)
				) ||
				(type == GUI_TYPE_TAB && gui_ButtonData[playerid][g][gui_but_Tab] == gui) ||
		 		(type == gui_ButtonData[playerid][g][gui_but_Type] && gui_ButtonData[playerid][g][gui_but_ID] == gui)
		 	) ||
	 		(
			 	oldw > 0 && oldw == gui_ButtonData[playerid][g][gui_but_Window] &&
			 	(type == GUI_TYPE_TAB && !gui_ButtonData[playerid][g][gui_but_Tab])
			) &&
			gui_ButtonData[playerid][g][gui_but_P] == playerid
	 	)
		{
		    //printf("%s(%d, %d)", str, playerid, io_PlayerText:gui_ButtonData[playerid][g][gui_but_tdbg]);
			CallLocalFunction(str, "dd", playerid, io_PlayerText:gui_ButtonData[playerid][g][gui_but_tdbg]);
			CallLocalFunction(str, "dd", playerid, io_PlayerText:gui_ButtonData[playerid][g][gui_but_tdout]);
			CallLocalFunction(str, "dd", playerid, io_PlayerText:gui_ButtonData[playerid][g][gui_but_tdbox]);
			CallLocalFunction(str, "dd", playerid, io_PlayerText:gui_ButtonData[playerid][g][gui_but_tdtxt]);
			CallLocalFunction(str, "dd", playerid, io_PlayerText:gui_ButtonData[playerid][g][gui_but_tdgl]);
		}
		if (end) continue;
	}
	return 1;
}
function guiSetVisibleAll(type, gui, bool:toggle)
{
	for(new playerid, m = GetMaxPlayers(); playerid < m; playerid++)
	{
	    if (!IsPlayerConnected(playerid)) continue;
	    guiSetVisible(playerid, type, gui, toggle);
	}
}
/*function guiSetVisibleAll(type, gui, bool:toggle)
{
	gui--;
	new str[32],end = 0;

 	if (toggle == true)
 	{
 		format(str, sizeof str, "TextDrawShowForAllEx");
	}
	else if (toggle == false)
	{
	    format(str, sizeof str, "TextDrawHideForAllEx");
	}

	if (type == GUI_TYPE_WINDOW)
	{
	    CallLocalFunction(str, "d", io_PlayerText:gui_WindowData[gui][gui_win_td]);
	    CallLocalFunction(str, "d", io_PlayerText:gui_WindowData[gui][gui_win_tdtop]);
	    CallLocalFunction(str, "d", io_PlayerText:gui_WindowData[gui][gui_win_tdtitle]);
	}
	else if (type != GUI_TYPE_WINDOW && type != GUI_TYPE_WINDOW) end = 1;

	new count;
	if (p_tab[playerid] > 0)
	{
		type = GUI_TYPE_TAB;
		gui = gui_TabData[p_tab[playerid]][gui_tab_ID]-1;
	}
	for(new g; g < MAX_GUI; g++)
	{
	    if (end)
	    {
		    switch (type)
			{
				case GUI_TYPE_TAB: goto TAB;
				case GUI_TYPE_LABEL: goto LABEL;
				case GUI_TYPE_BAR: goto BAR;
				case GUI_TYPE_ITEMLIST: goto ITEMLIST;
				case GUI_TYPE_CHECKBOX: goto CHECKBOX;
				case GUI_TYPE_BUTTON: goto BUTTON;
			}
		}

		TAB:
	    if (gui_TabData[g][gui_tab_ID] > 0 && ((type == GUI_TYPE_WINDOW && gui_TabData[g][gui_tab_Window] == gui) || type == gui_TabData[g][gui_tab_Type]))
		{
			if (!count)
			{
				for(new playerid; playerid < MAX_PLAYERS; playerid++)
				{
					if (IsPlayerConnected(playerid) && !p_tab[playerid])
					{
						p_tab[playerid] = g;
						CallLocalFunction(str, "d", io_PlayerText:gui_TabData[g][gui_tab_td2]); // first tab
						type = GUI_TYPE_TAB;
						gui = gui_TabData[p_tab[playerid]][gui_tab_ID]-1;
					}
				}
			}
			else CallLocalFunction(str, "d", io_PlayerText:gui_TabData[g][gui_tab_td]);
		    CallLocalFunction(str, "d", io_PlayerText:gui_TabData[g][gui_tab_tdbg]);
		    CallLocalFunction(str, "d", io_PlayerText:gui_TabData[g][gui_tab_tdbox]);

			count++;
		}
		if (end) break;

		LABEL:
	    if (gui_LabelData[g][gui_label_ID] > 0 && ((type == GUI_TYPE_WINDOW && gui_LabelData[g][gui_label_Window] == gui && !gui_LabelData[g][gui_label_Tab]) || (type == GUI_TYPE_TAB && gui_LabelData[g][gui_label_Tab] == gui) || type == gui_LabelData[g][gui_label_Type]))
			CallLocalFunction(str, "d", io_PlayerText:gui_LabelData[g][gui_label_td]);
		if (end) break;

		BAR:
	    if (gui_BarData[g][gui_bar_ID] > 0 && ((type == GUI_TYPE_WINDOW && gui_BarData[g][gui_bar_Window] == gui && !gui_BarData[g][gui_bar_Tab]) || (type == GUI_TYPE_TAB && gui_BarData[g][gui_bar_Tab] == gui) || type == gui_BarData[g][gui_bar_Type]))
		{
            CallLocalFunction(str, "d", io_PlayerText:gui_BarData[g][gui_bar_tdbg]);
            CallLocalFunction(str, "d", io_PlayerText:gui_BarData[g][gui_bar_tdbox]);
            CallLocalFunction(str, "d", io_PlayerText:gui_BarData[g][gui_bar_tdbar]);
		}
		if (end) break;

		ITEMLIST:
	    if (gui_ItemlistData[g][gui_list_ID] > 0 && ((type == GUI_TYPE_WINDOW && gui_ItemlistData[g][gui_list_Window] == gui && !gui_ItemlistData[g][gui_list_Tab]) || (type == GUI_TYPE_TAB && gui_ItemlistData[g][gui_list_Tab] == gui) || type == gui_ItemlistData[g][gui_list_Type]))
		{
            CallLocalFunction(str, "d", io_PlayerText:gui_ItemlistData[g][gui_list_tdbox]);
            CallLocalFunction(str, "d", io_PlayerText:gui_ItemlistData[g][gui_list_tdline]);
            CallLocalFunction(str, "d", io_PlayerText:gui_ItemlistData[g][gui_list_tdtitle]);
			count = 0;
			for(new r; r <= gui_ItemlistData[g][gui_list_RowMax]+1; r++)
			{
			    if (gui_ItemRowData[playerid][r][gui_row_ID] > 0)
			    {
					if (!count)
					{
						CallLocalFunction(str, "d", io_PlayerText:gui_ItemRowData[playerid][r][gui_row_td2]);
						for(new playerid; playerid < MAX_PLAYERS; playerid++)
						 	p_row[playerid] = g;
					}
					else CallLocalFunction(str, "d", io_PlayerText:gui_ItemRowData[playerid][r][gui_row_td]);
				}
				count++;
			}
		}
		if (end) break;

		CHECKBOX:
	    if (gui_CheckboxData[g][gui_check_ID] > 0 && ((type == GUI_TYPE_WINDOW && gui_CheckboxData[g][gui_check_Window] == gui && !gui_CheckboxData[g][gui_check_Tab]) || (type == GUI_TYPE_TAB && gui_CheckboxData[g][gui_check_Tab] == gui) || type == gui_CheckboxData[g][gui_check_Type]))
		{
			CallLocalFunction(str, "d", io_PlayerText:gui_CheckboxData[g][gui_check_td]);
		}
		if (end) break;

		BUTTON:
	    if (gui_ButtonData[g][gui_but_ID] > 0 && ((type == GUI_TYPE_WINDOW && gui_ButtonData[g][gui_but_Window] == gui && !gui_ButtonData[g][gui_but_Tab]) || (type == GUI_TYPE_TAB && gui_ButtonData[g][gui_but_Tab] == gui) || type == gui_ButtonData[g][gui_but_Type]))
		{
			CallLocalFunction(str, "d", io_PlayerText:gui_ButtonData[g][gui_but_tdbg]);
			CallLocalFunction(str, "d", io_PlayerText:gui_ButtonData[g][gui_but_tdout]);
			CallLocalFunction(str, "d", io_PlayerText:gui_ButtonData[g][gui_but_tdbox]);
			CallLocalFunction(str, "d", io_PlayerText:gui_ButtonData[g][gui_but_tdtxt]);
			CallLocalFunction(str, "d", io_PlayerText:gui_ButtonData[g][gui_but_tdgl]);
		}
		if (end) break;
	}
}*/

function guiCreateWindow(playerid, Float:x, Float:y, Float:size_x, Float:size_y, title[])
{
	new wid = -1;
	for(new c; c < MAX_GUI; c++)
	{
	    if (!gui_WindowData[playerid][c][gui_win_ID])
	    {
	        wid = c;
	        break;
	    }
	}
	if (wid == -1) return !printf("ERROR GUI: You cannot exceed the GUI window limit! (%d)", MAX_GUI);

	gui_WindowData[playerid][wid][gui_win_X] = x;
	gui_WindowData[playerid][wid][gui_win_Y] = y;
	gui_WindowData[playerid][wid][gui_win_SizeX] = size_x;
	gui_WindowData[playerid][wid][gui_win_SizeY] = size_y;
	strins(gui_WindowData[playerid][wid][gui_win_Title], title, 0);
	gui_WindowData[playerid][wid][gui_win_P] = playerid;
 	gui_WindowData[playerid][wid][gui_win_ID] = wid+1;

    gui_WindowData[playerid][wid][gui_win_td] = CreatePlayerTextDraw(playerid, x, y, "_");
	PlayerTextDrawAlignment(playerid, gui_WindowData[playerid][wid][gui_win_td], 2);
	PlayerTextDrawBackgroundColor(playerid, gui_WindowData[playerid][wid][gui_win_td], 255);
	PlayerTextDrawFont(playerid, gui_WindowData[playerid][wid][gui_win_td], 1);
	PlayerTextDrawLetterSize(playerid, gui_WindowData[playerid][wid][gui_win_td], 0.500000, size_y*UNIT);
	PlayerTextDrawColor(playerid, gui_WindowData[playerid][wid][gui_win_td], -1);
	PlayerTextDrawSetOutline(playerid, gui_WindowData[playerid][wid][gui_win_td], 1);
	PlayerTextDrawSetProportional(playerid, gui_WindowData[playerid][wid][gui_win_td], 1);
	PlayerTextDrawUseBox(playerid, gui_WindowData[playerid][wid][gui_win_td], 1);
	PlayerTextDrawBoxColor(playerid, gui_WindowData[playerid][wid][gui_win_td], 155);
	PlayerTextDrawTextSize(playerid, gui_WindowData[playerid][wid][gui_win_td], 0.000000, size_x);

	gui_WindowData[playerid][wid][gui_win_tdtop] = CreatePlayerTextDraw(playerid, x, y, "_");
	PlayerTextDrawAlignment(playerid, gui_WindowData[playerid][wid][gui_win_tdtop], 2);
	PlayerTextDrawBackgroundColor(playerid, gui_WindowData[playerid][wid][gui_win_tdtop], 255);
	PlayerTextDrawFont(playerid, gui_WindowData[playerid][wid][gui_win_tdtop], 1);
	PlayerTextDrawLetterSize(playerid, gui_WindowData[playerid][wid][gui_win_tdtop], 0.500000, 0.599997);
	PlayerTextDrawColor(playerid, gui_WindowData[playerid][wid][gui_win_tdtop], -1);
	PlayerTextDrawSetOutline(playerid, gui_WindowData[playerid][wid][gui_win_tdtop], 1);
	PlayerTextDrawSetProportional(playerid, gui_WindowData[playerid][wid][gui_win_tdtop], 1);
	PlayerTextDrawUseBox(playerid, gui_WindowData[playerid][wid][gui_win_tdtop], 1);
	PlayerTextDrawBoxColor(playerid, gui_WindowData[playerid][wid][gui_win_tdtop], -1296911838);
	PlayerTextDrawTextSize(playerid, gui_WindowData[playerid][wid][gui_win_tdtop], 0.000000, size_x);

	gui_WindowData[playerid][wid][gui_win_tdtitle] = CreatePlayerTextDraw(playerid, x, y-1.0, title);
	PlayerTextDrawAlignment(playerid, gui_WindowData[playerid][wid][gui_win_tdtitle], 2);
	PlayerTextDrawBackgroundColor(playerid, gui_WindowData[playerid][wid][gui_win_tdtitle], 255);
	PlayerTextDrawFont(playerid, gui_WindowData[playerid][wid][gui_win_tdtitle], 2);
	PlayerTextDrawLetterSize(playerid, gui_WindowData[playerid][wid][gui_win_tdtitle], 0.179999, 0.799997);
	PlayerTextDrawColor(playerid, gui_WindowData[playerid][wid][gui_win_tdtitle], -1);
	PlayerTextDrawSetOutline(playerid, gui_WindowData[playerid][wid][gui_win_tdtitle], 0);
	PlayerTextDrawSetProportional(playerid, gui_WindowData[playerid][wid][gui_win_tdtitle], 1);
	PlayerTextDrawSetShadow(playerid, gui_WindowData[playerid][wid][gui_win_tdtitle], 0);

	return gui_WindowData[playerid][wid][gui_win_ID];
}

function guiCreateTab(playerid, windowid, Float:x, Float:y, Float:height, Float:width, text[])
{
	new id = -1, pos, Float:len, wind = windowid;
	for(new c; c < MAX_GUI; c++)
	{
	    if (!gui_TabData[playerid][c][gui_tab_ID] && id == -1)
	    {
	        id = c;
	        //printf("TAB ID: %d", c);
	    }
	    if (gui_TabData[playerid][c][gui_tab_Window] == windowid)
	    {
	        pos++;
	        len += (float(strlen(gui_TabData[playerid][c][gui_tab_Text]))*5.0)+4.0 + gui_TabData[playerid][c][gui_tab_plusX];
	    }
	}
	if (id == -1) return !printf("ERROR GUI: You cannot exceed the GUI tab limit! (%d)", MAX_GUI);

	new units = strlen(text)*5; // Every char is 5 units space
	new Float:boxX = x, Float:boxY = y+10.0, Float:tabheight = 0.799996;

	if (windowid > 0) // If you set the tab under a GUI Window ...
	{
	    windowid = guiGetID(playerid, GUI_TYPE_WINDOW, windowid);
	    /*printf("CURRENT LEN: %.2f | MAX LEN: %.2f | TOTAL: %d(%d)", (gui_WindowData[windowid][gui_win_X]-(gui_WindowData[windowid][gui_win_SizeX]/2))+((len+units)/2)+4.0, gui_WindowData[windowid][gui_win_X]+(gui_WindowData[windowid][gui_win_SizeX]/2), len+units, units);
	    if (((gui_WindowData[windowid][gui_win_X]-(gui_WindowData[windowid][gui_win_SizeX]/2))+((len+units)/2)+4.0) > (gui_WindowData[windowid][gui_win_X]+(gui_WindowData[windowid][gui_win_SizeX]/2)))
	    {
	        printf("ERROR GUI: Tab %d cannot be created because it does not fit in the window!", id);
	        gui_TabData[playerid][id][gui_tab_ID] = 0;
	        return 0;
	    }*/

	    gui_TabData[playerid][id][gui_tab_plusX] = x;

	    boxX = gui_WindowData[playerid][windowid][gui_win_X];
	    x += (gui_WindowData[playerid][windowid][gui_win_X]-(gui_WindowData[playerid][windowid][gui_win_SizeX]/2)); // relative positioning
	    y += (gui_WindowData[playerid][windowid][gui_win_Y]+10.0);
	    boxY = y+10.5;
	    if (height == 0.0) height = ( ((gui_WindowData[playerid][windowid][gui_win_SizeY])*UNIT) - (20.0)*UNIT ) - (4.0*UNIT);
	    else height *= UNIT;
	    if (width == 0.0) width = gui_WindowData[playerid][windowid][gui_win_SizeX]-3.0;
	    else width += gui_WindowData[playerid][windowid][gui_win_SizeX];

	    //printf("CURRENT: %.2f | MAXIMUM: %.2f", (x+units+len+4.0), gui_WindowData[windowid][gui_win_X]+(gui_WindowData[windowid][gui_win_SizeX]/2));
	    if ((x+float(units)+len+4.0+gui_TabData[playerid][id][gui_tab_plusX]) > (gui_WindowData[playerid][windowid][gui_win_X]+(gui_WindowData[playerid][windowid][gui_win_SizeX]/2)))
	    {
	        printf("ERROR GUI: Tab %d cannot be created because it does not fit in the window!", id);
	        gui_TabData[playerid][id][gui_tab_ID] = 0;
	        return 0;
	    }
	    //printf("height:%.2f | width: %.2f | boxY: %.2f | winY: %.2f = %.2f", height, width, boxY, gui_WindowData[playerid][windowid][gui_win_SizeY], gui_WindowData[playerid][windowid][gui_win_Y]-boxY);
	}

	if (pos > 0)
	{
	    for(new c; c < MAX_GUI; c++)
		{
		    if (!gui_TabData[playerid][c][gui_tab_ID]) continue;
		    if (gui_TabData[playerid][c][gui_tab_Window] == wind)
		    {
		        gui_TabData[playerid][c][gui_tab_panel] = id;
		        x += float(strlen(gui_TabData[playerid][c][gui_tab_Text]))*5+4.0 + gui_TabData[playerid][c][gui_tab_plusX];
		        //if (pos == 7) x = gui_WindowData[playerid][windowid][gui_win_X]-(gui_WindowData[playerid][windowid][gui_win_SizeX]/2);
		        //printf("(%d)x:%.2f - %d(%s)", c, x, strlen(gui_TabData[playerid][c][gui_tab_Text]), gui_TabData[playerid][c][gui_tab_Text]);
		    }
		}
	}

	gui_TabData[playerid][id][gui_tab_X] = x;
	gui_TabData[playerid][id][gui_tab_Y] = y;
	gui_TabData[playerid][id][gui_tab_Height] = height;
	gui_TabData[playerid][id][gui_tab_Width] = width;
	strins(gui_TabData[playerid][id][gui_tab_Text], text, 0);
	gui_TabData[playerid][id][gui_tab_Window] = wind;
	gui_TabData[playerid][id][gui_tab_panelX] = boxX;
 	gui_TabData[playerid][id][gui_tab_panelY] = boxY+2.0;
	gui_TabData[playerid][id][gui_tab_Type] = GUI_TYPE_TAB;
	gui_TabData[playerid][id][gui_tab_P] = playerid;
	gui_TabData[playerid][id][gui_tab_ID] = id+1;

	gui_TabData[playerid][id][gui_tab_td] = CreatePlayerTextDraw(playerid, (x+2.0+float(units)/2), y, text);
	PlayerTextDrawAlignment(playerid, gui_TabData[playerid][id][gui_tab_td], 2);
	PlayerTextDrawBackgroundColor(playerid, gui_TabData[playerid][id][gui_tab_td], 255);
	PlayerTextDrawFont(playerid, gui_TabData[playerid][id][gui_tab_td], 2);
	PlayerTextDrawLetterSize(playerid, gui_TabData[playerid][id][gui_tab_td], 0.179998, tabheight);
	PlayerTextDrawColor(playerid, gui_TabData[playerid][id][gui_tab_td], -1);
	PlayerTextDrawSetOutline(playerid, gui_TabData[playerid][id][gui_tab_td], 0);
	PlayerTextDrawSetProportional(playerid, gui_TabData[playerid][id][gui_tab_td], 1);
	PlayerTextDrawSetShadow(playerid, gui_TabData[playerid][id][gui_tab_td], 0);
	PlayerTextDrawUseBox(playerid, gui_TabData[playerid][id][gui_tab_td], 1);
	PlayerTextDrawBoxColor(playerid, gui_TabData[playerid][id][gui_tab_td], 0x6F6F6F22);
	PlayerTextDrawTextSize(playerid, gui_TabData[playerid][id][gui_tab_td], tabheight/UNIT, float(units));
	PlayerTextDrawSetSelectable(playerid, gui_TabData[playerid][id][gui_tab_td], 1);

	gui_TabData[playerid][id][gui_tab_td2] = CreatePlayerTextDraw(playerid, (x+2.0+float(units)/2), y, text);
	PlayerTextDrawAlignment(playerid, gui_TabData[playerid][id][gui_tab_td2], 2);
	PlayerTextDrawBackgroundColor(playerid, gui_TabData[playerid][id][gui_tab_td2], 255);
	PlayerTextDrawFont(playerid, gui_TabData[playerid][id][gui_tab_td2], 2);
	PlayerTextDrawLetterSize(playerid, gui_TabData[playerid][id][gui_tab_td2], 0.179998, tabheight);
	PlayerTextDrawColor(playerid, gui_TabData[playerid][id][gui_tab_td2], -1);
	PlayerTextDrawSetOutline(playerid, gui_TabData[playerid][id][gui_tab_td2], 0);
	PlayerTextDrawSetProportional(playerid, gui_TabData[playerid][id][gui_tab_td2], 1);
	PlayerTextDrawSetShadow(playerid, gui_TabData[playerid][id][gui_tab_td2], 0);
	PlayerTextDrawUseBox(playerid, gui_TabData[playerid][id][gui_tab_td2], 1);
	PlayerTextDrawBoxColor(playerid, gui_TabData[playerid][id][gui_tab_td2], 0xC3C3C344);
	PlayerTextDrawTextSize(playerid, gui_TabData[playerid][id][gui_tab_td2], tabheight/UNIT, float(units));

	if (!pos) // only the first tab will create the tab panel
	{
	    gui_TabData[playerid][id][gui_tab_panel] = id;

		gui_TabData[playerid][id][gui_tab_tdbg] = CreatePlayerTextDraw(playerid, boxX, boxY, "_");
		PlayerTextDrawAlignment(playerid, gui_TabData[playerid][id][gui_tab_tdbg], 2);
		PlayerTextDrawBackgroundColor(playerid, gui_TabData[playerid][id][gui_tab_tdbg], 255);
		PlayerTextDrawFont(playerid, gui_TabData[playerid][id][gui_tab_tdbg], 1);
		PlayerTextDrawLetterSize(playerid, gui_TabData[playerid][id][gui_tab_tdbg], 0.199998, height);
		PlayerTextDrawColor(playerid, gui_TabData[playerid][id][gui_tab_tdbg], -1);
		PlayerTextDrawSetOutline(playerid, gui_TabData[playerid][id][gui_tab_tdbg], 0);
		PlayerTextDrawSetProportional(playerid, gui_TabData[playerid][id][gui_tab_tdbg], 1);
		PlayerTextDrawSetShadow(playerid, gui_TabData[playerid][id][gui_tab_tdbg], 0);
		PlayerTextDrawUseBox(playerid, gui_TabData[playerid][id][gui_tab_tdbg], 1);
		PlayerTextDrawBoxColor(playerid, gui_TabData[playerid][id][gui_tab_tdbg], 0xC3C3C344);
		PlayerTextDrawTextSize(playerid, gui_TabData[playerid][id][gui_tab_tdbg], 0.0, width);

		gui_TabData[playerid][id][gui_tab_tdbox] = CreatePlayerTextDraw(playerid, boxX, boxY+2.0, "_");
		PlayerTextDrawAlignment(playerid, gui_TabData[playerid][id][gui_tab_tdbox], 2);
		PlayerTextDrawBackgroundColor(playerid, gui_TabData[playerid][id][gui_tab_tdbox], 255);
		PlayerTextDrawFont(playerid, gui_TabData[playerid][id][gui_tab_tdbox], 1);
		PlayerTextDrawLetterSize(playerid, gui_TabData[playerid][id][gui_tab_tdbox], 0.199998, height-(4.0*UNIT));
		PlayerTextDrawColor(playerid, gui_TabData[playerid][id][gui_tab_tdbox], -1);
		PlayerTextDrawSetOutline(playerid, gui_TabData[playerid][id][gui_tab_tdbox], 0);
		PlayerTextDrawSetProportional(playerid, gui_TabData[playerid][id][gui_tab_tdbox], 1);
		PlayerTextDrawSetShadow(playerid, gui_TabData[playerid][id][gui_tab_tdbox], 0);
		PlayerTextDrawUseBox(playerid, gui_TabData[playerid][id][gui_tab_tdbox], 1);
		PlayerTextDrawBoxColor(playerid, gui_TabData[playerid][id][gui_tab_tdbox], 153);
		PlayerTextDrawTextSize(playerid, gui_TabData[playerid][id][gui_tab_tdbox], 0.0, width-3.0);
	}

	return gui_TabData[playerid][id][gui_tab_ID];
}

function guiCreateLabel(playerid, windowid, tabid, Float:x, Float:y, Float:length, color, font, text[])
{
	new id = -1, wind = windowid, t = tabid;
	for(new c; c < MAX_GUI; c++)
	{
	    if (!gui_LabelData[playerid][c][gui_label_ID])
	    {
	        id = c;
	        break;
	    }
	}
	if (id == -1) return !printf("ERROR GUI: You cannot exceed the GUI label limit! (%d)", MAX_GUI);

	if (windowid > 0) // If you set the label under a GUI Window ...
	{
 		windowid = guiGetID(playerid, GUI_TYPE_WINDOW, windowid);
	    if (tabid > 0) // if it's under a tab panel
	    {
 			tabid = guiGetID(playerid, GUI_TYPE_TAB, tabid);
	        x += (gui_TabData[playerid][tabid][gui_tab_panelX]-(gui_TabData[playerid][tabid][gui_tab_Width]/2))+1.5;
		    y += (gui_TabData[playerid][tabid][gui_tab_panelY]-(gui_TabData[playerid][tabid][gui_tab_Height]/2))+6.0; // relative positioning
		    if (length == 0.0) length = x+gui_TabData[playerid][tabid][gui_tab_Width];
		    else length += x;
	    }
	    else // only under a window gui
	    {
		    x += (gui_WindowData[playerid][windowid][gui_win_X]-(gui_WindowData[playerid][windowid][gui_win_SizeX]/2));
		    y += (gui_WindowData[playerid][windowid][gui_win_Y]+7.0); // relative positioning
//		    SendFormatMessage(0, 0xFFFFFFFF, "%f - %f", gui_WindowData[playerid][windowid][gui_win_SizeX], gui_WindowData[playerid][windowid][gui_win_X]+gui_WindowData[playerid][windowid][gui_win_SizeX]);
		    if (length == 0.0) length = x+gui_WindowData[playerid][windowid][gui_win_SizeX];
		    else length += x;
	    }
	}

	gui_LabelData[playerid][id][gui_label_X] = x;
	gui_LabelData[playerid][id][gui_label_Y] = y;
	gui_LabelData[playerid][id][gui_label_Length] = length;
	strins(gui_LabelData[playerid][id][gui_label_Text], text, 0);
	gui_LabelData[playerid][id][gui_label_Window] = wind;
	gui_LabelData[playerid][id][gui_label_Tab] = t;
	gui_LabelData[playerid][id][gui_label_Color] = color;
	gui_LabelData[playerid][id][gui_label_Type] = GUI_TYPE_LABEL;
	gui_LabelData[playerid][id][gui_label_P] = playerid;
	gui_LabelData[playerid][id][gui_label_ID] = id+1;

	gui_LabelData[playerid][id][gui_label_td] = CreatePlayerTextDraw(playerid, x, y, text);
	PlayerTextDrawBackgroundColor(playerid, gui_LabelData[playerid][id][gui_label_td], 255);
	PlayerTextDrawFont(playerid, gui_LabelData[playerid][id][gui_label_td], font);
	PlayerTextDrawLetterSize(playerid, gui_LabelData[playerid][id][gui_label_td], 0.199998, 0.799996);
	PlayerTextDrawColor(playerid, gui_LabelData[playerid][id][gui_label_td], color);
	PlayerTextDrawSetOutline(playerid, gui_LabelData[playerid][id][gui_label_td], 0);
	PlayerTextDrawSetProportional(playerid, gui_LabelData[playerid][id][gui_label_td], 1);
	PlayerTextDrawSetShadow(playerid, gui_LabelData[playerid][id][gui_label_td], 0);
	PlayerTextDrawUseBox(playerid, gui_LabelData[playerid][id][gui_label_td], 1);
	PlayerTextDrawBoxColor(playerid, gui_LabelData[playerid][id][gui_label_td], 0xFFFFFF00);
	PlayerTextDrawTextSize(playerid, gui_LabelData[playerid][id][gui_label_td], length, 0.000000);

	return gui_LabelData[playerid][id][gui_label_ID];
}

function guiLabelSetText(playerid, labelid, color, font, text[])
{
	if (labelid >= MAX_GUI) return 0;
	new id = guiGetID(playerid, GUI_TYPE_LABEL, labelid);
	if (id == -1) return 0;
	if (!IsPlayerConnected(playerid)) return 0;

	PlayerTextDrawDestroy(playerid, gui_LabelData[playerid][id][gui_label_td]);

	new PlayerText:txt = CreatePlayerTextDraw(playerid, gui_LabelData[playerid][id][gui_label_X], gui_LabelData[playerid][id][gui_label_Y], text);
	PlayerTextDrawBackgroundColor(playerid, txt, 255);
	PlayerTextDrawFont(playerid, txt, font);
	PlayerTextDrawLetterSize(playerid, txt, 0.199998, 0.799996);
	PlayerTextDrawColor(playerid, txt, color);
	PlayerTextDrawSetOutline(playerid, txt, 0);
	PlayerTextDrawSetProportional(playerid, txt, 1);
	PlayerTextDrawSetShadow(playerid, txt, 0);
	PlayerTextDrawUseBox(playerid, txt, 1);
	PlayerTextDrawBoxColor(playerid, txt, 0xFFFFFF00);
	PlayerTextDrawTextSize(playerid, txt, gui_LabelData[playerid][id][gui_label_Length], 0.000000);

	gui_LabelData[playerid][id][gui_label_Color] = color;
	strdel(gui_LabelData[playerid][id][gui_label_Text], 0, strlen(gui_LabelData[playerid][id][gui_label_Text]));
	strins(gui_LabelData[playerid][id][gui_label_Text], text, 0);

	//printf("%s",text);
	gui_LabelData[playerid][id][gui_label_td] = txt;
	if (GetTextDrawVisibilityForPlayer(playerid, txt)) PlayerTextDrawShow(playerid, txt);
	return 1;
}

function guiCreateProgressBar(playerid, windowid, tabid, Float:x, Float:y, Float:height, Float:width, color_bg, color_box, color_bar)
{
	new id = -1, wind = windowid, t = tabid;
	for(new c; c < MAX_GUI; c++)
	{
	    if (!gui_BarData[playerid][c][gui_bar_ID])
	    {
	        id = c;
	        break;
	    }
	}
	if (id == -1) return !printf("ERROR GUI: You cannot exceed the GUI progress bar limit! (%d)", MAX_GUI);

	if (windowid > 0) // If you set the label under a GUI Window ...
	{
 		windowid = guiGetID(playerid, GUI_TYPE_WINDOW, windowid);
	    if (tabid > 0) // if it's under a tab panel
	    {
 		    tabid = guiGetID(playerid, GUI_TYPE_TAB, tabid);
	        x += (gui_TabData[playerid][tabid][gui_tab_panelX]-(gui_TabData[playerid][tabid][gui_tab_Width]/2))+1.5;
		    y += (gui_TabData[playerid][tabid][gui_tab_panelY]-(gui_TabData[playerid][tabid][gui_tab_Height]/2))+6.0; // relative positioning
	    }
	    else // only under a window gui
	    {
		    x += (gui_WindowData[playerid][windowid][gui_win_X]-(gui_WindowData[playerid][windowid][gui_win_SizeX]/2));
		    y += (gui_WindowData[playerid][windowid][gui_win_Y]+7.0); // relative positioning
	    }
	}

	gui_BarData[playerid][id][gui_bar_X] = x;
	gui_BarData[playerid][id][gui_bar_Y] = y;
	gui_BarData[playerid][id][gui_bar_Height] = height;
	gui_BarData[playerid][id][gui_bar_Width] = width;
	gui_BarData[playerid][id][gui_bar_Window] = wind;
	gui_BarData[playerid][id][gui_bar_Tab] = t;
	gui_BarData[playerid][id][gui_bar_Progress] = 100.0; // 100%
	gui_BarData[playerid][id][gui_bar_bgcolor] = color_bg;
	gui_BarData[playerid][id][gui_bar_boxcolor] = color_box;
	gui_BarData[playerid][id][gui_bar_barcolor] = color_bar;
	gui_BarData[playerid][id][gui_bar_Type] = GUI_TYPE_BAR;
	gui_BarData[playerid][id][gui_bar_P] = playerid;
 	gui_BarData[playerid][id][gui_bar_ID] = id+1;

	gui_BarData[playerid][id][gui_bar_tdbg] = CreatePlayerTextDraw(playerid, x, y, "_");
	PlayerTextDrawBackgroundColor(playerid, gui_BarData[playerid][id][gui_bar_tdbg], 255);
	PlayerTextDrawFont(playerid, gui_BarData[playerid][id][gui_bar_tdbg], 1);
	PlayerTextDrawLetterSize(playerid, gui_BarData[playerid][id][gui_bar_tdbg], 0.0, height*UNIT);
	PlayerTextDrawColor(playerid, gui_BarData[playerid][id][gui_bar_tdbg], -1);
	PlayerTextDrawSetOutline(playerid, gui_BarData[playerid][id][gui_bar_tdbg], 1);
	PlayerTextDrawSetProportional(playerid, gui_BarData[playerid][id][gui_bar_tdbg], 1);
	PlayerTextDrawUseBox(playerid, gui_BarData[playerid][id][gui_bar_tdbg], 1);
	PlayerTextDrawBoxColor(playerid, gui_BarData[playerid][id][gui_bar_tdbg], color_bg);
	PlayerTextDrawTextSize(playerid, gui_BarData[playerid][id][gui_bar_tdbg], x+width, 0.000000);

	gui_BarData[playerid][id][gui_bar_tdbox] = CreatePlayerTextDraw(playerid, x+2.0, y+2.0, "_");
	PlayerTextDrawBackgroundColor(playerid, gui_BarData[playerid][id][gui_bar_tdbox], 255);
	PlayerTextDrawFont(playerid, gui_BarData[playerid][id][gui_bar_tdbox], 1);
	PlayerTextDrawLetterSize(playerid, gui_BarData[playerid][id][gui_bar_tdbox], 0.0, (height*UNIT)-(4.0*UNIT));
	PlayerTextDrawColor(playerid, gui_BarData[playerid][id][gui_bar_tdbox], -1);
	PlayerTextDrawSetOutline(playerid, gui_BarData[playerid][id][gui_bar_tdbox], 1);
	PlayerTextDrawSetProportional(playerid, gui_BarData[playerid][id][gui_bar_tdbox], 1);
	PlayerTextDrawUseBox(playerid, gui_BarData[playerid][id][gui_bar_tdbox], 1);
	PlayerTextDrawBoxColor(playerid, gui_BarData[playerid][id][gui_bar_tdbox], color_box);
	PlayerTextDrawTextSize(playerid, gui_BarData[playerid][id][gui_bar_tdbox], x+width-2.0, 0.000000);

	gui_BarData[playerid][id][gui_bar_tdbar] = CreatePlayerTextDraw(playerid, x+2.0, y+2.0, "_");
	PlayerTextDrawBackgroundColor(playerid, gui_BarData[playerid][id][gui_bar_tdbar], 255);
	PlayerTextDrawFont(playerid, gui_BarData[playerid][id][gui_bar_tdbar], 1);
	PlayerTextDrawLetterSize(playerid, gui_BarData[playerid][id][gui_bar_tdbar], 0.0, (height*UNIT)-(4.0*UNIT));
	PlayerTextDrawColor(playerid, gui_BarData[playerid][id][gui_bar_tdbar], -1);
	PlayerTextDrawSetOutline(playerid, gui_BarData[playerid][id][gui_bar_tdbar], 1);
	PlayerTextDrawSetProportional(playerid, gui_BarData[playerid][id][gui_bar_tdbar], 1);
	PlayerTextDrawUseBox(playerid, gui_BarData[playerid][id][gui_bar_tdbar], 1);
	PlayerTextDrawBoxColor(playerid, gui_BarData[playerid][id][gui_bar_tdbar], color_bar);
	PlayerTextDrawTextSize(playerid, gui_BarData[playerid][id][gui_bar_tdbar], x+width-2.0, 0.000000);

	return gui_BarData[playerid][id][gui_bar_ID];
}
function guiProgressBarSetProgress(playerid, barid, Float:progress)
{
    if (barid >= MAX_GUI) return 0;
	new r;
	for(new g; g < MAX_GUI; g++)
	{
	    if (gui_BarData[playerid][g][gui_bar_ID] == barid)
	    {
			barid = g;
			r = 1;
			break;
		}
	}
	if (!r) return 0;
	if (!gui_BarData[playerid][barid][gui_bar_ID]) return 0;

	gui_BarData[playerid][barid][gui_bar_Progress] = progress;
	new Float:size = (gui_BarData[playerid][barid][gui_bar_X]+gui_BarData[playerid][barid][gui_bar_Width]-2.0) - gui_BarData[playerid][barid][gui_bar_X];
	size *= progress/100.0;
	PlayerTextDrawTextSize(gui_BarData[playerid][barid][gui_bar_P], gui_BarData[playerid][barid][gui_bar_tdbar], gui_BarData[playerid][barid][gui_bar_X]+size, 0.000000);

	if (GetTextDrawVisibilityForPlayer(gui_BarData[playerid][barid][gui_bar_P], gui_BarData[playerid][barid][gui_bar_tdbg]))
	{
	    PlayerTextDrawShow(gui_BarData[playerid][barid][gui_bar_P], gui_BarData[playerid][barid][gui_bar_tdbg]);
	    PlayerTextDrawShow(gui_BarData[playerid][barid][gui_bar_P], gui_BarData[playerid][barid][gui_bar_tdbox]);
	    PlayerTextDrawShow(gui_BarData[playerid][barid][gui_bar_P], gui_BarData[playerid][barid][gui_bar_tdbar]);
    }
	/*for(new i; i < MAX_PLAYERS; i++)
	{
	    if (!IsPlayerConnected(i)) continue;

		if (GetTextDrawVisibilityForPlayer(i, gui_BarData[barid][gui_bar_tdbg]))
		{
		    PlayerTextDrawShow(i, gui_BarData[barid][gui_bar_tdbg]);
		    PlayerTextDrawShow(i, gui_BarData[barid][gui_bar_tdbox]);
		    PlayerTextDrawShow(i, gui_BarData[barid][gui_bar_tdbar]);
		}
	}*/
	return 1;
}
function Float:guiProgressBarGetProgress(playerid, barid)
{
    if (barid >= MAX_GUI) return -1.0;
	new r;
	for(new g; g < MAX_GUI; g++)
	{
	    if (gui_BarData[playerid][g][gui_bar_ID] == barid)
	    {
			barid = g;
			r = 1;
			break;
		}
	}
	if (!r) return -1.0;
	if (!gui_BarData[playerid][barid][gui_bar_ID]) return -1.0;
	return gui_BarData[playerid][barid][gui_bar_Progress];
}

function guiCreateItemList(playerid, windowid, tabid, Float:x, Float:y, Float:height, Float:width, title[])
{
	new id = -1, wind = windowid, t = tabid;
	for(new c; c < MAX_GUI; c++)
	{
	    if (!gui_ItemlistData[playerid][c][gui_list_ID])
	    {
	        id = c;
	        break;
	    }
	}
	if (id == -1) return !printf("ERROR GUI: You cannot exceed the GUI item list limit! (%d)", MAX_GUI);

	if (windowid > 0) // If you set the tab under a GUI Window ...
	{
	    windowid = guiGetID(playerid, GUI_TYPE_WINDOW, windowid);

		if (tabid > 0)
		{
		    tabid = guiGetID(playerid, GUI_TYPE_TAB, tabid);

		    new Float:offsetY = y;

		    x += gui_TabData[playerid][tabid][gui_tab_panelX]-0.5;
		    y += (gui_TabData[playerid][tabid][gui_tab_panelY]+3.0);
		    if (height == 0.0) height = gui_TabData[playerid][tabid][gui_tab_Height] - (8.0*UNIT) - (2.0*UNIT) - (offsetY*UNIT);
		    else height *= UNIT;
		    if (width == 0.0) width = gui_TabData[playerid][tabid][gui_tab_Width]-7.5;
		    else x = x-(gui_TabData[playerid][tabid][gui_tab_Width]/2)+(width/2)+4.0;
		}
		else
		{
		    x += gui_WindowData[playerid][windowid][gui_win_X];
		    y += (gui_WindowData[playerid][windowid][gui_win_Y]+10.5);
		    if (height == 0.0) height = ( ((gui_WindowData[playerid][windowid][gui_win_SizeY])*UNIT) - (20.0)*UNIT ) - (4.0*UNIT);
		    else height *= UNIT;
		    if (width == 0.0) width = gui_WindowData[playerid][windowid][gui_win_SizeX]-3.0;
		    else width += gui_WindowData[playerid][windowid][gui_win_SizeX];
	    }
	}
	else height *= UNIT;

	gui_ItemlistData[playerid][id][gui_list_X] = x;
	gui_ItemlistData[playerid][id][gui_list_Y] = y;
	gui_ItemlistData[playerid][id][gui_list_Height] = height;
	gui_ItemlistData[playerid][id][gui_list_Width] = width;
	strins(gui_ItemlistData[playerid][id][gui_list_Title], title, 0);
	gui_ItemlistData[playerid][id][gui_list_Window] = wind;
	gui_ItemlistData[playerid][id][gui_list_Tab] = t;

    gui_ItemlistData[playerid][id][gui_list_RowX] = x-(width/2) + 2.0;
    gui_ItemlistData[playerid][id][gui_list_RowY] = y+9.0;
    gui_ItemlistData[playerid][id][gui_list_RowMax] = 1;
    gui_ItemlistData[playerid][id][gui_list_Type] = GUI_TYPE_ITEMLIST;
    gui_ItemlistData[playerid][id][gui_list_P] = playerid;
    gui_ItemlistData[playerid][id][gui_list_ID] = id+1;

    gui_ItemlistData[playerid][id][gui_list_tdbox] = CreatePlayerTextDraw(playerid, x, y, "_");
	PlayerTextDrawAlignment(playerid, gui_ItemlistData[playerid][id][gui_list_tdbox], 2);
	PlayerTextDrawBackgroundColor(playerid, gui_ItemlistData[playerid][id][gui_list_tdbox], 255);
	PlayerTextDrawFont(playerid, gui_ItemlistData[playerid][id][gui_list_tdbox], 2);
	PlayerTextDrawLetterSize(playerid, gui_ItemlistData[playerid][id][gui_list_tdbox], 0.199998, height);
	PlayerTextDrawColor(playerid, gui_ItemlistData[playerid][id][gui_list_tdbox], -1);
	PlayerTextDrawSetOutline(playerid, gui_ItemlistData[playerid][id][gui_list_tdbox], 0);
	PlayerTextDrawSetProportional(playerid, gui_ItemlistData[playerid][id][gui_list_tdbox], 1);
	PlayerTextDrawSetShadow(playerid, gui_ItemlistData[playerid][id][gui_list_tdbox], 0);
	PlayerTextDrawUseBox(playerid, gui_ItemlistData[playerid][id][gui_list_tdbox], 1);
	PlayerTextDrawBoxColor(playerid, gui_ItemlistData[playerid][id][gui_list_tdbox], 255);
	PlayerTextDrawTextSize(playerid, gui_ItemlistData[playerid][id][gui_list_tdbox], 0.0, width);
	PlayerTextDrawSetPreviewModel(playerid, gui_ItemlistData[playerid][id][gui_list_tdbox], 0);

	gui_ItemlistData[playerid][id][gui_list_tdline] = CreatePlayerTextDraw(playerid, x, y+6.0, "_");
	PlayerTextDrawAlignment(playerid, gui_ItemlistData[playerid][id][gui_list_tdline], 2);
	PlayerTextDrawBackgroundColor(playerid, gui_ItemlistData[playerid][id][gui_list_tdline], 255);
	PlayerTextDrawFont(playerid, gui_ItemlistData[playerid][id][gui_list_tdline], 1);
	PlayerTextDrawLetterSize(playerid, gui_ItemlistData[playerid][id][gui_list_tdline], 0.199998, -0.200004);
	PlayerTextDrawColor(playerid, gui_ItemlistData[playerid][id][gui_list_tdline], -1);
	PlayerTextDrawSetOutline(playerid, gui_ItemlistData[playerid][id][gui_list_tdline], 0);
	PlayerTextDrawSetProportional(playerid, gui_ItemlistData[playerid][id][gui_list_tdline], 1);
	PlayerTextDrawSetShadow(playerid, gui_ItemlistData[playerid][id][gui_list_tdline], 0);
	PlayerTextDrawUseBox(playerid, gui_ItemlistData[playerid][id][gui_list_tdline], 1);
	PlayerTextDrawBoxColor(playerid, gui_ItemlistData[playerid][id][gui_list_tdline], -1);
	PlayerTextDrawTextSize(playerid, gui_ItemlistData[playerid][id][gui_list_tdline], 0.0, width-4.0);
	PlayerTextDrawSetPreviewModel(playerid, gui_ItemlistData[playerid][id][gui_list_tdline], 0);

	gui_ItemlistData[playerid][id][gui_list_tdtitle] = CreatePlayerTextDraw(playerid, x, y-2.0, title);
	PlayerTextDrawAlignment(playerid, gui_ItemlistData[playerid][id][gui_list_tdtitle], 2);
	PlayerTextDrawBackgroundColor(playerid, gui_ItemlistData[playerid][id][gui_list_tdtitle], 255);
	PlayerTextDrawFont(playerid, gui_ItemlistData[playerid][id][gui_list_tdtitle], 2);
	PlayerTextDrawLetterSize(playerid, gui_ItemlistData[playerid][id][gui_list_tdtitle], 0.139998, 0.799995);
	PlayerTextDrawColor(playerid, gui_ItemlistData[playerid][id][gui_list_tdtitle], -1);
	PlayerTextDrawSetOutline(playerid, gui_ItemlistData[playerid][id][gui_list_tdtitle], 0);
	PlayerTextDrawSetProportional(playerid, gui_ItemlistData[playerid][id][gui_list_tdtitle], 1);
	PlayerTextDrawSetShadow(playerid, gui_ItemlistData[playerid][id][gui_list_tdtitle], 0);
	PlayerTextDrawSetPreviewModel(playerid, gui_ItemlistData[playerid][id][gui_list_tdtitle], 0);

	return gui_ItemlistData[playerid][id][gui_list_ID];
}
function guiItemListAddRow(playerid, listid, text[])
{
	if (!(listid > 0)) return !print("ERROR GUI: Item row must be placed under a list id!");

	new id = -1, l = listid;
	for(new c; c < MAX_GUI; c++)
	{
	    if (!gui_ItemRowData[playerid][c][gui_row_ID])
	    {
	        id = c;
	        break;
	    }
	}
	if (id == -1) return !printf("ERROR GUI: You cannot exceed the GUI item row limit! (%d)", MAX_GUI);

	listid = guiGetID(playerid, GUI_TYPE_ITEMLIST, listid);

	gui_ItemRowData[playerid][id][gui_row_X] = gui_ItemlistData[playerid][listid][gui_list_RowX];
	gui_ItemRowData[playerid][id][gui_row_Y] = gui_ItemlistData[playerid][listid][gui_list_RowY];
	gui_ItemRowData[playerid][id][gui_row_Height] = 8.5;
	gui_ItemRowData[playerid][id][gui_row_Width] = gui_ItemRowData[playerid][id][gui_row_X]+gui_ItemlistData[playerid][listid][gui_list_Width] - 4.0;
	strins(gui_ItemRowData[playerid][id][gui_row_Text], text, 0);
	gui_ItemRowData[playerid][id][gui_row_List] = l;
	gui_ItemRowData[playerid][id][gui_row_Order] = gui_ItemlistData[playerid][listid][gui_list_RowMax];
	gui_ItemRowData[playerid][id][gui_row_ID] = id+1;

    gui_ItemlistData[playerid][listid][gui_list_RowY] += 9.5;
    gui_ItemlistData[playerid][listid][gui_list_RowMax]++;

    //printf("ADD: %d %s %.2f", playerid, text, gui_ItemRowData[playerid][id][gui_row_Y]);

    gui_ItemRowData[playerid][id][gui_row_td] = CreatePlayerTextDraw(playerid, gui_ItemRowData[playerid][id][gui_row_X], gui_ItemRowData[playerid][id][gui_row_Y], text);
	PlayerTextDrawBackgroundColor(playerid, gui_ItemRowData[playerid][id][gui_row_td], 55);
	PlayerTextDrawFont(playerid, gui_ItemRowData[playerid][id][gui_row_td], 1);
	PlayerTextDrawLetterSize(playerid, gui_ItemRowData[playerid][id][gui_row_td], 0.175000, gui_ItemRowData[playerid][id][gui_row_Height]*UNIT);
	PlayerTextDrawColor(playerid, gui_ItemRowData[playerid][id][gui_row_td], -1);
	PlayerTextDrawSetOutline(playerid, gui_ItemRowData[playerid][id][gui_row_td], 1);
	PlayerTextDrawSetProportional(playerid, gui_ItemRowData[playerid][id][gui_row_td], 1);
	PlayerTextDrawUseBox(playerid, gui_ItemRowData[playerid][id][gui_row_td], 1);
	PlayerTextDrawBoxColor(playerid, gui_ItemRowData[playerid][id][gui_row_td], 0x00000000);
	PlayerTextDrawTextSize(playerid, gui_ItemRowData[playerid][id][gui_row_td], gui_ItemRowData[playerid][id][gui_row_Width], gui_ItemRowData[playerid][id][gui_row_Height]);
	PlayerTextDrawSetSelectable(playerid, gui_ItemRowData[playerid][id][gui_row_td], 1);

	gui_ItemRowData[playerid][id][gui_row_td2] = CreatePlayerTextDraw(playerid, gui_ItemRowData[playerid][id][gui_row_X], gui_ItemRowData[playerid][id][gui_row_Y], text);
	PlayerTextDrawBackgroundColor(playerid, gui_ItemRowData[playerid][id][gui_row_td2], 55);
	PlayerTextDrawFont(playerid, gui_ItemRowData[playerid][id][gui_row_td2], 1);
	PlayerTextDrawLetterSize(playerid, gui_ItemRowData[playerid][id][gui_row_td2], 0.175000, gui_ItemRowData[playerid][id][gui_row_Height]*UNIT);
	PlayerTextDrawColor(playerid, gui_ItemRowData[playerid][id][gui_row_td2], -1);
	PlayerTextDrawSetOutline(playerid, gui_ItemRowData[playerid][id][gui_row_td2], 1);
	PlayerTextDrawSetProportional(playerid, gui_ItemRowData[playerid][id][gui_row_td2], 1);
	PlayerTextDrawUseBox(playerid, gui_ItemRowData[playerid][id][gui_row_td2], 1);
	PlayerTextDrawBoxColor(playerid, gui_ItemRowData[playerid][id][gui_row_td2], 0xFF000033);
	PlayerTextDrawTextSize(playerid, gui_ItemRowData[playerid][id][gui_row_td2], gui_ItemRowData[playerid][id][gui_row_Width], gui_ItemRowData[playerid][id][gui_row_Height]);

	return gui_ItemRowData[playerid][id][gui_row_ID];
}
function guiItemListRemoveRow(playerid, listid, rowid)
{
    if (!(listid > 0)) return !print("ERROR GUI: Itemlist ID required to remove row!");
    if (!(rowid > 0)) return !print("ERROR GUI: Row ID required to remove row!");

    new l = listid;
    listid = guiGetID(playerid, GUI_TYPE_ITEMLIST, listid);

	new id = -1;
	for(new r; r <= gui_ItemlistData[playerid][listid][gui_list_RowMax]; r++)
    {
        //printf("ROW: %d ID: %d", r, gui_ItemRowData[playerid][r][gui_row_ID]);
        if (gui_ItemRowData[playerid][r][gui_row_ID] == rowid)
		{
			rowid = r;
			id = 1;
			break;
		}
	}
	if (id == -1) return !printf("ERROR GUI: Invalid row ID. (%d)",rowid);
	
    for(new r; r <= gui_ItemlistData[playerid][listid][gui_list_RowMax]; r++)
    {
        if (!gui_ItemRowData[playerid][r][gui_row_ID]) continue;
        if (gui_ItemRowData[playerid][r][gui_row_List] != l) continue;

		if (gui_ItemRowData[playerid][r][gui_row_Order] > gui_ItemRowData[playerid][rowid][gui_row_Order])
		{
		    gui_ItemRowData[playerid][r][gui_row_Y] -= 9.5;
			gui_ItemRowData[playerid][r][gui_row_Order]--;

			PlayerTextDrawDestroy(playerid, gui_ItemRowData[playerid][r][gui_row_td]);
			gui_ItemRowData[playerid][r][gui_row_td] = CreatePlayerTextDraw(playerid, gui_ItemRowData[playerid][r][gui_row_X], gui_ItemRowData[playerid][r][gui_row_Y], gui_ItemRowData[playerid][r][gui_row_Text]);
			PlayerTextDrawBackgroundColor(playerid, gui_ItemRowData[playerid][r][gui_row_td], 55);
			PlayerTextDrawFont(playerid, gui_ItemRowData[playerid][r][gui_row_td], 1);
			PlayerTextDrawLetterSize(playerid, gui_ItemRowData[playerid][r][gui_row_td], 0.175000, gui_ItemRowData[playerid][r][gui_row_Height]*UNIT);
			PlayerTextDrawColor(playerid, gui_ItemRowData[playerid][r][gui_row_td], -1);
			PlayerTextDrawSetOutline(playerid, gui_ItemRowData[playerid][r][gui_row_td], 1);
			PlayerTextDrawSetProportional(playerid, gui_ItemRowData[playerid][r][gui_row_td], 1);
			PlayerTextDrawUseBox(playerid, gui_ItemRowData[playerid][r][gui_row_td], 1);
			PlayerTextDrawBoxColor(playerid, gui_ItemRowData[playerid][r][gui_row_td], 0x00000000);
			PlayerTextDrawTextSize(playerid, gui_ItemRowData[playerid][r][gui_row_td], gui_ItemRowData[playerid][r][gui_row_Width], gui_ItemRowData[playerid][r][gui_row_Height]);
			PlayerTextDrawSetSelectable(playerid, gui_ItemRowData[playerid][r][gui_row_td], 1);

			PlayerTextDrawDestroy(playerid, gui_ItemRowData[playerid][r][gui_row_td2]);
			gui_ItemRowData[playerid][r][gui_row_td2] = CreatePlayerTextDraw(playerid, gui_ItemRowData[playerid][r][gui_row_X], gui_ItemRowData[playerid][r][gui_row_Y], gui_ItemRowData[playerid][r][gui_row_Text]);
			PlayerTextDrawBackgroundColor(playerid, gui_ItemRowData[playerid][r][gui_row_td2], 55);
			PlayerTextDrawFont(playerid, gui_ItemRowData[playerid][r][gui_row_td2], 1);
			PlayerTextDrawLetterSize(playerid, gui_ItemRowData[playerid][r][gui_row_td2], 0.175000, gui_ItemRowData[playerid][r][gui_row_Height]*UNIT);
			PlayerTextDrawColor(playerid, gui_ItemRowData[playerid][r][gui_row_td2], -1);
			PlayerTextDrawSetOutline(playerid, gui_ItemRowData[playerid][r][gui_row_td2], 1);
			PlayerTextDrawSetProportional(playerid, gui_ItemRowData[playerid][r][gui_row_td2], 1);
			PlayerTextDrawUseBox(playerid, gui_ItemRowData[playerid][r][gui_row_td2], 1);
			PlayerTextDrawBoxColor(playerid, gui_ItemRowData[playerid][r][gui_row_td2], 0xFF000033);
			PlayerTextDrawTextSize(playerid, gui_ItemRowData[playerid][r][gui_row_td2], gui_ItemRowData[playerid][r][gui_row_Width], gui_ItemRowData[playerid][r][gui_row_Height]);
		}
    }

    if (id)
    {
		if (GetTextDrawVisibilityForPlayer(playerid, gui_ItemRowData[playerid][rowid][gui_row_td]))
		{
   			for(new r; r <= gui_ItemlistData[playerid][listid][gui_list_RowMax]; r++)
   			{
                if (!gui_ItemRowData[playerid][r][gui_row_ID]) continue;
		        if (gui_ItemRowData[playerid][r][gui_row_List] != l) continue;
				if (gui_ItemRowData[playerid][r][gui_row_Order] >= gui_ItemRowData[playerid][rowid][gui_row_Order])
					PlayerTextDrawShow(playerid, gui_ItemRowData[playerid][r][gui_row_td]);
			}
		}

		TextDrawDestroyEx(playerid, gui_ItemRowData[playerid][rowid][gui_row_td]);
		TextDrawDestroyEx(playerid, gui_ItemRowData[playerid][rowid][gui_row_td2]);
		strdel(gui_ItemRowData[playerid][rowid][gui_row_Text], 0, strlen(gui_ItemRowData[playerid][rowid][gui_row_Text]));
	    gui_ItemRowData[playerid][rowid][gui_row_ID] = 0;
	    gui_ItemRowData[playerid][rowid][gui_row_X] = 0.0;
		gui_ItemRowData[playerid][rowid][gui_row_Y] = 0.0;
		gui_ItemRowData[playerid][rowid][gui_row_Height] = 0.0;
		gui_ItemRowData[playerid][rowid][gui_row_Width] = 0.0;
		gui_ItemRowData[playerid][rowid][gui_row_List] = 0;
		gui_ItemRowData[playerid][rowid][gui_row_Order] = 0;

	    gui_ItemlistData[playerid][listid][gui_list_RowY] -= 9.5;
	    gui_ItemlistData[playerid][listid][gui_list_RowMax]--;
	    return 1;
    }

    return 0;
}
function guiItemListSetRowOrder(playerid, listid, rowid, orderid)
{
    if (!(listid > 0)) return !print("ERROR GUI: Itemlist ID required to remove row!");
    if (!(rowid > 0)) return !print("ERROR GUI: Row ID required to remove row!");
    new id = -1, l = listid;
    listid = guiGetID(playerid, GUI_TYPE_ITEMLIST, listid);
    if (listid == -1) return !print("ERROR GUI: Invalid list ID.");
	for(new r; r <= gui_ItemlistData[playerid][listid][gui_list_RowMax]; r++)
    {
        if (gui_ItemRowData[playerid][r][gui_row_ID] == rowid)
		{
			rowid = r;
			id = 1;
			break;
		}
	}
	if (id == -1) return !print("ERROR GUI: Invalid row ID.");
    if (orderid == gui_ItemRowData[playerid][rowid][gui_row_Order]) return 0;
    new current = gui_ItemRowData[playerid][rowid][gui_row_Order];
    
    for(new r; r <= gui_ItemlistData[playerid][listid][gui_list_RowMax]; r++)
    {
        if (!gui_ItemRowData[playerid][r][gui_row_ID]) continue;
        if (gui_ItemRowData[playerid][r][gui_row_List] != l) continue;

		new oldid;
		oldid = gui_ItemRowData[playerid][r][gui_row_Order];

        if (gui_ItemRowData[playerid][r][gui_row_Order] == orderid && orderid > current) gui_ItemRowData[playerid][r][gui_row_Order]--;
        else if (gui_ItemRowData[playerid][r][gui_row_Order] == orderid && orderid < current) gui_ItemRowData[playerid][r][gui_row_Order]++;
        else if (gui_ItemRowData[playerid][r][gui_row_Order] >= orderid && orderid < current && gui_ItemRowData[playerid][r][gui_row_Order] < current) gui_ItemRowData[playerid][r][gui_row_Order]++;
        else if (gui_ItemRowData[playerid][r][gui_row_Order] <= orderid && orderid > current && gui_ItemRowData[playerid][r][gui_row_Order] > current) gui_ItemRowData[playerid][r][gui_row_Order]--;
        else if (gui_ItemRowData[playerid][r][gui_row_Order] <= orderid && orderid == current && gui_ItemRowData[playerid][r][gui_row_Order] > current) gui_ItemRowData[playerid][r][gui_row_Order]--;

	    new Float:y = 9.0*gui_ItemRowData[playerid][r][gui_row_Order];

	    gui_ItemRowData[playerid][r][gui_row_Y] = (gui_ItemRowData[playerid][r][gui_row_Y]-(9.0*oldid))+y;

	    PlayerTextDrawDestroy(playerid, gui_ItemRowData[playerid][r][gui_row_td]);
		gui_ItemRowData[playerid][r][gui_row_td] = CreatePlayerTextDraw(playerid, gui_ItemRowData[playerid][r][gui_row_X], gui_ItemRowData[playerid][r][gui_row_Y], gui_ItemRowData[playerid][r][gui_row_Text]);
		PlayerTextDrawBackgroundColor(playerid, gui_ItemRowData[playerid][r][gui_row_td], 55);
		PlayerTextDrawFont(playerid, gui_ItemRowData[playerid][r][gui_row_td], 1);
		PlayerTextDrawLetterSize(playerid, gui_ItemRowData[playerid][r][gui_row_td], 0.150000, gui_ItemRowData[playerid][r][gui_row_Height]*UNIT);
		PlayerTextDrawColor(playerid, gui_ItemRowData[playerid][r][gui_row_td], -1);
		PlayerTextDrawSetOutline(playerid, gui_ItemRowData[playerid][r][gui_row_td], 1);
		PlayerTextDrawSetProportional(playerid, gui_ItemRowData[playerid][r][gui_row_td], 1);
		PlayerTextDrawUseBox(playerid, gui_ItemRowData[playerid][r][gui_row_td], 1);
		PlayerTextDrawBoxColor(playerid, gui_ItemRowData[playerid][r][gui_row_td], 0x00000000);
		PlayerTextDrawTextSize(playerid, gui_ItemRowData[playerid][r][gui_row_td], gui_ItemRowData[playerid][r][gui_row_Width], gui_ItemRowData[playerid][r][gui_row_Height]);
		PlayerTextDrawSetSelectable(playerid, gui_ItemRowData[playerid][r][gui_row_td], 1);

	    PlayerTextDrawDestroy(playerid, gui_ItemRowData[playerid][r][gui_row_td2]);
		gui_ItemRowData[playerid][r][gui_row_td2] = CreatePlayerTextDraw(playerid, gui_ItemRowData[playerid][r][gui_row_X], gui_ItemRowData[playerid][r][gui_row_Y], gui_ItemRowData[playerid][r][gui_row_Text]);
		PlayerTextDrawBackgroundColor(playerid, gui_ItemRowData[playerid][r][gui_row_td2], 55);
		PlayerTextDrawFont(playerid, gui_ItemRowData[playerid][r][gui_row_td2], 1);
		PlayerTextDrawLetterSize(playerid, gui_ItemRowData[playerid][r][gui_row_td2], 0.150000, gui_ItemRowData[playerid][r][gui_row_Height]*UNIT);
		PlayerTextDrawColor(playerid, gui_ItemRowData[playerid][r][gui_row_td2], -1);
		PlayerTextDrawSetOutline(playerid, gui_ItemRowData[playerid][r][gui_row_td2], 1);
		PlayerTextDrawSetProportional(playerid, gui_ItemRowData[playerid][r][gui_row_td2], 1);
		PlayerTextDrawUseBox(playerid, gui_ItemRowData[playerid][r][gui_row_td2], 1);
		PlayerTextDrawBoxColor(playerid, gui_ItemRowData[playerid][r][gui_row_td2], 0xFF000033);
		PlayerTextDrawTextSize(playerid, gui_ItemRowData[playerid][r][gui_row_td2], gui_ItemRowData[playerid][r][gui_row_Width], gui_ItemRowData[playerid][r][gui_row_Height]);
    }

    if (id)
    {
	    gui_ItemRowData[playerid][rowid][gui_row_Y] = (gui_ItemRowData[playerid][rowid][gui_row_Y]-(9.0*gui_ItemRowData[playerid][rowid][gui_row_Order]))+(9.0*orderid);

        PlayerTextDrawDestroy(playerid, gui_ItemRowData[playerid][rowid][gui_row_td]);
		gui_ItemRowData[playerid][rowid][gui_row_td] = CreatePlayerTextDraw(playerid, gui_ItemRowData[playerid][rowid][gui_row_X], gui_ItemRowData[playerid][rowid][gui_row_Y], gui_ItemRowData[playerid][rowid][gui_row_Text]);
		PlayerTextDrawBackgroundColor(playerid, gui_ItemRowData[playerid][rowid][gui_row_td], 55);
		PlayerTextDrawFont(playerid, gui_ItemRowData[playerid][rowid][gui_row_td], 1);
		PlayerTextDrawLetterSize(playerid, gui_ItemRowData[playerid][rowid][gui_row_td], 0.150000, gui_ItemRowData[playerid][rowid][gui_row_Height]*UNIT);
		PlayerTextDrawColor(playerid, gui_ItemRowData[playerid][rowid][gui_row_td], -1);
		PlayerTextDrawSetOutline(playerid, gui_ItemRowData[playerid][rowid][gui_row_td], 1);
		PlayerTextDrawSetProportional(playerid, gui_ItemRowData[playerid][rowid][gui_row_td], 1);
		PlayerTextDrawUseBox(playerid, gui_ItemRowData[playerid][rowid][gui_row_td], 1);
		PlayerTextDrawBoxColor(playerid, gui_ItemRowData[playerid][rowid][gui_row_td], 0x00000000);
		PlayerTextDrawTextSize(playerid, gui_ItemRowData[playerid][rowid][gui_row_td], gui_ItemRowData[playerid][rowid][gui_row_Width], gui_ItemRowData[playerid][rowid][gui_row_Height]);
		PlayerTextDrawSetSelectable(playerid, gui_ItemRowData[playerid][rowid][gui_row_td], 1);

        PlayerTextDrawDestroy(playerid, gui_ItemRowData[playerid][rowid][gui_row_td2]);
		gui_ItemRowData[playerid][rowid][gui_row_td2] = CreatePlayerTextDraw(playerid, gui_ItemRowData[playerid][rowid][gui_row_X], gui_ItemRowData[playerid][rowid][gui_row_Y], gui_ItemRowData[playerid][rowid][gui_row_Text]);
		PlayerTextDrawBackgroundColor(playerid, gui_ItemRowData[playerid][rowid][gui_row_td2], 55);
		PlayerTextDrawFont(playerid, gui_ItemRowData[playerid][rowid][gui_row_td2], 1);
		PlayerTextDrawLetterSize(playerid, gui_ItemRowData[playerid][rowid][gui_row_td2], 0.150000, gui_ItemRowData[playerid][rowid][gui_row_Height]*UNIT);
		PlayerTextDrawColor(playerid, gui_ItemRowData[playerid][rowid][gui_row_td2], -1);
		PlayerTextDrawSetOutline(playerid, gui_ItemRowData[playerid][rowid][gui_row_td2], 1);
		PlayerTextDrawSetProportional(playerid, gui_ItemRowData[playerid][rowid][gui_row_td2], 1);
		PlayerTextDrawUseBox(playerid, gui_ItemRowData[playerid][rowid][gui_row_td2], 1);
		PlayerTextDrawBoxColor(playerid, gui_ItemRowData[playerid][rowid][gui_row_td2], 0xFF000033);
		PlayerTextDrawTextSize(playerid, gui_ItemRowData[playerid][rowid][gui_row_td2], gui_ItemRowData[playerid][rowid][gui_row_Width], gui_ItemRowData[playerid][rowid][gui_row_Height]);

		if (GetTextDrawVisibilityForPlayer(playerid, gui_ItemRowData[playerid][rowid][gui_row_td]) || GetTextDrawVisibilityForPlayer(playerid, gui_ItemRowData[playerid][rowid][gui_row_td2]))
		{
		    PlayerTextDrawShow(playerid, gui_ItemRowData[playerid][rowid][gui_row_td]);
   			for(new r; r <= gui_ItemlistData[playerid][listid][gui_list_RowMax]; r++)
   			{
                if (!gui_ItemRowData[playerid][r][gui_row_ID]) continue;
		        if (gui_ItemRowData[playerid][r][gui_row_List] != l) continue;

				if (p_row[playerid] == r) PlayerTextDrawShow(playerid, gui_ItemRowData[playerid][r][gui_row_td2]);
				else PlayerTextDrawShow(playerid, gui_ItemRowData[playerid][r][gui_row_td]);
			}
		}

		gui_ItemRowData[playerid][rowid][gui_row_Order] = orderid;
	    return 1;
    }
    return 0;
}
function guiItemListGetSelectedRow(playerid)
{
	return gui_ItemRowData[playerid][p_row[playerid]][gui_row_ID];
}
function guiItemListGetRowText(playerid, listid, rowid, string[])
{
    if (rowid >= MAX_GUI || listid >= MAX_GUI) return 0;
	new r;
	for(new g; g < MAX_GUI; g++)
	{
	    if (gui_ItemRowData[playerid][g][gui_row_ID] == rowid && gui_ItemRowData[playerid][g][gui_row_List] == listid)
	    {
			rowid = g;
			r = 1;
			break;
		}
	}
	if (!r) return 0;
	if (!gui_ItemRowData[playerid][rowid][gui_row_ID]) return 0;
	strins(string, gui_ItemRowData[playerid][rowid][gui_row_Text], 0, strlen(gui_ItemRowData[playerid][rowid][gui_row_Text]));
	return 1;
}
function guiItemListGetCount(playerid, listid)
{
    if (listid >= MAX_GUI) return 0;
	new r;
	for(new g; g < MAX_GUI; g++)
	{
	    if (gui_ItemlistData[playerid][g][gui_list_ID] == listid)
	    {
			listid = g;
			r = 1;
			break;
		}
	}
	if (!r) return 0;
	if (!gui_ItemlistData[playerid][listid][gui_list_ID]) return 0;
	return gui_ItemlistData[playerid][listid][gui_list_RowMax];
}
function guiItemListGetRowList(playerid, rowid)
{
    if (rowid >= MAX_GUI) return 0;
	for(new g; g < MAX_GUI; g++)
	{
	    if (gui_ItemRowData[playerid][g][gui_row_ID] == rowid)
	    {
			return gui_ItemRowData[playerid][g][gui_row_List];
		}
	}
	return 0;
}

function guiCreateCheckBox(playerid, windowid, tabid, Float:x, Float:y)
{
	new id = -1, wind = windowid, t = tabid;
	for(new c; c < MAX_GUI; c++)
	{
	    if (!gui_CheckboxData[playerid][c][gui_check_ID])
	    {
	        id = c;
	        break;
	    }
	}
	if (id == -1) return !printf("ERROR GUI: You cannot exceed the GUI checkbox limit! (%d)", MAX_GUI);

	if (windowid > 0) // If you set the tab under a GUI Window ...
	{
	    windowid = guiGetID(playerid, GUI_TYPE_WINDOW, windowid);

		if (tabid > 0)
		{
		    tabid = guiGetID(playerid, GUI_TYPE_TAB, tabid);

		    x += (gui_TabData[playerid][tabid][gui_tab_panelX] - (gui_TabData[playerid][tabid][gui_tab_Width]/2) + 4.0);
		    y += (gui_TabData[playerid][tabid][gui_tab_panelY] +2.0);
		}
		else
		{
		    x += gui_WindowData[playerid][windowid][gui_win_X];
		    y += (gui_WindowData[playerid][windowid][gui_win_Y]+10.5);
	    }
	}

	gui_CheckboxData[playerid][id][gui_check_X] = x;
	gui_CheckboxData[playerid][id][gui_check_Y] = y;
	gui_CheckboxData[playerid][id][gui_check_Window] = wind;
	gui_CheckboxData[playerid][id][gui_check_Tab] = t;
	gui_CheckboxData[playerid][id][gui_check_Type] = GUI_TYPE_CHECKBOX;
	gui_CheckboxData[playerid][id][gui_check_P] = playerid;
	gui_CheckboxData[playerid][id][gui_check_ID] = id+1;

    gui_CheckboxData[playerid][id][gui_check_td] = CreatePlayerTextDraw(playerid, x, y, "O");
	PlayerTextDrawBackgroundColor(playerid, gui_CheckboxData[playerid][id][gui_check_td], 0xFFFFFFFF);
	PlayerTextDrawFont(playerid, gui_CheckboxData[playerid][id][gui_check_td], 1);
	PlayerTextDrawLetterSize(playerid, gui_CheckboxData[playerid][id][gui_check_td], 0.179998, 0.800000);
	PlayerTextDrawColor(playerid, gui_CheckboxData[playerid][id][gui_check_td], 0xFFFFFFFF);
	PlayerTextDrawSetOutline(playerid, gui_CheckboxData[playerid][id][gui_check_td], 1);
	PlayerTextDrawSetProportional(playerid, gui_CheckboxData[playerid][id][gui_check_td], 1);
	PlayerTextDrawTextSize(playerid, gui_CheckboxData[playerid][id][gui_check_td], x+8.0, 10.0);
	PlayerTextDrawSetSelectable(playerid, gui_CheckboxData[playerid][id][gui_check_td], 1);
	//printf("%f  %f", x, y);

    gui_CheckboxData[playerid][id][gui_check_td2] = CreatePlayerTextDraw(playerid, x, y, "O");
	PlayerTextDrawBackgroundColor(playerid, gui_CheckboxData[playerid][id][gui_check_td2], 0xFFFFFFFF);
	PlayerTextDrawFont(playerid, gui_CheckboxData[playerid][id][gui_check_td2], 1);
	PlayerTextDrawLetterSize(playerid, gui_CheckboxData[playerid][id][gui_check_td2], 0.179998, 0.800000);
	PlayerTextDrawColor(playerid, gui_CheckboxData[playerid][id][gui_check_td2], 0x00000000);
	PlayerTextDrawSetOutline(playerid, gui_CheckboxData[playerid][id][gui_check_td2], 1);
	PlayerTextDrawSetProportional(playerid, gui_CheckboxData[playerid][id][gui_check_td2], 1);
	PlayerTextDrawTextSize(playerid, gui_CheckboxData[playerid][id][gui_check_td2], x+8.0, 10.0);
	PlayerTextDrawSetSelectable(playerid, gui_CheckboxData[playerid][id][gui_check_td2], 1);

	return gui_CheckboxData[playerid][id][gui_check_ID];
}
function guiCheckBoxGetSelected(playerid, checkboxid)
{
    if (checkboxid >= MAX_GUI) return -1;
    new r;
	for(new g; g < MAX_GUI; g++)
	{
	    if (gui_CheckboxData[playerid][g][gui_check_ID] == checkboxid)
	    {
			checkboxid = g;
			r = 1;
			break;
		}
	}
	if (!r) return -1;
	if (!gui_CheckboxData[playerid][checkboxid][gui_check_ID]) return -1;
	return GetTextDrawVisibilityForPlayer(playerid, gui_CheckboxData[playerid][checkboxid][gui_check_td2]);
}
function guiCheckBoxSetSelected(playerid, checkboxid)
{
	if (checkboxid >= MAX_GUI) return 0;
	new r;
	for(new g; g < MAX_GUI; g++)
	{
	    if (gui_CheckboxData[playerid][g][gui_check_ID] == checkboxid)
	    {
			checkboxid = g;
			r = 1;
			break;
		}
	}
	if (!r) return 0;
	if (!gui_CheckboxData[playerid][checkboxid][gui_check_ID]) return 0;
    PlayerTextDrawHide(playerid, gui_CheckboxData[playerid][checkboxid][gui_check_td]);
    PlayerTextDrawShow(playerid, gui_CheckboxData[playerid][checkboxid][gui_check_td2]);
	return 1;
}
function guiGetCheckBoxPos(playerid, checkboxid, &Float:x, &Float:y)
{
    if (checkboxid >= MAX_GUI) return 0;
	new r;
	for(new g; g < MAX_GUI; g++)
	{
	    if (gui_CheckboxData[playerid][g][gui_check_ID] == checkboxid)
	    {
			checkboxid = g;
			r = 1;
			break;
		}
	}
	if (!r) return 0;
	if (!gui_CheckboxData[playerid][checkboxid][gui_check_ID]) return 0;
	x = gui_CheckboxData[playerid][checkboxid][gui_check_X];
	y = gui_CheckboxData[playerid][checkboxid][gui_check_Y];
	return 1;
}

function guiCreateButton(playerid, windowid, tabid, Float:x, Float:y, Float:height, Float:width, text[])
{
	new id = -1, wind = windowid, t = tabid;
	for(new c; c < MAX_GUI; c++)
	{
	    if (!gui_ButtonData[playerid][c][gui_but_ID])
	    {
	        id = c;
	        break;
	    }
	}
	if (id == -1) return !printf("ERROR GUI: You cannot exceed the GUI button limit! (%d)", MAX_GUI);

	if (windowid > 0) // If you set the label under a GUI Window ...
	{
 		windowid = guiGetID(playerid, GUI_TYPE_WINDOW, windowid);
	    if (tabid > 0) // if it's under a tab panel
	    {
 			tabid = guiGetID(playerid, GUI_TYPE_TAB, tabid);
	        x += (gui_TabData[playerid][tabid][gui_tab_panelX]-(gui_TabData[playerid][tabid][gui_tab_Width]/2))+10.0;
		    y += (gui_TabData[playerid][tabid][gui_tab_panelY]-(gui_TabData[playerid][tabid][gui_tab_Height]/2))+6.0; // relative positioning
	    }
	    else // only under a window gui
	    {
		    x += (gui_WindowData[playerid][windowid][gui_win_X]-(gui_WindowData[playerid][windowid][gui_win_SizeX]/2));
		    y += (gui_WindowData[playerid][windowid][gui_win_Y]+7.0); // relative positioning
	    }
	}

	new Float:len = strlen(text)*4.0;
	if (width == 0.0) width = len+16.0;
	if (height == 0.0) height = 20.0;

	x += (width/2)-8.0;

	gui_ButtonData[playerid][id][gui_but_X] = x;
	gui_ButtonData[playerid][id][gui_but_Y] = y;
	gui_ButtonData[playerid][id][gui_but_Height] = height;
	gui_ButtonData[playerid][id][gui_but_Width] = width;
	gui_ButtonData[playerid][id][gui_but_Window] = wind;
	gui_ButtonData[playerid][id][gui_but_Tab] = t;
	strins(gui_ButtonData[playerid][id][gui_but_Text], text, 0);
	gui_ButtonData[playerid][id][gui_but_Type] = GUI_TYPE_BUTTON;
	gui_ButtonData[playerid][id][gui_but_P] = playerid;
	gui_ButtonData[playerid][id][gui_but_ID] = id+1;

	gui_ButtonData[playerid][id][gui_but_tdbg] = CreatePlayerTextDraw(playerid, x, y, "_");
	PlayerTextDrawAlignment(playerid, gui_ButtonData[playerid][id][gui_but_tdbg], 2);
	PlayerTextDrawBackgroundColor(playerid, gui_ButtonData[playerid][id][gui_but_tdbg], 255);
	PlayerTextDrawFont(playerid, gui_ButtonData[playerid][id][gui_but_tdbg], 1);
	PlayerTextDrawLetterSize(playerid, gui_ButtonData[playerid][id][gui_but_tdbg], 0.179998, (height*UNIT));
	PlayerTextDrawColor(playerid, gui_ButtonData[playerid][id][gui_but_tdbg], -1);
	PlayerTextDrawSetOutline(playerid, gui_ButtonData[playerid][id][gui_but_tdbg], 1);
	PlayerTextDrawSetProportional(playerid, gui_ButtonData[playerid][id][gui_but_tdbg], 1);
	PlayerTextDrawUseBox(playerid, gui_ButtonData[playerid][id][gui_but_tdbg], 1);
	PlayerTextDrawBoxColor(playerid, gui_ButtonData[playerid][id][gui_but_tdbg], 255);
	PlayerTextDrawTextSize(playerid, gui_ButtonData[playerid][id][gui_but_tdbg], height, width);
	PlayerTextDrawSetSelectable(playerid, gui_ButtonData[playerid][id][gui_but_tdbg], 1);

	gui_ButtonData[playerid][id][gui_but_tdout] = CreatePlayerTextDraw(playerid, x, y+1.0, "_");
	PlayerTextDrawAlignment(playerid, gui_ButtonData[playerid][id][gui_but_tdout], 2);
	PlayerTextDrawBackgroundColor(playerid, gui_ButtonData[playerid][id][gui_but_tdout], 255);
	PlayerTextDrawFont(playerid, gui_ButtonData[playerid][id][gui_but_tdout], 1);
	PlayerTextDrawLetterSize(playerid, gui_ButtonData[playerid][id][gui_but_tdout], 0.159998, (height*UNIT)-0.25);
	//PlayerTextDrawLetterSize(playerid, gui_ButtonData[playerid][id][gui_but_tdout], 0.159998, ((height-2.0)*UNIT));
	PlayerTextDrawColor(playerid, gui_ButtonData[playerid][id][gui_but_tdout], -1);
	PlayerTextDrawSetOutline(playerid, gui_ButtonData[playerid][id][gui_but_tdout], 1);
	PlayerTextDrawSetProportional(playerid, gui_ButtonData[playerid][id][gui_but_tdout], 1);
	PlayerTextDrawUseBox(playerid, gui_ButtonData[playerid][id][gui_but_tdout], 1);
	PlayerTextDrawBoxColor(playerid, gui_ButtonData[playerid][id][gui_but_tdout], -892679629);
	PlayerTextDrawTextSize(playerid, gui_ButtonData[playerid][id][gui_but_tdout], height, width-2.0);

	gui_ButtonData[playerid][id][gui_but_tdbox] = CreatePlayerTextDraw(playerid, x, y+2.0, "_");
	PlayerTextDrawAlignment(playerid, gui_ButtonData[playerid][id][gui_but_tdbox], 2);
	PlayerTextDrawBackgroundColor(playerid, gui_ButtonData[playerid][id][gui_but_tdbox], 255);
	PlayerTextDrawFont(playerid, gui_ButtonData[playerid][id][gui_but_tdbox], 1);
	PlayerTextDrawLetterSize(playerid, gui_ButtonData[playerid][id][gui_but_tdbox], 0.159998, (height*UNIT)-0.4741);
	//PlayerTextDrawLetterSize(playerid, gui_ButtonData[playerid][id][gui_but_tdbox], 0.159998, ((height-4.0)*UNIT));
	PlayerTextDrawColor(playerid, gui_ButtonData[playerid][id][gui_but_tdbox], -1);
	PlayerTextDrawSetOutline(playerid, gui_ButtonData[playerid][id][gui_but_tdbox], 1);
	PlayerTextDrawSetProportional(playerid, gui_ButtonData[playerid][id][gui_but_tdbox], 1);
	PlayerTextDrawUseBox(playerid, gui_ButtonData[playerid][id][gui_but_tdbox], 1);
	PlayerTextDrawBoxColor(playerid, gui_ButtonData[playerid][id][gui_but_tdbox], 222);
	PlayerTextDrawTextSize(playerid, gui_ButtonData[playerid][id][gui_but_tdbox], height, width-4.0);

	gui_ButtonData[playerid][id][gui_but_tdtxt] = CreatePlayerTextDraw(playerid, x, y+(height/2)-((0.8/UNIT)/2), text);
	PlayerTextDrawAlignment(playerid, gui_ButtonData[playerid][id][gui_but_tdtxt], 2);
	PlayerTextDrawBackgroundColor(playerid, gui_ButtonData[playerid][id][gui_but_tdtxt], 255);
	PlayerTextDrawFont(playerid, gui_ButtonData[playerid][id][gui_but_tdtxt], 2);
	PlayerTextDrawLetterSize(playerid, gui_ButtonData[playerid][id][gui_but_tdtxt], 0.159999, 0.8);
	PlayerTextDrawColor(playerid, gui_ButtonData[playerid][id][gui_but_tdtxt], -1);
	PlayerTextDrawSetOutline(playerid, gui_ButtonData[playerid][id][gui_but_tdtxt], 1);
	PlayerTextDrawSetProportional(playerid, gui_ButtonData[playerid][id][gui_but_tdtxt], 1);
	PlayerTextDrawTextSize(playerid, gui_ButtonData[playerid][id][gui_but_tdtxt], height-(height/4), width);
	PlayerTextDrawSetSelectable(playerid, gui_ButtonData[playerid][id][gui_but_tdtxt], 1);

	gui_ButtonData[playerid][id][gui_but_tdgl] = CreatePlayerTextDraw(playerid, x, y+2.0, "_");
	PlayerTextDrawAlignment(playerid, gui_ButtonData[playerid][id][gui_but_tdgl], 2);
	PlayerTextDrawBackgroundColor(playerid, gui_ButtonData[playerid][id][gui_but_tdgl], 255);
	PlayerTextDrawFont(playerid, gui_ButtonData[playerid][id][gui_but_tdgl], 1);
	//PlayerTextDrawLetterSize(playerid, gui_ButtonData[playerid][id][gui_but_tdgl], 0.159998, (height*UNIT)-1.075);
	PlayerTextDrawLetterSize(playerid, gui_ButtonData[playerid][id][gui_but_tdgl], 0.159998, (((height/2)-4.0)*UNIT));
	PlayerTextDrawColor(playerid, gui_ButtonData[playerid][id][gui_but_tdgl], -1);
	PlayerTextDrawSetOutline(playerid, gui_ButtonData[playerid][id][gui_but_tdgl], 1);
	PlayerTextDrawSetProportional(playerid, gui_ButtonData[playerid][id][gui_but_tdgl], 1);
	PlayerTextDrawUseBox(playerid, gui_ButtonData[playerid][id][gui_but_tdgl], 1);
	PlayerTextDrawBoxColor(playerid, gui_ButtonData[playerid][id][gui_but_tdgl], -245);
	PlayerTextDrawTextSize(playerid, gui_ButtonData[playerid][id][gui_but_tdgl], height, width-4.0);

	return gui_ButtonData[playerid][id][gui_but_ID];
}
function Float:guiGetButtonHeight(playerid, buttonid)
{
    if (buttonid >= MAX_GUI) return 0.0;
    new r;
	for(new g; g < MAX_GUI; g++)
	{
	    if (gui_ButtonData[playerid][g][gui_but_ID]== buttonid)
	    {
			buttonid = g;
			r = 1;
			break;
		}
	}
	if (!r) return 0.0;
	if (!gui_ButtonData[playerid][buttonid][gui_but_ID]) return 0.0;
	return gui_ButtonData[playerid][buttonid][gui_but_Height];
}
function Float:guiGetButtonWidth(playerid, buttonid)
{
    if (buttonid >= MAX_GUI) return 0.0;
	new r;
	for(new g; g < MAX_GUI; g++)
	{
	    if (gui_ButtonData[playerid][g][gui_but_ID]== buttonid)
	    {
			buttonid = g;
			r = 1;
			break;
		}
	}
	if (!r) return 0.0;
	if (!gui_ButtonData[playerid][buttonid][gui_but_ID]) return 0.0;
	return gui_ButtonData[playerid][buttonid][gui_but_Width];
}
function guiGetButtonPos(playerid, buttonid, &Float:x, &Float:y)
{
    if (buttonid >= MAX_GUI) return 0;
	new r;
	for(new g; g < MAX_GUI; g++)
	{
	    if (gui_ButtonData[playerid][g][gui_but_ID]== buttonid)
	    {
			buttonid = g;
			r = 1;
			break;
		}
	}
	if (!r) return 0;
	if (!gui_ButtonData[playerid][buttonid][gui_but_ID]) return 0;
	x = gui_ButtonData[playerid][buttonid][gui_but_X];
	y = gui_ButtonData[playerid][buttonid][gui_but_Y];
	return 1;
}

function guiGetID(playerid, type, gui)
{
	switch (type)
	{
	    case GUI_TYPE_WINDOW:
	    {
	        for(new g; g < MAX_GUI; g++)
	        {
	            if (gui_WindowData[playerid][g][gui_win_ID] == gui)
		            return g;
	        }
	    }
	    case GUI_TYPE_TAB:
	    {
	        for(new g; g < MAX_GUI; g++)
	        {
	            if (gui_TabData[playerid][g][gui_tab_ID] == gui)
		            return g;
	        }
	    }
	    case GUI_TYPE_LABEL:
	    {
	        for(new g; g < MAX_GUI; g++)
	        {
	            if (gui_LabelData[playerid][g][gui_label_ID] == gui)
		            return g;
	        }
	    }
	    case GUI_TYPE_BAR:
	    {
	        for(new g; g < MAX_GUI; g++)
	        {
	            if (gui_BarData[playerid][g][gui_bar_ID] == gui)
		            return g;
	        }
	    }
	    case GUI_TYPE_ITEMLIST:
	    {
	        for(new g; g < MAX_GUI; g++)
	        {
	            if (gui_ItemlistData[playerid][g][gui_list_ID] == gui)
		            return g;
	        }
	    }
	    case GUI_TYPE_CHECKBOX:
	    {
	        for(new g; g < MAX_GUI; g++)
	        {
	            if (gui_CheckboxData[playerid][g][gui_check_ID] == gui)
		            return g;
	        }
	    }
	    case GUI_TYPE_BUTTON:
	    {
	        for(new g; g < MAX_GUI; g++)
	        {
	            if (gui_ButtonData[playerid][g][gui_but_ID] == gui)
		            return g;
	        }
	    }
	}
	return -1;
}

function guiIsVisible(playerid, type, gui)
{
	switch (type)
	{
	    case GUI_TYPE_WINDOW:
	    {
	        for(new g; g < MAX_GUI; g++)
	        {
	            if (gui_WindowData[playerid][g][gui_win_ID] == gui)
		            return GetTextDrawVisibilityForPlayer(playerid, gui_WindowData[playerid][g][gui_win_td]);
	        }
	    }
	    case GUI_TYPE_TAB:
	    {
	        for(new g; g < MAX_GUI; g++)
	        {
	            if (gui_TabData[playerid][g][gui_tab_ID] == gui)
	            {
	                if (!GetTextDrawVisibilityForPlayer(playerid, gui_TabData[playerid][g][gui_tab_td])) return GetTextDrawVisibilityForPlayer(playerid, gui_TabData[playerid][g][gui_tab_td2]);
		            else GetTextDrawVisibilityForPlayer(playerid, gui_TabData[playerid][g][gui_tab_td]);
				}
	        }
	    }
	    case GUI_TYPE_LABEL:
	    {
	        for(new g; g < MAX_GUI; g++)
	        {
	            if (gui_LabelData[playerid][g][gui_label_ID] == gui)
		            return GetTextDrawVisibilityForPlayer(playerid, gui_LabelData[playerid][g][gui_label_td]);
	        }
	    }
	    case GUI_TYPE_BAR:
	    {
	        for(new g; g < MAX_GUI; g++)
	        {
	            if (gui_BarData[playerid][g][gui_bar_ID] == gui)
		            return GetTextDrawVisibilityForPlayer(playerid, gui_BarData[playerid][g][gui_bar_tdbg]);
	        }
	    }
	    case GUI_TYPE_ITEMLIST:
	    {
	        for(new g; g < MAX_GUI; g++)
	        {
	            if (gui_ItemlistData[playerid][g][gui_list_ID] == gui)
		            return GetTextDrawVisibilityForPlayer(playerid, gui_ItemlistData[playerid][g][gui_list_tdbox]);
	        }
	    }
	    case GUI_TYPE_CHECKBOX:
	    {
	        for(new g; g < MAX_GUI; g++)
	        {
	            if (gui_CheckboxData[playerid][g][gui_check_ID] == gui)
	            {
		            if (!GetTextDrawVisibilityForPlayer(playerid, gui_CheckboxData[playerid][g][gui_check_td])) return GetTextDrawVisibilityForPlayer(playerid, gui_CheckboxData[playerid][g][gui_check_td2]);
		            else GetTextDrawVisibilityForPlayer(playerid, gui_CheckboxData[playerid][g][gui_check_td]);
				}
	        }
	    }
	    case GUI_TYPE_BUTTON:
	    {
	        for(new g; g < MAX_GUI; g++)
	        {
	            if (gui_ButtonData[playerid][g][gui_but_ID] == gui)
		            return GetTextDrawVisibilityForPlayer(playerid, gui_ButtonData[playerid][g][gui_but_tdtxt]);
	        }
	    }
	}
	return 0;
}

function guiDestroy(playerid, type, gui)
{
	if (!IsPlayerConnected(playerid)) return 0;

    switch (type)
	{
	    case GUI_TYPE_WINDOW:
	    {
	        for(new g; g < MAX_GUI; g++)
	        {
	            if (gui_WindowData[playerid][g][gui_win_ID] == gui)
				{
				    gui_WindowData[playerid][g][gui_win_ID] = 0;
				    TextDrawDestroyEx(playerid, gui_WindowData[playerid][g][gui_win_td]);
				    TextDrawDestroyEx(playerid, gui_WindowData[playerid][g][gui_win_tdtop]);
				    TextDrawDestroyEx(playerid, gui_WindowData[playerid][g][gui_win_tdtitle]);
				    return 1;
				}
	        }
	    }
	    case GUI_TYPE_TAB:
	    {
	        for(new g; g < MAX_GUI; g++)
	        {
	            if (gui_TabData[playerid][g][gui_tab_ID] == gui)
				{
				    gui_TabData[playerid][g][gui_tab_ID] = 0;
				    TextDrawDestroyEx(playerid, gui_TabData[playerid][g][gui_tab_td]);
				    TextDrawDestroyEx(playerid, gui_TabData[playerid][g][gui_tab_td2]);
				    TextDrawDestroyEx(playerid, gui_TabData[playerid][gui_TabData[playerid][g][gui_tab_panel]][gui_tab_tdbg]);
			    	TextDrawDestroyEx(playerid, gui_TabData[playerid][gui_TabData[playerid][g][gui_tab_panel]][gui_tab_tdbox]);
				    return 1;
				}
	        }
	    }
	    case GUI_TYPE_LABEL:
	    {
	        for(new g; g < MAX_GUI; g++)
	        {
	            if (gui_LabelData[playerid][g][gui_label_ID] == gui)
				{
				    gui_LabelData[playerid][g][gui_label_ID] = 0;
				    TextDrawDestroyEx(playerid, gui_LabelData[playerid][g][gui_label_td]);
				    return 1;
				}
	        }
	    }
	    case GUI_TYPE_BAR:
	    {
	        for(new g; g < MAX_GUI; g++)
	        {
	            if (gui_BarData[playerid][g][gui_bar_ID] == gui)
				{
				    gui_BarData[playerid][g][gui_bar_ID] = 0;
				    TextDrawDestroyEx(playerid, gui_BarData[playerid][g][gui_bar_tdbg]);
				    TextDrawDestroyEx(playerid, gui_BarData[playerid][g][gui_bar_tdbox]);
				    TextDrawDestroyEx(playerid, gui_BarData[playerid][g][gui_bar_tdbar]);
				    return 1;
				}
	        }
	    }
	    case GUI_TYPE_ITEMLIST:
	    {
	        for(new g; g < MAX_GUI; g++)
	        {
	            if (gui_ItemlistData[playerid][g][gui_list_ID] == gui)
				{
				    gui_ItemlistData[playerid][g][gui_list_ID] = 0;
				    TextDrawDestroyEx(playerid, gui_ItemlistData[playerid][g][gui_list_tdbox]);
				    TextDrawDestroyEx(playerid, gui_ItemlistData[playerid][g][gui_list_tdline]);
				    TextDrawDestroyEx(playerid, gui_ItemlistData[playerid][g][gui_list_tdtitle]);

				    for(new r; r <= gui_ItemlistData[playerid][g][gui_list_RowMax]; r++)
					{
					    if (gui_ItemRowData[playerid][r][gui_row_ID] > 0)
					    {
							gui_ItemRowData[playerid][r][gui_row_ID] = 0;
				    		TextDrawDestroyEx(playerid, gui_ItemRowData[playerid][r][gui_row_td]);
				    		TextDrawDestroyEx(playerid, gui_ItemRowData[playerid][r][gui_row_td2]);
						}
					}
					return 1;
				}
	        }
	    }
	    case GUI_TYPE_CHECKBOX:
	    {
	        for(new g; g < MAX_GUI; g++)
	        {
	            if (gui_CheckboxData[playerid][g][gui_check_ID] == gui)
				{
				    gui_CheckboxData[playerid][g][gui_check_ID] = 0;
				    TextDrawDestroyEx(playerid, gui_CheckboxData[playerid][g][gui_check_td]);
				    TextDrawDestroyEx(playerid, gui_CheckboxData[playerid][g][gui_check_td2]);
				    return 1;
				}
	        }
	    }
	    case GUI_TYPE_BUTTON:
	    {
	        for(new g; g < MAX_GUI; g++)
	        {
	            if (gui_ButtonData[playerid][g][gui_but_ID] == gui)
				{
				    gui_ButtonData[playerid][g][gui_but_ID] = 0;
				    TextDrawDestroyEx(playerid, gui_ButtonData[playerid][g][gui_but_tdbg]);
				    TextDrawDestroyEx(playerid, gui_ButtonData[playerid][g][gui_but_tdout]);
				    TextDrawDestroyEx(playerid, gui_ButtonData[playerid][g][gui_but_tdbox]);
				    TextDrawDestroyEx(playerid, gui_ButtonData[playerid][g][gui_but_tdtxt]);
				    TextDrawDestroyEx(playerid, gui_ButtonData[playerid][g][gui_but_tdgl]);
				    return 1;
				}
	        }
	    }
	}
	return 0;
}

function guiDestroyAll(playerid, type) // 0 = all
{
	if (!IsPlayerConnected(playerid)) return 0;

	new follow;
	START:
    switch (type)
	{
		case 0:
		{
		    follow = 1;
		    type = GUI_TYPE_WINDOW;
		    goto START;
		}
	    case GUI_TYPE_WINDOW:
	    {
	        for(new g; g < MAX_GUI; g++)
	        {
	            if (gui_WindowData[playerid][g][gui_win_ID] > 0)
				{
				    gui_WindowData[playerid][g][gui_win_ID] = 0;
				    TextDrawDestroyEx(playerid, gui_WindowData[playerid][g][gui_win_td]);
				    TextDrawDestroyEx(playerid, gui_WindowData[playerid][g][gui_win_tdtop]);
				    TextDrawDestroyEx(playerid, gui_WindowData[playerid][g][gui_win_tdtitle]);
				}
	        }
	        if (follow)
	        {
	            type = GUI_TYPE_TAB;
	            goto START;
	        }
	    }
	    case GUI_TYPE_TAB:
	    {
	        for(new g; g < MAX_GUI; g++)
	        {
	            if (gui_TabData[playerid][g][gui_tab_ID] > 0)
				{
				    gui_TabData[playerid][g][gui_tab_ID] = 0;
				    TextDrawDestroyEx(playerid, gui_TabData[playerid][g][gui_tab_td]);
				    TextDrawDestroyEx(playerid, gui_TabData[playerid][g][gui_tab_td2]);
			    	TextDrawDestroyEx(playerid, gui_TabData[playerid][gui_TabData[playerid][g][gui_tab_panel]][gui_tab_tdbg]);
			    	TextDrawDestroyEx(playerid, gui_TabData[playerid][gui_TabData[playerid][g][gui_tab_panel]][gui_tab_tdbox]);
				}
	        }
	        if (follow)
	        {
	            type = GUI_TYPE_LABEL;
	            goto START;
	        }
	    }
	    case GUI_TYPE_LABEL:
	    {
	        for(new g; g < MAX_GUI; g++)
	        {
	            if (gui_LabelData[playerid][g][gui_label_ID] > 0)
				{
				    gui_LabelData[playerid][g][gui_label_ID] = 0;
				    TextDrawDestroyEx(playerid, gui_LabelData[playerid][g][gui_label_td]);
				}
	        }
	        if (follow)
	        {
	            type = GUI_TYPE_BAR;
	            goto START;
	        }
	    }
	    case GUI_TYPE_BAR:
	    {
	        for(new g; g < MAX_GUI; g++)
	        {
	            if (gui_BarData[playerid][g][gui_bar_ID] > 0)
				{
				    gui_BarData[playerid][g][gui_bar_ID] = 0;
				    TextDrawDestroyEx(playerid, gui_BarData[playerid][g][gui_bar_tdbg]);
				    TextDrawDestroyEx(playerid, gui_BarData[playerid][g][gui_bar_tdbox]);
				    TextDrawDestroyEx(playerid, gui_BarData[playerid][g][gui_bar_tdbar]);
				}
	        }
	        if (follow)
	        {
	            type = GUI_TYPE_ITEMLIST;
	            goto START;
	        }
	    }
	    case GUI_TYPE_ITEMLIST:
	    {
	        for(new g; g < MAX_GUI; g++)
	        {
	            if (gui_ItemlistData[playerid][g][gui_list_ID] > 0)
				{
				    gui_ItemlistData[playerid][g][gui_list_ID] = 0;
				    TextDrawDestroyEx(playerid, gui_ItemlistData[playerid][g][gui_list_tdbox]);
				    TextDrawDestroyEx(playerid, gui_ItemlistData[playerid][g][gui_list_tdline]);
				    TextDrawDestroyEx(playerid, gui_ItemlistData[playerid][g][gui_list_tdtitle]);

				    for(new r; r <= gui_ItemlistData[playerid][g][gui_list_RowMax]; r++)
					{
					    if (gui_ItemRowData[playerid][r][gui_row_ID] > 0)
					    {
							gui_ItemRowData[playerid][r][gui_row_ID] = 0;
				    		TextDrawDestroyEx(playerid, gui_ItemRowData[playerid][r][gui_row_td]);
				    		TextDrawDestroyEx(playerid, gui_ItemRowData[playerid][r][gui_row_td2]);
						}
					}
				}
	        }
	        if (follow)
	        {
	            type = GUI_TYPE_CHECKBOX;
	            goto START;
	        }
	    }
	    case GUI_TYPE_CHECKBOX:
	    {
	        for(new g; g < MAX_GUI; g++)
	        {
	            if (gui_CheckboxData[playerid][g][gui_check_ID] > 0)
				{
				    gui_CheckboxData[playerid][g][gui_check_ID] = 0;
				    TextDrawDestroyEx(playerid, gui_CheckboxData[playerid][g][gui_check_td]);
				    TextDrawDestroyEx(playerid, gui_CheckboxData[playerid][g][gui_check_td2]);
				}
	        }
	        if (follow)
	        {
	            type = GUI_TYPE_BUTTON;
	            goto START;
	        }
	    }
	    case GUI_TYPE_BUTTON:
	    {
	        for(new g; g < MAX_GUI; g++)
	        {
	            if (gui_ButtonData[playerid][g][gui_but_ID] > 0)
				{
				    gui_ButtonData[playerid][g][gui_but_ID] = 0;
				    TextDrawDestroyEx(playerid, gui_ButtonData[playerid][g][gui_but_tdbg]);
				    TextDrawDestroyEx(playerid, gui_ButtonData[playerid][g][gui_but_tdout]);
				    TextDrawDestroyEx(playerid, gui_ButtonData[playerid][g][gui_but_tdbox]);
				    TextDrawDestroyEx(playerid, gui_ButtonData[playerid][g][gui_but_tdtxt]);
				    TextDrawDestroyEx(playerid, gui_ButtonData[playerid][g][gui_but_tdgl]);
				}
	        }
	    }
	}
	return 1;
}


forward gui_OnPlayerClickPlayerTextDraw(playerid, PlayerText:playertextid);
public OnPlayerClickPlayerTextDraw(playerid, PlayerText:playertextid)
{
	if ((tickcount()-GetPVarInt(playerid, "guiinc_i")) < 500) return 0; // Preventing spam, because of loop.

    for(new c; c < MAX_GUI; c++)
	{
	    if (gui_TabData[playerid][c][gui_tab_ID] > 0)
	    {
	        if (playerid != gui_TabData[playerid][c][gui_tab_P]) continue;
	        
			if (playertextid == gui_TabData[playerid][c][gui_tab_td])
			{
			    PlayerTextDrawHide(playerid, gui_TabData[playerid][p_tab[playerid]][gui_tab_td2]);
			    guiSetVisible(playerid, GUI_TYPE_TAB, gui_TabData[playerid][p_tab[playerid]][gui_tab_ID], false);

				PlayerTextDrawHide(playerid, gui_TabData[playerid][c][gui_tab_td]);
			    p_tab[playerid] = c;
			    guiSetVisible(playerid, GUI_TYPE_TAB, gui_TabData[playerid][c][gui_tab_ID], true);
			    OnPlayerClickTab(playerid, gui_TabData[playerid][c][gui_tab_ID]);
			    break;
			}
	    }
	    if (gui_ButtonData[playerid][c][gui_but_ID] > 0)
	    {
	        if (playerid != gui_ButtonData[playerid][c][gui_but_P]) continue;

			if (playertextid == gui_ButtonData[playerid][c][gui_but_tdtxt] || playertextid == gui_ButtonData[playerid][c][gui_but_tdbg])
			{
				OnPlayerClickButton(playerid, gui_ButtonData[playerid][c][gui_but_ID]);
			    break;
			}
	    }
	    if (gui_ItemRowData[playerid][c][gui_row_ID] > 0)
	    {
			if (playertextid == gui_ItemRowData[playerid][c][gui_row_td])
			{
			    PlayerTextDrawHide(playerid, gui_ItemRowData[playerid][p_row[playerid]][gui_row_td2]);
			    PlayerTextDrawShow(playerid, gui_ItemRowData[playerid][p_row[playerid]][gui_row_td]);

				PlayerTextDrawHide(playerid, gui_ItemRowData[playerid][c][gui_row_td]);
			    PlayerTextDrawShow(playerid, gui_ItemRowData[playerid][c][gui_row_td2]);
			    p_row[playerid] = c;
			    break;
			}
	    }
	    if (gui_CheckboxData[playerid][c][gui_check_ID] > 0)
	    {
	        if (playerid != gui_CheckboxData[playerid][c][gui_check_P]) continue;

			if (playertextid == gui_CheckboxData[playerid][c][gui_check_td])
			{
				PlayerTextDrawHide(playerid, gui_CheckboxData[playerid][c][gui_check_td]);
			    PlayerTextDrawShow(playerid, gui_CheckboxData[playerid][c][gui_check_td2]);
			    break;
			}
			if (playertextid == gui_CheckboxData[playerid][c][gui_check_td2])
			{
				PlayerTextDrawHide(playerid, gui_CheckboxData[playerid][c][gui_check_td2]);
			    PlayerTextDrawShow(playerid, gui_CheckboxData[playerid][c][gui_check_td]);
			    break;
			}
	    }
	}
	SetPVarInt(playerid, "guiinc_i", tickcount());
	return gui_OnPlayerClickPlayerTextDraw(playerid, playertextid);
	//return 0;
}
#define OnPlayerClickPlayerTextDraw gui_OnPlayerClickPlayerTextDraw

// END
#if defined function
	#undef function
#endif
