#Give a player a game stage on getting an item

76 messages · Page 1 of 1 (latest)

crimson moss
#

I want the player to obtain a game stage when picking up an item with the tag forge:tools/iron", how would I do this?

tame jasperBOT
#

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

candid copper
#

you would use either the item pickup server event or the player inventory changed server event

#

PlayerEvents.InventoryChanged would be the one I recommend using since it accounts for all ways that you can get an item in your inventory

#

If you only want to give the game stage when an item is picked up specifically then you can use ItemEvents.pickedUp

crimson moss
#

Still wish they had examples for these on the wiki

candid copper
#

yeah the wiki is in a terrible state. It has less and less examples with each version

#

I often use Object.keys(event).forEach(e=>console.log(e)) to figure out what properties an event has

#

probejs would also be useful if you can get that set up properly

crimson moss
#

I see

crimson moss
#

still having a bit of trouble

#

may just be bad code tho

candid copper
#

I don't think javascript works like that

#

use event.getItem() to get the item involved with the event

#

not sure what property of event.getItem() you use to get the tags though

#

Try event.getItem().getTags()

#

try this code

PlayerEvents.inventoryChanged(e => {
  const item = e.getItem();
  if (item.getTags().includes('forge:tools/iron')) {
    e.server.runCommandSilent(`say Works lol`);
  }
})
crimson moss
#

Should have pad more attention to the js part of web design class

#

But in my deffence I wouldn't think it would help me in mc mod packs

#

Still no works

#

riiiiiiiiiiiiip

novel wolf
#

If you're using FTB Quests you could run a command to give a player a stage when getting an item.

#

as a quest reward

crimson moss
#

I am not

novel wolf
#

okay let me open up a testing instance to create some code

#

and make sure it works before sending

crimson moss
#

Thank you

#

You are very real for that

novel wolf
#

i may be wrong, but i'm pretty sure you should use .contains() instead of .includes()

crimson moss
#

If that works thats dumb

#

testing now

novel wolf
#

also you can probably use e.player.tell() instead of e.server.runCommandSilent()

crimson moss
#

this is just a temp thing

#

that probably will be what I end up doing but i don't see a reason to change rn

novel wolf
#

fair

crimson moss
#

problably just gonna use the action bar for ascetics

#

first i gotta make this work tho ofc

novel wolf
#

im checking some old code of mine relating to checking tags rn

#

hopefully it contains something helpful

#

okay in my testing instance i used /kubejs hand to check an iron tools tags and it doesn't have a forge:tools/iron tag

crimson moss
#

wut

novel wolf
crimson moss
#

let me try with a different tag then

#

ok still doesn't work

#

hold on let me Frankenstein something together

#

because my code worked for individual items

novel wolf
#

yeah im also trying to cobble together unrelated code bits in an attempt to make something work

novel wolf
#

i genuinely dont know why it isnt working though

crimson moss
#

beats me too

#

mc is dumb

#

or whoever i should be blaming

#

probably myself

novel wolf
#

wait i have a kind of hacky solution

#
const tools = ['minecraft:iron_pickaxe','minecraft:iron_axe','minecraft:iron_shovel']

PlayerEvents.inventoryChanged(e => {
    if (tools.includes(e.item.id)) e.player.tell('player has iron tool')
})```
#

list all iron tools in the tools array

#

and the game should detect if a player has one of them on an inventory update

crimson moss
#

aaaaaaaaaaaaa i fuckin guess i can do that

novel wolf
#

it won't automatically take from the tags but it should work

crimson moss
#

tags would just be so much nicer tho

novel wolf
#

hopefully someone with actual experience comes along and helps you

crimson moss
#

thanks for trying at least

novel wolf
#

WAIT

#

hold everything i got it working

crimson moss
#

o shit

novel wolf
#
const tools = ['minecraft:iron_pickaxe','minecraft:iron_axe','minecraft:iron_shovel']

PlayerEvents.inventoryChanged(e => {
    if (e.item.hasTag('forge:tools/iron')) e.player.tell('player has iron tool')
})```
crimson moss
#

ayyyyyyyyyyyyyyyyy

#

10000 iq

#

thank you

novel wolf
#

all good

#

now just make sure to close the ticket

crimson moss
#

👍