local datasrv = lgs.DataSrv
local propsrv = lgs.PropertySrv

local amountOfParts = 0
local amountOfPins = 0
local amountOfTime = 0

local function RandPins()
	return datasrv.RandInt(1,5)
end

local function RandTime()
	return datasrv.RandInt(1,3)
end

local function RandLockPick()
	local a = datasrv.RandInt(0,10)
	if a < 5 then
		return 1
	else
		return 10
	end
end

function Sim(msg)
  amountOfParts = datasrv.RandInt(0,4)
  if msg.fStarting then
	if amountOfParts > 0 then
		propsrv.Set(script.objid,"Locked",true)
		if amountOfParts > 3 then
			propsrv.Set(script.objid,"PickCfg","LockBits 1",RandLockPick())
			propsrv.Set(script.objid,"PickCfg","Pins 1",RandPins())
			propsrv.Set(script.objid,"PickCfg","TimePct 1",RandTime())
		end
		if amountOfParts > 2 then
			propsrv.Set(script.objid,"PickCfg","LockBits 2",RandLockPick())
			propsrv.Set(script.objid,"PickCfg","Pins 2",RandPins())
			propsrv.Set(script.objid,"PickCfg","TimePct 2",RandTime())
		end
		if amountOfParts > 1 then
			propsrv.Set(script.objid,"PickCfg","LockBits 3",RandLockPick())
			propsrv.Set(script.objid,"PickCfg","Pins 3",RandPins())
			propsrv.Set(script.objid,"PickCfg","TimePct 3",RandTime())
		end
	end
  end
  return true
end

