#How to give players a specific book when pressing a button / ingame command?
42 messages · Page 1 of 1 (latest)
Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!
How to give players a specific book when pressing a button / ingame command?
Would this work? Then just connect a button to a command block with "/kubejs custom_command Rulebook"
ServerEvents.customCommand('Rulebook', event => {
event.player.give(Item.of('minecraft:written_book', '{author:"_BlueFireFox_",pages:[\'{"text":"Testing KubeJS script"}\'],title:"KubeJS Testing"}')`)
})
try /give playername kubejs:item_id
Doesn't work. Item ID name is way too long
ah, for some reason i thought this was a completely new item, i didnt read properly; sorry
if you intend to give this book to players, custom_command could work; you could also add a command to the command registry
this should work, let me know if it does not
So I created a custom command as you can see up there and that works fine. Though I rather have people be able to press a button rather than typing /kubejs custom_command Rulebook in chat (unless there's a way to make it something like /rulebook
you can make a command such as /rulebook or any other arbitrary command using the command registry
It doesn't give me anything when I press the button
ill pull up a wiki page for you
also, try /execute as @p run kubejs custom_command Rulebook
it needs to be sent from a player, so you need to execute the command as if the player sent it
Hero, that works!
glad it does; if youd still prefer a command like /rulebook so that your players can access your rulebook anywhere lmk
Wouldn't hurt to have it as a backup
ill write it for you when i get home since some of the info on it is slightly outdated
Yeah sure! No hurries! I might be in bed by then but I'll read it tomorrow if that's the case
Hey did you manage to find the info?
ya, i just slept as soon as i got home and dont have time to write the command rn
if youre confident, you can go on the kubejs legacy wiki and look there, though very few select things are different between that version and 1.19
otherwise ill get that done in a few hours after my dentist appt
I found this. Not sure if this is what I'm supposed to be looking for? And if so how exactly I'd change it
didnt know that was on the newer wiki; yeah, that works in modern versions and you would use something akin to this
ill set it up for you after i am home from my dentists appt
Sure ty!
alright, sorry this took so long but i finally snagged some free time so here you go
ServerEvents.commandRegistry(event => {//command registry event
const { commands: Commands, arguments: Arguments} = event;
event.register(//register a new command
Commands.literal("rulebook")//the command is called myCommand
.requires(src => src.hasPermission(0))//2 is op. This line is optional, but you can also instead of just one value, wrap it in {}s and use return to write a more complex requirement checks
.executes(ctx => {//run the command
ctx.source.player.give(Item.of('minecraft:written_book', '{author:"_BlueFireFox_",pages:[\'{"text":"Testing KubeJS script"}\'],title:"KubeJS Testing"}'))
return 1
})
)
})
put this in server scripts, obviously
i'd recommend using this so that your players can access the rulebook from anywhere and so they dont have to fight over who's closest to the commandblock in order to recieve a book
Right so with this players should be able to do /rulebook and it'll work
yes
tyvm it works!