- Supported Minecraft Versions:
- 1.8, 1.9, 1.10, 1.11About
Since RandomSk has this feature and I never saw someone saying that it is working, I decided to make this API that allows you edit, remove and create custom trades for villagers.
The usage is pretty simple and you only need some simple functions for that.
The NumberPage goes from 1 to the amount of trades of a villager. The ItemToBuy1, ItemToBuy2 and ItemToSell are the items but only the ItemToBuy2 can be air, since you can't create blank trades. The last 3 arguments are optional, Uses and MaxUses it's the number of uses/max uses that a villager can have. By default it's 0 and 7, respectively, BooleanExpReward accepts true or false if a villager should drop some xp's when the player trades a item, until this moment, you can't change the amount of xp in nbt.Code (Skript):
- setTrade(Entity, NumberPage, ItemToBuy1, ItemToBuy2, ItemToSell, Uses, MaxUses, BooleanExpReward)
It returns the item in a trade's slot. The NumberItemPosition accepts only 1, 2 or 3.Code (Skript):
- getTradeItem(Entity, NumberPage, NumberItemPosition)
It removes a trade. Also, all trades after that page will have they index changed. e.g. if you have 2 trades and remove the first one, the second will be the first after removed it.Code (Skript):
- removeTrade(Entity, NumberPage)
You can see a detailed usage of these functions in the API and other functions that can help you with external things, as some functions to serialize items as a string nbt.
- on spawn of villager:
- #A villager only have a trade when a player right clicks on it for the first time.
- setTrade(last spawned villager, 1, 9 emerald, air, emerald block named "&aEmerald Block")
- setTrade(last spawned villager, 2, 3 diamonds, 2 stick, diamond pickaxe of Sharpness 1)
- setTrade(last spawned villager, 3, 30 sands, flint and stell, 30 glass, 0, 999999, true)
- command /newTrades:
- #As mentioned before, you can remove the nbt tag of a villager to erase
- #all trades and make it generate a new one.
- remove "Offers" from nbt of targeted entity
- #It isn't from api, it's just a example how to do it.
- on damage of villager:
- if attacker is a player:
- loop integers from 1 to getSizeOfTrades(victim):
- if getItemTrade(victim, loop-integer, 3) is a diamond sword named "&bEpic sword":
- send "You hut the special villager, he won't sell Epic Sword anymore."
- removeTrade(victim, loop-integer)
This script needs to load before the script that you will use it. You can change the name of the file (if necessary) to 1VillagerAPI.sk (for example), so it will load first.
- Skript 2.2+
- SkStuff 18.104.22.168+You can use this api freely in your scripts. Just link to that resource in case you have it as a dependency.
Welcome to skUnity!
Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.
If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!
Now, what are you waiting for? Join the community now!
API VillagerAPI - Changes the trades of your villager 1.0
An API to manage the trades of a villager