local objsrv = lgs.ObjectSrv
local linktoolssrv = lgs.LinkToolsSrv
local linkSrv = lgs.LinkSrv

local function ApplyMP(state,target,metapropID)
	print("metapropID ",metapropID)
	print("Target ",target)
	print("Statut ",state)
	if state == "On" and not objsrv.HasMetaProperty(target,metapropID) then
		objsrv.AddMetaProperty(target,metapropID)
	elseif state == "Off" and objsrv.HasMetaProperty(target,metapropID) then
		objsrv.RemoveMetaProperty(target,metapropID)
	else
		print("Something's wrong with the message transmission")
	end
end

local function getinfo(state)
	local Parameter1 = linkSrv.GetOne("ScriptParams",script.objid)
	local dest,sour,flav = linktoolssrv.LinkGet(Parameter1)
	local data = linktoolssrv.LinkGetData(Parameter1,"")
	print("Data ",data)
	print("Destination ",dest," Source ",sour," Type ",flav)
	print("Statut ",state)
	
	local data2 = objsrv.Named(data)
	
	if data2 ~= nil then
		ApplyMP(state,dest,objsrv.Named(data))	
	else
		ApplyMP(state,dest,data)
	end
	
end

function TurnOn()
	getinfo("On")
	return true
end

function TurnOff()
	getinfo("Off")
	return true
end

