#event.server.runCommand dont work but the 2 other are working

75 messages · Page 1 of 1 (latest)

gentle kettle
#

hey ! this is my script :

PlayerEvents.loggedIn(event => { //when a player log in
    if (!event.player.stages.has('new_join')){
        while(!event.player.stages.has('new_join')){ //run until he has the new_join tag, 
            event.player.teleportTo((Math.random() * 10000) - 5000, 64, (Math.random() * 10000) - 5000); //random tp the player
            let {x, y, z} = event.player; //get is cord in x y and z
            let aabb = AABB.of(x + 250, 63, z + 250, x - 250, 65, z - 250); //select all entity at a 250 square range from the player at layer 64
            if (!(event.level.getEntitiesWithin(aabb).forEach(entity => {//for eatch entities of the selection 
                if (entity.type == "minecraft:marker" && entity.tags.has('island_spawn')) //is the entity a marker with the tag island_spawn (it mean an island ...)
                {
                    return true;
                }
                }))
            )
            {
                event.player.stages.add('new_join'); // add the tag new join to the player to mean that it go is island position
            }
        }
        event.server.runCommand(`execute as ${event.player.username} at ${event.player.username} run summon minecraft:marker ~ ~ ~ {Tags:["island_spawn"]}`);//summon the marker to set the place as an island pos
        event.server.runCommand(`execute as ${event.player.username} at ${event.player.username} run spawnpoint`); //set the player spawn here
        event.server.runCommand(`execute as ${event.player.username} at ${event.player.username} run setblock ~ ~ ~ minecraft:structure_block{mode: "LOAD", name: "from_nothing:island"}`); //set block a structure block with a loaded structure, command work when typed in the chat but dont do anything and show any log in the case of script execution
    }
});```
as you can see i use 3 run commands, the two first one work and output 
but the last one doesnt do anything
thorny cometBOT
#

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

gentle kettle
#

work when typed directly in the chat

cyan dragon
#

Does your log bring anything up

gentle kettle
#

is it becose the chunk isnt loaded yet ?

copper agateBOT
#

You can find your KubeJS server log in /minecraft/logs/kubejs/server.log.
If you are on 1.18 or 1.16 it will be called server.txt.
Please send it if asked, as it contains helpful information.

gentle kettle
#

[18:34:17] [Render thread/INFO]: Minimap updated server level id: 320874627 for world ResourceKey[minecraft:dimension / minecraft:overworld]
[18:34:17] [Render thread/INFO]: [CHAT] [Grognatou: Summoned new Marker]
[18:34:17] [Render thread/INFO]: [CHAT] [Grognatou: Set spawn point to 1175, 64, 3974 [0.0] in minecraft:overworld for Grognatou]
[18:34:17] [Render thread/INFO]: Loaded 30 advancements

#

can send you my entire log if you whant

#

but there is nothing

cyan dragon
#

Idk then sorry

gentle kettle
cyan dragon
#

You might be able to replace the setback command with a function

#

Tho I can't remember the exact function

gentle kettle
#

but is there a sort of shedule or pre set block

fresh wyvern
#

try this

console.log(event.server.runCommand(`execute as ${event.player.username} at ${event.player.username} run setblock ~ ~ ~ minecraft:structure_block{mode: "LOAD", name: "from_nothing:island"}`))
#

and see if the log says 0 or 1

gentle kettle
#
[18:44:27] [Server thread/INFO]: Set spawn point to -4230, 64, 2607 [0.0] in minecraft:overworld for Grognatou
[18:44:27] [Server thread/INFO]: example.js#25: 0.0```
#

i guess it say 0

cyan dragon
#

That means it failed

gentle kettle
#

yeah so i need to shedule i think

#

so i need to use mcfunction format or there is a proper kubejs function format and in which folder ?

fresh wyvern
#

do you need to run that as a command? why not just set the block with scripts

gentle kettle
#

how to do it ?

fresh wyvern
#
let block = event.player.block.down
block.set('minecraft:structure_block')

im not sure what the other bits are, i havent seen those before

cyan dragon
#

NBT blockdata

fresh wyvern
#

i dunno what any of that is sad_cat_lex

cyan dragon
#

It tells the structure block its loading a structure

#

And then what structure to losd

#

Load

#

Basically allowing you to place a structure with commands

fresh wyvern
#

im trying to find how to set the nbt, i dont remember off the top of my head

gentle kettle
#
 let block = event.player.block.down;
        block.set("structure_block", {mode: "LOAD", name: "from_nothing:island"});
        event.server.runCommand(`execute as ${event.player.username} at ${event.player.username} run summon minecraft:marker ~ ~ ~ {Tags:["island_spawn"]}`);//summon the marker to set the place as an island pos
        event.server.runCommand(`execute as ${event.player.username} at ${event.player.username} run spawnpoint`); //set the player spawn here
        //event.server.runCommand(`execute as ${event.player.username} at ${event.player.username} run setblock ~ ~ ~ minecraft:structure_block{mode: "LOAD", name: "from_nothing:island"}`); //set block a structure block with a loaded structure, command work when typed in the chat but dont do anything and show any log in the case of script execution
        block.pos(x ,y , z);```
#

i made that but it doesnt work

copper agateBOT
#

Paste version of message.txt from @gentle kettle

fresh wyvern
#

why is line 6 there

gentle kettle
#

becose i dont know how to place blocks ;C

fresh wyvern
#

you dont need to

#

delete that

gentle kettle
#

and it read my mind to know when and where i should place it ;C ?

fresh wyvern
#

show the entire log, that error is not related to the script you wrote so far

fresh wyvern
#

event.player.block.down

gentle kettle
#

there is no error without it

fresh wyvern
#

"block under the player"

#

the error is related to the event PlayerEvents.loggedIn

#

ah no wait

#

nvm

#

kubejs.level.BlockContainerJS.set(BlockContainerJS.java:166)

#

hmm it errors here

state = state.setValue(property, UtilsJS.cast(property.getValue(String.valueOf(entry.getValue())).orElseThrow()));
gentle kettle
#

now with that : js let block = event.player.block.down block.set("structure_block", {mode: "LOAD", name: "from_nothing:island"}); event.server.runCommand(`execute as ${event.player.username} at ${event.player.username} run summon minecraft:marker ~ ~ ~ {Tags:["island_spawn"]}`);//summon the marker to set the place as an island pos event.server.runCommand(`execute as ${event.player.username} at ${event.player.username} run spawnpoint`); //set the player spawn here

copper agateBOT
#

Paste version of message.txt from @gentle kettle

gentle kettle
#

okay so property is something else i guess

#

and i need to find how to summon a block with custom blockstate

#

i made it work !!!!

#
        let block = event.player.block.down
        block.set('structure_block');
        block.blockState= {mode: "LOAD", name: "from_nothing:island"};
#

this was the answere

gentle kettle
#

but it doesnt had the stats ;C

#

and i need the block pos to be relative from the player, like ~ 64 ~-1

fresh wyvern
#
let block = event.player.block.offset(0, 64, -1)
gentle kettle
#

and for the states do you know ?

fresh wyvern
#

i dont very_sad_kitty_lex

#

try searching for blockstate on discord

gentle kettle
#

thanks anyway

gentle kettle
#

omg i found it

gentle kettle
#

and it work

fresh wyvern
gentle kettle