--Script originally wrote by smallg
-- modified by 3com - 200919
-- this script working with "stop_rain.lua + doorauto4.lua" files, to stop rain on indoors.

stop_rain = 0
local rtimer = 0
local rtimer1 = g_Time
local timepassed = rtimer1 - rtimer
local imgNum = 0
math.randomseed(5)

--change to however many different images you have
local max_img = 4   
local delay = 0.05
local rainning = 0
local xpos = math.random(0,95)
local ypos = math.random(0,50)

function rain_init(e)
	LoadImages("weather",0)
	SetImagePosition(0,0)
	SetImageAlignment(1)
end

function rain_main(e)

if stop_rain == 0 then
	
if rtimer == 0 then
	rtimer = g_Time
end

	rtimer1 = g_Time
	timepassed = (rtimer1 - rtimer) / 1000

if timepassed >= delay then
	SetImagePosition(0,0)  --<<<<<<<<< need this to keep the rain images in place
	ShowImage(imgNum)
	LoopSound(e,0)
if imgNum < max_img - 1 then
	imgNum = imgNum + 1
  if math.random(10) == 5 then 
	rainning = 0
	xpos = math.random(0,50)
	ypos = math.random(0,50)
  end

else
	imgNum = 0
end -- imgNum

	rtimer = 0
end -- timepassed

if g_PlayerAngX <= -11 then
	if rainning < 5 then
		rainning = rainning + 1
		SetImagePosition(xpos,ypos) --<<<<<<<<< This places the rain randomly without going too low
		ShowImage(math.random(1,4))
		ypos = math.random(0,50)
		xpos = math.random(0,50)
	end
else
	rainning = 0
	xpos = math.random(0,50)
	ypos = math.random(0,50)
end -- g_PlayerAngX

else
	ShowImage(5)
	StopSound(e,0)
	LoopSound(e,1)
end -- stop_rain

if stop_rain == 2 then
	--for i = 868,871,1 do Spawn(i) end
	StopSound(e,0)	
	StopSound(e,1)
	ShowImage(5)
	Destroy(e)
end

end -- main
