Skip to content

CustomTaskEvent

youyihj edited this page Jan 19, 2021 · 8 revisions

CustomTaskEvent

The event is used to define the checker and other logic of custom tasks.

Importing the package

It might be required to import the class to avoid errors.

import mods.zenutils.ftbq.CustomTaskEvent;

Extension

ChapterCompletedEvent extends IEventCancelable. That means all Methods and ZenGetters that are available for IEventCancelable are also available for ChapterCompletedEvent!

ZenSetters and ZenGetters

ZenGetter ZenSetter Type Description
task Task
checker ITaskChecker
checkTimer checkTimer int how many ticks is the checker function is called
maxProgress maxProgress int Max progress of this task
enableButton enableButton bool Enable checking on button click

ITaskChecker

Package

mods.zenutils.ftbq.ITaskChecker

Usage

This is a function with the following parameters (in this order).

  • IPlayer player
  • int currentProgress -> the current progress of the task

the function needs return an int representing the new progress of the task. If the new progress is equal to or bigger than maxProgress of task, the task is complete.

Example

Besides the script, you need to add a custom task with a tag named test.

import mods.zenutils.ftbq.CustomTaskEvent;
import crafttweaker.event.PlayerLoggedInEvent;
import crafttweaker.player.IPlayer;

events.onPlayerLoggedIn(function(event as PlayerLoggedInEvent) {
    val player as IPlayer = event.player;
    if (player.world.remote) return;
    var n as int = 0;
    if (player.data has "PlayerPersisted" && player.data.PlayerPersisted has "LoggedInCount") {
        n = player.data.PlayerPersisted.LoggedInCount.asInt();
    }
    player.update({PlayerPersisted: {LoggedInCount: n + 1}});
});

events.onCustomTask(function(event as CustomTaskEvent) {
    if (event.task.hasTag("test")) {
        event.maxProgress = 10;
        event.checkTimer = 100;
        event.enableButton = false;
        event.checker = function(player, currentProgress) {
            if (player.data has "PlayerPersisted" && player.data.PlayerPersisted has "LoggedInCount") {
                return player.data.PlayerPersisted.LoggedInCount.asInt();
            } else {
                return 0;
            }
        };
    }
});
Clone this wiki locally