- Supported Minecraft Versions
- 1.8
- 1.9
- 1.10
- 1.11
About
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.
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.
Usage
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.
It returns the item in a trade's slot. The NumberItemPosition accepts only 1, 2 or 3.
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.
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.
The usage is pretty simple and you only need some simple functions for that.
code_language.skript:
setTrade(Entity, NumberPage, ItemToBuy1, ItemToBuy2, ItemToSell, Uses, MaxUses, BooleanExpReward)
code_language.skript:
getTradeItem(Entity, NumberPage, NumberItemPosition)
It returns the item in a trade's slot. The NumberItemPosition accepts only 1, 2 or 3.
code_language.skript:
removeTrade(Entity, NumberPage)
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.
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.
Examples
code_language.skript:
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:
trigger:
#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)
stop
Requirements
- Skript 2.2+
- SkStuff 1.6.3.7+