#Cannot read property of 'subscribe' of undefined

1 messages · Page 1 of 1 (latest)

merry skiff
#

manifest.json:

{
    "format_version": 2,
    "metadata": {
        "authors": [
            "Tavern"
        ],
        "license": "Heheheha"
    },
    "header": {
        "name": "Redstone Infused Iron Armor",
        "description": "Adds custom redstone-infused armor with special effects.",
        "min_engine_version": [
            1,
            21,
            0
        ],
        "uuid": "69158f18-866d-4213-b7c6-f070eb442c03",
        "version": [
            1,
            0,
            3
        ]
    },
    "modules": [
        {
            "type": "data",
            "uuid": "feb4c2b6-bf5d-487f-92ff-dac125d93f71",
            "version": [
                1,
                0,
                0
            ]
        },
        {
            "type": "script",
            "language": "javascript",
            "uuid": "0b4a6ced-8cf6-49e2-bff8-9fad9f5a263c",
            "entry": "scripts/main.js",
            "version": [
                1,
                0,
                0
            ]
        }
    ],
    "dependencies": [
        {
            "module_name": "@minecraft/server",
            "version": "1.8.0"
        },
        {
            "module_name": "@minecraft/server-ui",
            "version": "1.0.0"
        }
    ]
}```

main.js:
```js
import "./armorfunction.js"
#

armorfunction.js

import { world } from '@minecraft/server';

console.log("World object:", world);
console.log("World.afterEvents:", world?.afterEvents);
console.log("World.afterEvents.tick:", world?.afterEvents?.tick);

const armorPieces = [
    "arched:redstoneinfused_helmet",
    "arched:redstoneinfused_chestplate",
    "arched:redstoneinfused_leggings",
    "arched:redstoneinfused_boots"
];

const checkEquippedArmor = (player) => {
    const equipment = player.getComponent("equipment_inventory");
    if (!equipment) return;

    let piecesEquipped = 0;

    for (const slot of ["head", "chest", "legs", "feet"]) {
        const item = equipment.getEquipment(slot);
        if (item && armorPieces.includes(item.typeId)) {
            piecesEquipped++;
        }
    }

    return piecesEquipped;
};

const applyArmorEffects = (player, piecesEquipped) => {
    const healthComponent = player.getComponent("health");
    if (!healthComponent) return;

    const baseHealth = 20;
    healthComponent.setCurrent(baseHealth);

    if (piecesEquipped > 0) {
        healthComponent.setCurrent(baseHealth + piecesEquipped * 2);
    }
    if (piecesEquipped === 4) {
        healthComponent.setCurrent(baseHealth + 10);
    }
};

world.afterEvents.tick.subscribe(() => {
    for (const player of world.getPlayers()) {
        const piecesEquipped = checkEquippedArmor(player);
        applyArmorEffects(player, piecesEquipped);
    }
});```
#

.
It is meant to give them like an extra heart when they wear the armor but the tick thing isn't working and thus it is not operational. The armor itself works, just not the health bonus, I can send one of those files as well if needed though :3

buoyant relic
#

The "tick" event only exists for custom block components, if you want to run code, run it through the system with tickInterval https://learn.microsoft.com/en-us/minecraft/creator/scriptapi/minecraft/server/system?view=minecraft-bedrock-experimental#runinterval and the reason that your hearts don’t likely work is health is restricted to what is defined in your player.json file, you can’t go over that value unless you adjust it. You will probably need to just use an effect.

Contents of the @minecraft/server.System class.

warm prairie
#

The manifest needs to be updated as well. You are targeting outdated versions for server and server-ui modules.

#

Latest stable version for server is 1.16.0 and the latest stable-beta version is 1.17.0-beta, but that one will require you to enable Beta API in your world.

Latest stable version for server-ui is 1.3.0 and latest stable-beta version is 1.4.0-beta. That too will require you to enable Beta API in your world if using the stable-beta version.

https://stirante.com/script/

merry skiff
merry skiff
buoyant relic
#

You can’t add lore to items that are like in the creative menu and currently it works like that as you are only searching the players equipment slots, but yes if you look through the whole inventory you can apply lore once the item enters your inventory, also look through the docs most of your code using features from 1-3 years ago so there has been changes that you will need to take into account, mostly names.

merry skiff
#

I think I got the whole armor thing figured out, equipment?.getEquipment("Head") is the more proper way of doing it that isn't outdated (to my knowledge)

#

@buoyant relic can I ask you abour cursorInventory? Do you know what that is used for, I'm not quite sure I understand exactly what the documentation is saying

jovial coral
#

you see when they select items the item go to the cursor?

#

yes that's it

merry skiff
#

Sorry if I worded that poorly

#

😅

merry skiff
#

The item would be in the cursorInventory?

jovial coral
jovial coral
merry skiff
#

"Error checking equipped armor: TypeError: Native type conversion failed"

merry skiff
#

That

jovial coral
jovial coral
#

LOL

#

Now I know why

merry skiff
#

Oh, yeah 😅 I think I updated it, that's the version that was added by default in BridgeV2

#
{
    "format_version": 2,
    "metadata": {
        "authors": [
            "Hi mom"
        ],
        "license": "All rights reserved"
    },
    "header": {
        "name": "Redstone Armor",
        "description": "Adds custom redstone-infused armor with special effects.",
        "min_engine_version": [
            1,
            21,
            0
        ],
        "uuid": "69158f18-866d-4213-b7c6-f070eb442c03",
        "version": [
            1,
            0,
            13
        ]
    },
    "modules": [
        {
            "type": "data",
            "uuid": "feb4c2b6-bf5d-487f-92ff-dac125d93f71",
            "version": [
                1,
                0,
                0
            ]
        },
        {
            "type": "script",
            "language": "javascript",
            "uuid": "0b4a6ced-8cf6-49e2-bff8-9fad9f5a263c",
            "entry": "scripts/main.js",
            "version": [
                1,
                0,
                0
            ]
        }
    ],
    "dependencies": [
        {
            "module_name": "@minecraft/server",
            "version": "1.16.0"
        },
        {
            "module_name": "@minecraft/server-ui",
            "version": "1.3.0"
        }
    ]
}```
#

That's the new one

jovial coral
#

lol

merry skiff
#

😁

kindred pollen
merry skiff
#

Ehhh, mostly curiosity, thought it might be useful for smth in the future

kindred pollen
#

Fair enough

kindred pollen
#

If you add the other imports it should then stop giving that kind of error

jovial coral
#
import { EntityComponentTypes } from '@minecraft/server';

const equippable = Player.getComponent(EntityComponentTypes.Equippable);

const equippable = Player.getComponent('equippable');```
kindred pollen
jovial coral
kindred pollen
kindred pollen
jovial coral
# kindred pollen ^

nope, it's not required to use import you can just directly put equippable in components

#

but it's better to use import if you're typescript

merry skiff
#

@jovial coral @kindred pollen do either of you guys know if it is possible to use scripting API to edit the items in a chest? I can't seem to find anything on it in the docs, unless I am looking in the wrong place

jovial coral
#
const inventory = Block.component('inventory').container;

for (const i = 0; i < inventory.size; i++) {
   const item = inventory.getItem(i);
   if (!item) return;
   // ...
}```
merry skiff
#

Like let's say there is a loot pool of 5 random items, it picks 2 and puts them in a random slot of the chest

#

That sorta thing

jovial coral
#

learn basic scripts, I can't always help you