#custom item use

197 messages · Page 1 of 1 (latest)

stark nebula
#

im trying to make a gravescroll that will stretch when used and upon finishing use will run the event to teleport the player to their last death, the death teleport part is easy enough but for some reason its not being used on right click and obviously is not running any events either. i posted an example of what im basically going for

StartupEvents.registry('item', event => {
    event.create('grave_scroll').displayName('Grave Scroll')
    .useAnimation("bow")
    .useDuration((itemstack) => 64)
    .finishUsing((Utils, entity, player, event) => {
        if (entity.player) 
        {
        global.gravescroll(entity)
        }
    })
})
global.gravescroll = (entity) => {
    Utils.server.runCommand(`tell ${entity.player.name} Hi`)
}```this is the script so far
high plazaBOT
#

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

stark nebula
#

ignore my music playing in the background, had no idea it recorded that toopepelaugh

honest plover
#

what is that formatting BigEyes

stark nebula
#

lmao

#

i whipped it up quickly

#

there

elfin depot
#

=.=

honest plover
#

...

stark nebula
#

???

gritty lichenBOT
honest plover
elfin depot
#

where did you get this .finishUsing((Utils, entity, player, event) => {

honest plover
#

good question ahujel

stark nebula
#

sec ill link the discord thing

honest plover
gritty lichenBOT
#

[Quote ➤](#1127292324897112135 message) All you needed to do was swap event with entity.

.finishUsing((Utils, entity, player) => {
if (entity.player) 
{
Utils.server.runCommand(`tell ${entity.player.name} Hi`)
}})
elfin depot
#
@FunctionalInterface
public interface FinishUsingCallback {
    ItemStack finishUsingItem(ItemStack itemStack, Level level, LivingEntity livingEntity);
}
stark nebula
#

ah

honest plover
#

as probejs says heh

stark nebula
#

it doesnt even use tho

#

i right click and no animation

honest plover
#

use what?

elfin depot
#

probably because the callback is wrong

stark nebula
#

the item

#

ah

elfin depot
#

so its erroring somewhere

stark nebula
#

lemme fix it sec

#

so itd be something like this then? js .finishUsing((entity, server) => { if (entity.player) { global.gravescroll(entity) } })
then in the global js global.gravescroll = (entity) => { Utils.server.runCommand(`tell ${entity.player.name} Hi`) } would utils still be fine?

honest plover
#

no ahujel

stark nebula
#

oh

honest plover
#

use what lexxie sent

stark nebula
#

level?

elfin depot
#

you need all 3 args

stark nebula
#

ah

honest plover
#
StartupEvents.registry('item', e => {
    e.create('grave_scroll').displayName('Grave Scroll')
    .useAnimation("bow")
    .useDuration((itemstack) => 64)
    .finishUsing((itemstack, level, entity) => {
        if (entity.player) global.gravescroll(entity)
    })
})

global.gravescroll = entity => {
    Utils.server.runCommand(`tell ${entity.player.name} Hi`)
}
elfin depot
#
.finishUsing((item, level, entity) => {
  if (entity.player) global.gravescroll(entity)
})
honest plover
#

I was faster pepepointandlaugh

elfin depot
#

nu

honest plover
#

huh

elfin depot
#

ez proof

stark nebula
#
.finishUsing((level, entity, itemstack) => {
        if (entity.player) 
        {
        global.gravescroll(entity)
        }
    })```
honest plover
#

DISCORD ahujel

elfin depot
#

photoshop

honest plover
#

I'm not using photoshop

#

it's just discord being dum

stark nebula
#

oh i didnt even see your messages rofl

honest plover
elfin depot
#

wha

stark nebula
#

yall so fast

honest plover
elfin depot
honest plover
#

yes, this is an r154 reference heh

elfin depot
#

a what now

honest plover
#

...

#

you don't play antimatter dimensions despair

stark nebula
#

lmao

honest plover
stark nebula
#

still nothing lol

elfin depot
#

show logussy

stark nebula
#

kk

gritty lichenBOT
#

Paste version of startup.log, latest.log from @stark nebula

elfin depot
#

weird

stark nebula
#

yea

#

i saw somewhere someone had .use but that was 1.18 i think

#

nvm its 1.19 too i guess

elfin depot
#

just to make sure youre not doing derpy things, did you restart the game since the changes?

stark nebula
#

yea

honest plover
#

try adding a console.log before the runCommand

#

just for debugging

stark nebula
#

aight

elfin depot
#

they do

honest plover
#

they're exploiting using the global trick

elfin depot
#

??

honest plover
elfin depot
#

no

#

wat

honest plover
elfin depot
#

the changes werent to global

#

they were to the registry

stark nebula
#

imma do this ```js
StartupEvents.registry('item', e => {
e.create('grave_scroll').displayName('Grave Scroll')
.useAnimation("bow")
.useDuration((itemstack) => 64)
.finishUsing((itemstack, level, entity) => {
console.log('this runs before the global')
if (entity.player) global.gravescroll(entity)
})
})

global.gravescroll = entity => {
console.log('this runs before the command')
Utils.server.runCommand(tell ${entity.player.name} Hi)
console.log('this runs after the command')
}```

elfin depot
stark nebula
#

and do full restart

#

ah ok

elfin depot
#

and see if the animation starts

stark nebula
#

ill do that first then

elfin depot
#

start with the basics first

stark nebula
#

wow its the same deal with this js StartupEvents.registry('item', e => { e.create('grave_scroll').displayName('Grave Scroll') .useAnimation("bow") .useDuration((itemstack) => 64) /*.finishUsing((itemstack, level, entity) => { console.log('this runs before the global') if (entity.player) global.gravescroll(entity) })*/ })

#

do i comment out useduration next then?

elfin depot
#

dunno the rest look normal to me

stark nebula
#

right

#

yeah its the same deal with useduration commented so useanimation just isnt working i guess

#

unless

#

i need .use

elfin depot
#

any chance you can put everything back, rightclick, then show server log

stark nebula
#

bet

elfin depot
#

im clueless at this point

stark nebula
#

lol same

honest plover
#

my bad

stark nebula
#

i did find this ```js
.use((level, player, hand) => true)

#

oooo

#

wait i started it up with .use and it uses now

#

tho the event didnt fire despair

#

sec ill post logs

#

wait the console logs fired

gritty lichenBOT
#

Paste version of latest.log from @stark nebula

stark nebula
#

says no player was found in the command event i think

#
StartupEvents.registry('item', e => {
    e.create('grave_scroll').displayName('Grave Scroll')
    .use((level, player, hand) => true)
    .useAnimation("bow")
    .useDuration((itemstack) => 64)
    .finishUsing((itemstack, level, entity) => {
        console.log('this runs before the global')
        if (entity.player) global.gravescroll(entity)
    })
})

global.gravescroll = entity => {
    console.log('this runs before the command')
    Utils.server.runCommand(`tell ${entity.player.name} Hi`)
    console.log('this runs after the command')
}```
elfin depot
#

its entity.name most likely

#

entity.player is not a thing, its a boolean

stark nebula
#

ah

elfin depot
#

its beans for entity.isPlayer()

stark nebula
#

its wierd also because when i do this /tell Liopyu hi in game it errors in logs

#

aight ill try it

elfin depot
#

might be entity.username not sure

stark nebula
gritty lichenBOT
#

Paste version of latest.log from @stark nebula

stark nebula
#

yeah probably username

gritty lichenBOT
#

Paste version of crash-2023-10-16_13.53.52-server.txt from @stark nebula

stark nebula
#
global.gravescroll = entity => {
    console.log('this runs before the command')
    server.runCommand(`tell ${entity.username} Hi`)
    console.log('this runs after the command')
}```
#

ill try name i guess

elfin depot
#

you deleted Utils.

stark nebula
#

yeah

#

and thats the problem lol sec

elfin depot
#

do you have server defined anywhere

stark nebula
#

oh duh

#

i was going off of the old scriptdespair

elfin depot
honest plover
stark nebula
#

i did this for better testing purposes js global.gravescroll = entity => { console.log('this runs before the command') Utils.server.runCommand(`scoreboard players add ${entity.name} test 1`) console.log('this runs after the command') }worry

#

trying username next i guess

#

oo yeah its username

#

though it runs the command twice

#

progress tho lets goo lmao

#

how do i not make it consume the whole item stack?

#

cause every time i use it it takes the whole thing lol

#

oh im not returning the itemstack maybe?

elfin depot
#

ye

#

you need to return

stark nebula
#

ah

#

where do i return it?

elfin depot
#

use

#

i think

stark nebula
#

ah ok ill try that

#

wait how do i do that lol

elfin depot
#

or actually finishusing maybe

#

im reading the thing

stark nebula
#

ah ok

elfin depot
#

return item thats it

stark nebula
#

ooo kk sec

#

ty

stark nebula
#

so like this? js StartupEvents.registry('item', e => { e.create('grave_scroll').displayName('Grave Scroll') .use((level, player, hand) => true) .useAnimation("bow") .useDuration((itemstack) => 64) .finishUsing((itemstack, level, entity) => { console.log('this runs before the global') if (entity.player) global.gravescroll(entity) return item; }) })

#

right

#

ah that crashed me

gritty lichenBOT
#

Paste version of crash-2023-10-16_14.07.38-server.txt from @stark nebula

elfin depot
#

:v

stark nebula
#

ahh

#

XD

#

what about this? js Object.keys(itemstack).forEach(field => { console.log(field) }); return itemstack;

elfin depot
#

tho make sure you lower the count by 1 if you want it to be used

stark nebula
#

oh nvm thats the same thing

#

right right

stark nebula
#

not sure if that pinged him

honest plover
stark nebula
#

oh guess it did

honest plover
#

it didn't

stark nebula
#

lmao fair enough

honest plover
#

pings don't work in forums

stark nebula
#

rofl

#

uwu