Course Curriculum
-
Getting Started
Making Shopkeepers
There are lots of ways to build a shopkeeper NPC.
I have a few sample scripts for you and some hints about how to alter them.
The first script (simpleshop) is for a person who buys items from the player. If you’d like to alter this script, make sure to alter the first line with your NPC’s name. Change the chat text and the item the NPC buys. You can change the price too, and how many items are purchased together. If you want, you can copy the basic IF statement into your other scripts to have them purchase things form people.
The second script (buyandsell) allows a player to buy and sell. I wrote this script to be overly complicated using a random command in the first click trigger. I wanted the random command to select a group of lines rather than a single one, so I had the random command choose between two repeat 1 lines. Each of those repeat 1 lines has a number of sub-commands under them. This is a technique worth learning regardless of what type of interact script you’re writing.
The second thing to note in the second script is that I have different steps, and sometimes the same commands are repeated multiple times in different steps. Since whether the player is offered the chance to sell chickens or buy bows is determined randomly at the beginning, I added extra little chat triggers allowing a player to choose the other option, regardless of which one is first offered.
The third script (inventoryshop) works differently than the first two. The third script is a set of smaller scripts that makes an inventory open when the player talks to the NPC. When the player clicks on the NPC inventory, they can select the object they want and it is given to them and the money is deducted from their inventory.
The standard inventory has 27 slots. These are represented by the [] symbols in the script.
slots:
– “[i@myrabbit] [] [] [] [] [] [] [] []”
– “[] [] [] [] [] [] [] [] []”
– “[] [] [] [] [] [] [] [] []”
For every item you create, you need to:
- create a custom item with the price tag in the lore.
- choose which slot of the storekeeper’s inventory it goes in and add it to the inventory script.
- Create an event for when the player clicks on that item in the inventory. The item event will look like the following. Change the name of the item in the first line and in the give line. Change the cost of the item in the 2nd, 4th and 5th lines.
on player clicks myrabbit in ChristyShop:
– if <player.money> > 8 {
– inventory close
– money take quantity:8
– narrate “<&a>$<&e>8 <&a>has been taken from your balance”
– give myrabbit
} else {
– inventory close
– narrate “<&c>You do not have enough money!”
}
Adjustable Pricing
If you want to have the price adjustable, you need to do it in the script rather than as an inventory shop. You can use flags such as these:
flag server ChristysPriceCounter:++ (increases it by one)
flag server ChristysPriceCounter:– (decreases it by one)
flag server ChristysPriceCounter:+:3 (increases it by three)
Then when you need the price, use something like this: <server.flag[ChristysPriceCounter]>
Or, you can ask for half their money with this:
– define myvalue <parse:<player.money>>
– define mycost <def[myvalue].div_int[2]>
– chat “It will cost you <def[mycost]>.”

Comments