#Using armor effects with only a few pieces of armor

14 messages · Page 1 of 1 (latest)

tender skiff
#

How might I use #1247837010861756437 message but instead of a full set of armor its just the helmet and chestplate? Or for any combination of not a full set of armor.

muted salmonBOT
#

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

vivid ginkgoBOT
#

[➤](#1247837010861756437 message)
Get potion effect on specific armor set.
Not using player tick.

const passiveEffects = {
    'minecraft:leather_': [
        'minecraft:speed',
        'minecraft:jump_boost'
    ],
    'minecraft:iron_': [
        'minecraft:speed'
    ]
}

function checkArmorSet(e, prefix) {return !e.armorSlots.some(a => !a.id.startsWith(prefix))};
const armorIds = Object.keys(passiveEffects).reduce((a, b) => a.concat(['helmet', 'chestplate', 'leggings', 'boots'].map(suffix => b+suffix)), []);
const INFINITE = Java.loadClass('java.lang.Integer').MAX_VALUE;

armorIds.forEach(id => {
    PlayerEvents.inventoryChanged(id, e => {
        const player = e.player;
        const prefix = player.getHeadArmorItem().id.split('helmet')[0];
        const pData = player.persistentData;
        if(!pData.armor) return;
        const lastArmorSet = passiveEffects[pData.armor];
        const nowArmorSet = passiveEffects[prefix];
    
        if(!checkArmorSet(player, prefix)) lastArmorSet.forEach(effect => player.removeEffect(effect));
        else if(prefix != 'minecraft:air'){
            pData.armor = prefix;
            nowArmorSet.forEach(effect => player.potionEffects.add(effect, INFINITE, 0))
        }
    });
    ItemEvents.dropped(id, e => {
        const player = e.player;
        const pData = player.persistentData;
        if(!pData.armor) return;
        const lastArmorSet = passiveEffects[pData.armor];
        Utils.server.scheduleInTicks(0, ()=>{
            if(!checkArmorSet(player, pData.armor)) lastArmorSet.forEach(effect => player.removeEffect(effect));
        })
    })
})
tender skiff
#

strangely enough, even using the original script isnt working

plucky kite
#

nah, i've tested the original script, it's fully working

#

you can change the full armor check to a count check

#

what do you exactly need?

#

helmet + chestplate, or any combination?

tender skiff
#

I just wanted to know how to change it to the need, like helmet chestplate, chest plate leggings ect.

#

The default script wasn't working with leather or iron armor unless I'm misunderstanding how it works

tender skiff
#

im using playertick in the meantime, I was just confused why the original script wasn't working without any changes

plucky kite
#

i was also confused why it's working on my side?

#
function checkArmorSet(e, prefix, pieces) {
    let counter = 0;
    e.armorSlots.forEach(armor => {
        if(armor.id.startsWith(prefix)) counter++
    });
    if(counter >= pieces) return true;
    else return false;
}
#

anyway, if you want to check only for some pieces of armor set, you can check for every armor slot