#Is it possible to make something happen every, say, 200 ticks instead of every tick?

8 messages · Page 1 of 1 (latest)

spice osprey
#

I'm making a modpack for me n' my friends, and I used this script–which is 90% made by desync–to change the default player size of an origin, but I don't want it to trigger every tick. to be overly specific I would like it to run once when the origin is selected and again every 20-60s just in case someone finds a way to change their size. I've tried using PlayerEvents.onInventoryClosed but the origin selection menu doesn't count as an inventory (probably obvious but it was worth a shot).


const $OriginLayer = Java.loadClass('io.github.apace100.origins.origin.OriginLayer');
const $OriginLayers = Java.loadClass('io.github.apace100.origins.origin.OriginLayers');
const $ModComponents = Java.loadClass('io.github.apace100.origins.registry.ModComponents');
const $Origin = Java.loadClass('io.github.apace100.origins.origin.Origin');
const SCALE_TYPES = Java.loadClass('virtuoel.pehkui.api.ScaleTypes')
const playerOrigins = {};

/**
 * @param {Internal.Entity} entity
 * @param {string} originLayerString
 */
function getOrigin(entity, originLayerString) {
    let originLayer = $OriginLayers.getLayer(originLayerString ?? 'origins:origin');
    let origin = $ModComponents.ORIGIN.get(entity).getOrigin(originLayer);
    
    return origin.getIdentifier();
    
}

PlayerEvents.tick(event => {
    const {player} = event;
    //player.tell(getOrigin(player));

    if(playerOrigins[player.uuid.toString()] = getOrigin(player) == 'icarae_origin:icarae') {
        SCALE_TYPES.BASE.getScaleData(player).setScale(0.87)
        
        

    } else {
        SCALE_TYPES.BASE.getScaleData(player).setScale(1)
        
        
    }
})```
civic houndBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

random zephyr
#
if (player.age % 200 != 0) return

add that before you run your stuff in the tick event

#

also consider using player.persistentData instead of an object that will reset with every reload

spice osprey
#

Full script


const $OriginLayer = Java.loadClass('io.github.apace100.origins.origin.OriginLayer');
const $OriginLayers = Java.loadClass('io.github.apace100.origins.origin.OriginLayers');
const $ModComponents = Java.loadClass('io.github.apace100.origins.registry.ModComponents');
const $Origin = Java.loadClass('io.github.apace100.origins.origin.Origin');
const SCALE_TYPES = Java.loadClass('virtuoel.pehkui.api.ScaleTypes')
const playerOrigins = {};

/**
 * @param {Internal.Entity} entity
 * @param {string} originLayerString
 */
function getOrigin(entity, originLayerString) {
    let originLayer = $OriginLayers.getLayer(originLayerString ?? 'origins:origin');
    let origin = $ModComponents.ORIGIN.get(entity).getOrigin(originLayer);
    
    return origin.getIdentifier();
    
}

PlayerEvents.tick(event => {
    if (player.age % 200 != 0) return
    const {player} = event;
    //player.tell(getOrigin(player));

    if(playerOrigins[player.uuid.toString()] = getOrigin(player) == 'icarae_origin:icarae') {
        SCALE_TYPES.BASE.getScaleData(player).setScale(0.87)
        
        

    } else {
        SCALE_TYPES.BASE.getScaleData(player).setScale(1)
        
        
    }
})```
hollow mica
#

you're trying to reference 'player' before you define it, just move the age check down a line

spice osprey
#

ah