#A gradual effect increase that resets on hit?

38 messages · Page 1 of 1 (latest)

tacit aspen
#

I'm trying to make a belt that when worn will give you a small resistance effect boost that increases by +1% every few seconds up to 70% but when you take damage it resets to 0%

narrow valleyBOT
#

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

tacit aspen
#

So far this is what I get but the effect is not stacking or increasing amplifier like I want

solar saffronBOT
#

Paste version of gradual_buff.js from @tacit aspen

pallid onyx
#

Acessing player nbt can be costly

#

I'm going to see about helping you look for a better way to go about that.

#

But eh

#

If it works

#

Try putting some data on the player, persistantData that could hold some measurement

#

The higher that score the more it adds

#

I think it's neccesary becauss the only way it'll stack is if you change the modifer you applied.

tacit aspen
pallid onyx
#

The persistand data works exactly like nbt, it just apparently doesn't cause as many issues as asscessing nbt.

solar saffronBOT
#

What is persistent data and how to use it?
Persistent data is an object which exists on players, levels and servers!
It's super useful and easy to use!
Here's a simple example:

event.player.persistentData.myCoolNumber = 15
console.log(event.player.persistentData.myCoolNumber + 6) // 21
tacit aspen
solar saffronBOT
#

Paste version of gradual_buff.js from @tacit aspen

pallid onyx
#

This is a good example of getting persistentData.

// priority: 0
// requires: irons_spellbooks

(() => {

    /**
     * Fired when a player attempts to cast a spell
     * Code inside can be reloaded with /kubejs reload startup_scripts durnig runtime
     * @param {Internal.SpellPreCastEvent_} event
     */
    global.SpellPreCastEvent = function(event) {

        let player = event.entity
        if (!(player.isPlayer())) return

        if (event.schoolType.id != player.persistentData.getString('kubejsSpellSchool')) {
            event.setCanceled(true)
            return;
        }
    }

    // MUST be in startup script. Fired when a player attempts to cast a spell
    ForgeEvents.onEvent('io.redspace.ironsspellbooks.api.events.SpellPreCastEvent', event => global.SpellPreCastEvent(event))

})();
#

persistentData is a compund tag

#

Also, there is events for listening to when effects are active and all that.

#

I can give you examples, but I've never done this exact thing before so I won't promise a script or anything considering I don't know how long that would take.

tacit aspen
#

i do like the persistentData way tho but can't find a good solution to have a counter for that and then somehow find a way to have the amplifier increase itself instead of making about 70 script arrays for each tier

pallid onyx
#

Yeah I will have to make a example because I'm not good enough at explaning it.

pallid onyx
agile plover
#

Nope, I'm not good at using PersistentData

pallid onyx
#

All right, I'll get something together after workin today.

pallid onyx
solar saffronBOT
#

Paste version of BeltItemLogic.js from @pallid onyx

pallid onyx
#

And if you want I can change this so that it can stack different effects at different values.

#

Because right now it does pack leader and I know you wanted resistance however I went off of the script you gave me.

pallid onyx
#

Tell me if you have any issues

tacit aspen
#

i tested it out and it didnt do anything until i already gave myself the effect however after some time it increases the amplifier but the timer is at 0 so it immediately goes away

pallid onyx
#

Yeah, you get it for 1 second right now and then the belt goes on cooldown. Increase the duration or lower the cooldown.

About the effect, I assumed you had some logic for "On equip" effects. However changing this line would help allow them if they don't have the effect already:


const effectInstance = player.getEffect(effectMob)

        // Must not already be at max effect level
        if (!effectInstance || effectInstance.amplifier >= maxAmplifierStack) return;
#

Something like allowing a default mob effect instance for the varariable would be what you would likeky want.

pallid onyx
#

@tacit aspen Here's some patches

  • Belt cooldown was changed from 200 to 30 ticks
  • The effect duration was lengthen from 20 to 60 ticks to match the belt logic rate to give the player a sense of when the next amplifier stack will apply.
  • The belt logic will now apply the minimum effect if the player didn't already have one.