#Dont know where to put this...

166 messages ยท Page 1 of 1 (latest)

full slateBOT
#
daliavixen has been warned

Reason: Duplicated text

quartz reef
#

@static light what were you needing help with? the bot killed whatever you tried to post.

static light
#

I need help with finding out where to put this to make it work. Its ftb quests and kubejs

full slateBOT
#
daliavixen has been warned

Reason: Duplicated text

static light
#

its a script i tryig to paste

quartz reef
#

upload it.

#

don't paste it as text

#

<-- click that plus sign and choose upload file

static light
#

problem, i only have it saved to my clipboard :/

quartz reef
#

click that option and paste it.

#

or paste it to notepad, save it, and upload it

static light
quartz reef
#

now give me some words to explain what the issue is

#

because code without context means nothing and I can see a MOD chiming in that they don't help with coding.

#

I'm not a MOD, so I'm willing to help, but I need to know which mod pack, and what issues you are having.

static light
#

Its my custom modpack, im just confused on making it work.

quartz reef
#

explain to me what you are trying to make kubejs to do

static light
#

i wanna get it to work on ftb quests so the quests resets every 12 hour

quartz reef
#

so you don't want a standard repeatable quest, but one that is onlyl repeatable once every 12 hours per player, 12 hours from when the player last completed the quest.

static light
#

yea

#

or when the player hae completet the quests it will reset everyday at the same time

quartz reef
#

which version of ftb quests are you using, include minecraft version and mod loader version

#

did someone write t his quest for you? because i see a variable placeholder QUEST_ID_HERE

#

you have to put the id of the quest you are resetting in that spot

static light
#

ye someone wrote me this

quartz reef
#

probably a geek with no social skills because they didn't explain it to you

#

i also don't see a time offset in it

static light
#

yea

quartz reef
#

get me the full version of ftbquests you are using, it's in the filename

static light
quartz reef
#

send me the quest id

static light
#

32ACF80E24F7AD9C

quartz reef
#

right click on the quest and find the id, likely under quest properties

#

ok

#

this is gonna take a bit, but i should have something for you in about 30 minutes or so.

static light
#

you are an angle! Take the time you need

quartz reef
#

and you'll be able to copy this one for any number of quests, all the modifiable variables will be at the top for easy modification, you won't learn anything that way, but I'm cool with that. I prefer the masses to not know the dark arts of programming. ๐Ÿ™‚

static light
#

haha thanks

quartz reef
#

give this script a shot

// KubeJS server_script (e.g., in kubejs/server_scripts/quest_reset.js)

// === Configurable Settings ===
const QUEST_ID = "32ACF80E24F7AD9C";      // Quest ID to reset (use the quest's unique ID)
const RESET_INTERVAL_HOURS = 12;          // Interval after which the quest resets
const RESET_INTERVAL_TICKS = RESET_INTERVAL_HOURS * 60 * 60 * 20;  // 12 hours in game ticks (20 ticks = 1 second)
const RESET_INTERVAL_MS    = RESET_INTERVAL_HOURS * 60 * 60 * 1000; // 12 hours in milliseconds (for offline check)

// Key for storing last completion time in player persistent data
const LAST_COMPLETE_KEY = `questLastComplete_${QUEST_ID}`;

// Event: When the specified quest is completed by a player
FTBQuestsEvents.completed(QUEST_ID, event => {
  const player = event.player;
  const server = event.server;
  
  // Record the current time (timestamp) in the player's persistent data
  player.persistentData[LAST_COMPLETE_KEY] = Date.now().toString();
  
  // Schedule a quest reset after 12 hours (in ticks) for this player
  const playerName = player.username;
  server.scheduleInTicks(RESET_INTERVAL_TICKS, server, ctx => {
    // Reset the quest progress for the player after 12 hours
    ctx.data.runCommandSilent(`/ftbquests change_progress ${playerName} reset ${QUEST_ID}`);
    // (No need to run as player; this admin command will reset the quest:contentReference[oaicite:5]{index=5})
  });
});

// Event: When a player logs in, check if the quest should be reset due to time elapsed
PlayerEvents.loggedIn(event => {
  const player = event.player;
  const server = event.server;
  const lastCompleteStr = player.persistentData[LAST_COMPLETE_KEY];
  
  if (lastCompleteStr) {
    const lastCompleteTime = parseInt(lastCompleteStr);
    const elapsed = Date.now() - lastCompleteTime;
    
    if (elapsed >= RESET_INTERVAL_MS) {
      // More than 12 hours since last completion: reset the quest for this player
      server.runCommandSilent(`/ftbquests change_progress ${player.username} reset ${QUEST_ID}`);
      // Clear the stored timestamp so it won't reset again until quest is completed next time
      player.persistentData[LAST_COMPLETE_KEY] = "";
    }
  }
});
static light
#

Imma try it, you are the best!

quartz reef
#

all the CONST vars at the top are t he ones you change

#

however only the first 2 are the most relevant

#

so if you wanted a creeper kill quest at 30 hours, then naturaly the quest id for that, and interval would be 30

#

just copy paste and rename, then edit

#

you can always feed the script to ai and say "eli5"

#

explain like i'm 5

#

however i think this script reads better than the original one

static light
#

It does, thanks

quartz reef
#

btw if you need to test it, set the interval to something like 5 minutes

static light
#

was about to ask

#

xD

#

what number would it be if its 5 minutes? Sorry im really bad a this xD

quartz reef
#

// 5 minutes expressed in hours
const RESET_INTERVAL_HOURS = 5 / 60;

#

since 60 is the numerator here.

#

meaning if you wanted 1 minute, you can also use 1/60

#

not need to fully rationalize the number. let the computer math it out.

static light
#

hmm, i think i did something wrong, its not resetting

quartz reef
#

are there errors in the kubejs log?

static light
#

not what i see

quartz reef
#

did you reload the server after updating the script?

#

reload restart either works

static light
#

i did

quartz reef
#

is the quest on both sides as is also the script?

static light
#

I just copied and pasted what you worte into my kubejs folder

#

Do i need to fill in the quest ids thats just called quest id?

quartz reef
#

typically scripts go on both the client and server side.

#

send your latest log after try to do the quest again

#

did you remember to reset your quest progress? it probably won't work on an already existing quest.

#

that was completed.

static light
#

I did

#

Oh it does have an error

quartz reef
#

send me the whole log

#

!llogs

full slateBOT
#

Please send some logs over so we can help resolve your issue. To access logs on your Minecraft server, please navigate to your server panel's File Manager and take the following path:

1. Open the Server's File Manager
2. Navigate inside the 'logs' folder
3. Click on "latest.log" to download it and send the file over Discord to this channel.
static light
#

thats not it sorry

quartz reef
#

that doens't work, that's not how you get me the log. download the log, then upload it. you can download it via the 3 dots menu to the right of it

static light
quartz reef
#

here is another versin of the script that checks to see if the player data is null. try it and see what you get.

//  quest_reset.js  โ€“ย put in kubejs/server_scripts
// โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
// โ–‘โ–‘โ–‘โ–‘โ–‘  EASYโ€‘TOโ€‘TWEAK SETTINGS  โ–‘โ–‘โ–‘โ–‘โ–‘
const QUEST_ID            = '32ACF80E24F7AD9C'     // Quest to reset
const RESET_INTERVAL_HRS  = 12                     // Coolโ€‘down length
const MS  = RESET_INTERVAL_HRS * 60 * 60 * 1000    // โ€‘ milliseconds
const TICKS = RESET_INTERVAL_HRS * 60 * 60 * 20    // โ€‘ game ticks
const LAST_KEY = `questLast_${QUEST_ID}`           // NBT key

// Helper โ€“ silent quest reset
function reset(server, name) {
  server.runCommandSilent(`/ftbquests change_progress ${name} reset ${QUEST_ID}`) // official reset cmd :contentReference[oaicite:1]{index=1}
}

// โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
// 1๏ธโƒฃย Store a timestamp every time the quest is really completed
FTBQuestsEvents.completed(QUEST_ID, e => {          // event docs :contentReference[oaicite:2]{index=2}
  if (!e.player) return               // protect against null player
  e.player.persistentData[LAST_KEY] = Date.now().toString() // perโ€‘player NBT storage :contentReference[oaicite:3]{index=3}

  // Schedule an onโ€‘line reset after 12ย h
  e.server.scheduleInTicks(TICKS, e.server, ctx => {
    if (ctx.data.playerList.getPlayerByName(e.player.username)) {
      reset(ctx.data, e.player.username)
    }
  })
})

// 2๏ธโƒฃย Kickโ€‘off checker every minute for players that stay onโ€‘line
ServerEvents.high_tick(ev => {                      // high_tickย = 20โ€ฏtโ€ฏ*โ€ฏ~1โ€ฏs
  if ((ev.server.tickCount % 1200) !== 0) return    // run once per min
  ev.server.players.forEach(p => {
    const ts = parseInt(p.persistentData[LAST_KEY] || 0)
    if (ts && (Date.now() - ts) >= MS) {
      reset(ev.server, p.username)
      p.persistentData[LAST_KEY] = ''               // clear flag
    }
  })
})

// 3๏ธโƒฃย Catch people who logged out before the timer elapsed
PlayerEvents.loggedIn(ev => {
  const ts = parseInt(ev.player.persistentData[LAST_KEY] || 0)
  if (ts && (Date.now() - ts) >= MS) {
    reset(ev.server, ev.player.username)
    ev.player.persistentData[LAST_KEY] = ''
  }
})
#

you'll have to use 5/60; for the 5 minutes test again

#

so it looks like kubejs serverscripts don't go on the clientside. so that's nice.

static light
#

so i cant get it to work?

quartz reef
#

i just gave you a new script, try it out while i analayze the log you sent

static light
#

okay

quartz reef
#

and if it fails to complete, send me the latest.log again

static light
quartz reef
# static light

i admitted to not realizing it didn't need to be on the client side. go ahead and remove it there.

static light
#

what should i change?

quartz reef
#

remove the script from the local side

#

restart the client

static light
#

in here?

quartz reef
#

client

#

local

#

the part on your computer

#

i'm sure you added the script to your pack on your side after i said it goes on both sides

#

i was thinking of crafttweaker when i saidthat

#

that's why you got the dirtscreen message

quartz reef
static light
#

i have only been doing stuff on bisect

#

so i have top remove it from the mod pack?

quartz reef
#

how did you get this error?

static light
#

opened the game

quartz reef
#

note: in minecraft when opens the game, we call it opening the client

#

did you modify the client at all in our talk?

static light
#

nope

quartz reef
#

send the latest.log from the server, do yo u recall me saying that if it fails again?

#

in minecraft dev, we always send the latest.log from the side that failed

static light
#

have to go eat brb

quartz reef
#

๐Ÿ‡น ๐Ÿ‡ญ ๐Ÿ‡ช ๐Ÿ‡ท ๐Ÿ‡ช ๐Ÿ‡ผ ๐Ÿ‡ฆ ๐Ÿ‡ธ ๐Ÿ‡ฆ ๐Ÿ‡ธ ๐Ÿ‡ฑ ๐Ÿ‡ฎ ๐Ÿ‡ฌ ๐Ÿ‡ญ ๐Ÿ‡น ๐Ÿ‡น ๐Ÿ‡พ ๐Ÿ‡ต ๐Ÿ‡ด ๐Ÿ‡ฎ ๐Ÿ‡ณ ๐Ÿ‡น ๐Ÿ‡ญ ๐Ÿ‡ช ๐Ÿ‡ฑ ๐Ÿ‡ฆ ๐Ÿ‡ธ ๐Ÿ‡น ๐Ÿ‡ธ ๐Ÿ‡จ ๐Ÿ‡ท ๐Ÿ‡ฎ ๐Ÿ‡ต ๐Ÿ‡น

#
// quest_reset.js  โ€“ place in kubejs/server_scripts

// โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ• CONFIGURABLE SETTINGS โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
const QUEST_ID             = '32ACF80E24F7AD9C'; // Quest to reset
const RESET_INTERVAL_HRS   = 12;                 // Coolโ€‘down length
const RESET_INTERVAL_MS    = RESET_INTERVAL_HRS * 60 * 60 * 1000; // milliseconds
const RESET_INTERVAL_TICKS = RESET_INTERVAL_HRS * 60 * 60 * 20;   // game ticks
const LAST_KEY             = `questLast_${QUEST_ID}`;              // NBT key

// โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ• HELPER โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
function resetQuest(server, playerName) {
  server.runCommandSilent(`/ftbquests change_progress ${playerName} reset ${QUEST_ID}`);
}

// โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ• HANDLERS โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
// 1๏ธโƒฃย Store completion time & schedule inโ€‘session reset
FTBQuestsEvents.completed(QUEST_ID, event => {
  const player = event.player;
  if (!player) return; // guard against null

  player.persistentData[LAST_KEY] = Date.now().toString();

  event.server.scheduleInTicks(RESET_INTERVAL_TICKS, event.server, ctx => {
    if (ctx.data.playerList.getPlayerByName(player.username)) {
      resetQuest(ctx.data, player.username);
      player.persistentData[LAST_KEY] = '';
    }
  });
});

// 2๏ธโƒฃย Periodic checker (once per minute) for online players
ServerEvents.tick(event => {
  if (event.server.tickCount % 1200 !== 0) return; // 1200โ€ฏt = 60โ€ฏs
  event.server.players.forEach(p => {
    const ts = parseInt(p.persistentData[LAST_KEY] || '0', 10);
    if (ts && Date.now() - ts >= RESET_INTERVAL_MS) {
      resetQuest(event.server, p.username);
      p.persistentData[LAST_KEY] = '';
    }
  });
});

// 3๏ธโƒฃย Login checker for timers that expired while offline
PlayerEvents.loggedIn(event => {
  const player = event.player;
  const ts = parseInt(player.persistentData[LAST_KEY] || '0', 10);
  if (ts && Date.now() - ts >= RESET_INTERVAL_MS) {
    resetQuest(event.server, player.username);
    player.persistentData[LAST_KEY] = '';
  }
});
static light
#

i still cant get it working :/

quartz reef
#

when you copy the quest id from ftb quest, and then you paste it somewhere, is it not in lower case? because here we have it in uppercase.

#

i'm being told that the ftb quest ids have the alphabet part in lowercase

static light
#

let me try changing it

quartz reef
#

so you were changing it to uppercase?

static light
#

no, it came in uppercase

quartz reef
#

ok thats' odd then

static light
#

let me put the letters i lowercase

#

see if that does something

quartz reef
#

try this version of the script if that doesn't work

// server_scripts/quest_reset.js
// Autoโ€‘reset a quest for each player 12ย h after their last completion
// โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
const QUEST_ID        = '32acf80e24f7ad9c';   // ๐Ÿ” lowerโ€‘case!
const RESET_DELAY_MS  = 12 * 60 * 60 * 1000;  // 12ย hours
const CHECK_INTERVAL  = 20 * 60;              // serverโ€‘tick interval (1ย min)

// โ”€โ”€โ”€ 1.ย Stamp the moment a player finishes the quest โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
FTBQuestsEvents.completed(QUEST_ID, e => {        // fires once per finish
  const p = e.player;
  if (!p) return;                                 // safety guard

  const now = Date.now();
  p.persistentData[`last_${QUEST_ID}`] = now;
  console.log(`[quest_reset] ${p.username} completed, reset in 12h`);

  scheduleReset(p, now);
});

// โ”€โ”€โ”€ 2.ย Check on login so offline players donโ€™t get stuck โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
PlayerEvents.loggedIn(e => {
  const p = e.player;
  if (Date.now() - (p.persistentData[`last_${QUEST_ID}`] ?? 0) >= RESET_DELAY_MS)
    resetQuestFor(p);
});

// โ”€โ”€โ”€ 3.ย Lightweight ticker for active players โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
let ticks = 0;
ServerEvents.tick(e => {                           // official tick event
  if (++ticks % CHECK_INTERVAL) return;            // once per minute
  e.server.getPlayerList().getPlayers().forEach(p => {
    if (Date.now() - (p.persistentData[`last_${QUEST_ID}`] ?? 0) >= RESET_DELAY_MS)
      resetQuestFor(p);
  });
});

// โ”€โ”€โ”€ Helpers โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
function scheduleReset(p, stamp) {
  const delay = Math.ceil((stamp + RESET_DELAY_MS - Date.now()) / 50);
  p.server.scheduleInTicks(delay, ctx => {
    const live = ctx.server.getPlayerByUUID(p.uuid);
    if (live) resetQuestFor(live);                // online โ†’ instant
  });
}

function resetQuestFor(p) {
  p.server.runCommandSilent(`/ftbquests change_progress ${p.username} reset ${QUEST_ID}`);
  p.persistentData[`last_${QUEST_ID}`] = 0;       // clear timestamp
  console.log(`[quest_reset] reset performed for ${p.username}`);
}
static light
#

the hour is diffrent do i just pput 1/60 * 60 * 60 * 1000?

quartz reef
#

yes you can do that

#

we're going fast here because i'm using ai to help me get to the bottom of things faster. if we did this with manual read method, i'd have given up by now.

static light
#

i really appriciate your help

keen palm
#

PLEASE STOP USING AI

#

It hallucinates code! It makes things up from thin air!

#

This is BAD!!

quartz reef
#

we will wait on flyingbox to research the issue now.

#

because we're going to manually press nails into boards to build a house

static light
#

no stress, and thanks guys

quartz reef
#

ironically, but maybe not so, they will say this script business is beyond their scope. i'll be shocked if they don't say that.

#

are you able to share your sever with me?

#

like zip it up, not the world folder, just the configs,/mods/kubejs folders and put it on cloud somewhere?

static light
#

like the modpack zip file? is that good=

quartz reef
#

in that case the share code if you built it in curseforge app

#

and i need the kubejs folder from your server

static light
#

ozLT2gko

#

the zip is the kubejs file

quartz reef
#

the mod pack you sent me has no quests in it

#

therefore i need your config folder from the server

static light
quartz reef
#

the quests you made

static light
quartz reef
#

the pudding btw. it's a good idea to have the configs on the server match the one in the pack you are distributing. that way if players want do something in private before doing it on the server they can.

static light
#

oh okay

quartz reef
#

its' resetting for me.

#

i had to run it thru ai one more time and now it's golden

static light
#

awesome

quartz reef
#

don't watch the questbook screen btw

#

it reset three times now

#

and i was testing it insingle player too

#

wait hallucinating script

#

it dind't even enable debug mode and it was resetting every 1 minute

#

let me tweak it manually so ti works right

static light
#

it works!

#

you are the best

quartz reef
# static light it works!

it doesnt' really work. i kept testing and found minor issues, i've gone thru about 12 iterations so far.

#

it works way better than when you started this thread.

#

that's for sure. ๐Ÿ™‚