Jump to content

Weather System Problem.


itHyperoX

Recommended Posts

Hi guys.

The script:

local oldRand = 1

function settheweather()

repeat
	typee = math.random(0, 12)
	until oldRand ~= typee	

if typee == 0 then
 weather = "Weather1"
 
 elseif typee == 1 then
 weather = "Weather2"
 
 elseif typee == 2 then
 weather = "Weather3"
 
 elseif typee == 3 then
 weather = "Weather4"
 
 elseif typee == 4 then
 weather = "Weather5"
 
 elseif typee == 5 then
 weather = "Weather6"
 
 elseif typee == 6 then
 weather = "Weather7"
 
 elseif typee == 7 then
 weather = "Weather8"
 
 elseif typee == 8 then
 weather = "Weather9"
 
 elseif typee == 9 then
 weather = "Weather10"
 
 elseif typee == 10 then
 weather = "Weather11"
 
 elseif typee == 22 then
 weather = "Weather12" 
 
 end
 
setWeather (tonumber(typee))
outputChatBox("[Weather] " .. weather .. " ", getRootElement(), 255, 255, 20, true)		
end

addEventHandler("onResourceStart", getResourceRootElement(getThisResource()),
	function ()
		settheweather()
		setTimer(settheweather, 1800000, 0)
end
)

 

error:

"codeServer.lua:48: attempt to concatenate global 'weather' (a nil value)

 

Anyone can help me please?

Edited by MilOG
ww
Link to comment

...

local oldRand = 1


function settheweather(weather)

repeat
	typee = math.random(0, 12)
	until oldRand ~= typee	

	if typee == 0 then
	weather = "Weather1"
 
	elseif typee == 1 then
	weather = "Weather2"
 
	elseif typee == 2 then
	weather = "Weather3"
 
	elseif typee == 3 then
	weather = "Weather4"
 
	elseif typee == 4 then
	weather = "Weather5"
 
	elseif typee == 5 then
	weather = "Weather6"
 
	elseif typee == 6 then
	weather = "Weather7"
 
	elseif typee == 7 then
	weather = "Weather8"
 
	elseif typee == 8 then
	weather = "Weather9"
 
	elseif typee == 9 then
	weather = "Weather10"
	
	elseif typee == 10 then
	weather = "Weather11"
 
	elseif typee == 22 then
	weather = "Weather12" 
	end
	setWeather (tonumber(typee))
	outputChatBox("[Weather] " .. weather .. " ", getRootElement(), 255, 255, 20, true)		
end

addEventHandler("onResourceStart", getResourceRootElement(getThisResource()),
	function ()
		settheweather()
		setTimer(settheweather, 7800, 0) -- test
end
)

 

Edited by Hit+
Link to comment

Sorry, i can't edit my post. However, why you don't use this?

function settheweather()
	typee = math.random(0, 19)
	setWeather (tonumber(typee))
	outputChatBox("[Weather] Weather"..tonumber(typee), getRootElement(), 255, 255, 20, true)		
end


addEventHandler("onResourceStart", getResourceRootElement(getThisResource()),
	function ()
	settheweather()
	setTimer(settheweather, 1000, 0) -- test line
end) 

 

 

Link to comment

Here is my weather system, I think using this method (using tables) is easier.

local weatherTable={			
    { weatherid=0, name="very sunny" },
	{ weatherid=1, name="sunny" },
    { weatherid=2, name="sunny but foggy" },
	{ weatherid=8, name="rainy" },
    { weatherid=9, name="foggy" },
}

local currentWeatherTable={}

function setNewWeather()
	currentFogDistance = getFogDistance()
    while (#currentWeatherTable<7) do
		table.insert(currentWeatherTable,weatherTable[math.random(1,#weatherTable)])
    end
end


function weatherSystemStart()
	setTimer(newWeather, 1000, 1)
end
addEventHandler("onResourceStart", resourceRoot,setNewWeather)
addEventHandler("onResourceStart", resourceRoot,weatherSystemStart)

function newWeather()
    local weather=table.remove(currentWeatherTable,1)
    outputChatBox("the weather is now "..weather.name)
    setWeatherBlended(weather.weatherid)
    setNewWeather()
end
setTimer(newWeather, 1000*(math.random(5, 10))*60, 0)

You can add more weathers by just adding a new line to the table and changing the id and the name to whatever you want.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...