#how to place item in a slot with lore and specific score

1 messages · Page 1 of 1 (latest)

dull crescent
#
import { system, world, ItemStack } from "@minecraft/server";

// Function to update player's inventory based on quest score
function updateInventoryBasedOnScore() {
    // Iterate through all players in the world
    for (const player of world.getPlayers()) {
        // Get the score of entity's quest score
        const score = player.scoreboard.getScore('quest_score');
        const entity = world.getEntity('bridge:quest_booka');

        // Create an item stack of paper
        let paperItem = new ItemStack(("minecraft:paper"), 1);

        // Set the name of the paper item based on the quest score
        if (questScore === 0) {
            paperItem.nameTag = "Quest not available\nNeed to be level 1 ";
        } else if (questScore === 1) {
            paperItem.nameTag = "Quest available\nGo speak with mister test at 19 59 10";
        } else if (questScore === 2) {
            paperItem.nameTag = "Quest Started\nKill all the zombies";
        }

        // Get the entity's inventory and set the item in slot 0
        const inventory = player.getComponent("minecraft:inventory").container;
        inventory.setItem(0, paperItem);
    }
}

// Run the update function every second (20 ticks)
system.runInterval(updateInventoryBasedOnScore, 20);
dapper pond
#
id: string

Unique identifier of the entity. This identifier is intended to be consistent across loads of a world instance. No meaning should be inferred from the value and structure of this unique identifier - do not parse or interpret it. This property is accessible even if Entity.isValid is false.

dull crescent
dapper pond
# dull crescent oke how would i write that

first, u should get all the entities in the world, with getEntities, and then with entityqueryoptions, you use "type" for now use bridge:quest_booka, then make an interation to the entity array, and then you pass the id

#

let me make an example

#
const dimension = world.getDimension("overworld");
for (const entity of dimension.getEntities({ type: "bridge:quest_booka" })) {
  // entity code
}
#

something like this

#

now u get all the entities with this typeId

dapper pond
dull crescent
#

rookie mistakes bruh

dapper pond
#

also the player, doesn't have scoreboard property

dull crescent
dapper pond
#

well, i think u just confused the variable score with questScore

dull crescent
#

ohh

dapper pond
#

const score = world.scoreboard.getObjective(objectiveId).getScore(participant)

#

scoreboard docs for scripting

dull crescent
#
import { system, world, ItemStack } from "@minecraft/server";

// Function to update player's inventory based on quest score
function updateInventoryBasedOnScore() {
    // Iterate through all players in the world
    for (const player of world.getPlayers()) {

        // Get the score of entity's quest score
        const dimension = world.getDimension("overworld");
        const score = world.scoreboard.getObjective(objectiveId).getScore(quest_score)

        for (const entity of dimension.getEntities({ type: "bridge:quest_booka" })) {
            // entity code
        }
        // Create an item stack of paper
        let paperItem = new ItemStack(("minecraft:paper"), 1);

        // Set the name of the paper item based on the quest score
        if (score === 0) {
            paperItem.nameTag = "Quest not available\nNeed to be level 1 ";
        } else if (score === 1) {
            paperItem.nameTag = "Quest available\nGo speak with mister test at 19 59 10";
        } else if (score === 2) {
            paperItem.nameTag = "Quest Started\nKill all the zombies";
        }

        // Get the entity's inventory and set the item in slot 0
        const inventory = player.getComponent("minecraft:inventory").container;
        inventory.setItem(0, paperItem);
    }
}

// Run the update function every second (20 ticks)
system.runInterval(updateInventoryBasedOnScore, 20);
dull crescent
dapper pond
#
import { system, world, ItemStack } from "@minecraft/server";

// Function to update player's inventory based on quest score
function updateInventoryBasedOnScore() {
    // Iterate through all players in the world
    for (const player of world.getPlayers()) {
        const score = world.scoreboard.getObjective(objectiveId)?.getScore(quest_score)
        // Create an item stack of paper
        let paperItem = new ItemStack(("minecraft:paper"), 1);

        // Set the name of the paper item based on the quest score
        if (score.isValid() && score === 0) {
            paperItem.nameTag = "Quest not available\nNeed to be level 1 ";
        } else if (score.isValid() && score === 1) {
            paperItem.nameTag = "Quest available\nGo speak with mister test at 19 59 10";
        } else if (score.isValid() && score === 2) {
            paperItem.nameTag = "Quest Started\nKill all the zombies";
        }

        // Get the entity's inventory and set the item in slot 0
        const inventory = player.getComponent("minecraft:inventory").container;
        inventory.setItem(0, paperItem);
    }
}

// Run the update function every second (20 ticks)
system.runInterval(updateInventoryBasedOnScore, 20);

should be better this, but now, u have to change 2 things

getObjective and getScore, the arguments are:

getScore(participant): number
Parameters
participant: string | Entity | ScoreboardIdentity
getObjective(objectiveId): ScoreboardObjective
Parameters
objectiveId: string
#

uh wait, i delete i thing

#
import { system, world, ItemStack } from "@minecraft/server";

// Function to update player's inventory based on quest score
function updateInventoryBasedOnScore() {
    // Iterate through all players in the world
    for (const player of world.getPlayers()) {

        // Get the score of entity's quest score
        const dimension = world.getDimension("overworld");

        for (const entity of dimension.getEntities({ type: "bridge:quest_booka" })) {
            let paperItem = new ItemStack(("minecraft:paper"), 1);
            const score = world.scoreboard.getObjective('ObjectiveID')?.getScore(entity);
            if (score && score === 0) {
                paperItem.nameTag = "Quest not available\nNeed to be level 1 ";
            } else if (score && score === 1) {
                paperItem.nameTag = "Quest available\nGo speak with mister test at 19 59 10";
            } else if (score && score === 2) {
                paperItem.nameTag = "Quest Started\nKill all the zombies";
            }

            // Get the entity's inventory and set the item in slot 0
            const inventory = player.getComponent("minecraft:inventory").container;
            inventory.setItem(0, paperItem);
        }
    }
}

// Run the update function every second (20 ticks)
system.runInterval(updateInventoryBasedOnScore, 20);
vast zincBOT
#
Debug Result

There are 3 errors in this [code](#1251119975012368524 message):

<repl>.js:14:23 - error TS2339: Property 'isValid' does not exist on type 'number'.

14             if (score.isValid() && score === 0) {
                         ~~~~~~~

``````ansi
<repl>.js:16:30 - error TS2339: Property 'isValid' does not exist on type 'number'.

16             } else if (score.isValid() && score === 1) {
                                ~~~~~~~

``````ansi
<repl>.js:18:30 - error TS2339: Property 'isValid' does not exist on type 'number'.

18             } else if (score.isValid() && score === 2) {
                                ~~~~~~~

#
Debug Result

JavaScript/TypeScript code blocks not detected in [message](#1251119975012368524 message).
You can either send the script in code block highlighted in JS format:

​`​`​`js
world.sendMessage("Hello World");
​`​`​`

Or Send an attachment end in .js to debug the file.

dapper pond
#
import { system, world, ItemStack } from "@minecraft/server";

// Function to update player's inventory based on quest score
function updateInventoryBasedOnScore() {
    // Iterate through all players in the world
    for (const player of world.getPlayers()) {

        // Get the score of entity's quest score
        const dimension = world.getDimension("overworld");

        for (const entity of dimension.getEntities({ type: "bridge:quest_booka" })) {
            let paperItem = new ItemStack(("minecraft:paper"), 1);
            const score = world.scoreboard.getObjective('ObjectiveID')?.getScore(entity);
            if (score && score === 0) {
                paperItem.nameTag = "Quest not available\nNeed to be level 1 ";
            } else if (score && score === 1) {
                paperItem.nameTag = "Quest available\nGo speak with mister test at 19 59 10";
            } else if (score && score === 2) {
                paperItem.nameTag = "Quest Started\nKill all the zombies";
            }

            // Get the entity's inventory and set the item in slot 0
            const inventory = player.getComponent("minecraft:inventory").container;
            inventory.setItem(0, paperItem);
        }
    }
}

// Run the update function every second (20 ticks)
system.runInterval(updateInventoryBasedOnScore, 20);
vast zincBOT
#
No Errors

No errors in [code](#1251119975012368524 message)

dapper pond
#

@dull crescent

#

ok now

#

what's ur objective id?

dull crescent
#

quest_score

dapper pond
#

ok just replace 'ObjectiveID' with 'quest_score'

dull crescent
#

but the thing is it only sets the item in the players inventory and not in the entitys inventory

dapper pond
#

ok lets check

#

in that case, replace player

#

to entity

#

that will get the entity component

dull crescent
#

ahhh aight

#

yes it works now thanks for helping and sending links where i can learn more