/*
	PostNukeWasteland Vegetation
	Author: NeoPhoenix
	Date:	19.01.2012
*/
#define veg:: veg_
/*
	native veg::OnVegetationInit();
	native veg::DB_OnVegetationSync();
	native veg::DB_CreatePlant(breed,Float:pos_x,Float:pos_y,Float:pos_z,step=0,owner=0);
	native veg::UpdatePlant(plant,bool:_init=false);
	native veg::PlantSync();
	native veg::DB_SavePlant(plant);
	native veg::DeletePlant(plant);
	native veg::GetNearestPlant(playerid,Float:range=AVERAGE_TAKE_DEST);
*/
#define MAX_PLANTS				(50)
#define MAX_BREEDS				(4)
#define MAX_STEPS				(3)
#define MAX_PLANT_NAME_LEN		(20)
#define MAX_VEG_ITEM_NAME_LEN	(20)
#define PLANT_TEXT_DISTANCE		(15.0)
#define veg_PLANT_LOSE_WATER_HP	( 5.0)//Prozentangabe des HP-Verlustes bei Wassermangel	(Basis: Maximale HP)
#define veg_PLANT_ADD_WATER_HP	(15.0)//Prozentangabe des HP-Boosts bei genug Wasser	(Basis: Vorhandene HP)

#if !defined AVERAGE_TAKE_DEST
#define AVERAGE_TAKE_DEST 5.0
#endif

forward veg_OnPlantFarm(playerid,plantid,anzahl);

enum veg_data
{
	pLowestID,
	pHighestID,
}
new VegData[veg_data];

enum plant_data
{
	bool:pCreated[2],
	pID,
	pOwner,
	pBreed,
	pStep,
	pNextStep,//Minutes
	pFruitsIn,//Minutes
	pFruits,
	pObject,
	pTimeCache,
	Float:pHP,
	Float:pWater,
	Float:pPos[3],
	Text3D:pLabel,
}
new PlantInfo[MAX_PLANTS][plant_data];

enum grow_data
{
	PlantName[MAX_PLANT_NAME_LEN],
	ItemName[MAX_VEG_ITEM_NAME_LEN],
	Float:MaxHP[MAX_STEPS],//Insgesamt
	Float:MaxWater[MAX_STEPS],//Insgesamt
	Float:NeedWater[MAX_STEPS],//Stunden
	NextStep[MAX_STEPS],//Minuten
	MaxSteps,//Insgesamt
	MaxFruits,//Insgesamt
	FruitIntervall,//Minuten
	Float:FruitWahrsch,//Prozent (max: 100.0)
	NeedEquipLevel,//Stufe des Messers zum ernten der Früchte
	ObjectTypes[MAX_STEPS]
}
new GrowInfo[MAX_BREEDS][grow_data] = {
	{
		"Hanf",
		"Hanfknospe",
		{500.0,200.0},//MaxHP
		{200.0},//MaxWater
		{5.0},//NeedWater
		{0},//NextStep
		0,//MaxSteps
		20,//MaxFruits
		120,//Fruitintervall
		5.0,//Fruitwahrscheinlichkeit
		2,//Equiplevel
		{3409,00}	
	},	
	{"Apfelbaum",		"Apfel",		/*MaxHP*/{4000.0},	/*MaxWater*/2500.0,	/*NeedWater*/10.0,	/*NextStep*/{180},	/*MaxSteps*/1,	/*MaxFruits*/30,	/*FruitIntervall*/60, 	/*FruitWahrsch*/10.0,	/*EquipLevel*/0,  	{848,706}	},
	{"Kokosbaum",		"Kokosnuss",	/*MaxHP*/{1500.0},	/*MaxWater*/ 750.0,	/*NeedWater*/3.0,	/*NextStep*/{180},	/*MaxSteps*/1,	/*MaxFruits*/30,	/*FruitIntervall*/60, 	/*FruitWahrsch*/10.0,	/*EquipLevel*/1,	{831,676}	},
	{"Tanne",			"Tannenzapfen",	/*MaxHP*/{2000.0,1000.0},	/*MaxWater*/1000.0,	/*NeedWater*/4.0,	/*NextStep*/{120},	/*MaxSteps*/1,	/*MaxFruits*/20,	/*FruitIntervall*/60, 	/*FruitWahrsch*/10.0,	/*EquipLevel*/1,	{834,687}	}
};

veg::OnVegetationInit()
{
	format(query,sizeof(query),"SELECT * FROM pnwl_vegetation LIMIT %d",MAX_PLANTS);
	SQL_RES = db_query(SQL_DB,query);
	
	new plants_loaded = 0, p_id = 0;
	if(db_num_rows(SQL_RES) >= 1)
	{
		do
		{
			db_get_field_assoc(SQL_RES,"id",string,sizeof(string));
			PlantInfo[p_id][pID] 			= strval(string);
			db_get_field_assoc(SQL_RES,"owner",string,sizeof(string));
			PlantInfo[p_id][pOwner] 		= strval(string);			
			db_get_field_assoc(SQL_RES,"breed",string,sizeof(string));
			PlantInfo[p_id][pBreed] 		= strval(string);
			db_get_field_assoc(SQL_RES,"step",string,sizeof(string));
			PlantInfo[p_id][pStep] 			= strval(string);
			db_get_field_assoc(SQL_RES,"nextstep",string,sizeof(string));
			PlantInfo[p_id][pNextStep] 		= strval(string);
			db_get_field_assoc(SQL_RES,"fruitsin",string,sizeof(string));
			PlantInfo[p_id][pFruitsIn] 		= strval(string);			
			if(PlantInfo[p_id][pFruitsIn] <= 0 || PlantInfo[p_id][pFruitsIn] > GrowInfo[PlantInfo[p_id][pBreed]][FruitIntervall]) PlantInfo[p_id][pFruitsIn] = GrowInfo[PlantInfo[p_id][pBreed]][FruitIntervall];
			db_get_field_assoc(SQL_RES,"fruits",string,sizeof(string));
			PlantInfo[p_id][pFruits]		= strval(string);
			db_get_field_assoc(SQL_RES,"pos_x",string,sizeof(string));
			PlantInfo[p_id][pPos][0] 		= floatstr(string);
			db_get_field_assoc(SQL_RES,"pos_y",string,sizeof(string));
			PlantInfo[p_id][pPos][1] 		= floatstr(string);
			db_get_field_assoc(SQL_RES,"pos_z",string,sizeof(string));
			PlantInfo[p_id][pPos][2] 		= floatstr(string);
			db_get_field_assoc(SQL_RES,"health",string,sizeof(string));
			PlantInfo[p_id][pHP] 			= floatstr(string);
			db_get_field_assoc(SQL_RES,"water",string,sizeof(string));
			PlantInfo[p_id][pWater] 		= floatstr(string);	
			db_get_field_assoc(SQL_RES,"timecache",string,sizeof(string));
			PlantInfo[p_id][pTimeCache] 	= strval(string);
			
			PlantInfo[p_id][pCreated][0]	= true;
			PlantInfo[p_id][pCreated][1]	= false;
			veg::UpdatePlant(p_id,true);			
			
			plants_loaded++;
			if(++p_id >= MAX_PLANTS) 
			{
				printf("::VegetationInit -> Too much plants. Broke after %d",(p_id-1));
				break;
			}
		}
		while(db_next_row(SQL_RES));
		printf("::VegetationInit -> %d plants loaded",plants_loaded);
	}
	else print("::VegetationInit -> Empty table");
	db_free_result(SQL_RES);
	
	VegData[pHighestID] = plants_loaded;
	VegData[pLowestID]	= 0;	
	
	return plants_loaded;
}

stock veg::UpdatePlant(plant,bool:_init=false)
{
	printf("veh_UpdatePlant(%d,%s)",plant,_init==true?("true"):("false"));
	if(plant < 0 || plant >= MAX_PLANTS) return -1;
	if(!PlantInfo[plant][pCreated][0]) return 0;
	new bool:_change = false;

	if(!_init)
	{
		new p_id 		= PlantInfo[plant][pBreed],
			time 		= (++PlantInfo[plant][pTimeCache]),
			plant_step	= PlantInfo[plant][pStep];
		if(time > 0 && (time%60) == 0)
		{//Eine Stunde ist rum
			PlantInfo[plant][pWater] -= GrowInfo[p_id][NeedWater][plant_step];
			if(PlantInfo[plant][pWater] < 0.0) PlantInfo[plant][pWater] = 0.0;
			_change = true;
		}		
		
		if(PlantInfo[plant][pWater] <= 0.0)
		{//Hat kein Wasser mehr -> HP abziehen, Früchte entfernt, Wachstum gehemmt
			new Float:loose_hp = ((GrowInfo[p_id][MaxHP][plant_step]/100)*veg_PLANT_LOSE_WATER_HP);
			
			PlantInfo[plant][pHP] 		-= loose_hp;
			PlantInfo[plant][pFruits] 	= 0;
			
			if(PlantInfo[plant][pHP] <= 0.0)
			{//Pflanze ist gestorben
				veg::DeletePlant(plant);
				return 0;
			}
			_change = true;
		}
		else
		{//Hat genug Wasser, kann wachsen
			new Float:add_hp = ((PlantInfo[plant][pHP]/100.0)*veg_PLANT_ADD_WATER_HP);
			PlantInfo[plant][pHP] += add_hp;
			if(PlantInfo[plant][pHP] > GrowInfo[p_id][MaxHP][plant_step]) PlantInfo[plant][pHP] = GrowInfo[p_id][MaxHP][plant_step];
			
			if(PlantInfo[plant][pNextStep] > 0 && --PlantInfo[plant][pNextStep] <= 0)
			{//Pflanzenwachstum ==> Level up
				_change = true;
				PlantInfo[plant][pStep]++;
				plant_step 					= PlantInfo[plant][pStep];
				PlantInfo[plant][pHP] 		= GrowInfo[p_id][MaxHP][plant_step];
				PlantInfo[plant][pWater]	= GrowInfo[p_id][MaxWater][plant_step];
				
				if(PlantInfo[plant][pStep] < GrowInfo[p_id][MaxSteps])
				{//maximallevel noch nicht erreicht
					PlantInfo[plant][pNextStep] = GrowInfo[p_id][NextStep][PlantInfo[plant][pStep]];
				}
				else
				{//maximallevel erreicht
					PlantInfo[plant][pNextStep] = 0;
					PlantInfo[plant][pFruitsIn] = GrowInfo[p_id][FruitIntervall];
				}
			}
			
			if(GrowInfo[p_id][MaxFruits] >= 1 && PlantInfo[plant][pStep] == GrowInfo[p_id][MaxSteps])
			{//Maximallevel -> kann früchte tragen
				if(--PlantInfo[plant][pFruitsIn] <= 0)
				{//bekommt früchte
					PlantInfo[plant][pFruitsIn] = GrowInfo[p_id][FruitIntervall];
					new total_fruits = 0;
					for(new f; f<GrowInfo[p_id][MaxFruits]; f++)
					{
						if(floatrandom(100.0) <= GrowInfo[p_id][FruitWahrsch])
						{
							total_fruits++;
							continue;
						}
					}
					if(total_fruits >= 1 && total_fruits > PlantInfo[plant][pFruits]) 
					{
						PlantInfo[plant][pFruits] = total_fruits;
						_change = true;
					}
				}
			}		
		}
	}
	
	if(_change || _init)
	{
		format(string,sizeof(string),"Vegetation \"%s\"\nStufe %d/%d, %0.2f HP",GrowInfo[PlantInfo[plant][pBreed]][PlantName],PlantInfo[plant][pStep],GrowInfo[PlantInfo[plant][pBreed]][MaxSteps],PlantInfo[plant][pHP]);
		if(PlantInfo[plant][pCreated][1])
		{
			DestroyObject(PlantInfo[plant][pObject]);
			Update3DTextLabelText(PlantInfo[plant][pLabel],GRUEN,string);
		}
		else
		{//Erste Erstellung
			PlantInfo[plant][pLabel] = Create3DTextLabel(string,GRUEN,PlantInfo[plant][pPos][0],PlantInfo[plant][pPos][1],PlantInfo[plant][pPos][2],PLANT_TEXT_DISTANCE,0,0);
		}
		PlantInfo[plant][pObject] = CreateObject(GrowInfo[PlantInfo[plant][pBreed]][ObjectTypes][PlantInfo[plant][pStep]],PlantInfo[plant][pPos][0],PlantInfo[plant][pPos][1],PlantInfo[plant][pPos][2],0.0,0.0,0.0,50.0);
	}
	PlantInfo[plant][pCreated][0] 	= true;
	PlantInfo[plant][pCreated][1] 	= true;
	
	if(_change) veg::DB_SavePlant(plant);
	return 1;
}

stock veg::DB_CreatePlant(breed,Float:pos_x,Float:pos_y,Float:pos_z,step=0,owner=0)
{
	printf("veg::DB_CreatePlant(%d...)",breed);
	new freeslot = -1;
	for(new s; s<MAX_PLANTS; s++)
	{
		if(!PlantInfo[s][pCreated][0])
		{
			freeslot = s;
			break;
		}
	}
	if(freeslot == -1) return -1;
	
	new nextstep		= GrowInfo[breed][NextStep][step],
		fruitsin		= GrowInfo[breed][FruitIntervall],
		fruits			= 0,
		Float:health	= GrowInfo[breed][MaxHP][step],
		Float:water		= GrowInfo[breed][MaxWater][step];
		
	format(string,sizeof(string),	"INSERT INTO pnwl_vegetation (owner,breed,step,pos_x,pos_y,pos_z,nextstep,fruitsin,fruits,health,water,timecache) \
									VALUES ('%d', '%s', '%d', '%f', '%f', '%f', '%d', '%d', '%d','%f','%f','0')",owner,breed,step,pos_x,pos_y,pos_z,nextstep,fruitsin,fruits,health,water);
	new DBResult:res = = db_query(SQL_DB,string);
	new p_id = mysql_insert_id();
	db_free_result(res);
	
	PlantInfo[freeslot][pID]			= p_id;
	PlantInfo[freeslot][pOwner]			= owner;
	PlantInfo[freeslot][pBreed]			= breed;
	PlantInfo[freeslot][pStep]			= step;
	PlantInfo[freeslot][pNextStep]		= nextstep;
	PlantInfo[freeslot][pFruitsIn]		= fruitsin;
	PlantInfo[freeslot][pFruits]		= fruits;
	PlantInfo[freeslot][pPos][0]		= pos_x;
	PlantInfo[freeslot][pPos][1]		= pos_y;
	PlantInfo[freeslot][pPos][2]		= pos_z;
	PlantInfo[freeslot][pCreated][1]	= false;
	PlantInfo[freeslot][pCreated][0]	= true;
	PlantInfo[freeslot][pHP]			= health
	PlantInfo[freeslot][pWater]			= water;
	PlantInfo[freeslot][pTimeCache]		= 0;
	
	if(freeslot > VegData[pHighestID]) VegData[pHighestID]  = freeslot;
	if(freeslot < VegData[pLowestID])  VegData[pLowestID]	= freeslot;
	
	veg::UpdatePlant(freeslot);	
	return freeslot;
}

stock veg::DB_SavePlant(plant)
{
	printf("veg::DB_SavePlant(%d)",plant);
	if(plant < 0 || plant >= MAX_PLANTS) return -1;
	if(!PlantInfo[plant][pCreated][0]) return 0;
	
	format(string,sizeof(string),"UPDATE pnwl_vegetation SET owner='%d',breed='%d',step='%d',nextstep='%d',fruitsin='%d',fruits='%d',timecache='%d',pos_x='%0.2f',pos_y='%0.2f',pos_z='%0.2f' WHERE id='%d'",\
	PlantInfo[plant][pOwner],\
	PlantInfo[plant][pBreed],\
	PlantInfo[plant][pStep],\
	PlantInfo[plant][pNextStep],\
	PlantInfo[plant][pFruitsIn],\
	PlantInfo[plant][pFruits],\
	PlantInfo[plant][pTimeCache],
	PlantInfo[plant][pPos][0],\
	PlantInfo[plant][pPos][1],\
	PlantInfo[plant][pPos][2],
	PlantInfo[plant][pID]);
	db_query_once(SQL_DB,string);
	print(string);
	return 1;
}

stock veg::DB_OnVegetationSync()
{
	printf("veg::DB_OnVegetationSync()");
	new total_plants = 0;
	for(new plant; plant<MAX_PLANTS; plant++)
	{
		if(!PlantInfo[plant][pCreated][0]) continue;
		total_plants += veg::DB_SavePlant(plant)==1?1:0;
	}
	return total_plants;
}

stock veg::PlantSync()
{
	new total_plants = 0;
	for(new plant; plant<MAX_PLANTS; plant++)
	{
		if(!PlantInfo[plant][pCreated][0]) continue;
		total_plants += veg::UpdatePlant(plant)==1?1:0;
	}
	return total_plants;
}

stock veg::DeletePlant(plant)
{
	printf("veg::DeletePlant(%d)",plant);
	if(plant < 0 || plant >= MAX_PLANTS) return -1;
	if(!PlantInfo[plant][pCreated][0]) return 0;
	
	if(PlantInfo[plant][pCreated][1])
	{
		DestroyObject(PlantInfo[plant][pObject]);
		Update3DTextLabelText(PlantInfo[plant][pLabel],GRUEN,string);
	}

	format(string,sizeof(string),"DELETE FROM pnwl_vegetation WHERE id='%d'",PlantInfo[plant][pID]);
	db_query_once(SQL_DB,string);

	PlantInfo[plant][pCreated][0] 	= false;
	PlantInfo[plant][pCreated][1] 	= false;
	PlantInfo[plant][pID]			= 0;
	PlantInfo[plant][pBreed]		= 0;
	PlantInfo[plant][pOwner]		= 0;
	PlantInfo[plant][pStep]			= 0;
	PlantInfo[plant][pNextStep]		= 0;
	PlantInfo[plant][pFruitsIn]		= 0;
	PlantInfo[plant][pFruits]		= 0;
	
	if(plant == VegData[pHighestID])
	{
		for(new new_id=VegData[pHighestID]; new_id >= 0; new_id--)
		{
			VegData[pHighestID] = new_id;
			if(PlantInfo[new_id][pCreated][0]) break;
		}
	}	
	if(plant == VegData[pLowestID])
	{
		VegData[pLowestID] = 0;
		for(new new_id=0; new_id < MAX_PLANTS; new_id++)
		{
			if(PlantInfo[new_id][pCreated][0])
			{
				VegData[pLowestID] = new_id;
				break;
			}
		}
	}	
	return 1;
}

stock veg::GetNearestPlant(playerid,Float:range=AVERAGE_TAKE_DEST)
{
	new Float:lowest_range 	= 10000.0,
		lowest_id			= -1;	
	for(new i=VegData[pLowestID]; i<=VegData[pHighestID]; i++)
	{
	    if(PlantInfo[i][pCreated][0] == false) continue;
	    new Float:dist = GetPlayerDistanceFromPoint(playerid,PlantInfo[i][pPos][0],PlantInfo[i][pPos][1],PlantInfo[i][pPos][2]);
		if(dist > range || dist > lowest_range) continue;
		lowest_range	= dist;
		lowest_id		= i;
	}	
	return lowest_id;
}

veg_ShowPlayerDialog(playerid,dialogid,dialogstyle,header[],info[],but1[],but2[])
{
	SetPVarInt(playerid,"veg_dialog",1);
    ShowPlayerDialog(playerid,dialogid,dialogstyle,header,info,but1,but2);
    return 1;
}

enum (+=1)
{
	veg_DIALOG_PLANT_MAINRE = 1,
	veg_DIALOG_PLANT_MAIN,
	veg_DIALOG_PLANT_INFO,
	veg_DIALOG_PLANT_GIESSEN_SELECT,
	veg_DIALOG_PLANT_FRUIT_SELECT,
}

veg_OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
	if(GetPVarInt(playerid,"veg_dialog") != 1) return 0;
	SetPVarInt(playerid,"veg_dialog",0);
	new plant = GetPVarInt(playerid,"plant_interact");
	if(plant < 0 || plant >= MAX_PLANTS) return 1;
	if(!PlantInfo[plant][pCreated][0]) 
	{
		SendClientMessage(playerid,-1,#FORMAT_CHAT_ERROR "Die Pflanze wurde anscheinend zerstört");
		return 1;
	}
	new p_id 		= PlantInfo[plant][pBreed],
		plant_step	= PlantInfo[plant][pStep];
	
	switch(dialogid)
	{
		case 0: return 1;
		case veg_DIALOG_PLANT_MAINRE:
		{
			ncom_pflanze(playerid,0);
			return 1;
		}
		case veg_DIALOG_PLANT_MAIN:
		{
			if(!response) return 1;
			switch(listitem)
			{
				case 0://Informationen
				{
					new step_day,step_hour,step_min;
					ConvertTime(PlantInfo[plant][pNextStep],_,step_day,step_hour,step_min);
					new fruit_day,fruit_hour,fruit_min;
					ConvertTime(PlantInfo[plant][pFruitsIn],_,fruit_day,fruit_hour,fruit_min);
						
					format(string,sizeof(string),"{F1F7DC}\
					Art:            %s\n\
					Stufe:          %d\n\
					Nächste Stufe:  %d Tage, %d Stunden und %d Minuten\n\
					Früchte:        %d\n\
					Blütezeit in:   %d Tage, %d Stunden und %d Minuten"\
					,GrowInfo[p_id][PlantName],PlantInfo[plant][pStep],step_day,step_hour,step_min,PlantInfo[plant][pFruits],fruit_day,fruit_hour,fruit_min);
					
					format(string,sizeof(string),"%s\n\
					Wasser:         %d/%d Litern\n\
					Energie:        %0.2f/%0.2f\n\
					Besitzer:       \"%s\"",string,floatround(PlantInfo[plant][pWater]),floatround(GrowInfo[p_id][MaxWater][plant_step]),PlantInfo[plant][pHP],GrowInfo[p_id][MaxHP][plant_step],"Natur");
					
					veg_ShowPlayerDialog(playerid,veg_DIALOG_PLANT_INFO,DIALOG_STYLE_MSGBOX,"{F1F7DC}Pflanze",string,"Zurück","Beenden");
					return 1;
				}
				case 1://Gießen
				{
					if(PlayerResource[playerid][Wasser] >= 1)
					{
						veg_ShowPlayerDialog(playerid,veg_DIALOG_PLANT_MAINRE,DIALOG_STYLE_MSGBOX,"{F1F7DC}Pflanze gießen","{F1F7DC}Du hast kein Wasser","Zurück","");
						return 1;
					}
					else if(PlantInfo[plant][pWater] >= GrowInfo[p_id][MaxWater][plant_step])
					{//Hat schon genug Wasser
						veg_ShowPlayerDialog(playerid,veg_DIALOG_PLANT_MAINRE,DIALOG_STYLE_MSGBOX,"{F1F7DC}Pflanze gießen","{F1F7DC}Die Pflanze hat schon genug Wasser","Zurück","");
						return 1;
					}
					else
					{//Kann begossen werden
						format(string,sizeof(string),"{F1F7DC}Die Pflanze hat %0.2f/%0.2f Litern Wasser\nWie viel möchtest du gießen (Du hast %0.2f Liter Wasser)",PlantInfo[plant][pWater],GrowInfo[p_id][MaxWater][plant_step],PlayerResource[playerid][Wasser]);
						veg_ShowPlayerDialog(playerid,veg_DIALOG_PLANT_GIESSEN_SELECT,DIALOG_STYLE_INPUT,"{F1F7DC}Pflanze gießen",string,"Weiter","Zurück");
					}
					return 1;
				}
				case 2://Früchte ernten
				{
					if(1 >= GrowInfo[PlantInfo[plant][pBreed]][NeedEquipLevel])
					{
						if(PlantInfo[plant][pFruits] >= 1)
						{//Hat Früchte
							format(string,sizeof(string),"{F1F7DC}Die Pflanze hat %d/%d Früchte. Wie viele möchtest\ndu ernten?",PlantInfo[plant][pFruits],GrowInfo[p_id][MaxFruits]);
							veg_ShowPlayerDialog(playerid,veg_DIALOG_PLANT_FRUIT_SELECT,DIALOG_STYLE_INPUT,"{F1F7DC}Früchte ernten",string,"Weiter","Zurück");
						}
						else
						{//Hat garkeine Früchte
							veg_ShowPlayerDialog(playerid,veg_DIALOG_PLANT_MAINRE,DIALOG_STYLE_MSGBOX,"{F1F7DC}Früchte ernten","{F1F7DC}Die Pflanze trägt keine Früchte","Zurück","");
						}
					}
					else
					{
						format(string,sizeof(string),"{F1F7DC}Du hast nicht das nötige Equipment um die Früchte dieser\nPflanze zu ernten.\nDein Messer: %d\nBenötigte Stufe: %d",1,GrowInfo[PlantInfo[plant][pBreed]][NeedEquipLevel]);
						veg_ShowPlayerDialog(playerid,veg_DIALOG_PLANT_MAINRE,DIALOG_STYLE_MSGBOX,"{F1F7DC}Früchte ernten",string,"Zurück","");
					}
					return 1;
				}
			}
		}
		case veg_DIALOG_PLANT_INFO:
		{
			if(!response) return 0;
			ncom_pflanze(playerid,0);
			return 1;
		}
		case veg_DIALOG_PLANT_GIESSEN_SELECT:
		{
			if(response)
			{
				new Float:give_water = floatstr(inputtext);
				if(give_water > PlayerResource[playerid][Wasser])
				{//Spieler hat so viel Wasser nicht
					DeletePVar(playerid,"giess_status");
					veg_ShowPlayerDialog(playerid,veg_DIALOG_PLANT_MAINRE,DIALOG_STYLE_INPUT,"{F1F7DC}Pflanze gießen","{F1F7DC}Du hast so viel Wasser nicht","Zurück","");
				}
				else
				{//Spieler hat genug Wasser ;) lol xD
					new Float:need_water = (GrowInfo[p_id][MaxWater][plant_step]-PlantInfo[plant][pWater]);
					if(need_water <= 0.0)
					{//Pflanze hat genug wasser
						DeletePVar(playerid,"giess_status");
						veg_ShowPlayerDialog(playerid,veg_DIALOG_PLANT_MAINRE,DIALOG_STYLE_INPUT,"{F1F7DC}Pflanze gießen","{F1F7DC}Die Pflanze hat schon genug Wasser","Zurück","");
						return 1;
					}
					//Pflanze braucht wasser, spieler hat welches -> ye lol geht :D
					DeletePVar(playerid,"giess_status");
					if(give_water > need_water) give_water = need_water;//Ausgleich falls der spieler zu viel geben will :O
					PlantInfo[plant][pWater] 			+= give_water;
					PlayerResource[playerid][Wasser]	-= give_water;
					format(string,sizeof(string),"{F1F7DC}Du hast der Pflanze %0.2f Liter Wasser gegeben",give_water);
					veg_ShowPlayerDialog(playerid,veg_DIALOG_PLANT_MAINRE,DIALOG_STYLE_MSGBOX,"{F1F7DC}Pflanze gegossen",string,"Zurück","");
					return 1;
				}
				return 1;
			}
			ncom_pflanze(playerid,0);
			return 1;
		}
		case veg_DIALOG_PLANT_FRUIT_SELECT:
		{
			new anzahl = strval(inputtext);
			if(!response || anzahl <= 0)
			{
				ncom_pflanze(playerid,0);
				return 1;
			}			
			if(PlantInfo[plant][pFruits] >= 1)
			{//Hat Früchte
				CallLocalFunction("veg_OnPlantFarm","ddd",playerid,plant,anzahl);
			}
			else
			{//Hat garkeine Früchte
				veg_ShowPlayerDialog(playerid,veg_DIALOG_PLANT_MAINRE,DIALOG_STYLE_MSGBOX,"{F1F7DC}Früchte ernten","{F1F7DC}Die Pflanze trägt keine Früchte","Zurück","");
			}
			return 1;
		}
	}
	return 0;
}