• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

C++ [TFS 1.3] Add color palette to day/night cycle

Lyky

Well-Known Member
Joined
May 27, 2014
Messages
291
Solutions
8
Reaction score
89
Hi,
Not sure how to approach it, but i would like to request help with adding color of the light for each of the states

enum LightState_t {
LIGHT_STATE_DAY,
LIGHT_STATE_NIGHT,
LIGHT_STATE_SUNSET,
LIGHT_STATE_SUNRISE,
};



static constexpr int32_t LIGHT_LEVEL_DAY = 250;
static constexpr int32_t LIGHT_LEVEL_NIGHT = 40;
static constexpr int32_t SUNSET = 1305;
static constexpr int32_t SUNRISE = 430;

LightState_t lightState = LIGHT_STATE_DAY;
uint8_t lightLevel = LIGHT_LEVEL_DAY;
int32_t lightHour = SUNRISE + (SUNSET - SUNRISE) / 2;
// (1440 minutes/day)/(3600 seconds/day)*10 seconds event interval
int32_t lightHourDelta = 1400 * 10 / 3600;

Would want it to rotate around similar array of colors, rather than just intensity of light.
1641254022547.png


I appreciate all help,
Regards
 
I think the easiest way to make it is to implement the colours palette as map<hour, colour> and when checking the light/updating the world time set the light colour from hardcoded 215 to the one from map[hour]. 🤔
 
the colors correspond exactly with the color palette of the image that I provide in the thread
you need to make sure you go to your config.lua and change this: defaultWorldLight = true change it to false: defaultWorldLight = false

When the server starts, the light intensity and color are set, and another event will update this every 10 minutes.

data/scripts/daynightcycle.lua
Lua:
local lightInt = 255/12
local dayNightCycle = {[0]=8, [1]=8, [2]=8, [3]=8, [4]=8, [5]=15, [6]=15, [7]=22, [8]=100, [9]=214, [10]=206, [11]=206, [12]=200, [13]=200, [14]=200, [15]=199, [16]=194, [17]=159, [18]=81, [19]=44, [20]=38, [21]=44, [22]=1, [23]=1, [24]=8}
local function getLightLevel(hour)
    if hour <= 12 then return lightInt * hour end
    local light = lightInt * 12
    return light - (lightInt * math.abs(12 - hour))
end

local function setWorldLightByHour()
    local hour = tonumber(os.date("%H"))
    setWorldLight(getLightLevel(hour), dayNightCycle[hour])
    return true
end

local globalEvent = GlobalEvent("DayNightCycleEvent")
globalEvent.onThink = setWorldLightByHour
globalEvent:interval(1000 * 60 * 10)
globalEvent:register()

globalEvent = GlobalEvent("DayNightCycleStartup")
globalEvent.onStartup = setWorldLightByHour
globalEvent:register()

Note: colors are not exact as tibia does not support such a wide and precise color palette, but the palette that I configure in the script is very accurate, if someone else can provide some method or way to improve the precision of the colors, I would like to know it too ;)

Extra: if you prefer to have the default light intensity, you can change this: getLightLevel(hour) to the number 215, if it changes to 215 then you can remove the getLightLevel function without any problem
 
Last edited:
the colors correspond exactly with the color palette of the image that I provide in the thread
you need to make sure you go to your config.lua and change this: defaultWorldLight = true change it to false: defaultWorldLight = false

When the server starts, the light intensity and color are set, and another event will update this every 10 minutes.

data/scripts/daynightcycle.lua
Lua:
local lightInt = 255/12
local dayNightCycle = {[0]=8, [1]=8, [2]=8, [3]=8, [4]=8, [5]=15, [6]=15, [7]=22, [8]=100, [9]=214, [10]=206, [11]=206, [12]=200, [13]=200, [14]=200, [15]=199, [16]=194, [17]=159, [18]=81, [19]=44, [20]=38, [21]=44, [22]=1, [23]=1, [24]=8}
local function getLightLevel(hour)
    if hour <= 12 then return lightInt * hour end
    local light = lightInt * 12
    return light - (lightInt * math.abs(12 - hour))
end

local function setWorldLightByHour()
    local hour = tonumber(os.date("%H"))
    setWorldLight(getLightLevel(hour), dayNightCycle[hour])
    return true
end

local globalEvent = GlobalEvent("DayNightCycleEvent")
globalEvent.onThink = setWorldLightByHour
globalEvent:interval(1000 * 60 * 10)
globalEvent:register()

globalEvent = GlobalEvent("DayNightCycleStartup")
globalEvent.onStartup = setWorldLightByHour
globalEvent:register()

Note: colors are not exact as tibia does not support such a wide and precise color palette, but the palette that I configure in the script is very accurate, if someone else can provide some method or way to improve the precision of the colors, I would like to know it too ;)

Extra: if you prefer to have the default light intensity, you can change this: getLightLevel(hour) to the number 215, if it changes to 215 then you can remove the getLightLevel function without any problem
: attempt to call global 'setWorldLight' (a nil value)

I found it interesting I'm having this error
 
: attempt to call global 'setWorldLight' (a nil value)

I found it interesting I'm having this error
Sorry I forgot that it only supports with the new changes world light
 
Back
Top