Jots1_ Posted April 10, 2023 Share Posted April 10, 2023 What is wrong here? local weatherHour = { [0] = 0, [1] = 0, [2] = 0, [3] = 0, [4] = 0, [5] = 0, [6] = 1, [7] = 1, [8] = 1, [9] = 1, [10] = 2, [11] = 2, [12] = 3, [13] = 3, [14] = 3, [15] = 4, [16] = 4, [17] = 5, [18] = 5, [19] = 5, [20] = 11, [21] = 11, [22] = 11, [23] = 11 } function setWeatherHour() local hour = getRealTime().hour local weather = climaHora[hour] setWeather(weather) end setTimer(setWeatherHour, 3600000, 0) Link to comment
FLUSHBICEPS Posted April 10, 2023 Share Posted April 10, 2023 You are trying to access the table with climaHora variable replace setWeatherHour function with this function setWeatherHour() local hour = getRealTime().hour local weather = weatherHour[hour] setWeather(weather) end Link to comment
Jots1_ Posted April 10, 2023 Author Share Posted April 10, 2023 5 minutes ago, FLUSHBICEPS said: You are trying to access the table with climaHora variable replace setWeatherHour function with this function setWeatherHour() local hour = getRealTime().hour local weather = weatherHour[hour] setWeather(weather) end Didn't work. Link to comment
FLUSHBICEPS Posted April 10, 2023 Share Posted April 10, 2023 oops didn’t see, ur using getRealTime func, u should use getTime function to get in game time, also add if statement on weather variable to avoid any kind of error Link to comment
Jots1_ Posted April 10, 2023 Author Share Posted April 10, 2023 16 minutes ago, FLUSHBICEPS said: oops didn’t see, ur using getRealTime func, u should use getTime function to get in game time, also add if statement on weather variable to avoid any kind of error Didn't work too, I don't know if I'm doing any other mistake Link to comment
Jots1_ Posted April 10, 2023 Author Share Posted April 10, 2023 I made some small changes to the script but it still doesn't work local weatherHour = { [0] = 8, -- 0:00 - clear [1] = 7, -- 1:00 - clear [2] = 7, -- 2:00 - clear [3] = 7, -- 3:00 - clear [4] = 7, -- 4:00 - clear [5] = 7, -- 5:00 - clear [6] = 7, -- 6:00 - clear [7] = 0, -- 7:00 - extra sunny [8] = 0, -- 8:00 - extra sunny [9] = 0, -- 9:00 - extra sunny [10] = 0, -- 10:00 - extra sunny [11] = 0, -- 11:00 - extra sunny [12] = 0, -- 12:00 - extra sunny [13] = 0, -- 13:00 - extra sunny [14] = 0, -- 14:00 - extra sunny [15] = 3, -- 15:00 - cloudy [16] = 3, -- 16:00 - cloudy [17] = 3, -- 17:00 - cloudy [18] = 3, -- 18:00 - cloudy [19] = 3, -- 19:00 - cloudy [20] = 3, -- 20:00 - cloudy [21] = 2, -- 21:00 - foggy [22] = 8, -- 22:00 - foggy [23] = 2, -- 23:00 - foggy } function setWeatherHour() local hour = getTime().hour local weather = weatherHour[hour] setWeather(weather) end setTimer(setWeatherHour, 3600000, 0) Link to comment
Mkl Posted April 10, 2023 Share Posted April 10, 2023 Hi, I don't think getTime().hour is correct, check the wiki https://wiki.multitheftauto.com/wiki/GetTime Quote local timehour, timeminute = getTime() Link to comment
Anoir Tizaoui Posted April 12, 2023 Share Posted April 12, 2023 local weatherHour = { [0] = 0, [1] = 0, [2] = 0, [3] = 0, [4] = 0, [5] = 0, [6] = 1, [7] = 1, [8] = 1, [9] = 1, [10] = 2, [11] = 2, [12] = 3, [13] = 3, [14] = 3, [15] = 4, [16] = 4, [17] = 5, [18] = 5, [19] = 5, [20] = 11, [21] = 11, [22] = 11, [23] = 11 } function setWeatherHour() local hour = getRealTime().hour local weather = weatherHour[hour] setWeatherBlended(weather) end setTimer(setWeatherHour, 1000, 0) On 10/04/2023 at 17:59, Jots1_ said: What is wrong here? local weatherHour = { [0] = 0, [1] = 0, [2] = 0, [3] = 0, [4] = 0, [5] = 0, [6] = 1, [7] = 1, [8] = 1, [9] = 1, [10] = 2, [11] = 2, [12] = 3, [13] = 3, [14] = 3, [15] = 4, [16] = 4, [17] = 5, [18] = 5, [19] = 5, [20] = 11, [21] = 11, [22] = 11, [23] = 11 } function setWeatherHour() local hour = getRealTime().hour local weather = climaHora[hour] setWeather(weather) end setTimer(setWeatherHour, 3600000, 0) Try this local weatherHour = { [0] = 0, [1] = 0, [2] = 0, [3] = 0, [4] = 0, [5] = 0, [6] = 1, [7] = 1, [8] = 1, [9] = 1, [10] = 2, [11] = 2, [12] = 3, [13] = 3, [14] = 3, [15] = 4, [16] = 4, [17] = 5, [18] = 5, [19] = 5, [20] = 11, [21] = 11, [22] = 11, [23] = 11 } function setWeatherHour() local hour = getRealTime().hour local weather = weatherHour[hour] setWeatherBlended(weather) end setTimer(setWeatherHour, 1000, 0) Try this local weatherHour = { [0] = 0, [1] = 0, [2] = 0, [3] = 0, [4] = 0, [5] = 0, [6] = 1, [7] = 1, [8] = 1, [9] = 1, [10] = 2, [11] = 2, [12] = 3, [13] = 3, [14] = 3, [15] = 4, [16] = 4, [17] = 5, [18] = 5, [19] = 5, [20] = 11, [21] = 11, [22] = 11, [23] = 11 } function setWeatherHour() local hour = getRealTime().hour local weather = weatherHour[hour] setWeatherBlended(weather) end setTimer(setWeatherHour, 1000, 0) Link to comment
FLUSHBICEPS Posted April 12, 2023 Share Posted April 12, 2023 function setWeatherHour() local hour, minute = getTime() local rHour = math.floor(hour) local weatherID = weatherHour[rHour] if weatherID then setWeather(weatherID) end end setTimer(setWeatherHour, 3600000, 0) addEventHandler("onResourceStart", resourceRoot, setWeatherHour) Link to comment
Scripting Moderators xLive Posted April 12, 2023 Scripting Moderators Share Posted April 12, 2023 13 minutes ago, FLUSHBICEPS said: local rHour = math.floor(hour) This is useless. Why are you using floor on the hour? The getTime function will return an integer, not a float. 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