#Making a custom command that calls on a function from a datapack?
34 messages · Page 1 of 1 (latest)
Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!
Aren't functions natively executed through commands?
Or you just don't want it to be like /function ...
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.
Why do you need this?
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
There was a kubejs addon for FTB quests if I remember correctly
you can register a new command and then do server.runCommandSilent to run another command
though transferring the logic from a function into kubeJS directly is probably more efficient and easier to work with
i've tried my best to figure this out on my own but i still just can't seem to 😓 it sends an error every time i run the command. this is my code
const { commands: Commands, arguments: Arguments } = event
event.register(Commands.literal('killed_creeper')
.executes(c => event.server.runCommandSilent('execute as @s run function milestones:killed_creepers'))
)})```
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
i’ve done that now and it still sends an error, the log says it cannot call method “runCommandSilent” of undefined
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
i did c.server.runCommandSilent
*common JavaScript error
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
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;}))
})
it doesn't show an error anymore but it's not doing anything
How about this
ServerEvents.commandRegistry(event => {
const { commands: Commands, arguments: Arguments } = event
event.register(Commands.literal('killed_creeper')
.executes(c => {c.source.server.runCommand('execute as @s run function milestones:killed_creepers'); return 1;}))
})
I guess if that command is supposed to say something in the chat, then it shouldn't be run silent
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;}))
})
that works!! thank you so much for the help