#how to use setItem when player is in a certain location and distance?
1 messages · Page 1 of 1 (latest)
It’s just new Vector(), and imported from @minecraft/server
The error is location is incompatible with getPlayers
True
world.getAllPlayers() cant get EntityQueryOptions!!
Fix:
world.getPlayers({location: new Vector(x, y, z), maxDistance: r}).forEach(player =>{
player.getComponent("inventory").container.setItem(0, new ItemStack("compass"))
})
Or
[...] location: {x: x, y: y, z: x}, [...]
Debug Result
There are 4 errors in this [code](#1190806530782679200 message):
[36m<repl>.js[0m:[33m2[0m:[33m21[0m - [31merror[0m[30m TS2554: [0mExpected 0 arguments, but got 1.
[7m2[0m world.getAllPlayers({location: new Vector(375, -59, 78), maxDistance: 140}).forEach(player =>{
[7m [0m [31m ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~[0m
``````ansi
[36m<repl>.js[0m:[33m2[0m:[33m36[0m - [31merror[0m[30m TS2304: [0mCannot find name 'Vector'.
[7m2[0m world.getAllPlayers({location: new Vector(375, -59, 78), maxDistance: 140}).forEach(player =>{
[7m [0m [31m ~~~~~~[0m
``````ansi
[36m<repl>.js[0m:[33m3[0m:[33m5[0m - [31merror[0m[30m TS2532: [0mObject is possibly 'undefined'.
[7m3[0m player.getComponent("inventory").container.setItem(0, new ItemStack("compass"))
[7m [0m [31m ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~[0m
``````ansi
[36m<repl>.js[0m:[33m3[0m:[33m5[0m - [31merror[0m[30m TS2532: [0mObject is possibly 'undefined'.
[7m3[0m player.getComponent("inventory").container.setItem(0, new ItemStack("compass"))
[7m [0m [31m ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~[0m
And then have it in the getPlayers, yeah
world.getDimension('overworld').getPlayers({location: new Vector(375, -59, 78), maxDistance: 140}).forEach(player =>{
player.getComponent("inventory").container.setItem(0, new ItemStack("minecraft:compass"))
})
Its work for me
This code use @gentle helm
system.runInterval(() => {
world.getDimension("overworld").getPlayers({location: {x: 0, y: 0, z: 0}, maxDistance: 1}).forEach(player =>{
player.getComponent("inventory").container.setItem(0, new ItemStack("compass"))
})
}, 1)
Import it from "@minecraft/server"