Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var timeLimit = 16200.0; // 4.5h
- onEvent("player.tick", event => {
- if ((event.level.time % 20) == 0) {
- const currentDate = new Date().toDateString(); // ex: 'Mon Aug 15 2022'
- const player = event.player;
- if (player.persistentData.playedTime === undefined
- || player.persistentData.playedTime == null
- || isNaN(player.persistentData.playedTime)
- || player.persistentData.date != currentDate) {
- console.info(`Reseteado tiempo para: ${player.name} `)
- player.persistentData.playedTime = 0;
- }
- if (player.persistentData.playedTime >= timeLimit) {
- console.log("El jugador " + player.name + " ha superado el tiempo limite");
- console.info("El jugador " + player.name + " ha superado el tiempo limite");
- player.kick("Has superado las 4.5 horas, a descansar");
- }
- player.persistentData.date = currentDate;
- player.persistentData.playedTime += 1;
- }
- });
- function onRtpExecute(ctx) {
- const player = ctx.source.getPlayerOrException().asKJS();
- console.log(`Player: ${player.name}, Tiempo jugado hoy: ${(player.persistentData.playedTime / 3600.0).toFixed(2)} horas`);
- player.tell(`Tiempo jugado hoy: ${(player.persistentData.playedTime / 3600.0).toFixed(2)} horas`);
- return 1;
- }
- function commandRegistry(ev) {
- const { commands: Commands } = ev;
- ev.register(Commands.literal("tiempo").executes(onRtpExecute));
- }
- onEvent("command.registry", commandRegistry);
Advertisement
Comments
-
- Is there any way to execute a command to know how long I have been and how much I have left?
Add Comment
Please, Sign In to add comment
Advertisement