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);
#how to place item in a slot with lore and specific score
1 messages · Page 1 of 1 (latest)
getEntity don't work like that, u have to pass the entity id, not the typeId
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.
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
thanks ill try it
also, where u defined questScore?
i thought i didnt need to define that
rookie mistakes bruh
also the player, doesn't have scoreboard property
btw where exactly do i need to define questScore?
well, i think u just confused the variable score with questScore
ohh
const score = world.scoreboard.getObjective(objectiveId).getScore(participant)
scoreboard docs for scripting
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);
ive constructed it like this
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);
Debug Result
There are 3 errors in this [code](#1251119975012368524 message):
[36m<repl>.js[0m:[33m14[0m:[33m23[0m - [31merror[0m[30m TS2339: [0mProperty 'isValid' does not exist on type 'number'.
[7m14[0m if (score.isValid() && score === 0) {
[7m [0m [31m ~~~~~~~[0m
``````ansi
[36m<repl>.js[0m:[33m16[0m:[33m30[0m - [31merror[0m[30m TS2339: [0mProperty 'isValid' does not exist on type 'number'.
[7m16[0m } else if (score.isValid() && score === 1) {
[7m [0m [31m ~~~~~~~[0m
``````ansi
[36m<repl>.js[0m:[33m18[0m:[33m30[0m - [31merror[0m[30m TS2339: [0mProperty 'isValid' does not exist on type 'number'.
[7m18[0m } else if (score.isValid() && score === 2) {
[7m [0m [31m ~~~~~~~[0m
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);
No Errors
No errors in [code](#1251119975012368524 message)
thanks a lot
but the thing is it only sets the item in the players inventory and not in the entitys inventory