function init()
	blinkers = FindShapes("blinker")
	inten = 0
	init_rand = math.random(1,10)
	key_map = {
		full_key = {
			l = "leftarrow",
			r = "rightarrow",
			w = "downarrow",
			off = "uparrow"}
	}
end

function doBlink()
	local timer = GetTime() + init_rand	--float seconds
	if timer % 0.7 < 0.35 then
		inten = 1
	else
		inten = inten/1.5
	end
	
	for i=1,#blinkers do
		local blinkerTag = GetTagValue(blinkers[i], "blinker")
		if blinkerTag == blinkerState or blinkerState == "warn" then
			SetShapeEmissiveScale(blinkers[i],inten)
		else
			SetShapeEmissiveScale(blinkers[i],0)
		end
	end
end

function toggleState()
	curVehicle = GetPlayerVehicle()
	if InputPressed(key_map.full_key.l) then
		SetTag(curVehicle, "blinkerState", "l")
	elseif InputPressed(key_map.full_key.r) then
		SetTag(curVehicle, "blinkerState", "r")
	elseif InputPressed(key_map.full_key.w) then
		SetTag(curVehicle, "blinkerState", "warn")
	elseif InputPressed(key_map.full_key.off) then
		SetTag(curVehicle, "blinkerState", "off")
	end
end

function tick(dt)
	blinkerState = GetTagValue(FindVehicle("blinkerState"), "blinkerState")
	doBlink()
	toggleState()
end