#Making a custom command that calls on a function from a datapack?

34 messages · Page 1 of 1 (latest)

worthy mountain
#

I'm trying to make a custom command that calls on a function made through a datapack. All the examples I've found show a command changing an attribute or something like that so I'm a bit confused how I would execute this.

past finchBOT
#

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

vestal mason
#

Or you just don't want it to be like /function ...

stuck joltBOT
#

The XY problem is when you really want to do X, and you think that Y can achieve X. However, you can't get Y to work, and so ask for help exclusively about Y.

This can lead to a lot of confusion from the people trying to help you, as Y can seem like a very random thing to want to do, and a lot of the time isn't the best way to achieve X anyway.

Its fine to ask about Y, just always include some context about X so you can be put on the right track if Y won't do X well, or there is an easier way to do X.

safe cradle
#

Why do you need this?

worthy mountain
#

i’ve been doing a lot of player tracking through a datapack (i.e. mob with a certain tag killed detected through an achievement for a quest in FTB quests) and i have custom commands using a different mod that lets me run functions to tell the player how many kills are left to complete the quest. i just wanted to sort of transfer that code into kubejs if it was possible to do and maybe create a way to track if players are in a FTB team ( completely different thing here, im making a reputation system). i’m really new to kubejs though, and the docs didn’t help me much with trying other solutions for either of these

quiet sail
#

There was a kubejs addon for FTB quests if I remember correctly

safe cradle
#

though transferring the logic from a function into kubeJS directly is probably more efficient and easier to work with

worthy mountain
safe cradle
#

Almost, just do c.server.runCommandSilent

#

You have to do that because that's the context of when the command is being run, event is during registry if that makes sense

worthy mountain
#

i’ve done that now and it still sends an error, the log says it cannot call method “runCommandSilent” of undefined

quiet sail
#

that means that the thing before runCommandSilent is undefined

#

Wait did you do event.c.server or c.server

#

Im not sure which it is but whatever you went for mustve not been it :P

#

This is just a common error

worthy mountain
#

i did c.server.runCommandSilent

quiet sail
quiet sail
#

For some reason probejs isnt working on forge but my fabric version is telling me that the .execute method there doesn’t exist and there isn’t anything that resembles it

#

So perhaps double check that? That’s the most I can do like this at the moment

vestal mason
# worthy mountain i did c.server.runCommandSilent

Try this

ServerEvents.commandRegistry(event => {
    const { commands: Commands, arguments: Arguments } = event
  
    event.register(Commands.literal('killed_creeper')
    .executes(c => {c.source.server.runCommandSilent('execute as @s run function milestones:killed_creepers'); return 1;}))
})
worthy mountain
#

it doesn't show an error anymore but it's not doing anything

vestal mason
#

Oh

#

Wait

vestal mason
#

I guess if that command is supposed to say something in the chat, then it shouldn't be run silent

worthy mountain
#

it still does nothing 😭

vestal mason
#

Hmm

#

ah

#

The @s selector

vestal mason
# worthy mountain it still does nothing 😭
ServerEvents.commandRegistry(event => {
    const { commands: Commands, arguments: Arguments } = event
  
    event.register(Commands.literal('killed_creeper')
    .executes(c => {c.source.server.runCommand(`execute as ${c.source.player.username} run function milestones:killed_creepers`); return 1;}))
})
worthy mountain
#

that works!! thank you so much for the help