#First time logging items

7 messages · Page 1 of 1 (latest)

ancient coral
#

Hello, I'm trying to give the player items when they first log in. I've managed to give every time the loggedIn event triggers but unable to do it only once (I don't want to use another mod to do it). I've tried (and failed) with a boolean variable but obviously the script restart at each loggin x)

light fogBOT
#

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

quiet ospreyBOT
#

[➤](#1230535464201486477 message)
and use it like this

const starter_items = ["minecraft:torch", "minecraft:diamond"];

PlayerEvents.loggedIn(e => {
    if(e.player.stages.has('start')) return;
    e.player.stages.add('start');

    e.player.inventory.clear();
    starter_items.forEach(item => e.player.give(item));

    //If you'd like to add starter armor like leather boots
    //e.server.runCommandSilent(`item replace entity ${e.player.username} armor.feet with minecraft:leather_boots`);
});
sweet star
#

use player stage, not a variable

ancient coral
#

Oh I thought stages came from an addon. Thank you !

echo violet
#

or simply

PlayerEvents.loggedIn((event) => {
  const { player } = event;

  if (player.persistentData.getBoolean("first_join") === false) {
    player.give(Item.of("minecraft:ender_pearl", 16));
    player.persistentData.putBoolean("first_join", true);
  }
})
quiet ospreyBOT
#

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 should generally create a new post for unrelated issues.