local TraceFrame = DEFAULT_CHAT_FRAME;

local DBCS_mobs_wow_build;
local DBCS_mobs_wow_build_live = 13623;

_, DBCS_mobs_wow_build, _, _ = GetBuildInfo();
DBCS_mobs_wow_build = tonumber(DBCS_mobs_wow_build);

-- noms des mobs rares de BC : haut fait 1311 + 1312
-- noms des mobs rares de WOTLK : haut fait 2256 + 2257

--NEW - isTanking, state, scaledPercent, rawPercent, threatValue = UnitDetailedThreatSituation("unit", "mob") 

--/script DBMS["Minerai de saronite"]["1"][8][36912] = 0

--/script DBMS["Magowar"] = nil;

--/script DBMS["Ench. de brassards (Robustesse)"]["0"][8][22533] = 0
--/script DBMS["Ench. de brassards (Robustesse)"]["0"][4] = "350"
--/script DBMS["Ench. de plastron (Caractéristiques exceptionnelles)"]["0"][8][22547] = 0
--/script DBMS["Ench. de plastron (Caractéristiques exceptionnelles)"]["0"][8][24003] = 0
--/script DBMS["Ench. de plastron (Caractéristiques exceptionnelles)"]["0"][4] = "345"
--/script DBMS["Ench. de bottes (Dextérité)"]["0"][8][22544] = 0
--/script DBMS["Ench. de bottes (Dextérité)"]["0"][4] = "340"
--/script DBMS["Ench. de brassards (Défense majeure)"]["0"][8][22530] = 0
--/script DBMS["Ench. de brassards (Défense majeure)"]["0"][4] = "320"
--/script DBMS["Ench. d'arme (Puissance des sorts)"]["0"][8][18259] = 0
--/script DBMS["Ench. d'arme (Puissance des sorts)"]["0"][4] = "300"
--/script DBMS["Ench. de cape (Discrétion)"]["0"][8][20735] = 0
--/script DBMS["Ench. de plastron (Caract. supérieures)"]["0"][8][16253] = 0
--/script DBMS["Ench. de plastron (Caract. supérieures)"]["0"][4] = "300"

--/script DBMS["Ench. de brassards (Soin)"]["0"][8][19447] = 0	--	lien de craft inconnu

--/script DBMS["Ench. d'arme (Arme impie)"]["0"][8][16248] = 0
--/script DBMS["Ench. d'arme (Arme impie)"]["0"][4] = "295"
--/script DBMS["Ench. de cape (Défense excellente)"]["0"][8][16224] = 0
--/script DBMS["Ench. de cape (Défense excellente)"]["0"][4] = "285"
--/script DBMS["Ench. de bouclier (Résistance au Givre)"]["0"][8][11224] = 0
--/script DBMS["Ench. de bouclier (Résistance au Givre)"]["0"][4] = "235"
--/script DBMS["Ench. de cape (Résistance à l'Ombre inf.)"]["0"][8][11098] = 0
--/script DBMS["Ench. de cape (Résistance à l'Ombre inf.)"]["0"][4] = "135"
--/script DBMS["Ench. de bottes (Agilité mineure)"]["0"][8][6377] = 0
--/script DBMS["Ench. de bottes (Agilité mineure)"]["0"][4] = "125"

--/script DBMS["Ench. de brassards (Pouvoir de guérison)"]["0"][8][19447] = 0
--/script DBMS["Ench. de brassards (Pouvoir de guérison)"]["0"][4] = "300"

--/script DBMS["Diamant tonneterre de fringance"]["1"][8][25903] = 0
--/script DBMS["Diamant tonneterre de fringance"]["1"][4] = "365"

--/script DBMS["Transmutation primordiale\194\160: Air en Feu"]["0"][8][22915] = 0
--/script DBMS["Transmutation primordiale\194\160: Air en Feu"]["0"][4] = "350"
--/script DBMS["Transmutation primordiale\194\160: Eau en Air"]["0"][8][22918] = 0
--/script DBMS["Transmutation primordiale\194\160: Eau en Air"]["0"][4] = "350"
--/script DBMS["Transmutation primordiale\194\160: Eau en Air"]["0"][5] = "Alchimie"
--/script DBMS["Transmutation primordiale\194\160: Feu en Terre"]["0"][8][30443] = 0
--/script DBMS["Transmutation primordiale\194\160: Feu en Terre"]["0"][4] = "350"
--/script DBMS["Transmutation primordiale\194\160: Pouvoir"]["0"][8][23574] = 0
--/script DBMS["Transmutation primordiale\194\160: Pouvoir"]["0"][4] = "350"
--/script DBMS["Transmutation primordiale\194\160: Terre en Eau"]["0"][8][22916] = 0
--/script DBMS["Transmutation primordiale\194\160: Terre en Eau"]["0"][4] = "350"
--/script DBMS["Transmutation\194\160: Diamant brûleciel"]["0"][8][29232] = 0
--/script DBMS["Transmutation\194\160: Diamant brûleciel"]["0"][4] = "350"
--/script DBMS["Transmutation\194\160: Diamant tonneterre"]["0"][8][25869] = 0
--/script DBMS["Transmutation\194\160: Diamant tonneterre"]["0"][4] = "350"
--/script DBMS["Transmutation\194\160: Feu élémentaire"]["0"][8][20761] = 0
--/script DBMS["Transmutation\194\160: Feu élémentaire"]["0"][4] = "300"
--/script DBMS["Potion de purification"]["0"][8][13492] = 0
--/script DBMS["Potion de purification"]["0"][4] = "285"
--/script DBMS["Transmutation\194\160: Eau en Air"]["0"][8][13485] = 0
--/script DBMS["Transmutation\194\160: Eau en Air"]["0"][4] = "275"
--/script DBMS["Transmutation\194\160: Eau en Non-mort"]["0"][8][13487] = 0
--/script DBMS["Transmutation\194\160: Eau en Non-mort"]["0"][4] = "275"
--/script DBMS["Transmutation\194\160: Terre en Eau"]["0"][8][13484] = 0
--/script DBMS["Transmutation\194\160: Terre en Eau"]["0"][4] = "275"
--/script DBMS["Transmutation\194\160: Terre en Vie"]["0"][8][13489] = 0
--/script DBMS["Transmutation\194\160: Terre en Vie"]["0"][4] = "275"
--/script DBMS["Transmutation\194\160: Vie en Terre"]["0"][8][13488] = 0
--/script DBMS["Transmutation\194\160: Vie en Terre"]["0"][4] = "275"
--/script DBMS["Transmutation\194\160: Feu en Terre"]["0"][8][13483] = 0
--/script DBMS["Transmutation\194\160: Feu en Terre"]["0"][4] = "275"
--/script DBMS["Transmutation\194\160: Non-mort en Eau"]["0"][8][13486] = 0
--/script DBMS["Transmutation\194\160: Non-mort en Eau"]["0"][4] = "275"
--/script DBMS["Potion de soins majeure"]["0"][8][13480] = 0
--/script DBMS["Potion de soins majeure"]["0"][4] = "275"
--/script DBMS["Transmutation\194\160: Fer en Or"]["0"][8][9304] = 0
--/script DBMS["Transmutation\194\160: Fer en Or"]["0"][4] = "225"
--/script DBMS["Transmutation\194\160: Mithril en Vrai-argent"]["0"][8][9305] = 0
--/script DBMS["Transmutation\194\160: Mithril en Vrai-argent"]["0"][4] = "225"
--/script DBMS["Transmutation\194\160: Mithril en Vrai-argent"]["0"][5] = "Alchimie"
--/script DBMS["Potion de rapidité"]["0"][8][2555] = 0
--/script DBMS["Potion de rapidité"]["0"][4] = "060"

--/script DBMS["Prince Taldaram"] = nil;
--DBMS
--1 mob =
--	1 nommob			= "Crabe à pince"
--		1 numregion		= "205"
--			[1] nivmin		= 10
--			[2] nivmax	= 12
--			[3] classe		= "normal" ou "rare" ou "elite" ou "rareelite" ou "worldboss"
--			[4] famille		= "Crab" "Bear" "Wolf" etc
--			[5] type		= "Humanoid" "Demon" "Beast"
--			[6] plusmob	= true/false
--			[7] nbcorps	= 3 ( 3 fois lootés )
--			[8] objets		= tablo
--				1 numobjet			= 14047
--					1 numcourt2		= "0:0:0" = 1
--			[9] nbskin	= 1 ( 1 fois skinné )
--			[10] position = "25Y84@13Y88@"
--			[11] locprecise = {}	-- que pour minage/cueillette/ouverture
--				[11.521@26.842] = "posmingauche@posmaxdroite@posminhaut@posmaxbas@"
--			[12] datemaj	= date de dernière mise à jour de ce mob, local ou par autre utilisateur
--			[13] domptable	= nil ou 0 ou 1	( pas testé ou pas domptable ou domptable )
--			[14] regime		= { "viande" = 1, "poisson" = 1 }
--			[15] technique	= { "célérité" = 3, "Roder" = 4 }
--			[16] niveau		= { }
--				[1] dmin	=	degats min
--				[2] dmax	=	degats max
--				[3] armure	=	armure
--				[4] pdv	=	pdv
--			[20]	date du modèle
--			[21]	si character, rep du modèle
--			[22]	si character, genre du modèle
--			[23]	si character, nom du modèle
--			[24]	si character, blp du modèle
--			[25]	si creature, rep du modèle
--			[26]	si creature, nom du modèle
--			[27]	si creature, blp du modèle
--			[28]	modèles	=	{}
--				"creature@machin@@machin.m2@blp@"	=	date
--			[29]	GUID	=	"0000" à "FFFF"	en numérique
--
--1 loot =
--	1 nommob					= "Crabe à pinces"
--		1 region					= "205"
--			1 numobjet			= 14047
--				1 numcourt2		= "0:0:0" = 1
----					nb		= 1
--
--1 corp vide =
--	1 serveur									"Kirin thor"
--		1 nomlead							"Fauvette"
--			1 nomjoueur						"Fauvette"
--				1 time						125684759632
--					1 nommob				"Crabe à pince"
--						1 region				"205"
--							nbloot			1
--							1 numslot			1
--								numobjet		14047
--								numcourt2	"0:0:0"
--								nb		3
--/script DEFAULT_CHAT_FRAME:AddMessage(TargetPortrait:GetTexture());

--/script DEFAULT_CHAT_FRAME:AddMessage(tonumber(UnitGUID("Player")));
--/script DEFAULT_CHAT_FRAME:AddMessage(UnitGUID("target"));
--/script DEFAULT_CHAT_FRAME:AddMessage(UnitGUID("mouseover"));
--/script DEFAULT_CHAT_FRAME:AddMessage(tonumber("0x2683",16));

--/script DEFAULT_CHAT_FRAME:AddMessage(2000000*2000000);

function DBmobs_OnLoad(self)

	self:RegisterEvent("VARIABLES_LOADED");
--	this:RegisterEvent("CHAT_MSG_LOOT");
--	this:RegisterEvent("ITEM_PUSH");
--	this:RegisterEvent("LOOT_CLOSED");
--	this:RegisterEvent("LOOT_OPENED");
--	this:RegisterEvent("LOOT_SLOT_CLEARED");

-- Register our slash command
--	SLASH_LOOTMOB1 = "/lootmob";
--	SLASH_LOOTMOB2 = "/lm";
--	SlashCmdList["LOOTMOB"] = function(msg)
--		Lootmob_SlashCommandHandler(msg);
--	end

--	DBMS = {};

end

function DBmobs_OnEvent(self,event)

	if ( event == "" ) then
--	if ( event == "CHAT_MSG_COMBAT_HOSTILE_DEATH" ) then
--	elseif ( event == "CHAT_MSG_COMBAT_CREATURE_VS_CREATURE_HITS" ) then
	elseif ( event == "VARIABLES_LOADED" ) then
		if ( DBCS_data_Mobs_LOADED and DBCS_data_Mobs_LOADED == true ) then
		else
			DBcorps_deplacerDBCC(1000000000,0,true);
		end
	else
	end

end

function DBmobs_champ_8_en_nombre(tablo)

local inumobjet;
local itotal;
local scode;

	--if ( tablo == nil ) then
	--	return;
	--end
	--if ( 1 == 1 ) then
	--	return tablo;
	--end
	
	for inumobjet, _ in pairs(tablo) do
		if ( type(tablo[inumobjet]) == "table" ) then
			itotal = 0;
			for scode, _ in pairs(tablo[inumobjet]) do
				itotal = itotal + tablo[inumobjet][scode];
			end
			tablo[inumobjet] = itotal;
		end
	end
	
	return tablo;

end

function DBmobs_envoyermob(slangue,sdate,slead,stime,nommob,numregion,x,y,niv,classe,famille,stype,plusmob,nbcorp,nbskin,nbloot)

local message;

	message = "";
	message = message.."@ADBCS@";
	message = message..slangue.."@";
	message = message.."MA01@";
	message = message..sdate.."@";
	message = message..slead.."@";
	message = message..stime.."@";
	message = message..nommob.."@";
	message = message..(numregion or "").."@";
	message = message..(x or "").."@";
	message = message..(y or "").."@";
	message = message..(niv or "").."@";
	message = message..(classe or "").."@";
	if ( famille == nil ) then
		message = message.."@";
	else
		message = message..famille.."@";
	end
	if ( stype == nil ) then
		message = message.."@";
	else
		message = message..stype.."@";
	end
	if ( plusmob == nil ) then
		message = message.."@";
	else
		message = message..plusmob.."@";
	end
	message = message..(nbcorp or 0).."@";
	message = message..(nbskin or 0).."@";
	message = message..(nbloot or 0).."@";
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("DBCS_CMS_numcanalCMS = "..DBCS_CMS_numcanalCMS);
--end
	DBCS_SendChatMessage(message,"CHANNEL",DBCS_language,DBCS_CMS_numcanalCMS);
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("message = "..message);
--end

end

function DBmobs_envoyermob2(slangue,sdate,slead,stime,nommob,numregion,x,y,niv,classe,famille,stype,plusmob,nbcorp,nbskin,nbloot)

local message;

	message = "";
	message = message.."@ADBCS@";
	message = message..slangue.."@";
	message = message.."MA02@";
	message = message..sdate.."@";
	message = message..slead.."@";
	message = message..stime.."@";
	message = message..nommob.."@";
	message = message..numregion.."@";
	message = message..x.."@";
	message = message..y.."@";
	message = message..niv.."@";
	message = message..classe.."@";
	if ( famille == nil ) then
		message = message.."@";
	else
		message = message..famille.."@";
	end
	if ( stype == nil ) then
		message = message.."@";
	else
		message = message..stype.."@";
	end
	if ( plusmob == nil ) then
		message = message.."@";
	else
		message = message..plusmob.."@";
	end
	message = message..nbcorp.."@";
	message = message..nbskin.."@";
	message = message..nbloot.."@";
	DBCS_SendChatMessage(message,"CHANNEL",DBCS_language,DBCS_CMS_numcanalCMS);

end

function DBmobs_datemob(nommob,numregion)

local result = "0";

	if ( DBMS[nommob] ) then
		if ( DBMS[nommob][numregion] ) then
			result = ( DBMS[nommob][numregion][12] or "0");
		end
	end
	return result;

end

function DBmobs_ajoutregimebete(nommob,numregion,tregime)

	local sregime;

	if ( not DBMS ) then
		DBMS = {};
	end
	if ( not DBMS[nommob] ) then
		DBMS[nommob] = {};
	end
	if ( not DBMS[nommob][numregion] ) then
		DBMS[nommob][numregion] = {};
		DBMS[nommob][numregion][7] = 0;
	end
	DBMS[nommob][numregion][14] = {};
	for sregime, _ in pairs(tregime) do
		DBMS[nommob][numregion][14][sregime] = 1;
	end

end

function DBmobs_ajouttechniquebete(nommob,numregion,ttechnique)

	local stechnique;
	local irang;

	if ( not DBMS ) then
		DBMS = {};
	end
	if ( not DBMS[nommob] ) then
		DBMS[nommob] = {};
	end
	if ( not DBMS[nommob][numregion] ) then
		DBMS[nommob][numregion] = {};
		DBMS[nommob][numregion][7] = 0;
	end
	DBMS[nommob][numregion][15] = {};
	for stechnique, irang in pairs(ttechnique) do
		DBMS[nommob][numregion][15][stechnique] = irang;
	end

end

function DBmobs_ajoutconnaissancebete(nommob,numregion,niv,domptable,dmin,dmax,armure,pdv)

	if ( not DBMS ) then
		DBMS = {};
	end
	if ( not DBMS[nommob] ) then
		DBMS[nommob] = {};
	end
	if ( not DBMS[nommob][numregion] ) then
		DBMS[nommob][numregion] = {};
		DBMS[nommob][numregion][7] = 0;
	end
	if ( DBMS[nommob][numregion][1] ) then
		if ( niv < DBMS[nommob][numregion][1] ) then
			DBMS[nommob][numregion][1] = niv;
		end
	else
		DBMS[nommob][numregion][1] = niv;
	end
	if ( DBMS[nommob][numregion][2] ) then
		if ( ( niv < 99 ) and ( niv > DBMS[nommob][numregion][2] or DBMS[nommob][numregion][2] == 99 ) ) then
			DBMS[nommob][numregion][2] = niv;
		end
	else
		DBMS[nommob][numregion][2] = niv;
	end
	if ( domptable ) then
		DBMS[nommob][numregion][13] = domptable;
	else
		DBMS[nommob][numregion][13] = nil;
	end
	if ( DBMS[nommob][numregion][16] ) then
	else
		DBMS[nommob][numregion][16] = {};
	end
	if ( DBMS[nommob][numregion][16][niv] ) then
	else
		DBMS[nommob][numregion][16][niv] = {};
	end
	if ( DBMS[nommob][numregion][16][niv][1] ) then
		if ( DBMS[nommob][numregion][16][niv][1] < dmin ) then
		else
			DBMS[nommob][numregion][16][niv][1] = dmin;
		end
	else
		DBMS[nommob][numregion][16][niv][1] = dmin;
	end
	if ( DBMS[nommob][numregion][16][niv][2] ) then
		if ( DBMS[nommob][numregion][16][niv][2] > dmax ) then
		else
			DBMS[nommob][numregion][16][niv][2] = dmax;
		end
	else
		DBMS[nommob][numregion][16][niv][2] = dmax;
	end
	if ( DBMS[nommob][numregion][16][niv][3] ) then
		if ( DBMS[nommob][numregion][16][niv][3] > armure ) then
		else
			DBMS[nommob][numregion][16][niv][3] = armure;
		end
	else
		DBMS[nommob][numregion][16][niv][3] = armure;
	end
	if ( DBMS[nommob][numregion][16][niv][4] ) then
		if ( DBMS[nommob][numregion][16][niv][4] > pdv ) then
		else
			DBMS[nommob][numregion][16][niv][4] = pdv;
		end
	else
		DBMS[nommob][numregion][16][niv][4] = pdv;
	end

end

function DBmobs_region000(snommob,snumregion,iniv,sclasse,sfamille,stype,splusmob)

local sreturn = snumregion;
local a;
local numregion;
local i;
	
	if ( DBMS and DBMS[snommob] ) then
		i = 0;
		for a, _ in pairs(DBMS[snommob]) do
			if ( a == "000" ) then
			else
--			[3] classe		= "normal" ou "rare" ou "elite" ou "rareelite" ou "worldboss"
--			[4] famille		= "Crab" "Bear" "Wolf" etc
--			[5] type		= "Humanoid" "Demon" "Beast"
				if ( DBMS[snommob][a][3] and DBMS[snommob][a][3] == sclasse and DBMS[snommob][a][4] and DBMS[snommob][a][4] == sfamille and DBMS[snommob][a][5] and DBMS[snommob][a][5] == stype ) then
					i = i + 1;
					numregion = a;
				end
			end
		end
		if ( i > 0 ) then
			sreturn = numregion;
if ( DBCS_debug > 1 ) then
TraceFrame:AddMessage("une vrai region parmi "..i.." = "..sreturn.." : ["..DB_nomregionbynum(sreturn).."]");
end
		end
	end
	return sreturn;

end

function DBmobs_ajoutmob(nommob,numregion,x,y,niv,classe,famille,stype,plusmob,nbcorp,nbskin)

local sposition;
local ipos;
local tablo = {};
local inumobjet;
local bplan = false;

	if ( not DBMS ) then
		DBMS = {};
	end
	if ( not DBMS[nommob] ) then
		DBMS[nommob] = {};
	end
	if ( classe == "artisanat" ) then
		if ( numregion == "000" ) then
			numregion = "0";
		end
		if ( numregion == "0" ) then
			numregion = "1";
		end
		--if ( DBMS[nommob]["000"] ) then
		--	DBMS[nommob]["000"] = nil;
		--end
	end
	if ( not DBMS[nommob][numregion] ) then
		DBMS[nommob][numregion] = {};
		DBMS[nommob][numregion][7] = 0;
	end
	if ( classe == "artisanat" ) then
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("artisanat");
--end
		if ( stype == "d\195\169senchanter" or stype == "prospection" or stype == "mouture" ) then
		else
			if ( famille == nil or famille == "" ) then
				famille = DBMS[nommob][numregion][4];
			end
			if ( DBMS[nommob][numregion] and DBMS[nommob][numregion][8] ) then
				DBMS[nommob][numregion][8] = DBmobs_champ_8_en_nombre(DBMS[nommob][numregion][8]);
				for inumobjet, _ in pairs(DBMS[nommob][numregion][8]) do
					--if ( DBMS[nommob][numregion][8][inumobjet]["0:0:0:0:0:0:0"] and DBMS[nommob][numregion][8][inumobjet]["0:0:0:0:0:0:0"] == 0 ) then
					if ( DBMS[nommob][numregion][8][inumobjet] == 0 ) then
						tablo[inumobjet] = 0;
						bplan = true;
					end
				end
			end
			DBMS[nommob][numregion] = nil;
			DBMS[nommob][numregion] = {};
			DBMS[nommob][numregion][7] = 0;
			if ( bplan == true ) then
				DBMS[nommob][numregion][8] = {};
				for inumobjet, _ in pairs(tablo) do
					--DBMS[nommob][numregion][8][inumobjet] = {};
					--DBMS[nommob][numregion][8][inumobjet]["0:0:0:0:0:0:0"] = 0;
					DBMS[nommob][numregion][8][inumobjet] = 0;
				end
			end
		end
	end
	if ( classe and classe == "quete" and DBMS[nommob][numregion][3] ) then
		-- si la classe du mob est "quete" et que sa classe est déjà connue ds mon dbcs, je ne le remplace pas ( ca arrive quand le dbcs de l'émetteur ne connaissais pas ce mob
	else
		if ( DBMS[nommob][numregion][1] and DBMS[nommob][numregion][1] > 0 ) then
			if ( niv < DBMS[nommob][numregion][1] ) then
				DBMS[nommob][numregion][1] = niv;
			end
		else
			DBMS[nommob][numregion][1] = niv;
		end
		if ( DBMS[nommob][numregion][2] ) then
			if ( ( niv < 99 ) and ( niv > DBMS[nommob][numregion][2] or DBMS[nommob][numregion][2] == 99 ) ) then
				DBMS[nommob][numregion][2] = niv;
			end
		else
			DBMS[nommob][numregion][2] = niv;
		end
		DBMS[nommob][numregion][3] = classe;
		DBMS[nommob][numregion][4] = famille;
		DBMS[nommob][numregion][5] = stype;
		DBMS[nommob][numregion][6] = plusmob;
	end
	--if ( DBCS_chefdegroupe() == 0 ) then
		if ( DBMS[nommob][numregion][7] ) then
			DBMS[nommob][numregion][7] = DBMS[nommob][numregion][7] + nbcorp;
		else
			DBMS[nommob][numregion][7] = nbcorp;
		end
		if ( DBMS[nommob][numregion][9] ) then
			DBMS[nommob][numregion][9] = DBMS[nommob][numregion][9] + nbskin;
		else
			DBMS[nommob][numregion][9] = nbskin;
		end
	--end
	
	if ( DBMS[nommob][numregion][10] == nil ) then
		DBMS[nommob][numregion][10] = "";
	end
	if ( x == 0 and y == 0 ) then
	else
		--sposition = x.."Y"..y.."@";
		sposition = floor(x+.5).."Y"..floor(y+.5).."@";
		ipos = strfind(DBMS[nommob][numregion][10],sposition,1);
		if ( ipos == nil or DBMS[nommob][numregion][10] == "" ) then
			DBMS[nommob][numregion][10] = DBMS[nommob][numregion][10]..sposition;
		end
	end
	DBMS[nommob][numregion][12] = DBCS_date();

end

function DBmobs_ajoutmob2(nommob,numregion,x,y,niv,classe,famille,stype,plusmob,nbcorp,nbskin)

local sposition;
local ipos;
local ideb;
local nposition;
local ecartx;
local ecarty;
local a;
local b;
local elemx;
local elemy;
local elemgauchex,elemgauchey;
local elemdroitex,elemdroitey;
local elemhautx,elemhauty;
local elembasx,elembasy;
local smot;
local bexist = false;
local tablo = {};
local inumobjet;
local bplan = false;

if ( DBCS_debug > 1 ) then
TraceFrame:AddMessage("nommob : "..nommob.." , numregion : "..numregion.." , nomregion : "..DBCS_Region_nom_region(numregion));
end

	if ( not DBMS ) then
		DBMS = {};
	end
	if ( not DBMS[nommob] ) then
		DBMS[nommob] = {};
	end
	if ( classe == "artisanat" ) then
		if ( numregion == "000" ) then
			numregion = "0";
		end
		if ( numregion == "0" ) then
			numregion = "1";
		end
		--if ( DBMS[nommob]["000"] ) then
		--	DBMS[nommob]["000"] = nil;
		--end
	end
	if ( not DBMS[nommob][numregion] ) then
		DBMS[nommob][numregion] = {};
		DBMS[nommob][numregion][7] = 0;
	end
	if ( classe == "artisanat" ) then
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("artisanat2");
--end
		if ( stype == "d\195\169senchanter" or stype == "prospection" or stype == "mouture" ) then
		else
			--if ( DBMS[nommob][numregion] ) then
			--	if ( DBMS[nommob][numregion][4] == nil or DBMS[nommob][numregion][4] == "" ) then
			--	else
			--		if ( famille == nil or famille == "" ) then
			--		else
			--			famille = DBMS[nommob][numregion][4];
			--		end
			--	end
			--end
			if ( famille == nil or famille == "" ) then
				famille = DBMS[nommob][numregion][4];
			end
			if ( DBMS[nommob][numregion] and DBMS[nommob][numregion][8] ) then
				DBMS[nommob][numregion][8] = DBmobs_champ_8_en_nombre(DBMS[nommob][numregion][8]);
				for inumobjet, _ in pairs(DBMS[nommob][numregion][8]) do
					--if ( DBMS[nommob][numregion][8][inumobjet]["0:0:0:0:0:0:0"] and DBMS[nommob][numregion][8][inumobjet]["0:0:0:0:0:0:0"] == 0 ) then
					if ( DBMS[nommob][numregion][8][inumobjet] == 0 ) then
						tablo[inumobjet] = 0;
						bplan = true;
					end
				end
			end
			DBMS[nommob][numregion] = nil;
			DBMS[nommob][numregion] = {};
			DBMS[nommob][numregion][7] = 0;
			if ( bplan == true ) then
				DBMS[nommob][numregion][8] = {};
				for inumobjet, _ in pairs(tablo) do
					--DBMS[nommob][numregion][8][inumobjet] = {};
					--DBMS[nommob][numregion][8][inumobjet]["0:0:0:0:0:0:0"] = 0;
					DBMS[nommob][numregion][8][inumobjet] = 0;
				end
			end
		end
	end
	if ( DBMS[nommob][numregion][1] ) then
		if ( niv < DBMS[nommob][numregion][1] ) then
			DBMS[nommob][numregion][1] = niv;
		end
	else
		DBMS[nommob][numregion][1] = niv;
	end
	if ( DBMS[nommob][numregion][2] ) then
		if ( ( niv < 99 ) and ( niv > DBMS[nommob][numregion][2] or DBMS[nommob][numregion][2] == 99 ) ) then
			DBMS[nommob][numregion][2] = niv;
		end
	else
		DBMS[nommob][numregion][2] = niv;
	end
	DBMS[nommob][numregion][3] = classe;
	DBMS[nommob][numregion][4] = famille;
	DBMS[nommob][numregion][5] = stype;
	DBMS[nommob][numregion][6] = plusmob;
	--if ( DBCS_chefdegroupe() == 0 ) then
		if ( DBMS[nommob][numregion][7] ) then
			DBMS[nommob][numregion][7] = DBMS[nommob][numregion][7] + nbcorp;
		else
			DBMS[nommob][numregion][7] = nbcorp;
		end
		if ( DBMS[nommob][numregion][9] ) then
			DBMS[nommob][numregion][9] = DBMS[nommob][numregion][9] + nbskin;
		else
			DBMS[nommob][numregion][9] = nbskin;
		end
	--end
	
	if ( DBMS[nommob][numregion][10] == nil ) then
		DBMS[nommob][numregion][10] = "";
	end
	--if ( ( tonumber(sdate) < 20070523 ) and ( sclasse == "paysage" ) and ( stype == "Coffre" ) and ( sfamille == "Minage" ) ) then
	if ( x == 0 and y == 0 ) then
	else
if ( DBCS_debug > 1 ) then
TraceFrame:AddMessage("x : "..x.." , y : "..y);
end
		--a,b = DB_indexregionbynum(numregion);
		--ecartx = DBCS_RegionData[a][b].ressx;
		--ecarty = DBCS_RegionData[a][b].ressy;
		_, _, _, _, _, _, _, _, ecartx, ecarty, _, _ = DBCS_Region_nom_carte(numregion);
if ( DBCS_debug > 1 ) then
TraceFrame:AddMessage("ecartx : "..ecartx.." , ecarty : "..ecarty);
end

		if ( ecartx > 0 and ecarty > 0 ) then
		
			if ( DBMS[nommob][numregion][11] == nil ) then
				DBMS[nommob][numregion][11] = {};
			end
			
			elemgauchex = x;
			elemgauchey = y;
			elemdroitex = x;
			elemdroitey = y;
			elemhautx = x;
			elemhauty = y;
			elembasx = x;
			elembasy = y;
							
			sposition = "";
			for nposition, _ in pairs(DBMS[nommob][numregion][11]) do
				if ( sposition == "" ) then
					ipos = strfind(nposition,"@",1);
					if ( ipos ) then
						elemx = tonumber(strsub(nposition,1,ipos-1));
						elemy = tonumber(strsub(nposition,ipos+1));
						if ( ( math.abs(x-elemx) < ecartx ) and  ( math.abs(y-elemy) < ecarty ) ) then
						
							bexist = true;
							
							sposition = nposition;
if ( DBCS_debug > 1 ) then
TraceFrame:AddMessage("milieu avant : "..sposition);
end
							
							smot = DBMS[nommob][numregion][11][sposition];
if ( DBCS_debug > 1 ) then
TraceFrame:AddMessage("4pos avant : "..smot);
end
							
							ideb = 0;
							ipos = strfind(smot,"@",ideb+1);
							if ( ipos ) then
								elemgauchex = tonumber(strsub(smot,ideb+1,ipos-1));
								ideb = ipos;
							end
							ipos = strfind(smot,"@",ideb+1);
							if ( ipos ) then
								elemgauchey = tonumber(strsub(smot,ideb+1,ipos-1));
								ideb = ipos;
							end
							ipos = strfind(smot,"@",ideb+1);
							if ( ipos ) then
								elemdroitex = tonumber(strsub(smot,ideb+1,ipos-1));
								ideb = ipos;
							end
							ipos = strfind(smot,"@",ideb+1);
							if ( ipos ) then
								elemdroitey = tonumber(strsub(smot,ideb+1,ipos-1));
								ideb = ipos;
							end
							ipos = strfind(smot,"@",ideb+1);
							if ( ipos ) then
								elemhautx = tonumber(strsub(smot,ideb+1,ipos-1));
								ideb = ipos;
							end
							ipos = strfind(smot,"@",ideb+1);
							if ( ipos ) then
								elemhauty = tonumber(strsub(smot,ideb+1,ipos-1));
								ideb = ipos;
							end
							ipos = strfind(smot,"@",ideb+1);
							if ( ipos ) then
								elembasx = tonumber(strsub(smot,ideb+1,ipos-1));
								ideb = ipos;
							end
							ipos = strfind(smot,"@",ideb+1);
							if ( ipos ) then
								elembasy = tonumber(strsub(smot,ideb+1,ipos-1));
								ideb = ipos;
							end
							
							if ( x < elemgauchex ) then
								elemgauchex = x;
								elemgauchey = y;
							end
							if ( x > elemdroitex ) then
								elemdroitex = x;
								elemdroitey = y;
							end
							if ( y < elemhauty ) then
								elemhautx = x;
								elemhauty = y;
							end
							if ( y > elembasy ) then
								elembasx = x;
								elembasy = y;
							end
							
							DBMS[nommob][numregion][11][sposition] = nil;
							
						end
					end
				end
			end
			
			if ( bexist == false ) then
if ( DBCS_debug > 1 ) then
TraceFrame:AddMessage("je lance DBCS_memo_region_init.");
end
				DBCS_memo_region_init(numregion);
			end
			
			sposition = ""..((elemgauchex+elemdroitex)/2).."@"..((elemhauty+elembasy)/2);
if ( DBCS_debug > 1 ) then
TraceFrame:AddMessage("milieu apres : "..sposition);
end

			DBMS[nommob][numregion][11][sposition] = ""..elemgauchex.."@"..elemgauchey.."@"..elemdroitex.."@"..elemdroitey.."@"..elemhautx.."@"..elemhauty.."@"..elembasx.."@"..elembasy;
if ( DBCS_debug > 1 ) then
TraceFrame:AddMessage("4pos apres : "..DBMS[nommob][numregion][11][sposition]);
end

		end
		x = floor(x+.5);
		y = floor(y+.5);
		sposition = x.."Y"..y.."@";
		ipos = strfind(DBMS[nommob][numregion][10],sposition,1);
		if ( ipos == nil or DBMS[nommob][numregion][10] == "" ) then
			DBMS[nommob][numregion][10] = DBMS[nommob][numregion][10]..sposition;
		end
	end
	DBMS[nommob][numregion][12] = DBCS_date();

end

function DBmobs_envoyerloot(slangue,sdate,slead,stime,numloot,numobjet,numcourt2,nb)

local message;

	message = "";
	message = message.."@ADBCS@";
	message = message..slangue.."@";
	message = message.."LA01@";
	message = message..sdate.."@";
	message = message..slead.."@";
	message = message..stime.."@";
	message = message..numloot.."@";
	message = message..numobjet.."@";
	message = message..numcourt2.."@";
	message = message..nb.."@";
	DBCS_SendChatMessage(message,"CHANNEL",DBCS_language,DBCS_CMS_numcanalCMS);

end

function DBmobs_supprimerloot(nommob,numregion,numobjet)

local bbon = false;

	if ( DBMS ) then
		if ( DBMS[nommob] ) then
			if ( DBMS[nommob][numregion] ) then
				if ( DBMS[nommob][numregion][8] ) then
					if ( DBMS[nommob][numregion][8][numobjet] ) then
--TraceFrame:AddMessage("supprimer loot : nommob = "..nommob..", numregion = "..numregion..", numobjet = "..numobjet);
						DBMS[nommob][numregion][8][numobjet] = nil;
						bbon = true;
					end
				--else
				--	DBMS[nommob][numregion][8] = {};
				end
			end
		end
	end

	return bbon;

end

function DBmobs_ajoutloot(nommob,numregion,numobjet,numcourt2,nb)

local ipos;
local ideb;
local scode6;
local i;

	DBOS_tooltip_surqui[numobjet] = nil;
	DBmobs_DBOA_sauvegarde(numobjet,numcourt2);
	if ( numcourt2 == "0:0:0:0:0:0:0:0:0" ) then
	else
		-- ne garder que le 6 eme élément	-- ( sans bruce willis )
		i = 0;
		ipos = 0;
		while ( ipos and i < 5 ) do
			i = i + 1;
			ipos = strfind(numcourt2,":",ipos+1);
		end
		if ( i == 5 and ipos ) then
			ideb = ipos;
			ipos = strfind(numcourt2,":",ipos+1);
			scode6 = strsub(numcourt2,ideb+1,ipos-1);
--TraceFrame:AddMessage("code6 = "..scode6);
			numcourt2 = "0:0:0:0:0:"..scode6..":0:0:0";
		else
			numcourt2 = "0:0:0:0:0:0:0:0:0";
		end
	end

--TraceFrame:AddMessage("trace : 01");
	if ( DBMS ) then
--TraceFrame:AddMessage("trace : 02"..nommob);
		if ( DBMS[nommob] ) then
--TraceFrame:AddMessage("trace : 03"..numzone);
			if ( numregion == "0" ) then
				if ( ( DBMS[nommob]["0"] and DBMS[nommob]["0"][3] == "artisanat" ) or ( DBMS[nommob]["1"] and DBMS[nommob]["1"][3] == "artisanat" ) ) then
					numregion = "1";
				end
			end
			if ( DBMS[nommob][numregion] ) then
--TraceFrame:AddMessage("trace : 04".."8");
				if ( DBMS[nommob][numregion][8] ) then
					DBMS[nommob][numregion][8] = DBmobs_champ_8_en_nombre(DBMS[nommob][numregion][8]);
				else
--TraceFrame:AddMessage("trace : 05");
					DBMS[nommob][numregion][8] = {};
				end
--TraceFrame:AddMessage("trace : 06"..numobjet);
				if ( DBMS[nommob][numregion][8][numobjet] ) then
				else
--TraceFrame:AddMessage("trace : 07");
					--DBMS[nommob][numregion][8][numobjet] = {};
--TraceFrame:AddMessage("trace : 08"..numcourt2);
					--DBMS[nommob][numregion][8][numobjet][numcourt2] = 0;
					DBMS[nommob][numregion][8][numobjet] = 0;
				end
--TraceFrame:AddMessage("trace : 09"..nb);
				--if ( DBCS_chefdegroupe() == 0 ) then
				--if ( DBMS[nommob][numregion][8][numobjet][numcourt2] ) then
--TraceFrame:AddMessage("trace : 10");
				--	DBMS[nommob][numregion][8][numobjet][numcourt2] = DBMS[nommob][numregion][8][numobjet][numcourt2] + nb;
				--else
--TraceFrame:AddMessage("trace : 11");
				--	DBMS[nommob][numregion][8][numobjet][numcourt2] = nb;
				--end
				--end
				DBMS[nommob][numregion][8][numobjet] = DBMS[nommob][numregion][8][numobjet] + nb;
				return true;
			else
				return false;
			end
		else
			return false;
		end
	else
		return false;
	end

end

function DBmobs_envoyerloot2(slangue,sdate,slead,stime,numloot,numobjet,numcourt2,nb)

local message;

	message = "";
	message = message.."@ADBCS@";
	message = message..slangue.."@";
	message = message.."LA02@";
	message = message..sdate.."@";
	message = message..slead.."@";
	message = message..stime.."@";
	message = message..numloot.."@";
	message = message..numobjet.."@";
	message = message..numcourt2.."@";
	message = message..nb.."@";
	DBCS_SendChatMessage(message,"CHANNEL",DBCS_language,DBCS_CMS_numcanalCMS);

end

function DBmobs_ajoutloot2(nommob,numregion,numobjet,numcourt2,nb)

local ipos;
local ideb;
local scode6;
local i;

	DBmobs_DBOA_sauvegarde(numobjet,numcourt2);
	if ( numcourt2 == "0:0:0:0:0:0:0:0:0" ) then
	else
		-- ne garder que le 6 eme élément	-- ( sans bruce willis )
		i = 0;
		ipos = 0;
		while ( ipos and i < 5 ) do
			i = i + 1;
			ipos = strfind(numcourt2,":",ipos+1);
		end
		if ( i == 5 and ipos ) then
			ideb = ipos;
			ipos = strfind(numcourt2,":",ipos+1);
			scode6 = strsub(numcourt2,ideb+1,ipos-1);
--TraceFrame:AddMessage("code6 = "..scode6);
			numcourt2 = "0:0:0:0:0:"..scode6..":0:0:0";
		else
			numcourt2 = "0:0:0:0:0:0:0:0:0";
		end
	end

--TraceFrame:AddMessage("trace : 01");
	if ( DBMS ) then
--TraceFrame:AddMessage("trace : 02"..nommob);
		if ( DBMS[nommob] ) then
--TraceFrame:AddMessage("trace : 03"..numzone);
			if ( numregion == "0" ) then
				if ( ( DBMS[nommob]["0"] and DBMS[nommob]["0"][3] == "artisanat" ) or ( DBMS[nommob]["1"] and DBMS[nommob]["1"][3] == "artisanat" ) ) then
				--if ( DBMS[nommob][numregion][3] == "artisanat" ) then
					numregion = "1";
				end
			end
			if ( DBMS[nommob][numregion] ) then
--TraceFrame:AddMessage("trace : 04".."8");
				if ( DBMS[nommob][numregion][8] ) then
					DBMS[nommob][numregion][8] = DBmobs_champ_8_en_nombre(DBMS[nommob][numregion][8]);
				else
--TraceFrame:AddMessage("trace : 05");
					DBMS[nommob][numregion][8] = {};
				end
--TraceFrame:AddMessage("trace : 06"..numobjet);
				if ( DBMS[nommob][numregion][8][numobjet] ) then
				else
--TraceFrame:AddMessage("trace : 07");
					--DBMS[nommob][numregion][8][numobjet] = {};
--TraceFrame:AddMessage("trace : 08"..numcourt2);
					--DBMS[nommob][numregion][8][numobjet][numcourt2] = 0;
					DBMS[nommob][numregion][8][numobjet] = 0;
				end
--TraceFrame:AddMessage("trace : 09"..nb);
				--if ( DBCS_chefdegroupe() == 0 ) then
				--if ( DBMS[nommob][numregion][8][numobjet][numcourt2] ) then
--TraceFrame:AddMessage("trace : 10");
				--	DBMS[nommob][numregion][8][numobjet][numcourt2] = DBMS[nommob][numregion][8][numobjet][numcourt2] + nb;
				--else
--TraceFrame:AddMessage("trace : 11");
				--	DBMS[nommob][numregion][8][numobjet][numcourt2] = nb;
				--end
				--end
				DBMS[nommob][numregion][8][numobjet] = DBMS[nommob][numregion][8][numobjet] + nb;
				return true;
			else
				return false;
			end
		else
			return false;
		end
	else
		return false;
	end

end

function DBmobs_TrierConnaissanceBete(mob1,mob2,t_ordre,niveaufonction)

	local s_champ = t_ordre[niveaufonction].champ;
	local s_sens = t_ordre[niveaufonction].sens;
	local val1,val2;
	local bfin;
	local j;
	local ipos;
	local a;

	if ( s_champ == "nommob" ) then
		val1 = mob1[1];
		val2 = mob2[1];
	elseif ( s_champ == "niveau") then
		val1 = mob1[3];
		if ( val1 == nil ) then
			val1 = 0;
		end
		val2 = mob2[3];
		if ( val2 == nil ) then
			val2 = 0;
		end
	elseif ( s_champ == "classe" ) then
		val1 = mob1[4];
		if ( val1 == nil ) then
			val1 = "";
		end
		val2 = mob2[4];
		if ( val2 == nil ) then
			val2 = "";
		end
	elseif ( s_champ == "famille" ) then
		val1 = mob1[6];
		if ( val1 == nil ) then
			val1 = "";
		end
		val2 = mob2[6];
		if ( val2 == nil ) then
			val2 = "";
		end
	elseif ( s_champ == "dmin") then
		val1 = mob1[7];
		if ( val1 == nil ) then
			val1 = 0;
		end
		val2 = mob2[7];
		if ( val2 == nil ) then
			val2 = 0;
		end
	elseif ( s_champ == "dmax") then
		val1 = mob1[8];
		if ( val1 == nil ) then
			val1 = 0;
		end
		val2 = mob2[8];
		if ( val2 == nil ) then
			val2 = 0;
		end
	elseif ( s_champ == "armure") then
		val1 = mob1[9];
		if ( val1 == nil ) then
			val1 = 0;
		end
		val2 = mob2[9];
		if ( val2 == nil ) then
			val2 = 0;
		end
	elseif ( s_champ == "pdv") then
		val1 = mob1[10];
		if ( val1 == nil ) then
			val1 = 0;
		end
		val2 = mob2[10];
		if ( val2 == nil ) then
			val2 = 0;
		end
	elseif ( s_champ == "nomregion") then
		val1 = DB_nomregionbynum(mob1[2]);
		if ( val1 == nil ) then
			val1 = "";
		end
		val2 = DB_nomregionbynum(mob2[2]);
		if ( val2 == nil ) then
			val2 = "";
		end
	else
		val1 = mob1[1];
		val2 = mob2[1];
	end

	if ( s_sens == "ASC" ) then
		if ( val1 < val2 ) then
			return true;
		elseif ( val1 == val2 ) then
		else
			return false;
		end
	else
		if ( val1 > val2 ) then
			return true;
		elseif ( val1 == val2 ) then
		else
			return false;
		end
	end
	if ( val1 == val2 ) then
		if ( table.getn(t_ordre) > niveaufonction ) then
			return DBmobs_TrierConnaissanceBete(mob1,mob2,t_ordre,niveaufonction+1);
		else
			return false;
		end
	else
		return false; -- pas normal d etre ici
	end

end

function DBmobs_Trier(mob1,mob2,t_ordre,niveaufonction)

	local s_champ = t_ordre[niveaufonction].champ;
	local s_sens = t_ordre[niveaufonction].sens;
	local val1,val2;
	local bfin;
	local j;
	local ipos;
	local a;

	if ( s_champ == "nommob" ) then
		val1 = mob1[1];
		val2 = mob2[1];
	elseif ( s_champ == "numregion") then
		val1 = mob1[2];
		val2 = mob2[2];
	elseif ( s_champ == "nomregion") then
		val1 = DB_nomregionbynum(mob1[2]);
		if ( val1 == nil ) then
			val1 = "";
		end
		val2 = DB_nomregionbynum(mob2[2]);
		if ( val2 == nil ) then
			val2 = "";
		end
	elseif ( s_champ == "nivmin") then
		val1 = DBMS[mob1[1]][mob1[2]][1];
		if ( val1 == nil ) then
			val1 = 0;
		end
		val2 = DBMS[mob2[1]][mob2[2]][1];
		if ( val2 == nil ) then
			val2 = 0;
		end
	elseif ( s_champ == "nivmax") then
		val1 = DBMS[mob1[1]][mob1[2]][2];
		if ( val1 == nil ) then
			val1 = 0;
		end
		val2 = DBMS[mob2[1]][mob2[2]][2];
		if ( val2 == nil ) then
			val2 = 0;
		end
	elseif ( s_champ == "classe") then
		val1 = DBMS[mob1[1]][mob1[2]][3];
		if ( val1 == nil ) then
			val1 = "";
		end
		val2 = DBMS[mob2[1]][mob2[2]][3];
		if ( val2 == nil ) then
			val2 = "";
		end
	elseif ( s_champ == "famille") then
		val1 = DBMS[mob1[1]][mob1[2]][4];
		if ( val1 == nil ) then
			val1 = "";
		end
		val2 = DBMS[mob2[1]][mob2[2]][4];
		if ( val2 == nil ) then
			val2 = "";
		end
	elseif ( s_champ == "type") then
		val1 = DBMS[mob1[1]][mob1[2]][5];
		if ( val1 == nil ) then
			val1 = "";
		end
		val2 = DBMS[mob2[1]][mob2[2]][5];
		if ( val2 == nil ) then
			val2 = "";
		end
	elseif ( s_champ == "plusmob") then
		val1 = DBMS[mob1[1]][mob1[2]][6];
		if ( val1 == nil ) then
			val1 = "";
		end
		val2 = DBMS[mob2[1]][mob2[2]][6];
		if ( val2 == nil ) then
			val2 = "";
		end
	elseif ( s_champ == "nbcorps") then
		val1 = DBMS[mob1[1]][mob1[2]][7];
		if ( val1 == nil ) then
			val1 = 0;
		end
		val2 = DBMS[mob2[1]][mob2[2]][7];
		if ( val2 == nil ) then
			val2 = 0;
		end
	elseif ( s_champ == "nbskin") then
		if ( DBMS[mob1[1]][mob1[2]][4] == "Minage" or DBMS[mob1[1]][mob1[2]][4] == "Ouverture" or DBMS[mob1[1]][mob1[2]][4] == "Cueillette" ) then
			val1 = 0;
			if ( DBMS[mob1[1]][mob1[2]][11] ) then
				for a, _ in pairs(DBMS[mob1[1]][mob1[2]][11]) do
					val1 = val1 + 1;
				end
			else
			end
		else
			val1		= DBMS[mob1[1]][mob1[2]][9];
		end
		--val1 = DBMS[mob1[1]][mob1[2]][9];
		if ( val1 == nil ) then
			val1 = 0;
		end
		if ( DBMS[mob2[1]][mob2[2]][4] == "Minage" or DBMS[mob2[1]][mob2[2]][4] == "Ouverture" or DBMS[mob2[1]][mob2[2]][4] == "Cueillette" ) then
			val2 = 0;
			if ( DBMS[mob2[1]][mob2[2]][11] ) then
				for a, _ in pairs(DBMS[mob2[1]][mob2[2]][11]) do
					val2 = val2 + 1;
				end
			else
			end
		else
			val2		= DBMS[mob2[1]][mob2[2]][9];
		end
		--val2 = DBMS[mob2[1]][mob2[2]][9];
		if ( val2 == nil ) then
			val2 = 0;
		end
	elseif ( s_champ == "salaire" ) then
		val1 = mob1[4];
		if ( val1 == nil ) then
			val1 = 0;
		end
		val2 = mob2[4];
		if ( val2 == nil ) then
			val2 = 0;
		end
	elseif ( s_champ == "pctdrop") then
		val1 = mob1[3];
		if ( val1 == nil ) then
			val1 = 0;
		end
		val2 = mob2[3];
		if ( val2 == nil ) then
			val2 = 0;
		end
	elseif ( s_champ == "nommobminage") then
		val1 = 1000;
		bfin = 0;
		j = 0;
		while ( bfin == 0 and j < table.getn(DBCS_minage) ) do
			j = j + 1;
			ipos = strfind(strlower(mob1[1]),DBCS_minage[j].nomminerai,1);
			if ( ipos ) then
				if ( DBCS_minage[j].special ) then
					ipos = strfind(strlower(mob1[1]),DBCS_minage[j].special,1);
					if ( ipos ) then
						val1 = j;
						bfin = 1;
					end
				else
					val1 = j;
					bfin = 1;
				end
			end
		end
		val2 = 1000;
		bfin = 0;
		j = 0;
		while ( bfin == 0 and j < table.getn(DBCS_minage) ) do
			j = j + 1;
			ipos = strfind(strlower(mob2[1]),DBCS_minage[j].nomminerai,1);
			if ( ipos ) then
				if ( DBCS_minage[j].special ) then
					ipos = strfind(strlower(mob2[1]),DBCS_minage[j].special,1);
					if ( ipos ) then
						val2 = j;
						bfin = 1;
					end
				else
					val2 = j;
					bfin = 1;
				end
			end
		end
	elseif ( s_champ == "nommobcueillette") then
		val1 = 0;
		bfin = 0;
		j = 0;
		while ( bfin == 0 and j < table.getn(DBCS_cueillette) ) do
			j = j + 1;
			if ( strlower(mob1[1]) == DBCS_cueillette[j].nomplante ) then
				val1 = j;
				bfin = 1;
			end
		end
		val2 = 0;
		bfin = 0;
		j = 0;
		while ( bfin == 0 and j < table.getn(DBCS_cueillette) ) do
			j = j + 1;
			if ( strlower(mob2[1]) == DBCS_cueillette[j].nomplante ) then
				val2 = j;
				bfin = 1;
			end
		end
	else
		val1 = mob1[1];
		val2 = mob2[1];
	end

	if ( s_sens == "ASC" ) then
		if ( val1 < val2 ) then
			return true;
		elseif ( val1 == val2 ) then
		else
			return false;
		end
	else
		if ( val1 > val2 ) then
			return true;
		elseif ( val1 == val2 ) then
		else
			return false;
		end
	end
	if ( val1 == val2 ) then
		if ( table.getn(t_ordre) > niveaufonction ) then
			return DBmobs_Trier(mob1,mob2,t_ordre,niveaufonction+1);
		else
			return false;
		end
	else
		return false; -- pas normal d etre ici
	end

end

function DBmobsPNJ_Trier(mob1,mob2,t_ordre,niveaufonction)

local s_champ = t_ordre[niveaufonction].champ;
local s_sens = t_ordre[niveaufonction].sens;
local val1,val2;

	if ( s_champ == "numPNJ" ) then
		val1 = mob1[1];
		val2 = mob2[1];
	elseif ( s_champ == "nomPNJ") then
		if ( DBmobs_Local and DBmobs_Local[mob1[1]] and DBmobs_Local[mob1[1]][1] ) then
			val1 = DBmobs_Local[mob1[1]][1][1];
		else
			val1 = nil;
		end
		if ( val1 == nil ) then
			val1 = "";
		end
		if ( DBmobs_Local and DBmobs_Local[mob2[1]] and DBmobs_Local[mob2[1]][1] ) then
			val2 = DBmobs_Local[mob2[1]][1][1];
		else
			val2 = nil;
		end
		if ( val2 == nil ) then
			val2 = "";
		end
	else
		val1 = mob1[1];
		val2 = mob2[1];
	end

	if ( s_sens == "ASC" ) then
		if ( val1 < val2 ) then
			return true;
		elseif ( val1 == val2 ) then
		else
			return false;
		end
	else
		if ( val1 > val2 ) then
			return true;
		elseif ( val1 == val2 ) then
		else
			return false;
		end
	end
	if ( val1 == val2 ) then
		if ( table.getn(t_ordre) > niveaufonction ) then
			return DBmobsPNJ_Trier(mob1,mob2,t_ordre,niveaufonction+1);
		else
			return false;
		end
	else
		return false; -- pas normal d etre ici
	end

end

function DBmobs_Liste(criteres)

local tablo = {};
local i = 0;
local nommob;
local numregion;
local ibon;
local ipos;
local tMOB;

	if ( DBMS == nil ) then
		return tablo;
	end
	for nommob, _ in pairs(DBMS) do
		ibon = 1;
		if ( ibon == 1 and criteres.nommob and not ( criteres.nommob == "" ) ) then
			ipos, _ = strfind(strlower(nommob),strlower(criteres.nommob));
			if ( not ipos ) then
				ibon = 0;
			end
		end
		if ( ibon == 1 ) then
			for numregion, _ in pairs(DBMS[nommob]) do
				tMOB = DBMS[nommob][numregion];
				ibon = 1;
				if ( ibon == 1 and criteres.numregion ) then
					if ( numregion == criteres.numregion ) then
					else
						ibon = 0;
					end
				end
				if ( ibon == 1 and criteres.nivmin ) then
					if ( tMOB[1] == nil or tMOB[1] < criteres.nivmin ) then
						ibon = 0;
					end
				end
				if ( ibon == 1 and criteres.nivmax ) then
					if ( tMOB[2] > criteres.nivmax ) then
						ibon = 0;
					end
				end
				if ( ibon == 1 and criteres.nbcorpsmin ) then
					if ( ( not tMOB[7] ) or tMOB[7] < criteres.nbcorpsmin ) then
						ibon = 0;
					end
				end
				if ( ibon == 1 and criteres.nbcorpsmax ) then
					if ( tMOB[7] and tMOB[7] > criteres.nbcorpsmax ) then
						ibon = 0;
					end
				end
				if ( ibon == 1 and criteres.nbskinmin ) then
					if ( ( not tMOB[9] ) or tMOB[9] < criteres.nbskinmin ) then
						ibon = 0;
					end
				end
				if ( ibon == 1 and criteres.nbskinmax ) then
					if ( tMOB[9] and tMOB[9] > criteres.nbskinmax ) then
						ibon = 0;
					end
				end
				if ( ibon == 1 and criteres.nomregion and not ( criteres.nomregion == "" ) ) then
					ipos, _ = strfind(strlower(DB_nomregionbynum(numregion)),strlower(criteres.nomregion));
					if ( not ipos ) then
						ibon = 0;
					end
				end
				if ( ibon == 1 and criteres.classe and not ( criteres.classe == "" ) ) then
					if ( tMOB[3] == nil ) then
						ibon = 0;
					else
						ipos, _ = strfind(strlower(tMOB[3]),strlower(criteres.classe));
						if ( not ipos ) then
							ibon = 0;
						end
					end
				end
				if ( ibon == 1 and criteres.type and not ( criteres.type == "" ) ) then
					if ( tMOB[5] == nil ) then
						ibon = 0;
					else
						ipos, _ = strfind(strlower(tMOB[5]),strlower(criteres.type));
						if ( not ipos ) then
							ibon = 0;
						end
					end
				end
				if ( ibon == 1 and criteres.famille and not ( criteres.famille == "" ) ) then
					if ( tMOB[4] == nil ) then
						ibon = 0;
					else
						ipos, _ = strfind(strlower(tMOB[4]),strlower(criteres.famille));
						if ( not ipos ) then
							ibon = 0;
						end
					end
				end
				if ( ibon == 1 ) then
					i = i + 1 ;
					tablo[i] = {};
					tablo[i][1] = nommob;
					tablo[i][2] = numregion;
					tablo[i][4],tablo[i][5] = DBmobs_Salaire(nommob,numregion,criteres.salaireskin);
					--tablo[i][4] = 0;
					--tablo[i][5] = 0;
				end
			end
		end
	end
	return tablo;

end

function DBmobs_ListeConnaissanceBete(criteres)

local tablo = {};
local i = 0;
local nommob;
local numregion;
local ibon;
local tMOB;
local ipos;
local svaleur;
local iniveau;
local b16;
local stechnique,irang;
local sregime;
local tniveau;

	for nommob, _ in pairs(DBMS) do
		ibon = 1;
		if ( ibon == 1 and criteres.nommob and not ( criteres.nommob == "" ) ) then
			ipos, _ = strfind(strlower(nommob),strlower(criteres.nommob));
			if ( not ipos ) then
				ibon = 0;
			end
		end
		if ( ibon == 1 ) then
			for numregion, _ in pairs(DBMS[nommob]) do
				tMOB = DBMS[nommob][numregion];
				ibon = 0;
				if ( ibon == 0 ) then
					if ( tMOB[5] and strlower(tMOB[5]) == "b\195\170te" ) then
						ibon = 1;
					end
				end
				if ( ibon == 0 ) then
					if ( tMOB[13] ) then
						ibon = 1;
					end
				end
				if ( ibon == 1 ) then
					--if ( ibon == 1 and criteres.nivmin ) then
					--	if ( tMOB[1] < criteres.nivmin ) then
					--		ibon = 0;
					--	end
					--end
					--if ( ibon == 1 and criteres.nivmax ) then
					--	if ( tMOB[2] > criteres.nivmax ) then
					--		ibon = 0;
					--	end
					--end
					if ( ibon == 1 and criteres.famille and not ( criteres.famille == "" ) ) then
						ipos, _ = strfind(strlower((tMOB[4] or "")),strlower(criteres.famille));
						if ( not ipos ) then
							ibon = 0;
						end
					end
					if ( ibon == 1 and criteres.nomregion and not ( criteres.nomregion == "" ) ) then
						ipos, _ = strfind(strlower(DB_nomregionbynum(numregion)),strlower(criteres.nomregion));
						if ( not ipos ) then
							ibon = 0;
						end
					end
					if ( ibon == 1 and criteres.technique > -1 ) then
						svaleur = DBCS_ConnaissanceBete_technique[criteres.technique].nom;
						if ( tMOB[15] ) then
							if ( tMOB[15][svaleur] ) then
							else
								ibon = 0;
							end
						else
							ibon = 0;
						end
					end
				end
				if ( ibon == 1 ) then
					tniveau = {};
					tniveau[tMOB[1]] = 1;
					tniveau[tMOB[2]] = 1;
					if ( tMOB[16] ) then
						--b16 = false;
						for iniveau, _ in pairs(tMOB[16]) do
							tniveau[iniveau] = nil;
							--b16 = true;
							ibon = 1;
							if ( ibon == 1 and criteres.nivmin ) then
								if ( iniveau < criteres.nivmin ) then
									ibon = 0;
								end
							end
							if ( ibon == 1 and criteres.nivmax ) then
								if ( iniveau > criteres.nivmax ) then
									ibon = 0;
								end
							end
							if ( ibon == 1 ) then
								i = i + 1 ;
								tablo[i] = {};
								tablo[i][1] = nommob;
								tablo[i][2] = numregion;
								tablo[i][3] = iniveau;
								tablo[i][4] = tMOB[3];
								tablo[i][5] = tMOB[5];
								tablo[i][6] = tMOB[4];
								tablo[i][7] = tMOB[16][iniveau][1];
								tablo[i][8] = tMOB[16][iniveau][2];
								tablo[i][9] = tMOB[16][iniveau][3];
								tablo[i][10] = tMOB[16][iniveau][4];
								tablo[i][11] = tMOB[13];
								if ( tMOB[15] ) then
									tablo[i][12] = "";
									for stechnique, irang in pairs(tMOB[15]) do
										if ( tablo[i][12] == "" ) then
										else
											tablo[i][12] = tablo[i][12]..", ";
										end
										tablo[i][12] = tablo[i][12]..stechnique.."_"..irang;
									end
								end
								if ( tMOB[14] ) then
									tablo[i][13] = "";
									for sregime, _ in pairs(tMOB[14]) do
										if ( tablo[i][13] == "" ) then
										else
											tablo[i][13] = tablo[i][13]..", ";
										end
										tablo[i][13] = tablo[i][13]..sregime;
									end
								end
							end
						end
					end
					for iniveau, _ in pairs(tniveau) do
						if ( iniveau == 0 or iniveau == "0" ) then
						else
							ibon = 1;
							if ( ibon == 1 and criteres.nivmin ) then
								if ( iniveau < criteres.nivmin ) then
									ibon = 0;
								end
							end
							if ( ibon == 1 and criteres.nivmax ) then
								if ( iniveau > criteres.nivmax ) then
									ibon = 0;
								end
							end
							if ( ibon == 1 ) then
								i = i + 1 ;
								tablo[i] = {};
								tablo[i][1] = nommob;
								tablo[i][2] = numregion;
								tablo[i][3] = iniveau;
								tablo[i][4] = tMOB[3];
								tablo[i][5] = tMOB[5];
								tablo[i][6] = tMOB[4];
								tablo[i][11] = tMOB[13];
								if ( tMOB[15] ) then
									tablo[i][12] = "";
									for stechnique, irang in pairs(tMOB[15]) do
										if ( tablo[i][12] == "" ) then
										else
											tablo[i][12] = tablo[i][12]..", ";
										end
										tablo[i][12] = tablo[i][12]..stechnique.."_"..irang;
									end
								end
								if ( tMOB[14] ) then
									tablo[i][13] = "";
									for sregime, _ in pairs(tMOB[14]) do
										if ( tablo[i][13] == "" ) then
										else
											tablo[i][13] = tablo[i][13]..", ";
										end
										tablo[i][13] = tablo[i][13]..sregime;
									end
								end
							end
						end
					end
				end
			end
		end
	end
	return tablo;

end

function DBmobs_Liste_des_mobs_ayant_l_objet(tCRITERES)

local tablo = {};
local i = 0;
local nommob;
local numregion;
local tOBJETS;
local tMOB;
local idiviseur;
local numcourt2;
local isomme;

	for nommob, _ in pairs(DBMS) do
		for numregion, _ in pairs(DBMS[nommob]) do
			if ( DBMS[nommob][numregion][8] ) then
				DBMS[nommob][numregion][8] = DBmobs_champ_8_en_nombre(DBMS[nommob][numregion][8]);
			end
			tMOB = DBMS[nommob][numregion];
			tOBJETS = tMOB[8];
			if ( tOBJETS ) then
				if ( tOBJETS[tCRITERES.numobjet] ) then
					--if ( tCRITERES.numcourt2 == "0:0:0:0:0:0:0" or tOBJETS[tCRITERES.numobjet][tCRITERES.numcourt2] ) then
						i = i +1 ;
						tablo[i] = {};
						tablo[i][1] = nommob;
						tablo[i][2] = numregion;
						if ( tMOB[1] == nil or tMOB[1] == 0 ) then
							idiviseur = tMOB[7];
						else
							if ( DBCORPS_SKIN[tCRITERES.numobjet] ) then
								idiviseur = tMOB[9];
							else
								idiviseur = tMOB[7];
							end
						end
						if ( idiviseur == nil ) then
							idiviseur = 0;
						end
						if ( idiviseur == 0 ) then
							tablo[i][3] = nil;
						else
							--if ( tOBJETS[tCRITERES.numobjet][tCRITERES.numcourt2] ) then
							--	tablo[i][3] = ( tOBJETS[tCRITERES.numobjet][tCRITERES.numcourt2] / idiviseur ) * 100;
							--else
							--	isomme = 0;
							--	for numcourt2, _ in pairs(tOBJETS[tCRITERES.numobjet]) do
							--		isomme = isomme + tOBJETS[tCRITERES.numobjet][numcourt2] ;
							--	end
							--	tablo[i][3] = ( isomme / idiviseur ) * 100;
							--	--tablo[i][3] = nil; -- sommer tous les objets de ce numéro ( numobjet )
							--end
							tablo[i][3] = ( tOBJETS[tCRITERES.numobjet] / idiviseur ) * 100;
						end
					--end
				end
			end
		end
	end
	return tablo;

end

function DBmobsPNJ_Liste(criteres)

local j;
local ibon;
local i = 0;
local tablo = {};
local ipos;
local sval;
local stype;
local srep;
local srep2;
local ssexe;
local snom;
local k;
local imax;

	imax = 0;
	--if ( DBmobs_Local_exist ) then
	--	if ( DBmobs_Local_exist == DBCS_getlocale ) then
	--	else
	--		DBCS_loaded_addon("DBmobs_"..DBCS_getlocale);
	--	end
	--else
	--	DBCS_loaded_addon("DBmobs_"..DBCS_getlocale);
	--end
	if ( DBmobs_Local ) then
		for j , _ in pairs(DBmobs_Local) do
			if ( type(j) == "number" and j > imax ) then
				imax = j;
			end
		end
	end
	if ( DBCS_mobs_model ) then
		for j , _ in pairs(DBCS_mobs_model) do
			if ( j > imax ) then
				imax = j;
			end
		end
	end
	if ( DBCS_mobs_detail ) then
		for j , _ in pairs(DBCS_mobs_detail) do
			if ( j > imax ) then
				imax = j;
			end
		end
	end
	if ( DBCS_mobs_spell ) then
		for j , _ in pairs(DBCS_mobs_spell) do
			if ( j > imax ) then
				imax = j;
			end
		end
	end
	for j = 1 , imax do
		ibon = 0;
		if ( ibon == 0 and DBmobs_Local ) then
			if ( DBmobs_Local[j] ) then
				ibon = 1;
			end
		end
		if ( ibon == 0 and DBCS_mobs_model ) then
			if ( DBCS_mobs_model[j] ) then
				ibon = 1;
			end
		end
		if ( ibon == 0 and DBCS_mobs_detail ) then
			if ( DBCS_mobs_detail[j] ) then
				ibon = 1;
			end
		end
		if ( ibon == 0 and DBCS_mobs_spell ) then
			if ( DBCS_mobs_spell[j] ) then
				ibon = 1;
			end
		end
		--ibon = 1;
		if ( ibon == 1 and criteres.numPNJ ) then
			if ( j == criteres.numPNJ ) then
			else
				ibon = 0;
			end
		end
		if ( ibon == 1 and criteres.nomPNJ and not ( criteres.nomPNJ == "" ) ) then
			sval = nil;
			if ( DBmobs_Local and DBmobs_Local[j] and DBmobs_Local[j][1] ) then
				sval = DBmobs_Local[j][1][1];
			end
			if ( sval == nil ) then
				ibon = 0;
			else
				ipos, _ = strfind(strlower(sval),strlower(criteres.nomPNJ));
				if ( not ipos ) then
					ibon = 0;
				end
			end
		end
		if ( ibon == 1 and criteres.type and criteres.type > 0 ) then
			ibon = 0;
			if ( DBCS_mobs_model and DBCS_mobs_model[j] and DBCS_mobs_model[j][1] ) then
				sval = DBCS_mobs_model[j][1].model;
				sval = string.gsub(sval,"\\","/");
				stype, srep, ssexe, snom = strsplit("/",sval,4);
				if ( stype == "creature" ) then
					if ( snom == nil or snom == "" ) then
						snom = srep.."/"..ssexe;
					else
						snom = srep.."/"..ssexe.."/"..snom;
					end
				end
				if ( stype == DBmobsPNJ_Combo_t[criteres.type].nom ) then
					ibon = 1;
				end
				if ( ibon == 1 and criteres.rep and criteres.rep > 0 ) then
					ibon = 0;
					if ( stype == "creature" ) then
						srep2 = strsub(srep,1,1);
					else
						srep2 = srep;
					end
					if ( srep2 == DBmobsPNJ_Combo_t[criteres.type][criteres.rep].nom ) then
						ibon = 1;
					end
				end
				if ( ibon == 1 and criteres.sexe and criteres.sexe > 0 ) then
					ibon = 0;
					if ( stype == "creature" ) then
						ibon = 1;
					else
						if ( ssexe == DBmobsPNJ_Combo_t[criteres.type][criteres.rep][criteres.sexe].nom ) then
							ibon = 1;
						end
					end
				end
				if ( ibon == 1 and criteres.nom and criteres.nom > 0 ) then
					ibon = 0;
					if ( snom == DBmobsPNJ_Combo_t[criteres.type][criteres.rep][criteres.sexe][criteres.nom].nom ) then
						ibon = 1;
					end
				end
			end
		end
		if ( ibon == 1 and criteres.type2 and criteres.type2 > 0 ) then
			ibon = 0;
			if ( DBCS_mobs_detail and DBCS_mobs_detail[j] and DBCS_mobs_detail[j][3] and DBCS_mobs_detail[j][3] == criteres.type2 ) then
				ibon = 1;
			end
		end
		if ( ibon == 1 and criteres.classe and criteres.classe > 0 ) then
			ibon = 0;
			if ( DBCS_mobs_detail and DBCS_mobs_detail[j] ) then
				if ( DBCS_mobs_detail[j][11] and DBCS_mobs_detail[j][11] == criteres.classe ) then
					ibon = 1;
				elseif ( criteres.classe == 4 and DBCS_mobs_detail[j][2] ) then
					ibon = 1;
				elseif ( criteres.classe == 6 and DBCS_mobs_detail[j][9] ) then
					ibon = 1;
				end
			end
		end
		if ( ibon == 1 and criteres.numregion ) then
			ibon = 0;
			if ( DBCS_mobs_locs and DBCS_mobs_locs[j] and DBCS_mobs_locs[j][criteres.numregion] ) then
				ibon = 1;
			end
		end
		if ( ibon == 1 ) then
			i = i + 1 ;
			tablo[i] = {};
			tablo[i][1] = j;
		end
	end
	return tablo;

end

--/script DBmobsPNJ_Nettoyer();
function DBmobsPNJ_Nettoyer()

local i;
local j;
local k;
local sval;
local bbad;
--local itime;
--local l;

	--itime = GetTime();
	--l = 0;
	if ( DBCS_mobs_model ) then
		for i, _ in pairs(DBCS_mobs_model)  do
			if ( DBCS_mobs_model[i] == nil ) then
			else
			--l = l + 1;
--TraceFrame:AddMessage("DBmobsPNJ_Nettoyer i = "..(i));
				for j = 1 , table.getn(DBCS_mobs_model[i]) do
--TraceFrame:AddMessage("DBmobsPNJ_Nettoyer j = "..(j));
					DBCS_mobs_model[i][j]["model"] = string.gsub(DBCS_mobs_model[i][j]["model"],"\\","/");
				end
				for j = table.getn(DBCS_mobs_model[i]) , 2 , -1 do
--TraceFrame:AddMessage("DBmobsPNJ_Nettoyer j = "..(j));
					sval = DBCS_mobs_model[i][j]["model"];
					bbad = false;
					for k = j-1 , 1 , -1 do
--TraceFrame:AddMessage("DBmobsPNJ_Nettoyer k = "..(k));
						if ( sval == DBCS_mobs_model[i][k]["model"] ) then
							bbad = true;
						--exit do;
						end
					end
					if ( bbad == true ) then
						table.remove(DBCS_mobs_model[i],j);
					end
				end
			end
		end
--TraceFrame:AddMessage("DBmobsPNJ_Nettoyer time = "..(GetTime()-itime));
	end

end

function DBmobsPNJ_Combo_t_init_afficher(mmodel,smodele,sblp)

local stype;
local srep;
local srep2;
local ssexe;
local snom;
local itrouve;
local itrouve2;
local i;
local k;
local l;
local m;
local n;
local smot_milieu;
local ilen;
local smot_tout;

--TraceFrame:AddMessage("DBmobsPNJ_Combo_t_init_afficher -> smodele = "..smodele..", sblp = "..sblp);
	smodele = string.gsub(smodele,"\\","/");
	stype, srep, ssexe, snom = strsplit("/",smodele,4);
	if ( stype == "creature" ) then
		if ( snom == nil or snom == "" ) then
			snom = srep.."/"..ssexe;
			--ssexe = "inconnu";
		else
			snom = srep.."/"..ssexe.."/"..snom;
			--ssexe = "inconnu";
			--snom = strsub(snom,1,strlen(snom)-1);
		end
		itrouve = 0;
		for k = 1 , table.getn(DBmobsPNJ_Combo_t) do
			if ( itrouve == 0 and stype == DBmobsPNJ_Combo_t[k]["nom"] ) then
				itrouve = k;
			end
		end
		k = itrouve;
--TraceFrame:AddMessage("DBmobsPNJ_Combo_t_init_afficher -> k = "..k);
		srep2 = strsub(srep,1,1);
		if ( k > 0 ) then
			itrouve = 0;
			for l = 1 , table.getn(DBmobsPNJ_Combo_t[k]) do
				if ( itrouve == 0 and srep2 == DBmobsPNJ_Combo_t[k][l]["nom"] ) then
					itrouve = l;
				end
			end
			l = itrouve;
--TraceFrame:AddMessage("DBmobsPNJ_Combo_t_init_afficher -> l = "..l);
			if ( l > 0 ) then
				itrouve = 0;
				itrouve2 = 0;
				for m = 1 , table.getn(DBmobsPNJ_Combo_t[k][l]) do
					if ( itrouve == 0 ) then
						for n = 1 , table.getn(DBmobsPNJ_Combo_t[k][l][m]) do
							if ( itrouve == 0 and snom == DBmobsPNJ_Combo_t[k][l][m][n]["nom"] ) then
								itrouve = n;
								itrouve2 = m;
							end
						end
					end
				end
				m = itrouve2;
--TraceFrame:AddMessage("DBmobsPNJ_Combo_t_init_afficher -> m = "..m);
				n = itrouve;
--TraceFrame:AddMessage("DBmobsPNJ_Combo_t_init_afficher -> n = "..n);
				if ( m > 0 and n > 0 and DBmobsPNJ_Combo_t[k][l][m][n]["blp"] and DBmobsPNJ_Combo_t[k][l][m][n]["blp"][sblp] ) then
					if ( DBmobsPNJ_Combo_t[k][l][m][n]["blp"][sblp][0] > 0 ) then
--TraceFrame:AddMessage("DBmobsPNJ_Combo_t_init_afficher -> 0 = "..DBmobsPNJ_Combo_t[k][l][m][n]["blp"][sblp][0]);
						mmodel:SetCreature(DBmobsPNJ_Combo_t[k][l][m][n]["blp"][sblp][0]);
					else
						itrouve = 0;
						for i, _ in pairs(DBmobsPNJ_Combo_t[k][l][m][n]["blp"][sblp]) do
--TraceFrame:AddMessage("DBmobsPNJ_Combo_t_init_afficher -> i = "..i);
							if ( i == 0 ) then
							elseif ( itrouve == 0 ) then
								smot_milieu = format("%X",i);
								ilen = strlen(smot_milieu);
								--if ( DBCS_mobs_wow_build > DBCS_mobs_wow_build_live ) then
									smot_tout = "unit:0xF53"..strrep("0",5-ilen)..smot_milieu.."00000000:bla";
								--else
								--	smot_tout = "unit:0xF53"..strrep("0",7-ilen)..smot_milieu.."000000:bla";
								--end
								DBcorpsFrame_Tooltip4TextLeft1:SetText(nil);
								DBcorpsFrame_Tooltip4:SetOwner(WorldFrame,"ANCHOR_NONE");
								DBcorpsFrame_Tooltip4:SetHyperlink(smot_tout);
								snom = DBcorpsFrame_Tooltip4TextLeft1:GetText();
								if ( snom ) then
									DBmobsPNJ_Combo_t[k][l][m][n]["blp"][sblp][0] = i;
									DBmobsPNJ_Combo_t[k][l][m][n]["blp"][sblp][i] = 1;
									mmodel:SetCreature(i);
									itrouve = i;
--TraceFrame:AddMessage("DBmobsPNJ_Combo_t_init_afficher -> itrouve = "..i);
								end
							end
						end
					end
				end
			end
		end
	end

end

DBmobsPNJ_Combo_t = nil;

--/script DBmobsPNJ_Combo_t_init();
function DBmobsPNJ_Combo_t_init()

local i;
local j;
local k;
local l;
local m;
local n;
local o;
local p;
local stype;
local srep;
local srep2;
local ssexe;
local snom;
local sval;
local itrouve;

	DBmobsPNJ_Nettoyer();
	if ( DBmobsPNJ_Combo_t == nil ) then
	else
		return nil;
	end
	if ( DBCS_mobs_model ) then
		DBmobsPNJ_Combo_t = {};
		for i, _ in pairs(DBCS_mobs_model)  do
			if ( DBCS_mobs_model[i] == nil ) then
			else
			--for j = 1 , table.getn(DBCS_mobs_model[i]) do
				j = 1;
				if ( j == 1 and table.getn(DBCS_mobs_model[i]) > 0 ) then
					sval = strlower(DBCS_mobs_model[i][j]["model"]);	--	.."/";
					stype, srep, ssexe, snom = strsplit("/",sval,4);
					if ( stype == "character" or stype == "creature" ) then
						if ( stype == "creature" ) then
							if ( snom == nil or snom == "" ) then
								snom = srep.."/"..ssexe;
								ssexe = "inconnu";
							else
								snom = srep.."/"..ssexe.."/"..snom;
								ssexe = "inconnu";
								--snom = strsub(snom,1,strlen(snom)-1);
							end
						end
						itrouve = 0;
						for k = 1 , table.getn(DBmobsPNJ_Combo_t) do
							if ( itrouve == 0 and stype < DBmobsPNJ_Combo_t[k]["nom"] ) then
								itrouve = k;
							elseif ( itrouve == 0 and stype == DBmobsPNJ_Combo_t[k]["nom"] ) then
								itrouve = 0-k;
							end
						end
						if ( itrouve < 0 ) then
							k = 0-itrouve;
						elseif ( itrouve == 0 ) then
							table.insert(DBmobsPNJ_Combo_t,{});
							k = table.getn(DBmobsPNJ_Combo_t);
							DBmobsPNJ_Combo_t[k]["nom"] = stype;
						elseif ( itrouve > 0 ) then
							k = itrouve;
							table.insert(DBmobsPNJ_Combo_t,k,{});
							DBmobsPNJ_Combo_t[k]["nom"] = stype;
						end
						if ( stype == "creature" ) then
							srep2 = strsub(srep,1,1);
						else
							srep2 = srep;
						end
						itrouve = 0;
						for l = 1 , table.getn(DBmobsPNJ_Combo_t[k]) do
							if ( itrouve == 0 and srep2 < DBmobsPNJ_Combo_t[k][l]["nom"] ) then
								itrouve = l;
							elseif ( itrouve == 0 and srep2 == DBmobsPNJ_Combo_t[k][l]["nom"] ) then
								itrouve = 0-l;
							end
						end
						if ( itrouve < 0 ) then
							l = 0-itrouve;
						elseif ( itrouve == 0 ) then
							table.insert(DBmobsPNJ_Combo_t[k],{});
							l = table.getn(DBmobsPNJ_Combo_t[k]);
							DBmobsPNJ_Combo_t[k][l]["nom"] = srep2;
						elseif ( itrouve > 0 ) then
							l = itrouve;
							table.insert(DBmobsPNJ_Combo_t[k],l,{});
							DBmobsPNJ_Combo_t[k][l]["nom"] = srep2;
						end
						itrouve = 0;
						for m = 1 , table.getn(DBmobsPNJ_Combo_t[k][l]) do
							if ( itrouve == 0 and ssexe < DBmobsPNJ_Combo_t[k][l][m]["nom"] ) then
								itrouve = m;
							elseif ( itrouve == 0 and ssexe == DBmobsPNJ_Combo_t[k][l][m]["nom"] ) then
								itrouve = 0-m;
							end
						end
						if ( itrouve < 0 ) then
							m = 0-itrouve;
						elseif ( itrouve == 0 ) then
							table.insert(DBmobsPNJ_Combo_t[k][l],{});
							m = table.getn(DBmobsPNJ_Combo_t[k][l]);
							DBmobsPNJ_Combo_t[k][l][m]["nom"] = ssexe;
						elseif ( itrouve > 0 ) then
							m = itrouve;
							table.insert(DBmobsPNJ_Combo_t[k][l],m,{});
							DBmobsPNJ_Combo_t[k][l][m]["nom"] = ssexe;
						end
						itrouve = 0;
						for n = 1 , table.getn(DBmobsPNJ_Combo_t[k][l][m]) do
							if ( itrouve == 0 and snom < DBmobsPNJ_Combo_t[k][l][m][n]["nom"] ) then
								itrouve = n;
							elseif ( itrouve == 0 and snom == DBmobsPNJ_Combo_t[k][l][m][n]["nom"] ) then
								itrouve = 0-n;
							end
						end
						if ( itrouve < 0 ) then
							n = 0-itrouve;
						elseif ( itrouve == 0 ) then
							table.insert(DBmobsPNJ_Combo_t[k][l][m],{});
							n = table.getn(DBmobsPNJ_Combo_t[k][l][m]);
							DBmobsPNJ_Combo_t[k][l][m][n]["nom"] = snom;
						elseif ( itrouve > 0 ) then
							n = itrouve;
							table.insert(DBmobsPNJ_Combo_t[k][l][m],n,{});
							DBmobsPNJ_Combo_t[k][l][m][n]["nom"] = snom;
						end
						if ( stype == "creature" and DBCS_mobs_model[i][j]["blp"] ) then
							if ( DBmobsPNJ_Combo_t[k][l][m][n]["blp"] == nil ) then
								DBmobsPNJ_Combo_t[k][l][m][n]["blp"] = {};
							end
							if ( DBmobsPNJ_Combo_t[k][l][m][n]["blp"][DBCS_mobs_model[i][j]["blp"]] == nil ) then
								DBmobsPNJ_Combo_t[k][l][m][n]["blp"][DBCS_mobs_model[i][j]["blp"]] = {};
								DBmobsPNJ_Combo_t[k][l][m][n]["blp"][DBCS_mobs_model[i][j]["blp"]][0] = 0;
							end
							DBmobsPNJ_Combo_t[k][l][m][n]["blp"][DBCS_mobs_model[i][j]["blp"]][i] = 0;
						end
					end
				end
			end
		end
	--else
	--	DBmobsPNJ_Combo_t = nil;
	end
	if ( DBmobsPNJ_Combo_t ) then
		for k = 1 , table.getn(DBmobsPNJ_Combo_t) do
--TraceFrame:AddMessage("DBmobsPNJ_Combo type = "..DBmobsPNJ_Combo_t[k]["nom"]);
			if ( DBmobsPNJ_Combo_t[k]["nom"] == "creature" ) then
				for l = 1 , table.getn(DBmobsPNJ_Combo_t[k]) do
--TraceFrame:AddMessage("----DBmobsPNJ_Combo rep  = "..DBmobsPNJ_Combo_t[k][l]["nom"]);
--TraceFrame:AddMessage("DBmobsPNJ_Combo l = "..l);
					for m = 1 , 1 do
--TraceFrame:AddMessage("--------DBmobsPNJ_Combo sexe  = "..DBmobsPNJ_Combo_t[k][l][m]["nom"]);
--TraceFrame:AddMessage("DBmobsPNJ_Combo m = "..m);
						for n = 1 , table.getn(DBmobsPNJ_Combo_t[k][l][m]) do
--TraceFrame:AddMessage("------------DBmobsPNJ_Combo nom  = "..DBmobsPNJ_Combo_t[k][l][m][n]["nom"]);
							o = floor((n-1)/20)+1;
							p = n-((o-1)*20);
							if ( DBmobsPNJ_Combo_t[k][l][o+1] == nil ) then
								DBmobsPNJ_Combo_t[k][l][o+1] = {};
								--DBmobsPNJ_Combo_t[k][l][o+1]["nom"] = "inconnu"..o;
								DBmobsPNJ_Combo_t[k][l][o+1]["nom"] = "liste -> "..(o*20);
							end
							DBmobsPNJ_Combo_t[k][l][o+1][p] = DBmobsPNJ_Combo_t[k][l][m][n];
						end
					end
					table.remove(DBmobsPNJ_Combo_t[k][l],1);
				end
			end
--		for l = 1 , table.getn(DBmobsPNJ_Combo_t[k]) do
--TraceFrame:AddMessage("----DBmobsPNJ_Combo rep  = "..DBmobsPNJ_Combo_t[k][l]["nom"]);
--			for m = 1 , table.getn(DBmobsPNJ_Combo_t[k][l]) do
--TraceFrame:AddMessage("--------DBmobsPNJ_Combo sexe  = "..DBmobsPNJ_Combo_t[k][l][m]["nom"]);
--				for n = 1 , table.getn(DBmobsPNJ_Combo_t[k][l][m]) do
--TraceFrame:AddMessage("------------DBmobsPNJ_Combo nom  = "..DBmobsPNJ_Combo_t[k][l][m][n]["nom"]);
--				end
--			end
--		end
		end
	end
	DBcorpsFrame_PNJFrame_Criteres_Type_OnLoad();
	DBcorpsFrame_PNJFrame_Criteres_Type_OnClick(DBcorpsFrame_PNJFrame_Criteres_Type);
	UIDropDownMenu_SetSelectedValue(DBcorpsFrame_PNJFrame_Criteres_Type,-1);
	--DBcorpsFrame_PNJFrame_Criteres_Rep_OnLoad();
	--DBcorpsFrame_PNJFrame_Criteres_Sexe_OnLoad();
	--DBcorpsFrame_PNJFrame_Criteres_Nom_OnLoad();

end

function DBmobs_DetailConnaissanceBete(nommob,numregion,niveau)

	local sdomptable;
	local stechnique;
	local stechnique_temp;
	local irang;
	local tMOB;
	local tablo;
	local iniveau;
	
	if ( DBMS[nommob] and DBMS[nommob][numregion] ) then
		tMOB = DBMS[nommob][numregion];
		if ( tMOB[15] ) then
			stechnique = "";
			for stechnique_temp, irang in pairs(tMOB[15]) do
				if ( stechnique == "" ) then
				else
					stechnique = stechnique..", ";
				end
				stechnique = stechnique..stechnique_temp.."_"..irang;
			end
		end
		if ( tMOB[13] ) then
			if ( tMOB[13] == "1" ) then
				sdomptable = "Domptable";
			else
				sdomptable = "Insensible au domptage";
			end
		end
		tablo = {};
		tablo[niveau] = 0;
		tablo[tMOB[1]] = 0;
		tablo[tMOB[2]] = 0;
		if ( tMOB[16] ) then
			for iniveau, _ in pairs(tMOB[16]) do
				tablo[iniveau] = 1;
			end
		end
		if ( tablo[0] or tablo["0"] ) then
			tablo[0] = nil;
			tablo["0"] = nil;
		end
	end
	
	return sdomptable, stechnique, tablo;

end

function DBmobs_Detail(nommob,numregion,salaireskin)

local tablo = nil;
local isalaire;
local i;
local a;

	if ( DBMS[nommob] ) then
		if ( DBMS[nommob][numregion] ) then
			tablo = {};
			tablo.nummob		= DBMS[nommob][numregion][29];
			tablo.nivmin		= DBMS[nommob][numregion][1];
			tablo.nivmax		= DBMS[nommob][numregion][2];
			tablo.classe		= DBMS[nommob][numregion][3];
			tablo.famille		= DBMS[nommob][numregion][4];
			tablo.type			= DBMS[nommob][numregion][5];
			tablo.plusmob		= DBMS[nommob][numregion][6];
			tablo.nbcorps		= DBMS[nommob][numregion][7];
			if ( tablo.famille == "Minage" or tablo.famille == "Ouverture" or tablo.famille == "Cueillette" ) then
				i = 0;
				if ( DBMS[nommob][numregion][11] ) then
					for a, _ in pairs(DBMS[nommob][numregion][11]) do
						i = i + 1;
					end
				else
				end
				tablo.nbskin		= i;
			else
				tablo.nbskin		= DBMS[nommob][numregion][9];
			end
			tablo.salaire, _	= DBmobs_Salaire(nommob,numregion,salaireskin);
			--tablo.salaire	= 0;
			tablo.locs			= DBMS[nommob][numregion][10];
			tablo.locprecise 	= DBMS[nommob][numregion][11];
			tablo.datemaj	 	= DBMS[nommob][numregion][12];
		end
	end

	return tablo;

end

function DBmobs_Objets(tCRITERES)

local tablo = {};
local i = 0;
local tOBJETS;
local numobjet;
local numcourt2;
local tOBJET;
local tMOB;
local idivise;
local idiviseur;
local snom;
local ipos;

--TraceFrame:AddMessage("nommob : "..tCRITERES.nommob.." , numregion : "..tCRITERES.numregion);
	if ( DBMS[tCRITERES.nommob] ) then
		if ( DBMS[tCRITERES.nommob][tCRITERES.numregion] ) then
			if ( DBMS[tCRITERES.nommob][tCRITERES.numregion][8] ) then
				DBMS[tCRITERES.nommob][tCRITERES.numregion][8] = DBmobs_champ_8_en_nombre(DBMS[tCRITERES.nommob][tCRITERES.numregion][8]);
			end
			tMOB = DBMS[tCRITERES.nommob][tCRITERES.numregion];
			tOBJETS = tMOB[8];
			if ( tOBJETS ) then
				for numobjet, _ in pairs(tOBJETS) do
					if ( numobjet == 0 ) then
					else
						--for numcourt2, _ in pairs(tOBJETS[numobjet]) do
--TraceFrame:AddMessage("numobjet : "..numobjet..":"..numcourt2);
							numcourt2 = "0:0:0:0:0:0:0:0:0";
							i = i + 1;
							tablo[i] = {};
							tablo[i][1] = numobjet;
							tablo[i][2] = numcourt2;
							tOBJET = DBOS_detail(numobjet,numcourt2);
							if ( tOBJET.nomobjet ) then
								tablo[i][3] = tOBJET.nomobjet;
								--idivise = tOBJETS[numobjet][numcourt2];
								idivise = tOBJETS[numobjet];
								if ( tMOB[1] == nil or tMOB[1] == 0 ) then
									idiviseur = tMOB[7];
								else
									if ( DBCORPS_SKIN[numobjet] ) then
										idiviseur = tMOB[9];
									else
										idiviseur = tMOB[7];
									end
								end
								if ( idiviseur == nil or idiviseur < 1 ) then
									tablo[i][4] = nil;
								else
									tablo[i][4] = (idivise/idiviseur)*100;
								end
							end
							tablo[i][5] = "i";
						--end
					end
				end
			else
			end
			--if ( tCRITERES.detail and tCRITERES.detail.classe and tCRITERES.detail.classe == "artisanat" and tCRITERES.detail.type and tCRITERES.detail.type == "Enchantement" ) then
			--	snom = tCRITERES.nommob;
			--	if ( strsub(snom,1,12) == "Enchantement" ) then
			--		snom = "Ench."..strsub(snom,13);
			--	end
			--	for numobjet, _ in pairs(DBOS_enchant) do
			--		if ( strlower(DBOS_enchant[numobjet][1]) == strlower(snom) ) then
			--			i = i + 1;
			--			tablo[i] = {};
			--			tablo[i][1] = numobjet;
			--			tablo[i][2] = "";
			--			tablo[i][3] = snom;
			--			tablo[i][5] = "e";
			--		end
			--	end
			--end
			if ( tCRITERES.detail and tCRITERES.detail.classe and tCRITERES.detail.classe == "artisanat" ) then
				snom = tCRITERES.nommob;
				--if ( strsub(snom,1,12) == "Enchantement" ) then
				--	snom = "Ench."..strsub(snom,13);
				--end
				for numobjet, _ in pairs(DBOS_enchant) do
					ipos, _ = strfind(DBOS_enchant[numobjet][1],":");
					if ( ipos ) then
						ipos = ipos + 2;
						if ( strlower(strsub(DBOS_enchant[numobjet][1],ipos)) == strlower(snom) or ( DBOS_enchant[numobjet][8] and strlower(DBOS_enchant[numobjet][8]) == strlower(snom) ) ) then
							i = i + 1;
							tablo[i] = {};
							tablo[i][1] = numobjet;
							tablo[i][2] = "";
							tablo[i][3] = snom;
							tablo[i][5] = "e";
						end
					end
				end
			end
		end
	end

	return tablo;

end

function DBmobs_Salaire(nommob,numregion,salaireskin)

local tMOB;
local tOBJETS;
local tOBJET;
local numobjet;
local numcourt2;

local isalaire = nil;
local ipct = nil;

local isalairebrut = 0;

local imontant_corps = 0;
local imontant_skin = 0;
local inb = 0;
local inbtot = 0;

local idiviseur_corps;
local idiviseur_skin;

local ibonobjet;

local imontant_coffre;

	if ( DBMS[nommob] ) then
		if ( DBMS[nommob][numregion] ) then
			if ( DBMS[nommob][numregion][8] ) then
				DBMS[nommob][numregion][8] = DBmobs_champ_8_en_nombre(DBMS[nommob][numregion][8]);
			end
			tMOB = DBMS[nommob][numregion];
			tOBJETS = tMOB[8];
			if ( tOBJETS ) then
				idiviseur_corps = 0;
				idiviseur_skin = 0;
				if ( tMOB[7] ) then
					idiviseur_corps = tMOB[7];
				end
				if ( salaireskin == 1 ) then
					if ( tMOB[9] ) then
						idiviseur_skin = tMOB[9];
					end
				end
				if ( idiviseur_corps > 0 or idiviseur_skin > 0 ) then
					for numobjet, _ in pairs(tOBJETS) do
						if ( numobjet == 0 ) then
							--if ( tMOB[7] and tMOB[7] > 0 and tOBJETS[0] and tOBJETS[0]["0"] ) then
							--	isalairebrut = tOBJETS[0]["0"] / tMOB[7];
							if ( tMOB[7] and tMOB[7] > 0 and tOBJETS[0] ) then
								isalairebrut = tOBJETS[0] / tMOB[7];
							end
						else
if ( DBCS_debug > 0 ) then
							tOBJET = DBOS_detail(numobjet,"0:0:0:0:0:0:0:0:0");
							if ( tOBJET.nomobjet ) then
								ibonobjet = 1;
								if ( salaireskin == 0 ) then
									if ( tMOB[1] and tMOB[1] > 0 ) then
										if ( DBCORPS_SKIN[numobjet] ) then
											ibonobjet = 0;
										end
									end
								end
								--DBCORPS_SKIN[numobjet]
								if ( ibonobjet == 1 ) then
									--for numcourt2, _ in pairs(tOBJETS[numobjet]) do
										--if ( tOBJET.coffre and tOBJET.coffre == 1 ) then
										--	imontant_coffre, _ = DBmobs_Salaire(tOBJET.nomobjet,"0");
										--	--imontant_coffre = nil;
										--	imontant_coffre = ( imontant_coffre or 0 );
										--	imontant_corps = imontant_corps + ( tOBJETS[numobjet][numcourt2] * imontant_coffre );
										--	inb = inb + tOBJETS[numobjet][numcourt2];
										--else
											if ( tOBJET.prix ) then
												if ( tMOB[1] and tMOB[1] > 0 ) then
													if ( DBCORPS_SKIN[numobjet] ) then
														--imontant_skin = imontant_skin + ( tOBJETS[numobjet][numcourt2] * tOBJET.prix );
														imontant_skin = imontant_skin + ( tOBJETS[numobjet] * tOBJET.prix );
													else
														--imontant_corps = imontant_corps + ( tOBJETS[numobjet][numcourt2] * tOBJET.prix );
														imontant_corps = imontant_corps + ( tOBJETS[numobjet] * tOBJET.prix );
													end
												else
													--imontant_corps = imontant_corps + ( tOBJETS[numobjet][numcourt2] * tOBJET.prix );
													imontant_corps = imontant_corps + ( tOBJETS[numobjet] * tOBJET.prix );
												end
												--inb = inb + tOBJETS[numobjet][numcourt2];
												inb = inb + tOBJETS[numobjet];
											end
										--end
										--inbtot = inbtot + tOBJETS[numobjet][numcourt2];
										inbtot = inbtot + tOBJETS[numobjet];
									--end
								end
							else
							end
end
						end
					end
					isalaire = isalairebrut;
					if ( idiviseur_corps > 0 ) then
						isalaire = isalaire + ( imontant_corps / idiviseur_corps );
					end
					if ( idiviseur_skin > 0 ) then
						isalaire = isalaire + ( imontant_skin / idiviseur_skin );
					end
					isalaire = floor(isalaire);
					if ( inbtot > 0 ) then
						ipct = floor((inb / inbtot) * 100);
					end
				end
			end
		end
	end

	return isalaire,ipct;

end

--    NAXKelThuzard = {
--        { 0, "INV_Misc_QuestionMark", "=q4=Fists of the Unrelenting", "=ds=#s9#, #a4#" },
--        { 0, "INV_Misc_QuestionMark", "=q4=Gressil, Dawn of Ruin", "=ds=#h1# #w10#" },
--        { 0, "INV_Misc_QuestionMark", "=q4=Nerubian Slavemaker", "=ds=#w3#" },
--        { 0, "INV_Misc_QuestionMark", "=q4=Shield of Condemnation", "=ds=#w8#" },
--        { 0, "INV_Misc_QuestionMark", "=q4=Gem of Trapped Innocents", "=ds=#s2#" },
--        { 0, "INV_Misc_QuestionMark", "=q4=Ring of the Dreamwalker", "=ds=#s13# =q1=#m1# =ds=#c1#" },
--        { 0, "INV_Misc_QuestionMark", "=q4=Ring of the Cryptstalker", "=ds=#s13# =q1=#m1# =ds=#c2#" },
--        { 0, "INV_Misc_QuestionMark", "=q4=Bonescythe Ring", "=ds=#s13# =q1=#m1# =ds=#c6#" },
--        { 0, "INV_Misc_QuestionMark", "=q4=Ring of the Earthshatterer", "=ds=#s13# =q1=#m1# =ds=#c7#" },
--        { 0, "INV_Misc_QuestionMark", "=q4=Ring of the Dreadnaught", "=ds=#s13# =q1=#m1# =ds=#c9#" },
--        { 0, "INV_Misc_QuestionMark", "=q5=Atiesh, Greatstaff of the Guardian", "=ds=#m4#, =q1=#m1# =ds=#c1#"},
--        { 0, "INV_Misc_QuestionMark", "=q5=Atiesh, Greatstaff of the Guardian", "=ds=#m4#, =q1=#m1# =ds=#c3#"},

--/script DEFAULT_CHAT_FRAME:AddMessage(GetTrainerServiceInfo(7))
--/script DEFAULT_CHAT_FRAME:AddMessage(GetTrainerServiceSkillReq(7))
--/script DEFAULT_CHAT_FRAME:AddMessage(GetTrainerServiceDescription(7))
--/script DEFAULT_CHAT_FRAME:AddMessage(GetTrainerServiceIcon(7))
--/script DEFAULT_CHAT_FRAME:AddMessage(GetTrainerServiceItemLink(32))
--/script DEFAULT_CHAT_FRAME:AddMessage(GetNumTrainerServices())

--		return shexcouleuritem.."|Hitem:"..snumlong.."|h["..snom.."]|h|r";
--	for a, _, _, _, _, _, c, _ in string.gmatch(link,"item:(%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+)") do

--/script DBmobs_artisanat_GetTrainerService_all();
function DBmobs_artisanat_GetTrainerService_all()

	local imax;
	local i;
	
	imax = GetNumTrainerServices();
	
	for i = 0 , imax do
		DBmobs_artisanat_GetTrainerService(i);
	end

end

--/script DBmobs_artisanat_GetTrainerService(2)
--/script DBmobs_artisanat_GetTrainerService(7)
--/script DBmobs_artisanat_GetTrainerService(8)
--/script DBmobs_artisanat_GetTrainerService(32)
function DBmobs_artisanat_GetTrainerService(index)

	local slink;
	local sskill;
	local iskill;
	local a;
	local b;
	local inumobjet;
	local snom;
	local sname;
	local srank;
	local scategory;
	local sexpanded;
	local sreqLevel;
	
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("index = "..index);
--end
--name, rank, category, expanded = GetTrainerServiceInfo(id);
	sname, srank, scategory, sexpanded = GetTrainerServiceInfo(index);
if ( DBCS_debug > 1 ) then
TraceFrame:AddMessage("sname = "..(sname or "").." , srank = "..(srank or "").." , scategory = "..(scategory or "").." , sexpanded = "..(sexpanded or ""));
end
--skillName, skillAmt = GetTrainerServiceSkillReq(index);
	sskill, iskill = GetTrainerServiceSkillReq(index);
if ( DBCS_debug > 1 ) then
TraceFrame:AddMessage("sskill = "..(sskill or "").." , iskill = "..(iskill or ""));
end
	sreqLevel = GetTrainerServiceLevelReq(index);
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("sreqLevel = "..(sreqLevel or ""));
--end
	slink = GetTrainerServiceItemLink(index);
--if ( DBCS_debug > 1 ) then
--TraceFrame:AddMessage("slink = "..(slink or ""));
--end

	if ( scategory == nil or sskill == nil or scategory == "header" ) then
	else
		if ( DBCS_objet_metier_name[sskill] ) then
if ( DBCS_debug > 1 ) then
TraceFrame:AddMessage("sname = "..(sname or "").." , iskill = "..(iskill or ""));
end
			if ( tonumber(iskill) < 10 ) then
				iskill = "00"..iskill;
			elseif ( tonumber(iskill) < 100 ) then
				iskill = "0"..iskill;
			end
			if ( DBMS ) then
			else
				DBMS = {};
			end
			if ( DBMS[sname] ) then
			else
				DBMS[sname] = {};
			end
			if ( DBMS[sname]["1"] ) then
			else
				DBMS[sname]["1"] = {};
				DBMS[sname]["1"][1] = nil;
				DBMS[sname]["1"][2] = nil;
				DBMS[sname]["1"][6] = "";
				DBMS[sname]["1"][7] = nil;
				DBMS[sname]["1"][9] = nil;
			end
			DBMS[sname]["1"][3] = "artisanat";
			DBMS[sname]["1"][5] = sskill;
			DBMS[sname]["1"][4] = ""..iskill;
			inumobjet = nil;
			if ( slink ) then
				--snom = nil;
				for _, a, _, _, _, _, _, _, _, _, _, b in string.gmatch(slink,"(.+)%|Hitem:(%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+)%|h%[(.+)%]%|h%|r") do
					inumobjet = tonumber(a);
					--snom = b;
				end
				if ( inumobjet ) then
					if ( DBMS[sname]["1"][8] ) then
						DBMS[sname]["1"][8] = DBmobs_champ_8_en_nombre(DBMS[sname]["1"][8]);
					else
						DBMS[sname]["1"][8] = {};
					end
					if ( DBMS[sname]["1"][8][inumobjet] ) then
					else
						--DBMS[sname]["1"][8][inumobjet] = {};
						--DBMS[sname]["1"][8][inumobjet]["0:0:0:0:0:0:0"] = 1;
						DBMS[sname]["1"][8][inumobjet] = 0;
					end
				end
			end
		end
	end

	if ( 1 == 1 ) then
		return nil;
	end

	slink = GetTrainerServiceItemLink(index);
	if ( slink ) then
--skillName, skillAmt = GetTrainerServiceSkillReq(index);
		sskill, iskill = GetTrainerServiceSkillReq(index);
if ( DBCS_debug > 1 ) then
TraceFrame:AddMessage("sskill = "..sskill.." , iskill = "..iskill);
end
		if ( DBCS_objet_metier_name[sskill] ) then
--name, rank, category, expanded = GetTrainerServiceInfo(id);
			sname, _, _, _ = GetTrainerServiceInfo(index);
			inumobjet = nil;
			snom = nil;
			-- ajouter pour enchantement
			for _, a, _, _, _, _, _, _, _, _, _, b in string.gmatch(slink,"(.+)%|Hitem:(%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+)%|h%[(.+)%]%|h%|r") do
				inumobjet = tonumber(a);
				snom = b;
			end
			if ( tonumber(iskill) < 10 ) then
				iskill = "00"..iskill;
			elseif ( tonumber(iskill) < 100 ) then
				iskill = "0"..iskill;
			end
if ( DBCS_debug > 1 ) then
TraceFrame:AddMessage(index.." = "..slink.." , metier = "..sskill.." , niveau = "..iskill.." , name = "..sname.." , nomobjet = "..(snom or "").." , numobjet = "..(inumobjet or ""));
end
			if ( DBMS ) then
			else
				DBMS = {};
			end
			if ( DBMS[sname] ) then
			else
				DBMS[sname] = {};
			end
			if ( DBMS[sname]["1"] ) then
			else
				DBMS[sname]["1"] = {};
				DBMS[sname]["1"][1] = nil;
				DBMS[sname]["1"][2] = nil;
				DBMS[sname]["1"][6] = "";
				DBMS[sname]["1"][7] = nil;
				DBMS[sname]["1"][9] = nil;
			end
			DBMS[sname]["1"][3] = "artisanat";
			DBMS[sname]["1"][5] = sskill;
			DBMS[sname]["1"][4] = ""..iskill;
			if ( inumobjet ) then
				if ( DBMS[sname]["1"][8] ) then
					DBMS[sname]["1"][8] = DBmobs_champ_8_en_nombre(DBMS[sname]["0"][8]);
				else
					DBMS[sname]["1"][8] = {};
				end
				if ( DBMS[sname]["1"][8][inumobjet] ) then
				else
					--DBMS[sname]["1"][8][inumobjet] = {};
					--DBMS[sname]["1"][8][inumobjet]["0:0:0:0:0:0:0"] = 1;
					DBMS[sname]["1"][8][inumobjet] = 0;
				end
			end
		end
	end

end

--name, rank, category, expanded = GetTrainerServiceInfo(id);

--skillName, skillAmt = GetTrainerServiceSkillReq(index);
--	Alchimie
--	Couture
--	Cuisine
--	Enchantement
--	Forge
--	Ingénierie
--	Joaillerie
--	Minage
--	Poisons
--	Premiers soins
--	Travail du cuir

--	/script DBmobs_nettoyer_base();
function DBmobs_nettoyer_base()

	local snommob;
	local snumregion;
	local inumobjet;
	local i0;
	local i000;

if ( DBCS_debug > 1 ) then
TraceFrame:AddMessage("debut DBmobs_nettoyer_base");
end
	for snommob, _ in pairs(DBMS) do
		for snumregion, _ in pairs(DBMS[snommob]) do
			if ( DBMS[snommob][snumregion][8] ) then
				DBMS[snommob][snumregion][8] = DBmobs_champ_8_en_nombre(DBMS[snommob][snumregion][8]);
				--for inumobjet, _ in pairs(DBMS[snommob][snumregion][8]) do
				--	if ( inumobjet == 0 ) then
				--		i000 = 0;
				--		if ( DBMS[snommob][snumregion][8][inumobjet]["0:0:0:0:0:0:0"] ) then
				--			i000 = DBMS[snommob][snumregion][8][inumobjet]["0:0:0:0:0:0:0"];
				--		end
				--		DBMS[snommob][snumregion][8][inumobjet]["0:0:0:0:0:0:0"] = nil;
				--		i0 = 0;
				--		if ( DBMS[snommob][snumregion][8][inumobjet]["0"] ) then
				--			i0 = DBMS[snommob][snumregion][8][inumobjet]["0"];
				--		end
				--		DBMS[snommob][snumregion][8][inumobjet]["0"] = i0 + i000;
				--	else
				--		i000 = 0;
				--		if ( DBMS[snommob][snumregion][8][inumobjet]["0:0:0"] ) then
				--			i000 = DBMS[snommob][snumregion][8][inumobjet]["0:0:0"];
				--		end
				--		DBMS[snommob][snumregion][8][inumobjet]["0:0:0"] = nil;
				--		i0 = 0;
				--		if ( DBMS[snommob][snumregion][8][inumobjet]["0:0:0:0:0:0:0"] ) then
				--			i0 = DBMS[snommob][snumregion][8][inumobjet]["0:0:0:0:0:0:0"];
				--		end
				--		DBMS[snommob][snumregion][8][inumobjet]["0:0:0:0:0:0:0"] = i0 + i000;
				--	end
				--end
			end
		end
	end
if ( DBCS_debug > 1 ) then
TraceFrame:AddMessage("fin DBmobs_nettoyer_base");
end

end

--/script DBmobs_init_ensembles();
function DBmobs_init_ensembles()

	local snommob;
	local snumregion;
	local bbon;
	local i;
	local inumobjet;

	for snommob, _ in pairs(DBMS) do
		if ( DBMS[snommob]["0"] ) then
			if ( DBMS[snommob]["0"][3] == "ensemble" ) then
				DBMS[snommob]["0"] = nil;
				bbon = true;
				for snumregion, _ in pairs(DBMS[snommob]) do
					bbon = false;
				end
				if ( bbon == true ) then
					DBMS[snommob] = nil;
				end
			end
		end
	end
	for i = 1 , table.getn(DBCS_setsnom) do
		snommob = "set : "..DBCS_setsnom[i].name;
		if ( DBMS[snommob] ) then
		else
			DBMS[snommob] = {};
		end
		if ( DBMS[snommob]["0"] ) then
		else
			DBMS[snommob]["0"] = {};
		end
		DBMS[snommob]["0"][3] = "ensemble";
		DBMS[snommob]["0"][5] = DBCS_setsniveau_index_name[DBCS_setsnom[i].niveau];
		if ( DBMS[snommob]["0"][8] ) then
			DBMS[snommob]["0"][8] = DBmobs_champ_8_en_nombre(DBMS[snommob]["0"][8]);
		else
			DBMS[snommob]["0"][8] = {};
		end
		for inumobjet, _ in pairs(DBCS_setsnom[i].numobjet) do
			--DBMS[snommob]["0"][8][inumobjet] = {};
			--DBMS[snommob]["0"][8][inumobjet]["0:0:0:0:0:0:0"] = 0;
			DBMS[snommob]["0"][8][inumobjet] = 0;
		end
	end

end

--/script DBmobs_artisanat_0_vers_1()
function DBmobs_artisanat_0_vers_1()

local snommob;

	for snommob, _ in pairs(DBMS) do
		if ( DBMS[snommob]["0"] ) then
			if ( DBMS[snommob]["0"][3] == "artisanat" ) then
				if ( DBMS[snommob]["1"] == nil ) then
					DBMS[snommob]["1"] = DBMS[snommob]["0"];
				end
				DBMS[snommob]["0"] = nil;
			end
		end
	end

end

--/script DBmobs_viderartisanatfaux()
function DBmobs_viderartisanatfaux()

local snommob;
local bbon;
local inumobjet;
local sregion;

	for snommob, _ in pairs(DBMS) do
		if ( DBMS[snommob]["1"] ) then
			if ( DBMS[snommob]["1"][3] == "artisanat" ) then
				bbon = true;
				if ( DBMS[snommob]["1"][8] ) then
					for inumobjet, _ in pairs(DBMS[snommob]["1"][8]) do
						if ( DBOS[inumobjet] ) then
							if ( DBOS[inumobjet][4] and DBOS[inumobjet][4] == 12 ) then
							else
								bbon = false;
							end
						else
							bbon = false;
						end
					end
				end
				if ( bbon == true ) then
					DBMS[snommob]["1"] = nil;
					bbon = true;
					for sregion, _ in pairs(DBMS[snommob]) do
						bbon = false;
					end
					if ( bbon == true ) then
						DBMS[snommob] = nil;
					end
				end
			end
		end
	end

end

function DBmobs_MVW_detail_modele(snommob,snumregion)

local tablo;
local stype = nil;
local srep = nil;
local sgenre = nil;
local snom = nil;
local sblp = nil;
local idate;
local ideb;
local ipos;
local inumcreature = nil;

	if ( DBMS[snommob] ) then
		if ( DBMS[snommob][snumregion] ) then
			tablo = DBMS[snommob][snumregion];
			if ( tablo[28] ) then
				idate = -1;
				for snommodele , _ in pairs(tablo[28]) do
					if ( tablo[28][snommodele] > idate ) then
						idate = tablo[28][snommodele];
						ideb = 1;
						ipos = strfind(snommodele,"@",ideb);
						stype = strsub(snommodele,ideb,ipos-1);
						ideb = ipos + 1;
						ipos = strfind(snommodele,"@",ideb);
						srep = strsub(snommodele,ideb,ipos-1);
						ideb = ipos + 1;
						ipos = strfind(snommodele,"@",ideb);
						sgenre = strsub(snommodele,ideb,ipos-1);
						if ( sgenre and strlen(sgenre) == 0 ) then
							sgenre = nil;
						end
						ideb = ipos + 1;
						ipos = strfind(snommodele,"@",ideb);
						snom = strsub(snommodele,ideb,ipos-4);
						ideb = ipos + 1;
						ipos = strfind(snommodele,"@",ideb);
						sblp = strsub(snommodele,ideb,ipos-1);
					end
				end
			elseif ( tablo[21] ) then
				stype = "character";
				srep = tablo[21];
				sgenre = tablo[22];
				snom = tablo[23];
				sblp = tablo[24];
			elseif ( tablo[25] ) then
				stype = "creature";
				srep = tablo[25];
				sgenre = nil;
				snom = tablo[26];
				sblp = tablo[27];
			end
			inumcreature = tablo[29];
		end
	end
	
	return stype,srep,sgenre,snom,sblp,inumcreature;

--			[20]	date du modèle
--			[21]	si character, rep du modèle
--			[22]	si character, genre du modèle
--			[23]	si character, nom du modèle
--			[24]	si character, blp du modèle
--			[25]	si creature, rep du modèle
--			[26]	si creature, nom du modèle
--			[27]	si creature, blp du modèle
end

function DBmobs_DBOA_sauvegarde(inumobjet,snumcourt2_8)

local a6,a7;
local i6,i7;
local itemName;

	itemName, _, _, _, _, _, _, _, _, _ = GetItemInfo("item:"..inumobjet..":0:0:0:0:0:0:0:0:0");
	if ( itemName ) then
		for _, _, _, _, _, a6, a7, _, _ in string.gmatch(snumcourt2_8,"(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+):(%p?%d+)") do
			i6 = tonumber(a6);
			i7 = tonumber(a7);
			if ( i6 == 0 ) then
			else
				if ( DBOS ) then
					if ( DBOS[inumobjet] ) then
						DBOS[inumobjet][82] = 1;
					end
				end
			end
		end
	end
	if ( DBOA ) then
		DBOA_sauvegarde(inumobjet,snumcourt2_8);
	end

end

--/script DBmobs_MVW_enreg_modele("Kalecgos","061","creature/dragonkalecgos/dragonkalecgos.m2",0)
--/script DBmobs_MVW_enreg_modele("Kil'jaeden","061","creature/kiljaeden/kiljaeden.m2",0)
function DBmobs_MVW_enreg_modele(snommob,snumregion,snommodele,sdate)

local tablo;
local stype = "";
local srep = "";
local sgenre = "";
local snom = "";
local ideb;
local ipos;
local bbon;
--local smodele;
--local smessage;
local sDBMVWC;
local idate;
local smodele2;

	if ( DBMS[snommob] ) then
		if ( DBMS[snommob][snumregion] ) then
			bbon = false;
			tablo = DBMS[snommob][snumregion];
--TraceFrame:AddMessage("snommodele = "..snommodele);
			ideb = 1;
			ipos = strfind(snommodele,"/",ideb);
			if ( ipos ) then
				stype = strlower(strsub(snommodele,ideb,ipos-1));
--TraceFrame:AddMessage("stype = "..stype);
				ideb = ipos + 1;
				ipos = strfind(snommodele,"/",ideb);
				if ( ipos ) then
					srep = strlower(strsub(snommodele,ideb,ipos-1));
--TraceFrame:AddMessage("srep = "..srep);
					ideb = ipos + 1;
					if ( stype == "character" ) then
						ipos = strfind(snommodele,"/",ideb);
						if ( ipos ) then
							sgenre = strlower(strsub(snommodele,ideb,ipos-1));
--TraceFrame:AddMessage("sgenre = "..sgenre);
							ideb = ipos + 1;
							ipos = strfind(snommodele,"m2",ideb);
							if ( ipos ) then
								snom = strlower(strsub(snommodele,ideb,ipos-2));
--TraceFrame:AddMessage("snom = "..snom);
								--ideb = ipos + 1;
								bbon = true;
							end
						end
					elseif ( stype == "creature" ) then
						ipos = strfind(snommodele,"m2",ideb);
						if ( ipos ) then
							snom = strlower(strsub(snommodele,ideb,ipos-2));
--TraceFrame:AddMessage("snom = "..snom);
							--ideb = ipos + 1;
							bbon = true;
						end
					end
				end
			end
--			[20]	date du modèle
--			[21]	si character, rep du modèle
--			[22]	si character, genre du modèle
--			[23]	si character, nom du modèle
--			[24]	si character, blp du modèle
--			[25]	si creature, rep du modèle
--			[26]	si creature, nom du modèle
--			[27]	si creature, blp du modèle
			if ( bbon == true ) then
				if ( srep == "sheep" or srep == "pig" or srep == "turtle" or srep == "penguinpet" ) then
if ( DBCS_debug > 1 ) then
TraceFrame:AddMessage("snommob = "..snommob.." , region = "..snumregion.." est une transformation en "..srep);
end
					return nil;
				end
				sDBMVWC = "";
				sDBMVWC = sDBMVWC..snommob.."#";
				sDBMVWC = sDBMVWC..snumregion.."#";
				if ( stype == "character" ) then
					--tablo[21] = srep;
					--tablo[22] = sgenre;
					--tablo[23] = snom;
					----smodele = stype.."/"..srep.."/"..sgenre.."/"..snom..".m2";
					sDBMVWC = sDBMVWC..stype.."@"..srep.."@"..sgenre.."@"..snom..".m2@@";
				elseif ( stype == "creature" ) then
					--tablo[25] = srep;
					--tablo[26] = snom;
					----smodele = stype.."/"..srep.."/"..snom..".m2";
					sDBMVWC = sDBMVWC..stype.."@"..srep.."@@"..snom..".m2@@";
				end
				idate = tonumber(sdate);
				DBMVWC[sDBMVWC] = idate;
				smodele2 = stype.."@"..srep.."@"..sgenre.."@"..snom..".m2@@";
				if ( tablo[28] == nil ) then
					tablo[28] = {};
				end
				if ( tablo[28][smodele2] == nil ) then
					tablo[28][smodele2] = idate;
				end
				if ( tablo[28][smodele2] < idate ) then
					tablo[28][smodele2] = idate;
				end
				DBMS[snommob][snumregion] = tablo;
			end
			--tablo[20] = sdate;
			--if ( tablo[20] == nil or ( tonumber(tablo[20]) < tonumber(sdate) ) ) then
			--end
		end
	end

end

function DBmobs_MVW_enreg_modele_et_blp(snommob,snumregion,snommodele,snomblp,sdate)

local tablo;
local stype = "";
local srep = "";
local sgenre = "";
local snom = "";
local ideb;
local ipos;
local bbon;
--local smodele;
--local smessage;
local sDBMVWC;
local smodele2;

	if ( DBMS[snommob] ) then
		if ( DBMS[snommob][snumregion] ) then
			bbon = false;
			tablo = DBMS[snommob][snumregion];
--TraceFrame:AddMessage("snommodele = "..snommodele);
			ideb = 1;
			ipos = strfind(snommodele,"/",ideb);
			if ( ipos ) then
				stype = strlower(strsub(snommodele,ideb,ipos-1));
--TraceFrame:AddMessage("stype = "..stype);
				ideb = ipos + 1;
				ipos = strfind(snommodele,"/",ideb);
				if ( ipos ) then
					srep = strlower(strsub(snommodele,ideb,ipos-1));
--TraceFrame:AddMessage("srep = "..srep);
					ideb = ipos + 1;
					if ( stype == "character" ) then
						ipos = strfind(snommodele,"/",ideb);
						if ( ipos ) then
							sgenre = strlower(strsub(snommodele,ideb,ipos-1));
--TraceFrame:AddMessage("sgenre = "..sgenre);
							ideb = ipos + 1;
							ipos = strfind(snommodele,"m2",ideb);
							if ( ipos ) then
								snom = strlower(strsub(snommodele,ideb,ipos-2));
--TraceFrame:AddMessage("snom = "..snom);
								--ideb = ipos + 1;
								bbon = true;
							end
						end
					elseif ( stype == "creature" ) then
						ipos = strfind(snommodele,"m2",ideb);
						if ( ipos ) then
							snom = strlower(strsub(snommodele,ideb,ipos-2));
--TraceFrame:AddMessage("snom = "..snom);
							--ideb = ipos + 1;
							bbon = true;
						end
					end
				end
			end
--			[20]	date du modèle
--			[21]	si character, rep du modèle
--			[22]	si character, genre du modèle
--			[23]	si character, nom du modèle
--			[24]	si character, blp du modèle
--			[25]	si creature, rep du modèle
--			[26]	si creature, nom du modèle
--			[27]	si creature, blp du modèle
			if ( bbon == true ) then
				if ( srep == "sheep" or srep == "pig" or srep == "turtle" or srep == "penguinpet" ) then
if ( DBCS_debug > 1 ) then
TraceFrame:AddMessage("snommob = "..snommob.." , region = "..snumregion.." est une transformation en "..srep);
end
					return nil;
				end
				sDBMVWC = "";
				sDBMVWC = sDBMVWC..snommob.."#";
				sDBMVWC = sDBMVWC..snumregion.."#";
				if ( stype == "character" ) then
					--tablo[21] = srep;
					--tablo[22] = sgenre;
					--tablo[23] = snom;
					--tablo[24] = snomblp;
					----smodele = stype.."/"..srep.."/"..sgenre.."/"..snom..".m2";
					sDBMVWC = sDBMVWC..stype.."@"..srep.."@"..sgenre.."@"..snom..".m2@"..snomblp.."@";
				elseif ( stype == "creature" ) then
					--tablo[25] = srep;
					--tablo[26] = snom;
					--tablo[27] = snomblp;
					----smodele = stype.."/"..srep.."/"..snom..".m2";
					sDBMVWC = sDBMVWC..stype.."@"..srep.."@@"..snom..".m2@"..snomblp.."@";
				end
				idate = tonumber(sdate);
				DBMVWC[sDBMVWC] = idate;
				smodele2 = stype.."@"..srep.."@"..sgenre.."@"..snom..".m2@"..snomblp.."@";
				if ( tablo[28] == nil ) then
					tablo[28] = {};
				end
				if ( tablo[28][smodele2] == nil ) then
					tablo[28][smodele2] = idate;
				end
				if ( tablo[28][smodele2] < idate ) then
					tablo[28][smodele2] = idate;
				end
				DBMS[snommob][snumregion] = tablo;
			end
			--tablo[20] = sdate;
			--if ( tablo[20] == nil or ( tonumber(tablo[20]) < tonumber(sdate) ) ) then
			--end
		end
	end

end

--/script DBmobs_MVW_recup_modele_et_blp_existe_deja();
function DBmobs_MVW_recup_modele_et_blp_existe_deja()

local smodeleblp;
local ideb;
local ipos;
local bbon;
local snommon;
local snumregion;
local stype = "";
local srep = "";
local sgenre = "";
local snommodele = "";
local snomblp = "";
local snomm2;
local smodele2;

	for smodeleblp, _ in pairs(DBMVWC) do
		bbon = true;
		if ( bbon == true ) then
			ideb = 1;
			ipos = strfind(smodeleblp,"#",ideb);
			if ( ipos ) then
				snommob = strsub(smodeleblp,ideb,ipos-1);
			else
				bbon = false;
			end
		end
		if ( bbon == true ) then
			ideb = ipos + 1;
			ipos = strfind(smodeleblp,"#",ideb);
			if ( ipos ) then
				snumregion = strsub(smodeleblp,ideb,ipos-1);
			else
				bbon = false;
			end
		end
		if ( bbon == true ) then
			ideb = ipos + 1;
			ipos = strfind(smodeleblp,"@",ideb);
			if ( ipos ) then
				stype = strsub(smodeleblp,ideb,ipos-1);
			else
				bbon = false;
			end
		end
		if ( bbon == true ) then
			ideb = ipos + 1;
			ipos = strfind(smodeleblp,"@",ideb);
			if ( ipos ) then
				srep = strsub(smodeleblp,ideb,ipos-1);
			else
				bbon = false;
			end
		end
		if ( bbon == true ) then
			ideb = ipos + 1;
			ipos = strfind(smodeleblp,"@",ideb);
			if ( ipos ) then
				sgenre = strsub(smodeleblp,ideb,ipos-1);
			else
				bbon = false;
			end
		end
		if ( bbon == true ) then
			ideb = ipos + 1;
			ipos = strfind(smodeleblp,"@",ideb);
			if ( ipos ) then
				snommodele = strsub(smodeleblp,ideb,ipos-1);
			else
				bbon = false;
			end
		end
		if ( bbon == true ) then
			ideb = ipos + 1;
			ipos = strfind(smodeleblp,"@",ideb);
			if ( ipos ) then
				snomblp = strsub(smodeleblp,ideb,ipos-1);
			else
				bbon = false;
			end
		end
		sdate = DBMVWC[smodeleblp];
		if ( type(sdate) == "number" ) then
			sdate = ""..sdate;
		end
--	["Gardien du Crâne ricanant#034#character@orc@male@orcmale.m2@@"] = 0,

		if ( bbon == true ) then
			snomm2 = "";
			if ( stype == "" ) then
			else
				snomm2 = snomm2..stype;
			end
			if ( srep == "" ) then
			else
				snomm2 = snomm2.."/"..srep;
			end
			if ( sgenre == "" ) then
			else
				snomm2 = snomm2.."/"..sgenre;
			end
			if ( snommodele == "" ) then
			else
				snomm2 = snomm2.."/"..snommodele;
			end
			smodele2 = stype.."@"..srep.."@"..sgenre.."@"..snommodele.."@"..snomblp.."@";
--TraceFrame:AddMessage("smodele2 = "..smodele2);
			--if ( DBMS and DBMS[snommob] and DBMS[snommob][snumregion] and DBMS[snommob][snumregion][20] ) then
			if ( DBMS and DBMS[snommob] and DBMS[snommob][snumregion] ) then
				if ( DBMS[snommob][snumregion][28] == nil ) then
					DBMS[snommob][snumregion][28] = {};
				end
				if ( DBMS[snommob][snumregion][28][smodele2] ) then
					DBmobs_MVW_enreg_modele_et_blp(snommob,snumregion,snomm2,snomblp,sdate);
					DBMVWC[smodeleblp] = nil;
				end
			end
		else
			DBMVWC[smodeleblp] = nil;
		end

--DBMS
--1 mob =
--	1 nommob			= "Crabe à pince"
--		1 numregion		= "205"
--			[20]	date du modèle
--			[21]	si character, rep du modèle
--			[22]	si character, genre du modèle
--			[23]	si character, nom du modèle
--			[24]	si character, blp du modèle
--			[25]	si creature, rep du modèle
--			[26]	si creature, nom du modèle
--			[27]	si creature, blp du modèle
	end

end

--/script DBmobs_MVW_recup_modele_et_blp_existe_pas();
function DBmobs_MVW_recup_modele_et_blp_existe_pas()

local smodeleblp;
local ideb;
local ipos;
local bbon;
local snommon;
local snumregion;
local stype;
local srep;
local sgenre;
local snommodele;
local snomblp;
local snomm2;
local smodele2;

	for smodeleblp, _ in pairs(DBMVWC) do
		bbon = true;
		if ( bbon == true ) then
			ideb = 1;
			ipos = strfind(smodeleblp,"#",ideb);
			if ( ipos ) then
				snommob = strsub(smodeleblp,ideb,ipos-1);
			else
				bbon = false;
			end
		end
		if ( bbon == true ) then
			ideb = ipos + 1;
			ipos = strfind(smodeleblp,"#",ideb);
			if ( ipos ) then
				snumregion = strsub(smodeleblp,ideb,ipos-1);
			else
				bbon = false;
			end
		end
		if ( bbon == true ) then
			ideb = ipos + 1;
			ipos = strfind(smodeleblp,"@",ideb);
			if ( ipos ) then
				stype = strsub(smodeleblp,ideb,ipos-1);
			else
				bbon = false;
			end
		end
		if ( bbon == true ) then
			ideb = ipos + 1;
			ipos = strfind(smodeleblp,"@",ideb);
			if ( ipos ) then
				srep = strsub(smodeleblp,ideb,ipos-1);
			else
				bbon = false;
			end
		end
		if ( bbon == true ) then
			ideb = ipos + 1;
			ipos = strfind(smodeleblp,"@",ideb);
			if ( ipos ) then
				sgenre = strsub(smodeleblp,ideb,ipos-1);
			else
				bbon = false;
			end
		end
		if ( bbon == true ) then
			ideb = ipos + 1;
			ipos = strfind(smodeleblp,"@",ideb);
			if ( ipos ) then
				snommodele = strsub(smodeleblp,ideb,ipos-1);
			else
				bbon = false;
			end
		end
		if ( bbon == true ) then
			ideb = ipos + 1;
			ipos = strfind(smodeleblp,"@",ideb);
			if ( ipos ) then
				snomblp = strsub(smodeleblp,ideb,ipos-1);
			else
				bbon = false;
			end
		end
		sdate = DBMVWC[smodeleblp];
		if ( type(sdate) == "number" ) then
			sdate = ""..sdate;
		end
--	["Gardien du Crâne ricanant#034#character@orc@male@orcmale.m2@@"] = 0,

		if ( bbon == true ) then
			snomm2 = "";
			if ( stype == "" ) then
			else
				snomm2 = snomm2..stype;
			end
			if ( srep == "" ) then
			else
				snomm2 = snomm2.."/"..srep;
			end
			if ( sgenre == "" ) then
			else
				snomm2 = snomm2.."/"..sgenre;
			end
			if ( snommodele == "" ) then
			else
				snomm2 = snomm2.."/"..snommodele;
			end
			smodele2 = stype.."@"..srep.."@"..sgenre.."@"..snommodele.."@"..snomblp.."@";
			--if ( DBMS and DBMS[snommob] and DBMS[snommob][snumregion] and ( DBMS[snommob][snumregion][20] == nil ) ) then
			if ( DBMS and DBMS[snommob] and DBMS[snommob][snumregion] ) then
				if ( DBMS[snommob][snumregion][28] == nil ) then
					DBMS[snommob][snumregion][28] = {};
				end
				if ( DBMS[snommob][snumregion][28][smodele2] == nil ) then
					DBmobs_MVW_enreg_modele_et_blp(snommob,snumregion,snomm2,snomblp,sdate);
					DBMVWC[smodeleblp] = nil;
				end
			end
		end

--DBMS
--1 mob =
--	1 nommob			= "Crabe à pince"
--		1 numregion		= "205"
--			[20]	date du modèle
--			[21]	si character, rep du modèle
--			[22]	si character, genre du modèle
--			[23]	si character, nom du modèle
--			[24]	si character, blp du modèle
--			[25]	si creature, rep du modèle
--			[26]	si creature, nom du modèle
--			[27]	si creature, blp du modèle
	end

end

--/script DBmobs_recup_modele_20()
function DBmobs_recup_modele_20()

local snommob;
local sregion;
local tablo;
local smodele2;
local idate;

	for snommob, _ in pairs(DBMS) do
		for sregion, _ in pairs(DBMS[snommob]) do
			tablo = DBMS[snommob][sregion];
			if ( tablo[20] ) then
				if ( tablo[28] == nil ) then
					tablo[28] = {};
				end
				idate = tonumber(tablo[20]);
				smodele2 = nil;
				if ( tablo[21] ) then
					smodele2 = "character@"..tablo[21].."@"..tablo[22].."@"..tablo[23]..".m2@"..(tablo[24] or "").."@";
					if ( tablo[28][smodele2] == nil ) then
						tablo[28][smodele2] = idate;
					end
				end
				if ( tablo[25] ) then
					smodele2 = "creature@"..tablo[25].."@@"..tablo[26]..".m2@"..(tablo[27] or "").."@";
					if ( tablo[28][smodele2] == nil ) then
						tablo[28][smodele2] = idate;
					end
				end
				tablo[20] = nil;
				tablo[21] = nil;
				tablo[22] = nil;
				tablo[23] = nil;
				tablo[24] = nil;
				tablo[25] = nil;
				tablo[26] = nil;
				tablo[27] = nil;
				DBMS[snommob][sregion] = tablo;
			end
		end
	end

end

--/script DBmobs_enlever_region_inconnu_1mob("aaaaaaaaaaaaaaaaaaaa");
--/script DBmobs_enlever_region_inconnu_1mob("Hungarfen");
--/script DBmobs_enlever_region_inconnu_1mob("Marmon");
function DBmobs_enlever_region_inconnu_1mob(snommob)

local sregion;
local btrouve;
local inumobjet;

	if ( DBMS[snommob] and DBMS[snommob]["000"] ) then
		btrouve = false;
		for sregion, _ in pairs(DBMS[snommob]) do
			if ( sregion == "000" or sregion == "0" ) then
			else
				--if ( DBMS[snommob]["000"][2] == DBMS[snommob][sregion][2] ) then
					if ( DBMS[snommob]["000"][3] == DBMS[snommob][sregion][3] ) then
						if ( DBMS[snommob]["000"][4] == DBMS[snommob][sregion][4] ) then
							if ( DBMS[snommob]["000"][5] == DBMS[snommob][sregion][5] ) then
								btrouve = true;
								if ( DBMS[snommob]["000"][7] ) then
									if ( DBMS[snommob][sregion][7] == nil ) then
										DBMS[snommob][sregion][7] = 0;
									end
									DBMS[snommob][sregion][7] = DBMS[snommob][sregion][7] + DBMS[snommob]["000"][7];
								end
								if ( DBMS[snommob]["000"][9] ) then
									if ( DBMS[snommob][sregion][9] == nil ) then
										DBMS[snommob][sregion][9] = 0;
									end
									DBMS[snommob][sregion][9] = DBMS[snommob][sregion][9] + DBMS[snommob]["000"][9];
								end
								if ( DBMS[snommob]["000"][8] ) then
									if ( DBMS[snommob][sregion][8] == nil ) then
										DBMS[snommob][sregion][8] = {};
									end
									for inumobjet, _ in pairs(DBMS[snommob]["000"][8]) do
										if ( DBMS[snommob][sregion][8][inumobjet] == nil ) then
											DBMS[snommob][sregion][8][inumobjet] = 0;
										end
										DBMS[snommob][sregion][8][inumobjet] = DBMS[snommob][sregion][8][inumobjet] + DBMS[snommob]["000"][8][inumobjet];
									end
								end
							end
						end
					end
				--end
			end
		end
		if ( btrouve == true ) then
			DBMS[snommob]["000"] = nil;
		end
	end

end

--/script DBmobs_enlever_region_inconnu_allmob()
function DBmobs_enlever_region_inconnu_allmob()

local snommob;

	for snommob, _ in pairs(DBMS) do
		DBmobs_enlever_region_inconnu_1mob(snommob);
	end

end

function fDBmobs_Local_ajouter(inum,snom,snumregion,idate,bcms)

local benvoi;
local i;
local j;
local smessage;
--local snumregion;
local smot_milieu;
local smot_tout;
local slink;

	--if ( DBmobs_Local_exist ) then
	--	if ( DBmobs_Local_exist == DBCS_getlocale ) then
	--	else
	--		DBCS_loaded_addon("DBmobs_"..DBCS_getlocale);
	--	end
	--else
	--	DBCS_loaded_addon("DBmobs_"..DBCS_getlocale);
	--end
	benvoi = true;
	if ( DBmobs_Local_exist and DBmobs_Local_exist == DBCS_getlocale ) then
		benvoi = false;
		if ( DBmobs_Local[inum] == nil ) then
			DBmobs_Local_inverse_b = false;
			DBmobs_Local[inum] = {};
if ( DBCS_debug > 1 ) then
		smot_milieu = format("%X",inum);
		--if ( DBCS_mobs_wow_build > DBCS_mobs_wow_build_live ) then
			smot_tout = "unit:0xF53"..strrep("0",5-strlen(smot_milieu))..smot_milieu.."00000000:"..snom;
		--else
		--	smot_tout = "unit:0xF53"..strrep("0",7-strlen(smot_milieu))..smot_milieu.."000000:"..snom;
		--end
		slink = "|cff4e96f7|H"..smot_tout.."|h["..snom.."]|h|r";
TraceFrame:AddMessage("ajout de "..inum.." : "..slink..".");
end
		end
		j = 0;
		for i = 1 , table.getn(DBmobs_Local[inum]) do
			if ( DBmobs_Local[inum][i][1] == snom ) then
				j = i;
				if ( snumregion == nil ) then
					snumregion = DBmobs_Local[inum][1][3];
				end
			end
		end
		if ( j > 1 ) then
			table.remove(DBmobs_Local[inum],j);
		end
		if ( DBmobs_Local[inum][1] == nil ) then
			benvoi = true;
			DBmobs_Local[inum][1] = {};
		else
			if ( DBmobs_Local[inum][1][2] < idate ) then
				benvoi = true;
			end
		end
		if ( benvoi == true ) then
			--DBmobs_Local_inverse_b = false;
			DBmobs_Local[inum][1][1] = snom;
			DBmobs_Local[inum][1][2] = idate;
			DBmobs_Local[inum][1][3] = snumregion;
			if ( DBCS_prog_serveur == 0 ) then
				if ( DBMobs_Local_Client[DBCS_getlocale] == nil ) then
					DBMobs_Local_Client[DBCS_getlocale] = {};
				end
				DBMobs_Local_Client[DBCS_getlocale][inum] = {};
				DBMobs_Local_Client[DBCS_getlocale][inum][1] = snom;
				DBMobs_Local_Client[DBCS_getlocale][inum][2] = idate;
				DBMobs_Local_Client[DBCS_getlocale][inum][3] = snumregion;
			end
		end
		if ( bcms == true and benvoi == true ) then
			if ( DBCS_CMS_numcanalCMS > 0 ) then
				smessage = "";
				smessage = smessage.."@ADBCS@";
				smessage = smessage..DBCS_getlocale.."@";
				smessage = smessage.."MN01@";
				smessage = smessage..inum.."@";
				smessage = smessage..snom.."@";
				smessage = smessage..snumregion.."@";
				smessage = smessage..idate.."@";
				DBCS_SendChatMessage(smessage,"CHANNEL",DBCS_language,DBCS_CMS_numcanalCMS);
			end
		end
	end
	if ( benvoi == true and DBMS and DBMS[snom] ) then
		--snumregion = DBCS_Region_liste_code_region_courante_new();	--DBCS_numregionbyname(GetRealZoneText());
		if ( DBMS[snom][snumregion] ) then
			DBMS[snom][snumregion][29] = inum;
		end
	end

end

--/script fDBmobs_Local_copier_client_vers_serveur()
function fDBmobs_Local_copier_client_vers_serveur(bafficher)

local inummob;

	if ( bafficher == nil ) then
		bafficher = true;
	end
	if ( DBMobs_Local_Client and DBMobs_Local_Client[DBCS_getlocale] ) then
		for inummob, _ in pairs(DBMobs_Local_Client[DBCS_getlocale]) do
			if ( type(inummob) == "string" ) then
				--inummob = tonumber(inummob,16);
			end
			fDBmobs_Local_ajouter(inummob,DBMobs_Local_Client[DBCS_getlocale][inummob][1],DBMobs_Local_Client[DBCS_getlocale][inummob][3],DBMobs_Local_Client[DBCS_getlocale][inummob][2],false);
			if ( bafficher == true ) then
				DBMobs_Local_Client[DBCS_getlocale][inummob] = nil;
			end
		end
	end

end
