Time, weather and the world

kcds.world.World holds the time of day, sky, rain and wind on the server, and all players' games follow it. A new server starts at 9:00, and by default 15 game seconds pass per real second. The clock never goes backwards.

const { World } = kcds.world;

World.setTimeScale(30);
World.setHour(18); // the next 18:00, which may be tomorrow
World.setWeather('cloudless_sunny', 60); // fade over 60 game seconds
World.setRain(0.5);
World.setWind({ x: 3, y: 0, z: 0 });

kcds.core.Events.on('worldDayChange', (day) => {
  console.info(`Day ${day} begins`);
});

Changing the world

Each setter returns true when it worked and false when a value is out of range.

CallAccepted values
setTime(day, hour)whole day from 0, hour from 0 up to (not including) 24; a past time returns false
setHour(hour)winds the clock on to that hour, which can be tomorrow
setTimeScale(scale)0 to 200; 0 stops the clock
setWeather(preset, seconds?)name of 1 to 64 characters from A-Z a-z 0-9 _ . -; fade of 0 to 21600 game seconds
setRain(intensity, amount?)both 0 to 1; amount defaults to 1
setWind({ x, y, z })metres per second; a missing component is 0; above 50 m/s is refused

setWeather also returns false while an earlier fade is still running.

Reading the world

GroupProperties
Timeday, hour, timeScale
Weatherweather (target preset), lastWeather, weatherFade, weatherLeft
RainrainStrength, rainLevel, wetness (0 to 3), puddles (0 to 1)
Windwind (a Vector3), windSpeed

Events

  • worldDayChange(day): midnight passed.
  • worldWeatherChange(preset, previous, seconds): a weather fade started.

Items placed by the level

Tankards, tools, goods on shop counters and similar items are shared between all players. The first player in reach to pick one up gets it, and it then disappears for everyone, including those who join later. Taken items come back when the server restarts.

Return false from worldItemPickup(player, { item, name, position }) to refuse a pick-up.

You can also remove these items altogether:

kcds.world.World.setLevelItemsEnabled(false); // hidden for all, nothing can be picked up

setLevelItemsEnabled(true) brings them back and World.levelItemsEnabled reads the setting. To start the server with them off, put { "enabled": false } in resources\level-items.json.

Renaming places

setPlaceName(place, name) renames a town or place for all current and future players, and null restores the game's name. World.places() lists the ids.

kcds.world.World.setPlaceName('troskovice', 'Zahradka');

This replaces the place's quest location and settlement name, with the same name in every language. Names written inside a sentence, such as a dialogue line or quest text, stay as the game has them.

Reference: World.