• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

How to have day/night cycle outside of caves in my server?

sharkeiqu

New Member
Joined
Mar 9, 2019
Messages
2
Reaction score
0
IIRC I need to edit my GAME.CPP file, what do I need to change? It's always full brightness in the mainland. I want a more realistic day night cycle.




LUA:
void Game::checkLight()
{
    g_scheduler.addEvent(createSchedulerTask(EVENT_LIGHTINTERVAL, std::bind(&Game::checkLight, this)));

    lightHour += lightHourDelta;

    if (lightHour > 1440) {
        lightHour -= 1440;
    }

    if (std::abs(lightHour - SUNRISE) < 2 * lightHourDelta) {
        lightState = LIGHT_STATE_SUNRISE;
    } else if (std::abs(lightHour - SUNSET) < 2 * lightHourDelta) {
        lightState = LIGHT_STATE_SUNSET;
    }

    int32_t newLightLevel = lightLevel;
    bool lightChange = false;

    switch (lightState) {
        case LIGHT_STATE_SUNRISE: {
            newLightLevel += (LIGHT_LEVEL_DAY - LIGHT_LEVEL_NIGHT) / 30;
            lightChange = true;
            break;
        }
        case LIGHT_STATE_SUNSET: {
            newLightLevel -= (LIGHT_LEVEL_DAY - LIGHT_LEVEL_NIGHT) / 30;
            lightChange = true;
            break;
        }
        default:
            break;
    }

    if (newLightLevel <= LIGHT_LEVEL_NIGHT) {
        lightLevel = LIGHT_LEVEL_NIGHT;
        lightState = LIGHT_STATE_NIGHT;
    } else if (newLightLevel >= LIGHT_LEVEL_DAY) {
        lightLevel = LIGHT_LEVEL_DAY;
        lightState = LIGHT_STATE_DAY;
    } else {
        lightLevel = newLightLevel;
    }

    if (lightChange) {
        LightInfo lightInfo = getWorldLightInfo();

        for (const auto& it : players) {
            it.second->sendWorldLight(lightInfo);
        }
    }
}

LightInfo Game::getWorldLightInfo() const
{
    return {lightLevel, 0xD7};
}

void Game::shutdown()
{
    std::cout << "Shutting down..." << std::flush;

    g_scheduler.shutdown();
    g_databaseTasks.shutdown();
    g_dispatcher.shutdown();
    map.spawns.clear();
    raids.clear();

    cleanup();

    if (serviceManager) {
        serviceManager->stop();
    }

    ConnectionManager::getInstance().closeAll();

    std::cout << " done!" << std::endl;
}
 
Back
Top