Skip to main content

Ability to trade items with NPCs



  • Evgenii Permiakov

    Tom Banaszewski Deb Borba Thanks for your interest in beta testing the project. Please send me an email so we can continue the conversation.

  • teacher

    How to return items back to Player Inventory when he has "no money"? I've spent some time to solve this.

    We can use command blocks For/While Loops, same as in this video

    In LOOP we clear Emeralds or something else from Player's inventiry and count this in scorebpard variable

    Finaly if Player has small amount of "money" we start second LOOP and give Emeralds back one-by-one

    This is flat world with simple solution 

  • Evgenii Permiakov

    Hello teacher, thanks for joining the conversation. 

    I've run your world and it did work. A quick question: in the project I am working on I have a total of 50+ transactions. Do I need to create a second loop for every transaction? 

  • teacher

    Hello. I don't tested the 50+ transaction at the same time. I think the best way - clone "LOOP" for every NPS

    About "moneyback" - the best and super quick way to do this - use functions. We can test "Score" with moneyback and make list of commands from 32768 (maximum items in give command). If we store coins in scoreboard "moneyback":

    give @s[scores={moneyback=32768..}] emerald 32768 0
    scoreboard players remove @s[scores={moneyback=32768..}] moneyback 32768

    give @s[scores={moneyback=16384..}] emerald 16384 0
    scoreboard players remove @s[scores={moneyback=16384..}] moneyback 16384 

    Using: import resource pack attached, declare scoreboard moneyback and set some value

    and in command block run /execute @p[x=5,y=4,z=5,r=3] ~ ~ ~ function moneyback

    :) offcource specify Your x,y,z in selector


  • Debbie Alexander Community moderator
    Beacon of Knowledge Expert (Gold) Moderator

    Perhaps what is missing is a command to know what is in the player's inventory? I can't remember at the moment, but it seems to me that it is hard to test whether or not a player has something or not.

  • Trinity Ahie

    A simple option would be to allow an option to customize the trades for villagers. Or add an option where for NPCs to trade.

  • Valentina Galvez



Please sign in to leave a comment.