local doorsrv = lgs.DoorSrv
local linksrv = lgs.LinkSrv
local propsrv = lgs.PropertySrv
local OO = 0 --Point d'ouverture d'origine

function FrobWorldBegin(msg)	
	if propsrv.Possessed(script.objid, "ScriptTiming") then
	propsrv.Set(script.objid, "FrobInfo", "World Action",0x0)
		if propsrv.Possessed(script.objid,"TransDoor") then
			if OO > 0 then
				propsrv.Set(script.objid, "TransDoor", "Open Position",1)
			end
			if OO < 0 then
				propsrv.Set(script.objid, "TransDoor", "Open Position",-1)
			end
		end
		if propsrv.Possessed(script.objid,"RotDoor") then
			if OO > 180 then
				propsrv.Set(script.objid, "RotDoor", "Open Angle",350)
			end
			if OO < 180 then
				propsrv.Set(script.objid, "RotDoor", "Open Angle",10)
			end
		end
		doorsrv.OpenDoor(script.objid)
		if linksrv.AnyExist('ControlDevice',script.objid) then
			linksrv.BroadcastOnAllLinks(script.objid,'TurnOn','ControlDevice')
		end
	end
	if not propsrv.Possessed(script.objid, "ScriptTiming") then
		if propsrv.Possessed(script.objid,"RotDoor") then
			propsrv.Set(script.objid, "RotDoor", "Open Angle",OO)
		end
		if propsrv.Possessed(script.objid,"TransDoor") then
			propsrv.Set(script.objid, "TransDoor", "Open Position",OO)
		end
	end	
	return true
end

function DoorOpen(msg)
	propsrv.Set(script.objid, "FrobInfo", "World Action",0x2)	
	return true
end

function DoorClose(msg)
	propsrv.Set(script.objid, "FrobInfo", "World Action",0x2)	
	return true
end

function Sim(msg)
  if msg.fStarting then
	if propsrv.Possessed(script.objid,"TransDoor") then
		OO = propsrv.Get(script.objid, "TransDoor", "Open Position")
	end
	if propsrv.Possessed(script.objid,"RotDoor") then
		OO = propsrv.Get(script.objid, "RotDoor", "Open Angle")
	end
  end
  script.m_bSim = msg.fStarting
  return true
end