Renault on 29/12/2012 at 06:19
I was messing around with some of the tutorials for creating an in-game shop, when I discovered that the tnhscript module by Telliamed provides some awesome scripts for this very same purpose, and in a much simpler and quicker way. And it's all done by creating objects, editing their properties, and creating links. No knowledge of sources/receptrons or conversations is required. Since it was all very fresh on the brain, I figured I'd whip up a quick tutorial. I also created a demo mission displaying 5 different variations on stores based on the info in this tutorial. Demo is here: (
http://www.southquarter.com/downloads/2012/tnhscript_ingamestore.zip) tnhscript_ingamestore.zip.
In-game Store Tutorial using tnhscriptLoad tnhscriptExtract the script into your Thief 2 dromed directory.
Enter script_load tnhscript into the dromed command window.
Make The StoreCreate a trap trigger. This is essentially your Store. You might want to rename it.
Add the
ShoppingCart script to the trigger.
Add Trap->Quest Var. Enter a variable name, i.e.
store. This must be a unique variable.
Add Editor->Design Note. Use one of the following:
*
vendor=gold_only (store only accepts gold).
*
vendor=gems_only (store only accepts gems).
*
vendor=goods_only (store only accepts goods).
*
vendor=gold_first (spends all gold, then gems and goods).
*
vendor=even (pulls evenly from all three categories).
Make The Shopping CartCreate any object (something like a footlocker is good). This is your Cart.
Link from the Cart to the Store using flavor
Lock.
Link from the Store to The Cart using flavor
Script Params. Enter
Cart in the data field.
Create Items For SaleDo the following for each item in your store:
Create a button and a trap trigger.
Link the button to the trigger with flavor
Control Device.
Add the
PurchaseItem script to the trigger.
Link from the trigger to the Store using flavor
Script Params. Enter
Store in the data field.
Link from the trigger to the Cart using flavor
Script Params. Enter
Cart in the data field.
Items can be either a unique item (object) you create in a blue room or an archetype.
Link from the trigger to the Item using flavor
Script Params. Enter
Item in the data field.
Set item's cost under Inventory->Purchase Price. If modifying archetypes, make sure to save your gamesys.
For unique items, set total amount of items available under Engine Features->Stack Count.
If an item in your blue room does not have the property Engine Features->Combine Type, you must add it or the store reset will not work properly.
Odometer (optional)Add an odometer object anywhere in the mission. This keeps track of your total purchases.
Add Trap->Quest Var to the object, and enter the value
store (or whatever you used earlier).
Finishing UpCreate a button and link it to the Store using flavor
Control Device.
This is your “Check Out” button. It sends an “on” signal to the Store.
Create another button and an inverter.
Link the button to the inverter using flavor
Control Device.
Link the inverter to the Store using flavor
Control Device.
This button is your “Reset” button.
It empties the shopping cart by sending an “off” signal to the Store.
Now we need a warning in case the player doesn't have enough loot.
Link from the Store to any object using flavor
Script Params. Enter
ErrorOutput in the data field.
The object can be anything but something like a Sound Trap makes sense.
A Sound Trap will give an audio clue to the player that something is wrong. This does not however reset the store or change the contents of the shopping cart.
AestheticsAdd some plaques or posters to label everything for the player.
Add a countertop, register, display case, shopkeeper, etc, to make it look like a real shop.
Usage* Press the various item buttons to “buy” items and place them in the shopping cart.
* The odometer will keep track of what you owe.
* Press the “Check Out” button to pay for your items and unlock the shopping cart.
* Frob the shopping cart to retrieve your items.
* Press the “Reset” button to clear out your shopping cart and odometer and start over.
VariationsNo Shopping Cart:
Delete the Cart from the above setup.
Now when pressing the “Check Out" button, objects will go directly into the player's inventory.
Individual Purchases - No Cart or “Check Out”:
Delete the Cart, Odometer, Reset button and “Check Out” button from the original setup.
For each item for sale, set up another link with flavor
Control Device from it's button to the Store.
By pressing the button, the player will both select an item and “Check Out” in one step.
One issue with this setup is that if the player attempts to buy something before they have loot, they will get the error message but the item will remain in the Store's virtual cart.
The next time they buy something, they'll get two items, the one they're buying and the one already in the cart.
To resolve this, remove the link from the Store to the ErrorOutput object.
Create a Relay Trap, and set up a new
Script Params link from the Store to the Relay Trap, and again enter
ErrorOutput in the data field.
Create a link from the Relay Trap to the ErrorOutput object using flavor
Control Device.
Create a link from the Relay Trap to the Inverter using flavor
Control Device.
Now when there is an error, the ErrorOutput object will still be activated (probably a Sound Trap) and the Cart will also be reset and emptied.
No Buttons:
For each item button, set Shape->Model to whatever object you want, i.e.
watercry or
gasmine.
Now to make a purchase, the player is frobbing what appears to be the object itself instead of just a button.
Individual Items:
In this scenario, items are not stacked, each item is available individually in the game, and when the player frobs them, they are destroyed, giving the illusion that the player is picking them up.
The Store itself stays the same, so we'll keep that mostly as is.
The setup for each item for sale is slightly more complicated, & requires a few additional objects.
For each item for sale:
Create a button, 2 traps triggers, and a destroy trap.
Link the button to the 1st trap trigger using flavor
Control Device.
Add Shape->Model to change the button to the model of your item, i.e.
watercry.
Put the script
VendorRelay on the 1st trap trigger.
Under Editor->Design Note, enter
loot=X, X being the price of this item.
You can also put
vendor=gold_only or something similar to specify type of loot accepted.
Link the 1st trap trigger to the second trap trigger using flavor
Control Device.
Put the script
PurchaseItem on the 2nd trap trigger.
Link the 2nd trap trigger to the Store using flavor
Script Params. Enter
Store in the data field.
Instead of one stackable item in your blue room you'll now need one for each item in the game.
For each item in your blue room, make sure Inventory->Purchase is 0.
Link the 2nd trap trigger to the Item using flavor
Script Params. Enter
Item in the data field.
Create a destroy trap, and link it to the button using flavor
Control Device.
Link the 1st trap trigger to the destroy trap using flavor
Control Device.
Link the 1st trap trigger to the object you are using for errors using flavor
Script Params.
Enter
ErrorOutput in the data field for this same link.
Remove the link from the Store to the object you are using for errors.
Link the 1st trap trigger to the Store using the flavor
Control Device.
In this scenario, the first trap trigger (w/VendorRelay) handles the money part of the transaction.
If the player has enough loot, the money is deducted, the item (button) is destroyed, and the transaction continues on to the 2nd trap trigger.
If the player is short on loot, they get the error output and the item (button) stays in the game.
The 2nd trap trigger (w/PurchaseItem) handles the item distribution using the Store.
If anyone has anything to add, modifications, corrections, whatever, let me know and I'll modify this post.