#Giving player item on first time loading into world

28 messages · Page 1 of 1 (latest)

frigid wedge
#

Trying to make a client script that, when the player first loads into a world, gives them an item (akashic tome with the guidebooks from each mod pre-installed). Using the template on the kubejs wiki, I put together this script:

ClientEvents.loggedIn(event => {
  // Check if player doesn't have "starting_items" stage yet
  if (!event.player.stages.has('starting_tome')) {
    // Add the stage
    event.player.stages.add('starting_tome')
    // Give akashic tome to player
    event.player.give(Item.of('akashictome:tome', '{"akashictome:data":{immersiveengineering:{Count:1b,id:"immersiveengineering:manual"}}}'))
    }
})```

But when I try this code out, I don't get the item or the starting_tome gamestage, and kubejs shows no error messages. What's wrong with this code?
mellow roverBOT
#

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

boreal jewel
frigid wedge
#

should be in client_scripts

boreal jewel
#

I think you have misread the wiki

#

Player login would be a server event

#

If the wiki is using ClientEvents then that is an error, someone may have typoed when writing the KJS6 information

#

Hmm

blazing quarry
#

theres both ClientEvents and PlayerEvents

#

PlayerEvents.loggedIn and ClientEvents.loggedIn

boreal jewel
#

Why is there a client one?

#

What is it used for?

blazing quarry
#

not exactly sure when that fires

boreal jewel
#

You will need to use the player event in the server scripts folder for giving items

frigid wedge
#

yeah I've just tried putting my code snippet into the server scripts and it spits out an error

#

should I be using playerEvents in that case?

blazing quarry
#

use PlayerEvents.loggedIn in server_scripts

boreal jewel
#

Yeah

#

God knows why there are client events for login and logout

#

A good rule of thumb is, if you're doing manipulation (like adding to someone's inventory or changing game stages) it needs to be done on the server

boreal jewel
#

Is it just a wiki error

#

I'll look properly when I'm at my pc later and update the wiki if so

#

Bbl

frigid wedge
#

changed the event and it works now, thank you both

#

should I close this ticket?

blazing quarry