Resource icon

API VillagerAPI - Changes the trades of your villager 1.0

  • 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!

Supported Minecraft Versions
  1. 1.8
  2. 1.9
  3. 1.10
  4. 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.​

—————————————————————————————————————————————————————————————————————————————————
Usage

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)
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_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+
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.​

—————————————————————————————————————————————————————————————————————————————————
You can use this api freely in your scripts. Just link to that resource in case you have it as a dependency.
Author
Tuke_Nuke
Downloads
1,235
Views
1,235
First release
Last update
Rating
0.00 star(s) 0 ratings

More resources from Tuke_Nuke