Check XP level, and add Item

Started by Kent15 on

Topic category: Help with MCreator software

Last seen on 16:14, 8. Sep 2018
Joined Jan 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Check XP level, and add Item

Hey! 

So in a mod I need an action that when you right click an item in the air, it will check if you have 40 XP levels.

If you do, it will take 40 away and give an item.

I have tried the command "/xp -40L @p" but it will happen even if you have less than 40.

Even then, I can't see how to make an if/then action with this.

On this forum: https://www.minecraftforum.net/forums/minecraft-java-edition/redstone-discussion-and/commands-command-blocks-and/2816165-anyway-to-use-the-if-then-command-all-in-one

I found this piece of code from "nigathan":

if (player.level >= 5) {

player.addLevel(-5)

player.giveItem(...)

}

So in MCreator, I set it to where if you right click the item in the air it will run that code.

But when exporting the mod, I get 2 errors:

error: ';' expected player.addLevel(-40)

error: ';' expected player.giveItem(mcreator_testLightsaberXP.block)

 

I just need a way for this to work, whether the code gets fixed or a work-around.

Sorry for such a long post :D

Any help would be appreciated.

Last seen on 15:27, 11. Mar 2022
Joined Dec 2014
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
have you tried global events
Mon, 04/16/2018 - 07:48

have you tried global events

Last seen on 16:14, 8. Sep 2018
Joined Jan 2016
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I looked at that, but these…
Thu, 05/03/2018 - 13:59

I looked at that, but these trigger an event. But I need an event, not a trigger.

Last seen on 00:13, 19. Apr 2024
Joined Mar 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
This was the first result on…
Thu, 04/04/2024 - 07:07

This was the first result on google when I wanted to do the same, found most of the code blocks in Math and Logic to get "if [[get xp level of [player]] greater than or equal to [5] then [remove [5] xp levels from [player], [add [item] to [player] inventory]"