itHyperoX Posted November 26, 2016 Share Posted November 26, 2016 (edited) 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 November 26, 2016 by MilOG ww Link to comment
Rose Posted November 26, 2016 Share Posted November 26, 2016 (edited) ... 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 November 26, 2016 by Hit+ Link to comment
pa3ck Posted November 26, 2016 Share Posted November 26, 2016 You create a random number between 0 and 12, but in the "elseif blocks" you only have 0 to 10 and 22. Shouldn't you have 0 -> 12? Link to comment
Rose Posted November 26, 2016 Share Posted November 26, 2016 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
itHyperoX Posted November 27, 2016 Author Share Posted November 27, 2016 (edited) Thanks Hit again But i wanted like this: if typee == 0 then weather = "Very Hot" elseif typee == 1 then weather = "Hot" elseif typee == 2 then weather = "Rain" i hoep you understand. Edited November 27, 2016 by MilOG dffda Link to comment
Dzsozi (h03) Posted November 27, 2016 Share Posted November 27, 2016 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
itHyperoX Posted November 27, 2016 Author Share Posted November 27, 2016 Thanks Dzsozi! 1 Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now