/*
	PostNuke Wasteland Core
	Author: NeoPhoenix
	Date: 25.07.2011
*/
#if defined included_pnwl_core
	#endinput
#else
	#define included_pnwl_core
#endif
#define CORE:: CORE_
#define PLAYER:: PLAYER_

///////////////////////////////////////// Includes /////////////////////////////
#include <a_samp>//Unabhängige dateien
#include "misc/samp_fix"
#include <mapandreas>
#include "n_lib/lib_sql"
#include "misc/sa_areas"
#include "n_lib/pnwl_color"
#include "INI"
//#include "n_lib/lib_lang"
////////////////////////////////////////////////////////////////////////////////
/*
	native DB:CORE::OnSQLiteInit(database[]);
	native CORE::OnMySQLInit(source[])
	native CORE::OnCoreInit(source[])
	native CreatePlayerSpecialObject(playerid,modelid,Float:X,Float:Y,Float:Z,Float:rX,Float:rY,Float:rZ,Float:drawdistance=100.0,OBJECT_TYPE=OBJECT_TYPE_DEFAULT)
	native DeletePlayerSpecialObject(playerid,object=OBJECTS_ALL,OBJECT_TYPE=OBJECT_TYPE_ALL)	
	native CreatePlayerSpecial3DText(playerid,color,text[],Float:X,Float:Y,Float:Z,Float:drawdistance=20.0,TEXT_TYPE=TEXT3D_TYPE_DEFAULT)
	native DeletePlayerSpecial3DText(playerid,label=TEXT3D_ALL,TEXT3D_TYPE=TEXT3D_TYPE_ALL)
	native IsValidPlayerSpecial3DText(playerid,label)
	native aPlayAudioStreamForPlayer(playerid,url[],Float:posX=0.0,Float:posY=0.0,Float:posZ=0.0,Float:d=0.0)
	native Float:frandom(Float:max,Float:min=0.0,dp=2)
	native IsPlayerLookingAt(playerid,Float:x,Float:y,Float:z,Float:radius);
	native GetWeaponSlot(weaponid);
	native ResetVars(playerid);
	native Wochentag(day=0, month=0, year=0);	
	native GetUserData(userID,Data[]);
	native _WBB_CheckPassword(userID,Password[]);
	native GetHash(Value[],Method[]);
	native GetSaltedHash(String[],Salt[]);
	native GetDoubleSaltedHash(String[],Salt[]);
	native GetWBBConfig(Data[]);
*/

/////////////TUTORIAL//////////
new CSpawn[MAX_PLAYERS][10],
	Currentstep[MAX_PLAYERS],
	cam_Ziel[MAX_PLAYERS],
	cam_Ort[MAX_PLAYERS];
#include "n_lib/pnwl_camscript"
///// Textdraws ///////////////////////////////
new Text:Filmstreifen[2],
	PlayerText:FilmInfoUnten[MAX_PLAYERS],
	Text:Infobox_0,
	Text:Infobox_1,
	PlayerText:Infobox_Header[MAX_PLAYERS],
	PlayerText:Infobox_Body[MAX_PLAYERS],
	Text:ScreenHide,
	Text:LoadDraw,
	Text:NoDmZoneDraw,
	Text:HealingDraw,
	PlayerText:PlayerErfolgTextDraw[MAX_PLAYERS][2];
///STATUS DRAWS
new Text:PBarRAussen[5],
	Text:PBarRInnen[5],
	PlayerText:PBarStatus[MAX_PLAYERS][5],
	PlayerText:PBarText[MAX_PLAYERS][5];
///////////////////////////////////////////////
new __PICKUP[MAX_DEVELOPER_PICKUPS+1/*0 is unused*/],
	PublicPickup[10] = {-1,...};
///////////////////////////////
enum __stats__
{
	QUESTS_FINISHED,
	USER_REGISTERED,
	USER_CONNECTIONS,
	USER_DEATHS,
	USER_KILLS,
}
new __STATS[__stats__];

enum __server__
{
	CONNECTED_PLAYERS,
	HIGHEST_PLAYER_ID,
	GLOBAL_TIME[2],
	GLOBAL_WEATHER,
	WOCHENTAG,
	TIMER[10],
	TUT_PICKUP,
	PICKUPS,
	VEHICLES,
	MAX_VEHICLE_ID,
	START_COUNT,
	START_UNIXTS,
	CURRENT_HOSTNAME,
	GLOBAL_CHAT,
	PAYDAY_ESSEN,
	CJ_LAST[3],
	Float:PREMIUM_COST,
	WCF_INSTALL,
	
	bool:TRUE,
	bool:FALSE,
	Float:OPT_EXPRATE,
	Float:OPT_DROPRATE,
}
new __SERVER[__server__];

CORE::OnCoreInit()
{
	format(query,sizeof(query),"SELECT * FROM pnwl_server_var");
	mysql_query(query);
	mysql_store_result();
	while(mysql_retrieve_row())
	{
		mysql_fetch_field_row(query,	"k3y");
		mysql_fetch_field_row(string,	"value");
		if(!strcmp(query,"wcf_install"))
		{
			__SERVER[WCF_INSTALL] = strval(string);
			printf("CONFIG++ (%d) WCF Installation",__SERVER[WCF_INSTALL]);
			continue;
		}
		if(!strcmp(query,"game_time"))
		{
			__SERVER[GLOBAL_TIME][0] 	= strval(string);
			printf("CONFIG++ (%d) GameTime",__SERVER[GLOBAL_TIME][0]);
			continue;
		}
		if(!strcmp(query,"global_chat"))
		{	
			printf("CONFIG++ (%d) GlobalChat",__SERVER[GLOBAL_CHAT]);
			continue;
		}
		if(!strcmp(query,"weather_id"))
		{
			__SERVER[GLOBAL_WEATHER] 	= strval(string);
			printf("CONFIG++ (%d) GlobalWeather",__SERVER[GLOBAL_WEATHER]);
			continue;
		}
		if(!strcmp(query,"opt_droprate"))
		{
			__SERVER[OPT_DROPRATE] 		= floatstr(string);
			printf("CONFIG++ (%0.2f) OPT_Droprate",__SERVER[OPT_DROPRATE]);
			continue;
		}
		if(!strcmp(query,"opt_exprate"))
		{
			__SERVER[OPT_EXPRATE] 		= floatstr(string);
			printf("CONFIG++ (%0.2f) OPT_Exprate",__SERVER[OPT_EXPRATE]);
			continue;
		}
	}
	mysql_free_result();
	
	ShowPlayerMarkers(0);
	ShowNameTags(0);
	EnableStuntBonusForAll(0);		
	UsePlayerPedAnims();
	DisableInteriorEnterExits();
	ManualVehicleEngineAndLights();
	
	SendRconCommand("mapname Robada Wasteland");
	SendRconCommand("weburl http://www.pnwl.de");
	SendRconCommand("gamemodetext Endzeit-RPG");

	gettime(__SERVER[GLOBAL_TIME][0],__SERVER[GLOBAL_TIME][1]);
	__SERVER[HIGHEST_PLAYER_ID] 	= 2;	
	__SERVER[TRUE] 				= true;
	__SERVER[FALSE] 			= false;
	__SERVER[START_COUNT] 		= GetTickCount();
	__SERVER[START_UNIXTS] 		= gettime(_,_,_);
	__SERVER[WOCHENTAG]			= Wochentag();

	SetWeather(__SERVER[GLOBAL_WEATHER]);
	SetWorldTime(__SERVER[GLOBAL_TIME][0]);	
	printf("::CORE => Server starting at point %d",__SERVER[START_UNIXTS]);

	//BUGFIXING
    floatrandom(100.0);
    floatrandom(100.0);
	
	#include "misc/objects"
	#include "misc/pickups"
	return 1;
}

DB:CORE::OnSQLiteInit(database[])
{
	if(fexist(database))
	{
		SQL_DB = db_open(database);
		return SQL_DB;
	}
	return DB:0;
}

CORE::OnMySQLInit(source[])//eg "/core/connection.ini"
{
	if(!INI::Exists(source))
	{
		printf("CONFIG++ %s does not exist",source);
		SendRconCommand("exit");
		return 0;
	}
	INI::Global(INI::FILE,source);
	INI::Global(INI::SECTION,"Connection");	
	Connect_To_Database(INI::GetValue(_,"ip"),INI::GetValue(_,"usr"),INI::GetValue(_,"db"),INI::GetValue(_,"pw"));
	INI::Reset(INI::FILE);
	INI::Reset(INI::SECTION);
	return 1;
}

CORE::ReloadBans(bool:delete_tmp=true)
{
	if(delete_tmp) SendRconCommand("reloadbans");
	new timestamp = gettime(_,_,_);
	if(timestamp)
	{
		new ban_count = 0;
		format(query,sizeof(query),"SELECT * FROM pnwl_banned WHERE (timestamp+time)>%d",timestamp);
		mysql_query(query);
		mysql_store_result();
		while(mysql_retrieve_row())
		{
			mysql_fetch_field_row(query,"ip");
			format(query,sizeof(query),"banip %s",query);
			SendRconCommand(query);
			ban_count++;
		}
		printf("::CORE %d IP adresses are banned",ban_count);
	}
	return 0;
}

/*stock CORE::ResetUsers()
{
	print("________ CORE::ResetUsers");
	new truncate_tables[][] = {
		"pnwl_user",
		"pnwl_user_achievements",
		"pnwl_user_equipment",
		"pnwl_user_event",
		"pnwl_user_item",
		"pnwl_user_jobs",
		"pnwl_user_logins",
		"pnwl_user_logouts",
		"pnwl_user_mon_online",
		"pnwl_user_npc",
		"pnwl_user_option",
		"pnwl_user_permissions",
		"pnwl_user_pos",
		"pnwl_user_premium",
		"pnwl_user_quests",
		"pnwl_user_resource",
		"pnwl_user_skill",
		"pnwl_user_status",
		"pnwl_user_time_online",
		"pnwl_user_weapons",
		"pnwl_user_weapon_skill",
		"pnwl_user_weapon_stats",
		"pnwl_user_wt_online",
		"pnwl_server_wt_online",
		"pnwl_server_time_online",
		"pnwl_server_mon_online",
		"pnwl_user_item_storage"
	};
	for(new i; i<sizeof(truncate_tables); i++)
	{
		format(string,sizeof(string),"TRUNCATE %s",truncate_tables[i]);
		mysql_query_once(string);
	}
	return 1;
}*/

CORE::LoadStats()
{
	format(query,sizeof(query),"SELECT * FROM pnwl_server_stats");
	mysql_query(query);
	mysql_store_result();
	while(mysql_retrieve_row())
	{
		mysql_fetch_field_row(query,	"k3y");
		mysql_fetch_field_row(string,	"value");
		if(!strcmp(query,"quests_finished"))
		{
			__STATS[QUESTS_FINISHED] = strval(string);
			continue;
		}
		if(!strcmp(query,"user_registered"))
		{
			__STATS[USER_REGISTERED] = strval(string);
			continue;
		}
		if(!strcmp(query,"user_connections"))
		{
			__STATS[USER_CONNECTIONS] = strval(string);
			continue;
		}
		if(!strcmp(query,"user_deaths"))
		{
			__STATS[USER_DEATHS] = strval(string);
			continue;
		}
		if(!strcmp(query,"user_kills"))
		{
			__STATS[USER_KILLS] = strval(string);
			continue;
		}
	}
	mysql_free_result();
	return 1;
}

new Hostnames[][] = {
{"PNWL.de"},
{"PostnukeWasteland.de"},
{"PNWL - Endzeit RPG"},
{"PNWL - Alpha"},
{"PNWL - Version 0.1a"}
};
enum option_list
{
	Skin,
	Crashed,
	HouseSelect,
	SelectedSpawn,
	OptionC,
	dialog[30],
	GChat[4],
	pFunkgeraet[5],
	HouseCache[3],
	FightingStyle,
	Vote,
}
new PlayerOption[MAX_PLAYERS][option_list];

enum (<<=1)
{//Popups
	optCRoom = 1,
	optCTod,
	optCSound,
	optCMail,
	optCAlogin,
}

GetDialogOption(playerid,listitem)
{
	if(listitem >= 0 && listitem < 30) return PlayerOption[playerid][dialog][listitem];
	return 0;
}

stock OnSportstudioExit(playerid=-1,trainid=-1273)
{
	new train = playerid==-1?trainid:(trainid!=-1273?trainid:GetPVarInt(playerid,"pev_train"));
	switch(train)
	{
		case 1:
		{
			SportStudioTexts[0] = Create3DTextLabel("Fahrrad\nF oder ENTER",GRUEN,-1477.6403,2610.9968,40.6781,15.0,1234,0);
			SportstudioUse &= ~(1<<1);
		}
		case 2:
		{
			SportStudioTexts[1] = Create3DTextLabel("Laufband\nF oder ENTER",GRUEN,-1467.1683,2602.4785,40.6784,15.0,1234,0);
			SportstudioUse &= ~(1<<2);
		}
		case 3:
		{
			SportStudioTexts[2] = Create3DTextLabel("Hanteln\nF oder ENTER",GRUEN,-1472.2189,2602.1113,40.0524,15.0,1234,0);
			SportstudioUse &= ~(1<<3);
		}
	}
	if(playerid != -1) SetPVarInt(playerid,"pev_train",0);
	return 1;
}
	
stock IsPlayerLookingAt(playerid,Float:x,Float:y,Float:z,Float:radius)
{
     new Float:Distanz,Float:CamX,Float:CamY,Float:CamZ,Float:FrontX,Float:FrontY,Float:FrontZ;
     GetPlayerCameraPos(playerid, CamX, CamY, CamZ);
     GetPlayerCameraFrontVector(playerid, FrontX, FrontY, FrontZ);
     Distanz=floatsqroot((CamX - x) * (CamX - x) + (CamY - y) * (CamY - y) + (CamZ - z) * (CamZ - z));
     new Float:tmpX, Float:tmpY, Float:tmpZ;
     tmpX = FrontX * Distanz+ CamX;
     tmpY = FrontY * Distanz+ CamY;
     tmpZ = FrontZ * Distanz+ CamZ;
     new Float:res=floatsqroot((tmpX - x) * (tmpX - x) + (tmpY - y) * (tmpY - y) + (tmpZ - z) * (tmpZ - z));
     return (radius >= res);
}
Float:DistanceCameraTargetToLocation(Float:CamX, Float:CamY, Float:CamZ, Float:ObjX, Float:ObjY, Float:ObjZ, Float:FrX, Float:FrY, Float:FrZ) 
{

	new Float:TGTDistance;
	TGTDistance = floatsqroot((CamX - ObjX) * (CamX - ObjX) + (CamY - ObjY) * (CamY - ObjY) + (CamZ - ObjZ) * (CamZ - ObjZ));
	new Float:tmpX, Float:tmpY, Float:tmpZ;
	tmpX = FrX * TGTDistance + CamX;
	tmpY = FrY * TGTDistance + CamY;
	tmpZ = FrZ * TGTDistance + CamZ;
	return floatsqroot((tmpX - ObjX) * (tmpX - ObjX) + (tmpY - ObjY) * (tmpY - ObjY) + (tmpZ - ObjZ) * (tmpZ - ObjZ));
}

stock Float:GetPointAngleToPoint(Float:x2, Float:y2, Float:X, Float:Y) 
{
	new Float:DX, Float:DY,Float:angle;
	DX = floatabs(floatsub(x2,X));
	DY = floatabs(floatsub(y2,Y));
	if (DY == 0.0 || DX == 0.0) 
	{
		if(DY == 0 && DX > 0)		angle = 0.0;
		else if(DY == 0 && DX < 0)	angle = 180.0;
		else if(DY > 0 && DX == 0)	angle = 90.0;
		else if(DY < 0 && DX == 0)	angle = 270.0;
		else if(DY == 0 && DX == 0)	angle = 0.0;
	}
	else 
	{
		angle = atan(DX/DY);
		if(X > x2 && Y <= y2)		angle += 90.0;
		else if(X <= x2 && Y < y2)	angle = floatsub(90.0,angle);
		else if(X < x2 && Y >= y2)	angle -= 90.0;
		else if(X >= x2 && Y > y2)	angle = floatsub(270.0,angle);
	}
	return floatadd(angle,90.0);
}
stock GetXYInFrontOfPoint(&Float:x, &Float:y, Float:angle, Float:distance) 
{
	x += (distance * floatsin(-angle, degrees));
	y += (distance * floatcos(-angle, degrees));
	return ;
}
stock IsPlayerAimingAt(playerid, Float:x, Float:y, Float:z, Float:radius) 
{
	new Float:camera_x,Float:camera_y,Float:camera_z,Float:vector_x,Float:vector_y,Float:vector_z;
	GetPlayerCameraPos(playerid, camera_x, camera_y, camera_z);
	GetPlayerCameraFrontVector(playerid, vector_x, vector_y, vector_z);
	new Float:vertical, Float:horizontal;
	switch(GetPlayerWeapon(playerid)) 
	{
		case 34,35,36: 
		{
			if (DistanceCameraTargetToLocation(camera_x, camera_y, camera_z, x, y, z, vector_x, vector_y, vector_z) < radius) return true;
			return false;
		}
		case 30,31: {vertical = 4.0; horizontal = -1.6;}
		case 33: 	{vertical = 2.7; horizontal = -1.0;}
		default: 	{vertical = 6.0; horizontal = -2.2;}
	}
	new Float:angle = GetPointAngleToPoint(0, 0, floatsqroot(vector_x*vector_x+vector_y*vector_y), vector_z) - 270.0;
	new Float:resize_x, Float:resize_y, Float:resize_z = floatsin(angle+vertical, degrees);
	GetXYInFrontOfPoint(resize_x, resize_y, GetPointAngleToPoint(0, 0, vector_x, vector_y)+horizontal, floatcos(angle+vertical, degrees));
	if (DistanceCameraTargetToLocation(camera_x, camera_y, camera_z, x, y, z, resize_x, resize_y, resize_z) < radius) return true;
	return false;
}

forward bool:is_numeric(str[]);
stock bool:is_numeric(str[])
{
	for(new c; c<strlen(str); c++)
	{
		if(str[c] >= '0' && str[c] <= '9') continue;
		return false;
	}
	return true;
}

stock GetWeaponSlot(weaponid)
{
	switch(weaponid)
	{
		case 0,1:		return 0;
		case 2..9:		return 1;
		case 10..15:	return 10;
		case 16..18, 39:return 8;
		case 22..24:	return 2;
		case 25..27:	return 3;
		case 28,29,32:	return 4;
		case 30,31: 	return 5;
		case 33,34:		return 6;
		case 35..38:	return 7;
		case 40:		return 12;
		case 41..43:	return 9;
		case 44..46:	return 11;
	}
	return 0;
}

enum p_equip
{
	Rucksack,
	bought_Skins[2],
	unlocked_Skins,
}
new PlayerEquipment[MAX_PLAYERS][p_equip];

enum enum_pcache
{
	Float:item_Gewicht,
	current_weapon_id,
	equip_fist_item,
	holding_item,
}
new PlayerCache[MAX_PLAYERS][enum_pcache];

enum enum_pinfo
{
	pID,
	Admin[2],//Adminberechtigungen
	GangP[2],//Gangberechtigungen
	Fraktion,
	Float:TotPos[3],

	Float:RevivePos[3],
	ReviveVW,
	ReviveINT,
	ReviveHouse,
	
	Geschlecht,
	Vorname[MAX_VORNAME_LEN],
	Nachname[MAX_NACHNAME_LEN],
	pName[MAX_PLAYER_NAME],
	Connection,
	ConnectedTimes,
	IP[16],
	Spielzeit,

	PLAYER_ID,
	IsInCRoom,
	CRoomAction,
	CRoomSubAction,
	pGang,
	pGangRang,
	Job,
	JobSkill,
	Phone,

	Float:pMissionCP[4],
	bool:pOnMission,
	pMissionFlare,
	pScreenHide,
	pPickup,
	pTotPickup,
	Text3D:TotTag,
	Text3D:Nametag
}
new PlayerInfo[MAX_PLAYERS][enum_pinfo];
#define GetName(%0) PlayerInfo[%0][pName]
enum p_resource
{
	Float:Batterien,
	Float:Wasser,
	Float:Benzin
}
new PlayerResource[MAX_PLAYERS][p_resource];

enum event_enum
{
	bool:LOGGED_IN,
	DevComment[2],
	TutorialStep[2],
	IstTot,
	CountTode,
	InteractHouse,
	bool:WeaponsGiven,
	MedicalEvent[3],
	Training,
	PayDayTime,
	Float:tmpPos[3],
	Float:distGefahren,
	Float:distGelaufen,
	FrozenTime,
	Float:FrozenPos[3],
	Float:MaxWeight,
	bool:CanRun,
	Float:Ausdauer,
}
new PlayerEvent[MAX_PLAYERS][event_enum];

enum prem_enum
{
	PointsBought,
	PointsLeft,
	PointsSpent,
	PremiumLevel,
	ExpTime,
	SkillBoostTime,
	DoubleSkillTime,
	GasmaskTime,
	HelmetTime,
	ArmourTime,
	NightvisionTime,
}
new PlayerPremium[MAX_PLAYERS][prem_enum];

stock aPlayAudioStreamForPlayer(playerid,url[],Float:posX=0.0,Float:posY=0.0,Float:posZ=0.0,Float:d=0.0)
{
	if(PlayerOption[playerid][OptionC]&optCSound != 1) PlayAudioStreamForPlayer(playerid,url,posX,posY,posZ,d);
	return 1;
}

enum ssenum
{
	ssID,
	ssStatus,
}
#define MAX_SS_OBJECTS (10)
new __OBJECTS[MAX_SS_OBJECTS][ssenum];

CORE::LoadObjects()
{
	__OBJECTS[0][ssID]		= CreateObject(2927,-2922.39746094,180.05273438,252.62432861,0.00000000,0.00000000,270.00000000); //toraum 1 zu
	__OBJECTS[0][ssStatus]	= false;//Geschlossen
	//CreateObject(2927,-3222.41308594,177.16358948,252.61529541,0.00000000,0.00000000,270.00000000); //toraum 1 offen
	__OBJECTS[1][ssID] 		= CreateObject(2927,-2893.32763672,243.50512695,251.84133911,0.00000000,0.00000000,269.24743652); //toraum 2 zu
	__OBJECTS[1][ssStatus]	= false;//Geschlossen
	//CreateObject(2927,-3193.36865234,241.26370239,251.84133911,0.00000000,0.00000000,269.24743652); //toraum 2 offen
	
	//Area 51
	CreateObject(19313, 134.89, 1941.34, 21.63,   0.00, 0.00, 0.00);//TORauf
	CreateObject(19313, 120.33, 1941.54, 21.24,   0.00, 0.00, 0.00);//TORzu
	CreateObject(19313, 96.62, 1920.23, 18.19,   0.00, 0.00, 89.83);//Fußgängereingang schließen
	return 1;
}

#define MAX_PLAYER_OBJECTS 50
#define GetIP(%0)   PlayerInfo[%0][IP]
#define TEXT3D_TYPE_NONE	(0)
#define TEXT3D_TYPE_DEFAULT	(1)
#define TEXT3D_TYPE_ALL		(-1)
#define TEXT3D_TYPE_HOUSE	(2)
#define TEXT3D_ALL			(-1)
#define MAX_PLAYER_3DTEXTS	(10)

enum t_3d {PlayerText3D:Label,Type}
new PlayerText3D[MAX_PLAYERS][MAX_PLAYER_3DTEXTS][t_3d];
DeletePlayerSpecial3DText(playerid,label=TEXT3D_ALL,TEXT3D_TYPE=TEXT3D_TYPE_ALL)
{
	if(label != TEXT3D_ALL)
	{
        if(IsValidPlayerSpecial3DText(playerid,label))
		{
			DeletePlayer3DTextLabel(playerid,PlayerText3D[playerid][label][Label]);
			PlayerText3D[playerid][label][Type] = TEXT3D_TYPE_NONE;
			return label;
		}
		return -1;
	}
	new t_deleted = 0;
    for(new t3d=0; t3d<MAX_PLAYER_3DTEXTS; t3d++)
	{
		if(IsValidPlayerSpecial3DText(playerid,t3d))
		{
		    if(TEXT3D_TYPE == TEXT3D_TYPE_ALL || PlayerText3D[playerid][t3d][Type] == TEXT3D_TYPE)
		    {
				if(IsValidPlayerSpecial3DText(playerid,t3d)) DeletePlayer3DTextLabel(playerid,PlayerText3D[playerid][t3d][Label]);
		        PlayerText3D[playerid][t3d][Type] = TEXT3D_TYPE_NONE;
				t_deleted++;
		    }
		}
	}
	return t_deleted;
}
IsValidPlayerSpecial3DText(playerid,label) return PlayerText3D[playerid][label][Type]==TEXT3D_TYPE_NONE?0:1; 
CreatePlayerSpecial3DText(playerid,color,text[],Float:X,Float:Y,Float:Z,Float:drawdistance=20.0,TEXT_TYPE=TEXT3D_TYPE_DEFAULT)
{
    for(new t3d=0; t3d<MAX_PLAYER_3DTEXTS; t3d++)
	{
		if(!IsValidPlayerSpecial3DText(playerid,t3d))
		{//Not created
		    PlayerText3D[playerid][t3d][Type] = TEXT_TYPE;
		    PlayerText3D[playerid][t3d][Label] = CreatePlayer3DTextLabel(playerid,text,color,X,Y,Z,drawdistance,INVALID_PLAYER_ID,INVALID_VEHICLE_ID,0);
			return t3d;
		}
	}
	return -1;
}

#define OBJECT_TYPE_DEFAULT 	(0)
#define OBJECT_TYPE_HOUSE   	(1)
#define OBJECT_TYPE_ALL	    	(2)
#define OBJECT_TYPE_IMPORTANT	(3)
#define OBJECTS_ALL	    		(-1)
enum p_obj {Object,Type}
new PlayerObject[MAX_PLAYERS][MAX_PLAYER_OBJECTS][p_obj];
GetPlayerSlotBySpecialObject(playerid,object)
{
	for(new o; o<MAX_PLAYER_OBJECTS; o++) if(PlayerObject[playerid][o][Object] == object && IsValidPlayerObject(playerid,PlayerObject[playerid][o][Object])) return o;
	return -1;
}

stock DeletePlayerSpecialObject(playerid,object=OBJECTS_ALL,OBJECT_TYPE=OBJECT_TYPE_ALL)
{
	if(object != -1)
	{
		if(IsValidPlayerObject(playerid,PlayerObject[playerid][object][Object]))
		{
			DestroyPlayerObject(playerid,PlayerObject[playerid][object][Object]);
			PlayerObject[playerid][object][Type] = OBJECT_TYPE_DEFAULT;
			return PlayerObject[playerid][object][Object];
		}
		else return -1;
	}
	new o_deleted = 0;
    for(new obj=0; obj<MAX_PLAYER_OBJECTS; obj++)
	{
		if(IsValidPlayerObject(playerid,PlayerObject[playerid][obj][Object]))
		{
		    if(OBJECT_TYPE == OBJECT_TYPE_ALL || PlayerObject[playerid][obj][Type] == OBJECT_TYPE)
		    {
		        DestroyPlayerObject(playerid,PlayerObject[playerid][obj][Object]);
		        PlayerObject[playerid][obj][Type] = OBJECT_TYPE_DEFAULT;
				o_deleted++;
		    }
		}
	}
	return o_deleted;
}

CreatePlayerSpecialObject(playerid,modelid,Float:X,Float:Y,Float:Z,Float:rX,Float:rY,Float:rZ,Float:drawdistance=100.0,OBJECT_TYPE=OBJECT_TYPE_DEFAULT)
{
    for(new obj=0; obj<MAX_PLAYER_OBJECTS; obj++)
	{
		if(!IsValidPlayerObject(playerid,PlayerObject[playerid][obj][Object]))
		{
		    PlayerObject[playerid][obj][Type] 	= OBJECT_TYPE;
		    PlayerObject[playerid][obj][Object] = CreatePlayerObject(playerid,modelid,X,Y,Z,rX,rY,rZ,drawdistance);
			return PlayerObject[playerid][obj][Object];
		}
	}
	return -1;
}

forward Float:frandom(Float:max,Float:min=0.0,dp=2);
Float:frandom(Float:max,Float:min=0.0,dp=2)
{
	if(max == 0.0 && min == 0.0) return 0.0;
    new Float:mul = floatpower(10.0, dp),
        imin = floatround(min * mul),
        imax = floatround(max * mul);
    return float(random(imax - imin) + imin) / mul;
}

HidePlayerDialog(playerid)
{
	SetPVarInt(playerid,"car_dialog"		,0);
	SetPVarInt(playerid,"player_haus_dialog",0);
	SetPVarInt(playerid,"cont_dialog"		,0);
	SetPVarInt(playerid,"am_dialog"      	,0);
    SetPVarInt(playerid,"q_dialog"			,0);
    SetPVarInt(playerid,"i_dialog"          ,0);
    SetPVarInt(playerid,"veg_dialog"        ,0);

	DeletePVar(playerid,"car_dialog");
	DeletePVar(playerid,"player_haus_dialog");
	DeletePVar(playerid,"cont_dialog");
	DeletePVar(playerid,"am_dialog");
	DeletePVar(playerid,"q_dialog");
	DeletePVar(playerid,"i_dialog");
	DeletePVar(playerid,"veg_dialog");
	ShowPlayerDialog(playerid,dialog_NULL,0,"","","","");
	ShowPlayerDialog(playerid,-1,0,"","","","");
	ShowPlayerDialog(playerid,-1,0,"","","","");
	ShowPlayerDialog(playerid,-1,0,"","","","");	
	return 1;
}

IsValidName(samp_name[])
{
	if(strlen(samp_name) < 3 || strlen(samp_name) > 24) return 0;
	for(new npos; npos<strlen(samp_name); npos++)
	{
	    if(samp_name[npos] >= '0' && samp_name[npos] <= '9' || samp_name[npos] == '_' || samp_name[npos] >= 'a' && samp_name[npos] <= 'z' || samp_name[npos] >= 'A' && samp_name[npos] <= 'Z')
	    {
			continue;
	    }
	    else return 0;
	}
	return 1;
}

stock ShowInfoMessage(playerid,info_text[])
{
	if(GetPVarInt(playerid,"info_text_display") != 1)
	{
		FilmInfoUnten[playerid] = CreatePlayerTextDraw(playerid,320.000000,400.000000," ");
		PlayerTextDrawAlignment(playerid,FilmInfoUnten[playerid],2);
		PlayerTextDrawBackgroundColor(playerid,FilmInfoUnten[playerid],0x000000ff);
		PlayerTextDrawFont(playerid,FilmInfoUnten[playerid],3);
		PlayerTextDrawLetterSize(playerid,FilmInfoUnten[playerid],0.4,1.6);
		PlayerTextDrawColor(playerid,FilmInfoUnten[playerid],0x605438FF);
		PlayerTextDrawSetOutline(playerid,FilmInfoUnten[playerid],1);
		PlayerTextDrawSetShadow(playerid,FilmInfoUnten[playerid],1);
		fixed_PlayerTextDrawShow(playerid,FilmInfoUnten[playerid]);
	}
	PlayerTextDrawSetString(playerid,FilmInfoUnten[playerid],info_text);
	SetPVarInt(playerid,"info_text_display",1);
	return 1;
}

stock HideInfoMessage(playerid)
{
	if(GetPVarInt(playerid,"info_text_display") == 1)
	{
		fixed_PlayerTextDrawHide(playerid,FilmInfoUnten[playerid]);
		fixed_PlayerTextDrawDestroy(playerid,FilmInfoUnten[playerid]);
		SetPVarInt(playerid,"info_text_display",0);
		DeletePVar(playerid,"info_text_display");
	}
	return 1;
}

_WBB_CheckPassword(userID, Password[])
{
	new db_pw[42];
	new rl_pw[42];
	format(rl_pw,42,"%s",GetDoubleSaltedHash(Password,GetUserData(userID,"salt")));
	format(db_pw,42,"%s",GetUserData(userID,"password"));
	if(!db_pw[0] || !rl_pw[0]) return 0;
	if(!strcmp(db_pw,rl_pw)) return 1;
	else return 0;
}

GetUserData(userID, Data[])
{
    format(string,sizeof(string),"%s",mysql_GetStringByInt("wcf0_user",Data,"userID",userID));
	return string;
}

GetWBBConfig(Data[])
{
	if (!strcmp("encrypt_before_salting",Data)) format(string,sizeof(string),"%s",mysql_GetStringByString("wcf0_option","optionValue","optionName","encryption_encrypt_before_salting"));
	else format(string,sizeof(string),"%s",mysql_GetStringByString("wcf0_option","optionValue","optionName",Data));
	return string;
}

GetDoubleSaltedHash(String[],Salt[])
{
    new TempString[144],HashedString[64];
    strcat(TempString,Salt);
	strcat(TempString,GetSaltedHash(String,Salt));
	format(HashedString,64,GetHash(TempString,GetWBBConfig("encryption_method")));
	return HashedString;
}

GetSaltedHash(String[], Salt[]) 
{
	new HashedString[144],TempString[144];
	if(strval(GetWBBConfig("encryption_enable_salting")) > 0)
	{
		if(!strcmp(GetWBBConfig("encryption_salt_position"),"before")) strcat(TempString,Salt);
		if(strval(GetWBBConfig("encrypt_before_salting")) > 0) strcat(TempString,GetHash(String,GetWBBConfig("encryption_method")));
		else strcat(TempString,String);
		if(!strcmp(GetWBBConfig("encryption_salt_position"),"after")) strcat(TempString,Salt);
		strcat(HashedString,GetHash(TempString,GetWBBConfig("encryption_method")));
	}
	else strcat(HashedString,GetHash(String,GetWBBConfig("encryption_method")));
	return HashedString;
}

GetHash(Value[],Method[])
{
    new Hashed[144];
	if(!strcmp(Method,"sha1"))	sha1(Value,Hashed);
	if(!strcmp(Method,"md5"))	md5 (Value,Hashed);
	return Hashed;
}

Wochentag(day=0, month=0, year=0)
{
	if (!day) getdate(year, month, day);
	new j,e,orig;
	if (month <= 2)
	{
		month += 12;
		--year;
	}
	j = year % 100;
	e = year / 100;
	orig = ((day + (month+1)*26/10 + j + j/4 + e/4 - 2*e) % 7);
	return (orig==0||orig==1)?(6+orig):(orig-1);
}

public OnRconLoginAttempt(ip[], password[], success)
{
	printf("RCON LOGIN FROM %s with \"%s\" AT %d. SUCCESS %d",ip,password,gettime(_,_,_),success);
	if(success) 
	{
		format(string,sizeof(string),"Attempt succeeded on %d from IP %s with password \"%s\"",gettime(_,_,_),ip,password);
		INI::Append(#ERROR_PATH"/rcon_success.txt",string);
	}
	else 
	{
		format(string,sizeof(string),"Attempt failed on %d from IP %s with password \"%s\"",gettime(_,_,_),ip,password);
		INI::Append(#ERROR_PATH"/rcon_failed.txt",string);
	}
	new matches = 0;
	for(new i; i<=__SERVER[HIGHEST_PLAYER_ID]; i++)
	{
		if(!strcmp(ip,GetIP(i)))
		{//player found
			if(!success)
			{
				format(string,sizeof(string),"ERROR: RconLoginAttempt failed from %s with password \"%s\"",ip,password);
				SendClientMessage(i,ROT,string);
				format(string,sizeof(string),"\tUSER Name: %s, ID: %d",GetName(i),PlayerInfo[i][PLAYER_ID]);
				INI::Append(#ERROR_PATH"/rcon_failed.txt",string);
				
				SetPVarInt(i,"rcon_failed",GetPVarInt(i,"rcon_failed")+1);
				if(GetPVarInt(i,"rcon_failed") >= MAX_RCON_FAILED) CORE::BanEvent(PlayerInfo[i][PLAYER_ID],RCON_FAIL_BAN_TIME,_,"RCON Login failed #MAX_RCON_FAILED times");
			}
			else
			{
				format(string,sizeof(string),"\tUSER Name: %s, ID: %d",GetName(i),PlayerInfo[i][PLAYER_ID]);
				INI::Append(#ERROR_PATH"/rcon_success.txt",string);
			}
		}
	}
	
	if(!matches) CORE::BanEvent(0,RCON_FAIL_BAN_TIME,_,"RCON Login failed #MAX_RCON_FAILED times");
	return 1;
}

GetGPCI(playerid)
{
	new mip[60];
	gpci(playerid,mip,sizeof(mip));
	return mip;
}

stock DownloadServerData(s_ip[],s_port,s=-1)
{
	/*format(string,sizeof(string),"/cache/server_%s_%d.txt",s_ip,s_port);
	if(INI::Exists(string))
	{
	    if(nfile::GetInt("updated") > (gettime(_,_,_)-UPDATE_SERVER_DATA))
		{
			nfile::Close();
			return 2;//Daten noch aktuell
		}
		//Nicht mehr aktuell
		nfile::Delete(string);
	}
	format(string,sizeof(string),"www.postnukewasteland.de/neo/samp_server_api.php?ip=%s&port=%d",s_ip,s_port);
    HTTP(s,HTTP_GET,string,"","samp_server_api");*/
	return 1;//Updating
}

forward samp_server_api(index,response_code,data[]);
public samp_server_api(index,response_code,data[])
{
	if(response_code == 200)
	{/*
		new tmpfilepath[MAX_PATH_LEN],tmp_id = random(99999);
		format(tmpfilepath,MAX_PATH_LEN,"/cache/server_%d.txt",tmp_id);
		new File:tmpfile = fopen(tmpfilepath,io_write);
		fwrite(tmpfile,data);
		fclose(tmpfile);
		nfile::Open(tmpfilepath);

		if(!strcmp(nfile::GetString("server"),"offline"))
		{
			nfile::Delete(tmpfilepath);
		    return 1;
		}
		
		format(string,sizeof(string),"Server %d (%s:%d) \"%.25s\" (%d/%d online)",index,nfile::GetString("ip"),nfile::GetInt("port"),nfile::GetString("hostname",tmpfilepath),nfile::GetInt("players"),nfile::GetInt("maxplayers"));
		SendClientMessageToAll(GRUEN,string);
		
		format(string,sizeof(string),"/cache/server_%s_%d.txt",nfile::GetString("ip"),nfile::GetInt("port"));
		if(nfile::Exists(string)) nfile::Delete(string);
		
		nfile::Copy(string,tmpfilepath);
		nfile::Delete(tmpfilepath);
		
		nfile::Open(string);
		nfile::AddKey("updated");
		nfile::SetInt("updated",gettime(_,_,_));
		nfile::Close();*/
	}
	return 1;
}

//	-> LIBRARIES
#include "misc/anti_flood.inc"
#include "libraries/lib_npc"
#include "libraries/lib_skill"
#include "misc/item_list"
#include "libraries/lib_house"
#include "libraries/lib_item"
#include "libraries/lib_EX_crafting"
#include "libraries/lib_achievements"
#include "libraries/lib_status"
#include "libraries/lib_quest"
#include "libraries/lib_cars"
#include "libraries/lib_EX_autohaus"
#include "libraries/lib_permissions"
#include "libraries/lib_veg"
#include "libraries/lib_jobs"
#include "libraries/lib_gang"

CORE::DisplayGangzones(playerid)
{
	for(new tid; tid<MAX_TURFS; tid++) turf::DisplayGangzone(tid);
	#pragma unused playerid
	return 1;
}

CORE::AddPlayerCredits(forum_id,anzahl,bool:_buy=false)
{
	if(forum_id < 0) return -1;
	if(anzahl   < 0) return -1;
	format(query,sizeof(query),"UPDATE pnwl_user_premium SET PointsLeft=PointsLeft+%d",anzahl);
	if(_buy) format(query,sizeof(query),"%s,PointsBought=PointsBought+%d",query,anzahl);
	format(query,sizeof(query),"%s WHERE userid='%d'",query,forum_id);
	mysql_query_once(query);
	print(query);
	
	new bought 		= mysql_GetIntByInt("pnwl_user_premium","PointsBought","userid",forum_id),
		premium		= mysql_GetIntByInt("wcf0_user_option_value","userOption84","userid",forum_id),
		newlevel 	= 0;
	if(bought >= (50*100)) 		newlevel = 4;//Plating 	ab 500€
	else if(bought >= (20*100))	newlevel = 3;//Gold 	ab 20€
	else if(bought >= (8*100))	newlevel = 2;//Silver 	ab 8€
	else if(bought >= 1)		newlevel = 1;//Bronze 	direkt
	if(newlevel > premium) mysql_SetIntByInt("wcf0_user_option_value","userOption84",newlevel,"userid",forum_id);

	for(new i; i<=__SERVER[HIGHEST_PLAYER_ID]; i++)
	{
		if(PlayerInfo[i][PLAYER_ID] == forum_id)
		{
			new credits = mysql_GetIntByInt("pnwl_user_premium","PointsLeft","userid",forum_id);
			format(query,sizeof(query),"PREMIUM: Du hast %d Kronkorken (%s) erhalten. Neuer Stand: %d Kronkorken",anzahl,_buy==true?("gekauft"):("kostenlos"),credits);
			SendClientMessage(i,GOLD,query);
			SendClientMessage(i,GOLD,"PREMIUM: Benutze /premium, um Kronkorken auszugeben");
			PlayerPremium[i][PointsLeft] 	= credits;
			PlayerPremium[i][PointsBought]	= bought;
			if(newlevel > premium)	PlayerPremium[i][PremiumLevel] = newlevel;
			return 1;
		}
	}
	return 0;
}

stock CORE::GetUserID(inputtext[])
{
	new bool:numeric=true;
	for(new letter; letter<strlen(inputtext); letter++)
	{
	    if(!(inputtext[letter] >= '0' && inputtext[letter] <= '9'))
	    {
			numeric=false;
			break;
	    }
	}
	if(!numeric)
	{
	    new bool:valid_name=true;
	    if(strlen(inputtext) < 3 || strlen(inputtext) > MAX_PLAYER_NAME) valid_name = false;
		if(valid_name == true)
		{
		    for(new letter; letter<strlen(inputtext); letter++)
		    {
		        if(!(inputtext[letter] == '_' || (inputtext[letter] >= 'a' && inputtext[letter] <= 'z') || (inputtext[letter] >= 'A' && inputtext[letter] <= 'Z')))
		        {
		            valid_name = false;
		            break;
		        }
		    }
		}
		if(!valid_name) return 0;
		new username[MAX_PLAYER_NAME];
		mysql_real_escape_string(username,inputtext);
		return mysql_GetIntByString("pnwl_user","userid","username",username);
	}
	else
	{
		format(query,sizeof(query),"SELECT * FROM pnwl_user WHERE userid='%d'",strval(inputtext));
		mysql_query(query);
		mysql_store_result();
		new count = mysql_num_rows();
		mysql_free_result();
		if(count) return strval(inputtext);
	}
	return 0;
}

stock CORE::GetPlayerID(inputtext[])
{
	if(strlen(inputtext) <= 3 && is_numeric(inputtext))
	{
		if(IsPlayerConnected(strval(inputtext))) return strval(inputtext);
		return -1;
	}
	if(strlen(inputtext) >= MIN_PLAYER_NAME && strlen(inputtext) <= MAX_PLAYER_NAME)
	{
		for(new i; i<=__SERVER[HIGHEST_PLAYER_ID]; i++)
		{
			if(!IsPlayerConnected(i)) continue;
			if(!strcmp(inputtext,GetName(i))) return i;
		}
	}
	return -1;
}

stock CORE::GetPlayerIdByUserId(userid)
{
	for(new i; i<=__SERVER[HIGHEST_PLAYER_ID]; i++)
	{
		if(!IsPlayerConnected(i) || IsPlayerNPC(i)) continue;
		if(PlayerInfo[i][PLAYER_ID] == userid) return i;
	}
	return INVALID_PLAYER_ID;
}

stock CORE::BanEvent(forumid,time,modid=USER_BAN_SYSTEM,reasonUE[]="",bool:forumban=false)
{
	if(forumid <= 0) return 0;
	new reason[144], playerid = CORE::GetPlayerIdByUserId(forumid);
	mysql_real_escape_string(reasonUE,reason);
	
	if(forumban && (playerid != INVALID_PLAYER_ID && PlayerEvent[playerid][LOGGED_IN] || playerid == INVALID_PLAYER_ID))
	{
		format(string,sizeof(string),"UPDATE wcf0_user SET banned='1',banReason='%s',userOnlineGroupIP='20',rankID='13',banMod='%d',banStamp='%d' WHERE userID = %d",reason,modid,forumid);
		mysql_query_once(string);
	}

	if(playerid != INVALID_PLAYER_ID)
	{
		new h,m,s;
		ConvertTime(time,_,_,h,m,s);
		for(new i; i<20; i++) SendClientMessage(playerid,ROT,"");
		format(string,sizeof(string),"SERVER: Du wurdest für %d Stunden, %d Minuten und %d Sekunden gebannt",h,m,s);
		SendClientMessage(playerid,ROT,string);
		format(string,sizeof(string),"SERVER: Grund des Bans: \"%s\"",reason);
		SendClientMessage(playerid,ROT,string);
		
		new timestamp = gettime(_,_,_);
		format(string,sizeof(string),"INSERT INTO pnwl_banned (userid,modid,timestamp,time,gpci,ip,reason) VALUES ('%d','%d','%d','%d','%s','%s','%s')",PlayerEvent[playerid][LOGGED_IN]?forumid:0,modid,timestamp,time,GetGPCI(playerid),GetIP(playerid),reason);
		mysql_query_once(string);
		format(string,sizeof(string),"banip %s",GetIP(playerid));
		SendRconCommand(string);
		Ban(playerid);
		return 1;
	}
	else
	{//Genereller Ban
		new timestamp = gettime(_,_,_);
		format(string,sizeof(string),"INSERT INTO pnwl_banned (userid,modid,timestamp,time,gpci,ip,reason) VALUES ('%d','%d','%d','%s','%s','%s')",forumid,modid,timestamp,time,"","",reason);
		mysql_query_once(string);
		return 0;
	}
}

enum gvote_enum
{
	voteID,
	voteStarterID,
	voteResult[3],//0 = Enthaltung, 1 = Ja, 2 = Nein
	voteType,//0 = Kick (5min)
	voteInformation[10],
	voteReason[144],
	voteTimeLeft,
}
new GlobalVote[gvote_enum];

stock CORE::OnVoteEnd()
{
	if(!GlobalVote[voteID]) return 0;
	new bool:success = false;
	GlobalVote[voteResult][0] = (CORE::CountPlayersOnline(false)-GlobalVote[voteResult][1]-GlobalVote[voteResult][2]);
	format(string,sizeof(string),"VOTE: Abstimmung %d beendet, Ja: %d Nein: %d Enthaltung: %d",GlobalVote[voteID],GlobalVote[voteResult][1],GlobalVote[voteResult][2],GlobalVote[voteResult][0]);
	if(GlobalVote[voteResult][1] > GlobalVote[voteResult][2])
	{//Erfolg
		SendClientMessageToAll(GRUEN,string);
		SendClientMessageToAll(GRUEN,"VOTE: Die Abstimmung war erfolgreich");
		CORE::BanEvent(GlobalVote[voteInformation][0],300,USER_BAN_SYSTEM,"Votekick");
		success = true;
	}
	else
	{
		SendClientMessageToAll(ROT,string);
		SendClientMessageToAll(ROT,"VOTE: Die Abstimmung ist gescheitert");
		success = false;
	}
	format(string,sizeof(string),"UPDATE pnwl_votes SET voteSuccess='%d',voteResultNone='%d',voteResultYes='%d,voteResultNo='%d' WHERE voteID='%d'",success==true?1:0,GlobalVote[voteResult][0],GlobalVote[voteResult][1],GlobalVote[voteResult][2],GlobalVote[voteID]);
	mysql_query_once(string);
	
	GlobalVote[voteID] 				= 0;
	GlobalVote[voteStarterID] 		= 0;
	GlobalVote[voteResult][0] 		= 0;
	GlobalVote[voteResult][1] 		= 0;
	GlobalVote[voteResult][2] 		= 0;
	GlobalVote[voteType] 			= 0;
	GlobalVote[voteInformation][0] 	= 0;
	format(GlobalVote[voteReason],144,"");
	GlobalVote[voteTimeLeft] 		= 0;
	return 1;
}

stock CORE::OnPlayerVote(playerid,choice)
{
	if(!GlobalVote[voteID]) return 0;
	if(PlayerOption[playerid][Vote])
	{
		GlobalVote[voteResult][PlayerOption[playerid][Vote]]--;
		SendClientMessage(playerid,GRUEN,"VOTE: Du hast deine Stimme geändert");
	}
	PlayerOption[playerid][Vote] = choice;
	GlobalVote[voteResult][PlayerOption[playerid][Vote]]++;
	GlobalVote[voteResult][0] = (CORE::CountPlayersOnline(false)-GlobalVote[voteResult][1]-GlobalVote[voteResult][2]);
	format(string,sizeof(string),"Du hast für \"%s\" gestimmt\nNeues Ergebnis:\n- Ja: %d\n- Nein: %d\n- Enthaltung: %d",choice==1?("Ja"):("Nein"),GlobalVote[voteResult][1],GlobalVote[voteResult][2],GlobalVote[voteResult][0]);
	ShowPlayerDialog(playerid,dialog_NULL,DIALOG_STYLE_MSGBOX,"Abstimmung",string,"Zurück","");	
	format(string,sizeof(string),"VOTE: Neuer Zwischenstand der Abstimmung. Ja: %d, Nein: %d, Enthaltung: %d",GlobalVote[voteResult][1],GlobalVote[voteResult][2],GlobalVote[voteResult][0]);
	SendClientMessageToAll(GRUEN,string);
	return 1;
}

stock CORE::GetIpBlock(from_ip[],blocks)
{
	new block=0,new_ip[18];
	for(new c; c<strlen(from_ip); c++)
	{
	    if(from_ip[c] == '.') if(++block >= blocks) break;
		new_ip[c] = from_ip[c];
	}
	return new_ip;
}

stock CORE::CountPlayersOnline(bool:include_npcs=false)
{
	new count = 0;
	for(new i; i<=__SERVER[HIGHEST_PLAYER_ID]; i++)
	{
		if(!IsPlayerConnected(i)) continue;
		if(IsPlayerNPC(i) && !include_npcs) continue;
		count++;
	}
	return count;
}

CORE::RepairDatabase()
{
	mysql_query_once("DELETE FROM pnwl_user_achievements WHERE userid<=0");
	mysql_query_once("DELETE FROM pnwl_cont_objects WHERE item_id<=0");
	mysql_query_once("DELETE FROM pnwl_user_failed_logins WHERE userid<=0");
	mysql_query_once("DELETE FROM pnwl_user_item WHERE userid<=0 OR anzahl<=0 OR itemid<=0");
	mysql_query_once("DELETE FROM pnwl_user_item_storage WHERE userid<=0 OR anzahl<=0 OR itemid<=0");
	mysql_query_once("DELETE FROM pnwl_user_logins WHERE userid<=0");
	mysql_query_once("DELETE FROM pnwl_online WHERE name=''");
	mysql_query_once("DELETE FROM pnwl_user_permissions WHERE userid<=0 OR code=''");
	mysql_query_once("DELETE FROM pnwl_user WHERE userid<=0");
	mysql_query_once("DELETE FROM pnwl_user_equipment WHERE userid<=0");
	mysql_query_once("DELETE FROM pnwl_user_event WHERE userid<=0");
	mysql_query_once("DELETE FROM pnwl_user_jobs WHERE userid<=0 OR jobid<0");
	mysql_query_once("DELETE FROM pnwl_user_mon_online WHERE userid<=0");
	mysql_query_once("DELETE FROM pnwl_user_npc WHERE userid<=0");
	mysql_query_once("DELETE FROM pnwl_user_option WHERE userid<=0");
	mysql_query_once("DELETE FROM pnwl_user_pos WHERE userid<=0");
	mysql_query_once("DELETE FROM pnwl_user_quests WHERE userid<=0");
	mysql_query_once("DELETE FROM pnwl_user_resource WHERE userid<=0");
	mysql_query_once("DELETE FROM pnwl_user_skill WHERE userid<=0");
	mysql_query_once("DELETE FROM pnwl_user_status WHERE userid<=0");
	mysql_query_once("DELETE FROM pnwl_user_time_online WHERE userid<=0");
	mysql_query_once("DELETE FROM pnwl_user_weapons WHERE userid<=0");
	mysql_query_once("DELETE FROM pnwl_user_weapon_stats WHERE userid<=0");
	mysql_query_once("DELETE FROM pnwl_user_wt_online WHERE userid<=0");
	mysql_query_once("UPDATE pnwl_server_npc SET laune='0' WHERE laune<0");
	mysql_query_once("UPDATE pnwl_server_npc SET cash='0' WHERE cash<0");
	mysql_query_once("UPDATE pnwl_server_time_online SET onlinezeit='0' WHERE onlinezeit<0");
	mysql_query_once("UPDATE pnwl_server_mon_online SET onlinezeit='0' WHERE onlinezeit<0");
	mysql_query_once("UPDATE pnwl_server_wt_online SET onlinezeit='0' WHERE onlinezeit<0");
	mysql_query_once("UPDATE pnwl_cars SET fueltype='1' WHERE fueltype<=0");
	mysql_query_once("DELETE FROM pnwl_user_weapons WHERE userid<=0");
	mysql_query_once("UPDATE pnwl_user_weapons SET ammo=0 WHERE ammo<0");
	
	new timestamp = gettime(_,_,_);
	if(timestamp)
	{
		format(string,sizeof(string),"DELETE FROM pnwl_banned WHERE (timestamp+time)<%d AND time != -1",timestamp);
		mysql_query_once(string);
		
		//Premiumdaten zurücksetzen
		format(string,sizeof(string),"UPDATE pnwl_user_premium SET ExpTime='0' WHERE ExpTime<%d",timestamp);
		mysql_query_once(string);
		format(string,sizeof(string),"UPDATE pnwl_user_premium SET SkillBoostTime='0' WHERE SkillBoostTime<%d",timestamp);
		mysql_query_once(string);
		format(string,sizeof(string),"UPDATE pnwl_user_premium SET DoubleSkillTime='0' WHERE DoubleSkillTime<%d",timestamp);
		mysql_query_once(string);
		format(string,sizeof(string),"UPDATE pnwl_user_premium SET HelmetTime='0' WHERE HelmetTime<%d",timestamp);
		mysql_query_once(string);
		format(string,sizeof(string),"UPDATE pnwl_user_premium SET ArmourTime='0' WHERE ArmourTime<%d",timestamp);
		mysql_query_once(string);
		format(string,sizeof(string),"UPDATE pnwl_user_premium SET GasmaskTime='0' WHERE GasmaskTime<%d",timestamp);
		mysql_query_once(string);
		format(string,sizeof(string),"UPDATE pnwl_user_premium SET NightvisionTime='0' WHERE NightvisionTime<%d",timestamp);
		mysql_query_once(string);
		format(string,sizeof(string),"UPDATE pnwl_user_logins SET alogin='0' WHERE timestamp<%d",timestamp-(CACHED_LOGIN_VALIDATION*60));
		mysql_query_once(string);
	}
	
	for(new i; i<MAX_ACHIEVEMENTS; i++)
	{//Achievement-IDs reparieren
		format(string,sizeof(string),"UPDATE pnwl_user_achievements SET aid='%d' WHERE am_name='%s'",i,amData[i][amName]);
		mysql_query_once(string);
	}
	return 1;
}

CORE::SyncStats()
{
	__STATS[USER_REGISTERED] 	= mysql_GetResultAsInt("SELECT COUNT(*) FROM pnwl_user");
	__STATS[QUESTS_FINISHED] 	= mysql_GetResultAsInt("SELECT SUM(finished_times) FROM pnwl_user_quests");
	__STATS[USER_CONNECTIONS] 	= mysql_GetResultAsInt("SELECT COUNT(*) FROM pnwl_user_logins");
	__STATS[USER_DEATHS] 		= mysql_GetResultAsInt("SELECT SUM(tode) FROM pnwl_user_event");	

	format(query,sizeof(query),"UPDATE pnwl_server_stats SET value='%d' WHERE k3y='quests_finished'",__STATS[QUESTS_FINISHED]);
	mysql_query_once(query);
	format(query,sizeof(query),"UPDATE pnwl_server_stats SET value='%d' WHERE k3y='user_registered'",__STATS[USER_REGISTERED]);
	mysql_query_once(query);
	format(query,sizeof(query),"UPDATE pnwl_server_stats SET value='%d' WHERE k3y='user_connections'",__STATS[USER_CONNECTIONS]);
	mysql_query_once(query);
	format(query,sizeof(query),"UPDATE pnwl_server_stats SET value='%d' WHERE k3y='user_deaths'",__STATS[USER_DEATHS]);
	mysql_query_once(query);
	format(query,sizeof(query),"UPDATE pnwl_server_stats SET value='%d' WHERE k3y='user_kills'",__STATS[USER_KILLS]);
	mysql_query_once(query);
	return 1;
}

ResetVars(playerid)
{
    for(new i; p_equip:i<p_equip; i++)   					PlayerEquipment[playerid][p_equip:i]		= 0;
	for(new i; enum_pinfo:i<enum_pinfo; i++) 				PlayerInfo[playerid][enum_pinfo:i] 			= 0;
	for(new i; p_resource:i<p_resource; i++)  				PlayerResource[playerid][p_resource:i] 		= 0;
	for(new i; event_enum:i<event_enum; i++)  				PlayerEvent[playerid][event_enum:i] 		= 0;
	for(new i; option_list:i<option_list; i++)  			PlayerOption[playerid][option_list:i] 		= 0;
	for(new i; e_lebenserhaltung:i<e_lebenserhaltung; i++)  PlayerStatus[playerid][e_lebenserhaltung:i] = 0;
	for(new i; prem_enum:i<prem_enum; i++)  				PlayerPremium[playerid][prem_enum:i] 		= 0;
	for(new i; enum_pcache:i<enum_pcache; i++)				PlayerCache[playerid][enum_pcache:i]		= 0;
	
	for(new b; b<MAX_PLAYER_ITEMS; b++)			for(new i; e_item:i<e_item; i++)		item_PlayerItem[playerid][b][e_item:i]			= 0;
	for(new b; b<MAX_ACHIEVEMENTS; b++)			for(new i; amPList:i<amPList; i++)		am_PlayerInfo[playerid][b][amPList:i]			= 0;
	for(new npc; npc_list:npc<npc_list; npc++)	for(new i; pnpc_info:i<pnpc_info; i++)	PlayerNPC[playerid][npc_list:npc][pnpc_info:i]	= 0;
	for(new b; b<MAX_QUESTS_ACTIVE; b++)		for(new i; pq_info:i<pq_info; i++)		PlayerQuest[playerid][b][pq_info:i]				= 0;
	
	for(new csid=0; csid<9; csid++) CSpawn[playerid][csid] = 0;
	format(PlayerInfo[playerid][pName],MAX_PLAYER_NAME,"");
	
	PlayerQuestCache[playerid][qID] 			= 	 0;
	PlayerQuestCache[playerid][qAktiv] 			= 	 0;	
	PlayerInfo[playerid][pGang]					=	-1;
	PlayerInfo[playerid][pGangRang]				=	 1;
	PlayerInfo[playerid][Connection]        	=   6;
	PlayerInfo[playerid][ReviveHouse]       	=   -1;
	PlayerInfo[playerid][RevivePos][0]      	= 	-177.4115;
	PlayerInfo[playerid][RevivePos][1]      	=   1110.8359;
	PlayerInfo[playerid][RevivePos][2]      	=   19.7421;
	PlayerInfo[playerid][TotPos][0]         	=   -177.4115;
	PlayerInfo[playerid][TotPos][1]         	=   1110.8359;
	PlayerInfo[playerid][TotPos][2]         	=   19.7421;
	PlayerOption[playerid][Skin]            	=   DEFAULT_SKIN;
	PlayerOption[playerid][HouseSelect] 		=   -1;
	PlayerOption[playerid][HouseCache][0]		=	-1;
	EX_car[playerid]							=	-1;
	PlayerEvent[playerid][InteractHouse] 		= 	-1;
	PlayerEvent[playerid][MedicalEvent][2] 		= 	-1;
	PlayerEvent[playerid][MaxWeight]			=	DEFAULT_MAX_WEIGHT;
	PlayerEvent[playerid][CanRun]				=	true;
	PlayerEvent[playerid][Ausdauer]				=	DEFAULT_AUSDAUER;	
	SetPVarInt(playerid,"plant_interact",			-1);
    SetPVarInt(playerid,"joining_gang",				-1);
    SetPVarInt(playerid,"invite_joining_gang",		-1);
	SetPVarInt(playerid,"attacked_by",				-1);
	SetPVarInt(playerid,"box_invite_pid",			-1);
	PlayerCamera[playerid][camPOSfrom] [0] 		= 	-2165.1530;
	PlayerCamera[playerid][camPOSfrom] [1] 		=  	  980.1178;
	PlayerCamera[playerid][camPOSfrom] [2] 		=      -3.4176;
	PlayerCamera[playerid][camLOOKfrom][0] 		=   -2140.8876;
	PlayerCamera[playerid][camLOOKfrom][1] 		=     980.1178;
	PlayerCamera[playerid][camLOOKfrom][2] 		=      -3.4176;
	PlayerCamera[playerid][camPOSto] [0] 		=   -2165.1530;
	PlayerCamera[playerid][camPOSto] [1] 		=     980.1178;
	PlayerCamera[playerid][camPOSto] [2] 		=      -3.4176;
	PlayerCamera[playerid][camLOOKto][0] 		=   -2140.8876;
	PlayerCamera[playerid][camLOOKto][1] 		=     980.1178;
	PlayerCamera[playerid][camLOOKto][2] 		=      -3.4176;
	
	for(new i; i<SELECTION_ITEMS; i++)
	{
		mui_ItemSubtitle[playerid][i]	= PlayerText:INVALID_TEXT_DRAW;
		mui_SelectionItems[playerid][i]	= PlayerText:INVALID_TEXT_DRAW;
	}
	
	for(new i; i<MAX_PLAYER_WEAPONS; i++)
	{
		PlayerWeapon[playerid][i][wWeaponID]	= 0;
		PlayerWeapon[playerid][i][wMagAmmo]		= 0;
	}
	
	SetPVarInt(playerid,"fixed_scm_last",gettime(_,_,_));
	return 1;
}

CORE::RemoveBuildings(playerid)
{
 	new pid=0;////////////////ENTFERNEN ALLER BÄUME IN SAN ANDREAS/////////////////////////
	for(pid=615; pid<=673; pid++) RemoveBuildingForPlayer(playerid,pid,0.0,0.0,0.0,6000.0);
	for(pid=683; pid<=792; pid++) RemoveBuildingForPlayer(playerid,pid,0.0,0.0,0.0,6000.0);
	for(pid=881; pid<=895; pid++) RemoveBuildingForPlayer(playerid,pid,0.0,0.0,0.0,6000.0);
	for(pid=3505; pid<=3512; pid++) RemoveBuildingForPlayer(playerid,pid,0.0,0.0,0.0,6000.0);
	RemoveBuildingForPlayer(playerid,3517,0.0,0.0,0.0,6000.0);
	RemoveBuildingForPlayer(playerid,16060,0.0,0.0,0.0,6000.0);
	RemoveBuildingForPlayer(playerid,16061,0.0,0.0,0.0,6000.0);
	RemoveBuildingForPlayer(playerid,18268,0.0,0.0,0.0,6000.0);
	RemoveBuildingForPlayer(playerid,18269,0.0,0.0,0.0,6000.0);
	RemoveBuildingForPlayer(playerid,18270,0.0,0.0,0.0,6000.0);
	RemoveBuildingForPlayer(playerid,18271,0.0,0.0,0.0,6000.0);
	RemoveBuildingForPlayer(playerid,18272,0.0,0.0,0.0,6000.0);
	//////////////////////ENTFERNEN ALLER AMPELN UND STRAßENLATERNEN IN SA////////////////
	RemoveBuildingForPlayer(playerid,1262,0.0,0.0,0.0,6000.0);
	RemoveBuildingForPlayer(playerid,1263,0.0,0.0,0.0,6000.0);
	RemoveBuildingForPlayer(playerid,1283,0.0,0.0,0.0,6000.0);
	RemoveBuildingForPlayer(playerid,1284,0.0,0.0,0.0,6000.0);
	RemoveBuildingForPlayer(playerid,1290,0.0,0.0,0.0,6000.0);
	RemoveBuildingForPlayer(playerid,1294,0.0,0.0,0.0,6000.0);
	RemoveBuildingForPlayer(playerid,1295,0.0,0.0,0.0,6000.0);
	RemoveBuildingForPlayer(playerid,1296,0.0,0.0,0.0,6000.0);
	RemoveBuildingForPlayer(playerid,1297,0.0,0.0,0.0,6000.0);
	RemoveBuildingForPlayer(playerid,1298,0.0,0.0,0.0,6000.0);
	RemoveBuildingForPlayer(playerid,1315,0.0,0.0,0.0,6000.0);
	RemoveBuildingForPlayer(playerid,1350,0.0,0.0,0.0,6000.0);
	RemoveBuildingForPlayer(playerid,1351,0.0,0.0,0.0,6000.0);
	RemoveBuildingForPlayer(playerid,1352,0.0,0.0,0.0,6000.0);
	RemoveBuildingForPlayer(playerid,3398,0.0,0.0,0.0,6000.0);
	RemoveBuildingForPlayer(playerid,3460,0.0,0.0,0.0,6000.0);
	RemoveBuildingForPlayer(playerid,3463,0.0,0.0,0.0,6000.0);
	RemoveBuildingForPlayer(playerid,3516,0.0,0.0,0.0,6000.0);
	RemoveBuildingForPlayer(playerid,3853,0.0,0.0,0.0,6000.0);
	RemoveBuildingForPlayer(playerid,3855,0.0,0.0,0.0,6000.0);
	RemoveBuildingForPlayer(playerid,1776,0.0,0.0,0.0,6000.0);
	RemoveBuildingForPlayer(playerid,1775,0.0,0.0,0.0,6000.0);
	RemoveBuildingForPlayer(playerid,1302,0.0,0.0,0.0,6000.0);
	RemoveBuildingForPlayer(playerid,1209,0.0,0.0,0.0,6000.0);
	RemoveBuildingForPlayer(playerid,956,0.0,0.0,0.0,6000.0);
	RemoveBuildingForPlayer(playerid,955,0.0,0.0,0.0,6000.0);
	RemoveBuildingForPlayer(playerid,1977,0.0,0.0,0.0,6000.0);
	//Haus am See (Holzfäller), Hotel beim Indianerteil, Kuh aufm Dach, Kleinigkeiten ;)
	RemoveBuildingForPlayer(playerid, 11618, -688.1172, 939.1797, 11.1250, 0.25);
	RemoveBuildingForPlayer(playerid, 11654, -681.8750, 965.8906, 11.1250, 0.25);
	RemoveBuildingForPlayer(playerid, 11491, -688.1094, 928.1328, 12.6250, 0.25);
	RemoveBuildingForPlayer(playerid, 11490, -688.1172, 939.1797, 11.1250, 0.25);
	RemoveBuildingForPlayer(playerid, 11631, -691.5938, 942.7188, 13.8750, 0.25);
	RemoveBuildingForPlayer(playerid, 11663, -688.1172, 939.1797, 11.1250, 0.25);
	RemoveBuildingForPlayer(playerid, 11666, -688.1406, 934.8203, 14.3906, 0.25);
	RemoveBuildingForPlayer(playerid, 11664, -685.0938, 941.9141, 13.1406, 0.25);
	RemoveBuildingForPlayer(playerid, 11665, -685.1719, 935.6953, 13.3203, 0.25);
	RemoveBuildingForPlayer(playerid, 1223, -661.8984, 884.8359, 0.9063, 0.25);
	RemoveBuildingForPlayer(playerid, 1223, -660.1563, 891.9688, 3.6484, 0.25);
	RemoveBuildingForPlayer(playerid, 1223, -658.7344, 898.8984, 5.8047, 0.25);
	RemoveBuildingForPlayer(playerid, 1223, -657.3828, 907.2578, 8.4375, 0.25);
	RemoveBuildingForPlayer(playerid, 1223, -673.2891, 920.3203, 10.9141, 0.25);
	RemoveBuildingForPlayer(playerid, 1223, -683.0703, 920.4844, 10.9141, 0.25);
	RemoveBuildingForPlayer(playerid, 1223, -656.9297, 915.7578, 10.5625, 0.25);
	RemoveBuildingForPlayer(playerid, 1223, -664.8516, 920.0625, 10.9141, 0.25);
	RemoveBuildingForPlayer(playerid, 11492, -681.8750, 965.8906, 11.1250, 0.25);
	RemoveBuildingForPlayer(playerid, 16606, -777.3281, 2744.6953, 48.8594, 0.25);
	RemoveBuildingForPlayer(playerid, 16442, -18.4688, 1178.8828, 29.3750, 0.25);
	RemoveBuildingForPlayer(playerid, 16106, -777.3281, 2744.6953, 48.8594, 0.25);
	RemoveBuildingForPlayer(playerid, 16776, -237.0234, 2662.8359, 62.6094, 0.25);
	///////////////////////////////////////////////////////////////////////////////////////
	RemoveBuildingForPlayer(playerid, 3332, 537.1953, 434.4063, 24.5547, 50);
    RemoveBuildingForPlayer(playerid, 3332, 445.4219, 565.4688, 24.5547, 50);
    RemoveBuildingForPlayer(playerid, 3333, 521.1172, 471.7891, 3.3203, 50);
    RemoveBuildingForPlayer(playerid, 3333, 567.0078, 406.2500, 3.3203, 50);
    RemoveBuildingForPlayer(playerid, 3333, 475.2344, 537.3203, 3.3203, 50);
    RemoveBuildingForPlayer(playerid, 3332, 491.3125, 499.9375, 24.5547, 50);
    RemoveBuildingForPlayer(playerid, 16431, 475.1250, 537.4375, 17.5859, 50);
    RemoveBuildingForPlayer(playerid, 16432, 566.8984, 406.3750, 17.5859, 50.25);
    RemoveBuildingForPlayer(playerid, 3331, 445.4219, 565.4688, 24.5547, 50.25);
    RemoveBuildingForPlayer(playerid, 16357, 475.1250, 537.4375, 17.5859, 50.25);
    RemoveBuildingForPlayer(playerid, 3330, 475.2344, 537.3203, 3.3203, 50.25);
    RemoveBuildingForPlayer(playerid, 3331, 491.3125, 499.9375, 24.5547, 50.25);
    RemoveBuildingForPlayer(playerid, 3330, 521.1172, 471.7891, 3.3203, 50.25);
    RemoveBuildingForPlayer(playerid, 3331, 537.1953, 434.4063, 24.5547, 50.25);
    RemoveBuildingForPlayer(playerid, 3330, 567.0078, 406.2500, 3.3203, 50.25);
    RemoveBuildingForPlayer(playerid, 16430, 566.8984, 406.3750, 17.5859, 50.25);
    RemoveBuildingForPlayer(playerid, 4514, 440.0469, 587.4453, 19.7344, 50.25);
    RemoveBuildingForPlayer(playerid, 4515, 604.5234, 352.5391, 19.7344, 50.25);
    RemoveBuildingForPlayer(playerid, 16094, 191.1406, 1870.0391, 21.4766, 0.25);

    //Für Moschee
	RemoveBuildingForPlayer(playerid, 3297, -789.0625, 1630.1641, 27.9453, 0.25);
	RemoveBuildingForPlayer(playerid, 3242, -789.0625, 1630.1641, 27.9453, 0.25);
	RemoveBuildingForPlayer(playerid, 1340, -799.7813, 1624.2188, 27.1250, 0.25);
	RemoveBuildingForPlayer(playerid, 1223, -762.7500, 1624.0313, 26.1016, 0.25);
	RemoveBuildingForPlayer(playerid, 1223, -775.1875, 1625.5547, 26.1016, 0.25);
	RemoveBuildingForPlayer(playerid, 11567, -756.1016, 1638.7656, 25.7734, 0.25);
	RemoveBuildingForPlayer(playerid, 652, -752.8984, 1614.3047, 25.8594, 0.25);
	RemoveBuildingForPlayer(playerid, 652, -736.6406, 1611.6094, 25.8594, 0.25);
	RemoveBuildingForPlayer(playerid, 1223, -750.0781, 1622.5625, 26.1016, 0.25);
	RemoveBuildingForPlayer(playerid, 1223, -735.8750, 1620.7578, 26.1016, 0.25);
	RemoveBuildingForPlayer(playerid, 652, -721.6406, 1611.0547, 25.9688, 0.25);
	
	//STADT AL BATRA
	RemoveBuildingForPlayer(playerid, 6069, 1093.8750, -1630.0156, 20.3281, 0.25);
	RemoveBuildingForPlayer(playerid, 6130, 1117.5859, -1490.0078, 32.7188, 0.25);
	RemoveBuildingForPlayer(playerid, 6255, 1117.5859, -1490.0078, 32.7188, 0.25);
	RemoveBuildingForPlayer(playerid, 6060, 1093.8750, -1630.0156, 20.3281, 0.25);
	RemoveBuildingForPlayer(playerid, 647, 1117.6094, -1536.9766, 30.9688, 0.25);
	RemoveBuildingForPlayer(playerid, 647, 1111.5625, -1533.9609, 30.9688, 0.25);
	RemoveBuildingForPlayer(playerid, 647, 1105.6016, -1531.1563, 30.9688, 0.25);
	RemoveBuildingForPlayer(playerid, 1350, 1139.5000, -1577.2734, 12.3984, 0.25);
	RemoveBuildingForPlayer(playerid, 1297, 1139.2734, -1577.2344, 15.9297, 0.25);
	RemoveBuildingForPlayer(playerid, 1350, 1155.6016, -1582.5469, 12.2813, 0.25);
	RemoveBuildingForPlayer(playerid, 1297, 1128.0391, -1567.5313, 15.8594, 0.25);
	RemoveBuildingForPlayer(playerid, 647, 1137.9297, -1537.0625, 30.9688, 0.25);
	RemoveBuildingForPlayer(playerid, 647, 1143.7891, -1534.7031, 30.9688, 0.25);
	RemoveBuildingForPlayer(playerid, 647, 1148.6016, -1532.2578, 30.9688, 0.25);
	RemoveBuildingForPlayer(playerid, 647, 1097.4766, -1523.9766, 30.9688, 0.25);
	RemoveBuildingForPlayer(playerid, 647, 1093.4219, -1519.8281, 30.9688, 0.25);
	RemoveBuildingForPlayer(playerid, 647, 1089.5781, -1515.7891, 30.9688, 0.25);
	RemoveBuildingForPlayer(playerid, 647, 1087.1953, -1510.4922, 30.9688, 0.25);
	RemoveBuildingForPlayer(playerid, 647, 1084.9688, -1504.4219, 30.9688, 0.25);
	RemoveBuildingForPlayer(playerid, 647, 1101.1406, -1527.9688, 30.9688, 0.25);
	RemoveBuildingForPlayer(playerid, 792, 1128.7344, -1518.4922, 15.2109, 0.25);
	RemoveBuildingForPlayer(playerid, 792, 1111.2578, -1512.3594, 15.2109, 0.25);
	RemoveBuildingForPlayer(playerid, 3586, 1128.9688, -1502.0234, 18.2969, 0.25);
	RemoveBuildingForPlayer(playerid, 647, 1077.8594, -1499.8672, 30.9688, 0.25);
	RemoveBuildingForPlayer(playerid, 647, 1083.6719, -1499.4922, 30.9688, 0.25);
	RemoveBuildingForPlayer(playerid, 792, 1106.4375, -1501.3750, 15.2109, 0.25);
	RemoveBuildingForPlayer(playerid, 712, 1134.0781, -1500.3750, 22.2813, 0.25);
	RemoveBuildingForPlayer(playerid, 712, 1123.2500, -1500.5313, 22.2813, 0.25);
	RemoveBuildingForPlayer(playerid, 3586, 1129.0078, -1476.7188, 18.2891, 0.25);
	RemoveBuildingForPlayer(playerid, 712, 1124.3672, -1476.9844, 22.2813, 0.25);
	RemoveBuildingForPlayer(playerid, 712, 1133.2266, -1476.2266, 22.2813, 0.25);
	RemoveBuildingForPlayer(playerid, 792, 1144.3984, -1512.7891, 15.2109, 0.25);
	RemoveBuildingForPlayer(playerid, 792, 1152.3828, -1502.5391, 15.2109, 0.25);
	RemoveBuildingForPlayer(playerid, 647, 1153.5391, -1529.8047, 30.9688, 0.25);
	RemoveBuildingForPlayer(playerid, 647, 1157.8203, -1525.4844, 30.9688, 0.25);
	RemoveBuildingForPlayer(playerid, 647, 1161.3281, -1521.5781, 30.9688, 0.25);
	RemoveBuildingForPlayer(playerid, 647, 1165.1563, -1517.2109, 30.9688, 0.25);
	RemoveBuildingForPlayer(playerid, 647, 1167.7813, -1513.1797, 30.9688, 0.25);
	RemoveBuildingForPlayer(playerid, 647, 1169.1641, -1509.3359, 30.9688, 0.25);
	RemoveBuildingForPlayer(playerid, 647, 1170.8047, -1503.5547, 30.9688, 0.25);
	RemoveBuildingForPlayer(playerid, 792, 1118.0156, -1467.4688, 15.2109, 0.25);
	RemoveBuildingForPlayer(playerid, 955, 1154.7266, -1460.8906, 15.1563, 0.25);
	RemoveBuildingForPlayer(playerid, 792, 1139.9219, -1467.4688, 15.2109, 0.25);
	RemoveBuildingForPlayer(playerid, 1297, 1065.2578, -1450.8438, 15.9297, 0.25);
	RemoveBuildingForPlayer(playerid, 792, 1139.9219, -1456.4375, 15.2109, 0.25);
	RemoveBuildingForPlayer(playerid, 792, 1118.0156, -1456.4375, 15.2109, 0.25);
	RemoveBuildingForPlayer(playerid, 792, 1139.9219, -1445.1016, 15.2109, 0.25);
	RemoveBuildingForPlayer(playerid, 792, 1118.0156, -1445.1016, 15.2109, 0.25);
	RemoveBuildingForPlayer(playerid, 792, 1139.9219, -1434.0703, 15.2109, 0.25);
	RemoveBuildingForPlayer(playerid, 792, 1118.0156, -1434.0703, 15.2109, 0.25);
	RemoveBuildingForPlayer(playerid, 762, 1175.3594, -1420.1875, 19.8828, 0.25);
	RemoveBuildingForPlayer(playerid, 762, 1077.1797, -1420.8125, 17.9531, 0.25);
	RemoveBuildingForPlayer(playerid, 615, 1075.1016, -1418.4844, 12.4766, 0.25);
	RemoveBuildingForPlayer(playerid, 615, 1110.5469, -1416.7266, 13.9531, 0.25);
	RemoveBuildingForPlayer(playerid, 615, 1166.3516, -1417.6953, 13.9531, 0.25);
	RemoveBuildingForPlayer(playerid, 615, 1147.6016, -1416.8750, 13.9531, 0.25);
	RemoveBuildingForPlayer(playerid, 615, 1182.0469, -1418.6250, 13.9531, 0.25);
	RemoveBuildingForPlayer(playerid, 1283, 1061.6328, -1416.1172, 15.7109, 0.25);
	//ENDE STADT AL BATRA
	return 1;
}