#Executing commands once every second on server tick not working

79 messages · Page 1 of 1 (latest)

lusty arrow
#

Im probably doing something wrong. Im trying to make items place a block on the closest air block after 3 minutes of being on the ground, and then use /kill on themselves. I got this working with a function, but it was laggy. I want to do it with a server script, but I cant find documentation for most aspects of what Im trying to do (server.tick, timer, item entity lifespan, check y position and relative blocks, etc) currently I have what is in the image attached.

This doesnt work. The current non working code was from a tutorial zip, so I currently only understand it somewhat. It doesnt change the scoreboard when it should, every second

tight basinBOT
#

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

lusty arrow
#

If I can do everything with as little minecraft commands as possible, I would prefer to do so

fair shore
#

So there are multiple issues here

bright badger
#

i was just about to say lol

fair shore
#

First you never seem to define pDatatimer

bright badger
#

why are you using player tick event hmmm

#

instead of server tick

fair shore
#

Then you have two If Checks while only one is needed

#

And the second one has only 1 equal sign

mystic lion
#

are these in the server scripts folder?

#

oh yeah hes missing this```js
//Gives players the timer's persistent data to initialize the timer on each player who logs in.
PlayerEvents.loggedIn(event => {
if(!event.player.persistentData.timer) event.player.persistentData.timer = 0
})

//Sets a timer on a 20 tick interval
PlayerEvents.tick(event => {
let pData = event.player.persistentData
pData.timer = (++pData.timer) % 20
if(pData.timer != 0) return //event here if you wanted to ignore the lower event block
})```

#

he copied from one part of my example scripts and not the whole part

#

really you could just use this code here ```js
/*

  • SHORTER ALTERNATIVE
  • alternatively you can use the player's age. This works for most cases, but keep in mind the player's age resets on relogging
    /
    PlayerEvents.tick(event => {
    if(event.player.age%20!=0) return
    /
    Code below here runs once every 20 ticks (20 ticks = 1 second) */
    })``` its a very simplified version of the above script (and ill probably end up removing that since event.player.age is a lot shorter)
#

you wouldnt have to worry about persistent data or anything

rich girder
lusty arrow
onyx basalt
#

this scoreboard manipulation feels so 2010

lusty arrow
onyx basalt
#

since this is level related, should be level tick no?

lusty arrow
#

im working on responding to everyone lol, Ill get to reading stuff

lusty arrow
mystic lion
formal willowBOT
#

[Quote ➤](#1176887886801551430 message) really you could just use this code here ```js
/*

  • SHORTER ALTERNATIVE
  • alternatively you can use the player's age. This works for most cases, but keep in mind the player's age resets on relogging
    /
    PlayerEvents.tick(event => {
    if(event.player.age%20!=0) return
    /
    Code below here runs once every 20 ticks (20 ticks = 1 second) */
    })``` its a very simplified version of the above script (and ill probably end up removing that since event.player.age is a lot shorter)
mystic lion
#

you can just move your code into that

onyx basalt
lusty arrow
mystic lion
#

youd have to have someone online in the first place to load in the chunks

lusty arrow
onyx basalt
#

what are you trying to simulate in the end? some sort of block growing?

mystic lion
#

with commands?

#

why not just download a chunk loader mod?

#

oh youre saying what about chunk loaders?

lusty arrow
mystic lion
#

hmm i see

#

then youd probably want them in the ServerEvents.tick

lusty arrow
mystic lion
#

itd be the same concept as playerevents.tick

#

also

#

??sendcode

formal willowBOT
# mystic lion ??sendcode

Send your code here instead of a screenshot

It makes it easier to diagnose your code and help you fix it or make the required changes/additions.

lusty arrow
#

it told me it was more than 2000 characters last time I tried

mystic lion
#

you can send it in multiple messages

#

would be better than a screenshot tbh

#

wait no

#

just send the problem related text

#

not your whole file

lusty arrow
#

what does event.player.age become on server end?

rich girder
#

more than 2k characters should also just send a txt file through discord

lusty arrow
#

if using serverevent instead

mystic lion
#

player.age is for players only not servers

#

youd need the server persistent data

#

similar to the example with the timer

#

sec

rich girder
#
ServerEvents.loaded(event => {
    let {server, server:{persistentData}} = event
    if (persistentData.firstLoad) return
    persistentData.firstLoad = true

    persistentData.timer = 0
    //first load stuff can go here
})

ServerEvents.tick(event => {
    let {server, server:{persistentData}} = event
    persistentData.timer++
    if (persistentData.timer < 20) return
    persistentData.timer = 0

    //do stuff here
})
lusty arrow
#

where does first load stuff go, sorry?

rich girder
#

edited the message
just put it below the line to set the timer

rich girder
#

literally had it in the file i was editing xd

mystic lion
#

fair

#

could even do stuff like this if you wanted to load things every server load js ServerEvents.loaded(event => { const {server, server:{persistentData}} = event if (persistentData.firstLoad) { persistentData.firstLoad = true persistentData.timer = 0 //first load stuff can go here } //things you want to load every time server loads goes here })

lusty arrow
#

alright, thanks. I dont want to leech off of everyone knowledge, but I feel like questions are good to ask and knowledge is generally good to know. Given that; is there any possibility I could be guided to somewhere that will let me understand how to do the execute commands I have, but within kubejs entirely or mostly? I dont need to be given answers if thats too much on yall, but I can read a tutorial etc and figure out how to, for example, search for the nearest air block and do the other stuff. Idk how to make kubejs interact with the world on server or level. If I have docs to read I could do it, but ive been looking through the github and its not easy to read that stuff for me

mystic lion
#

dont be afraid to ask questions, people ask a lot simpler questions in the support section

#

thats what it's there for

lusty arrow
#

alright, thanks

#

so I can make a new ticket for the new question, right? I dont have to worry about getting timed out for too many questions?

mystic lion
#

yea

#

first close this ticket with /ticket close

formal willowBOT
#

Please close your ticket (with </ticket close:1054771505520717835> or the button atop this thread) once you resolved your issue! This also helps others that would like to help out, as they don't have to look into this thread to check if it has been resolved by now.

Do you have any other questions regarding your issue? Feel free to ask!
Note: You generally should create a new post for unrelated issues.