Shops & Items: New methods, Item Validation, Team Shops & More
Introduction
[A quick note: Using this method prevents the "inventory manipulation - unit BUYS item" event from working. However, you can still use unit gains/loses item. ]
Shops have been discussed a lot in the SC2 Comunity. Typically they use a train order command to purchase items. This tutorial isnt going to cover making an item or a shop. That has already been extensivly discussed in other topics. Instead, what we're going to be focusing on is new methods to use for item buying, selling, and using validators to control what's allowed or not when purchasing our items (ex. Limit 1 item type in inventory, Selling items with multiple charges, combining items, etc)
I'm going to assume you already have created some items and a shop and just need help limiting how a player can buy them. Lets start from there.
First, the Ability
Ignore what people have told you about the train ability. We do NOT want to train an item. We want to CREATE it. So, lets get started.
Create a new ability, type: Effect - Instant. Set the cost to what you want your item to cost. Leave the effect field blank for now. we'll get back to it. (You can check the Stats: Flags: Transient if you want units to purchase while moving, but I dont recommend it)
Lets name this ability "Purchase Rareity Item".
Now lets go to effects.
Create a new effect, type issue order. Name it "Purchase Item - Add to inventory".
Set the "Ability:" field to your hero's inventory ability, and the Ability command to 2. This will order our unit to pick up the item when its created. Set Effect: Unit to caster, Effect: Player to caster, and Effect: Target to Target Unit.
Create a new effect, type create unit. Lets name it "Create Rare item".
Set the "Unit" field to the item you want to create. Set Effect: Spawn to the effect we just created, purchase item - add to inventory. Set Effect: Select Unit to "Caster", and the effect in that field to "purchase item - add item to inventory". Uncheck the "placement" and "offset by radius" flags. We dont want our created unit to have a footprint, nor do we want it to collide with the unit thats creating the item. Set the spawn owner to caster, and target location to caster unit. For good measure set the spawn range to 0, and the offset to (0,0).
Validator
Now go over to our validators tab. Create a new validator, type "unit inventory contains item". Name it "Has Rare Item". Set the "Item" field to our item. Set Validator: Find to disabled (Enabled means its in our inventory, disabled means its not). Set the Validator unit to caster.
Go back to the create unit effect and add our new validator to its Effect: validation field.
Goto our ability and add our create unit effect.
Now goto your shop, add the ability to your unit's Abilities, then set up a command card button for it and you're done. You can now purchase your unit, and it will only let you buy one of that kind of item.
Additional validators
- If you want your shop's items to always be visible, but only purchasable within a certain radius, add a "Location Range" validator to your create unit (item) effect and set the shop's interact ability range to 500. For the Range validator, youll want to set the target location to "target" and leave the location value at caster.
- If your item is part of a group of unique units (example, you have several weapon items, but a hero can only have 1 weapon at any time), use a Combine validator. First, add a normal compare inventory unit validator for each of your units, then add a combine validator and add each item validator to the combine. Set the Type to "And".
- Want to have items with prerequisite items? Simply use the previously discussed validator "unit has inventory item".
If you want to combine items, youll need to use a series of effects and validators for the prerequisite items in order to destroy the old ones and create the new one.
Team Shops
If you want to have a NON NEUTRAL team shop, its pretty simple. You need one simple trigger, and a computer player to act as a host (otherwise things get tricky). First, add a new trigger on map initilization to set alliance one way. Tell Player (shop owner) to treat player (team player) as allied with shared control, vision, and spending. Set alliance one way to tell player (team player) to treat player (shop owner) as ally.
This lets the computer spend your resources to purchase items. The bought items will appear in your units inventory, and will cost you money. However, you wont be able to spend the shop owners money. Pretty cool huh?
Consumables
There has long thought to be a problem with pawning consumable items. This is not the case. People are accustom to setting the pawn fraction to 1 in the pawn ability. However, THIS IS NOT THE CASE WITH CONSUMABLES! In your pawn ability, youll notice it has about 20-30 fields. There is a REASON for this!
About consumables
Typically if your item is consumable, youll have a maximum # of charges. However, when the item is sold, the fraction is based on the MAXIMUM number of charges the consumable can hold. If you have a pawn fraction of 1, and your consumable can have 5 charges and starts with 1 charge when being bought, then when you pawn it youll only get back 1/5th of the amount you bought it for. In order to correct it, we need to utilize the excluded and required fields in the pawn ability
Pawn 01
- Set the refund fraction to 1 for all fields. This allows your typical items to be sold for their normal amount.
- At the bottom, set the classes excluded field to exclude "consumables" (or whatever class your consumable items use)
Pawn 02
- Set the Refund fraction to the MAXIMUM # of charges you item can use. In my case, My items start with 1 charge, and have a max stack count of 255. So here I set my refund fraction to 255.
- At the bottom, set class required to "consumables" (or whatever class your consumables is)
Using this method, youd get a full refund for every charge. In this case, if your item cost 25 minerals, youd get 25 minerals per charge back.
Using this method, you can have items with different classes and different stack counts, and control how items are refunded.
Quick Addition: Looking to customize how your inventory looks? How about keeping your inventory containers permanently open or adding an empty face icon to the container slots (ex. weapon/ammo specific slots with a background image). IT CAN BE DONE! See here: http://www.sc2mapster.com/forums/development/gui/40021-9-slot-inventory-always-open/#p11
Shops & Items: New methods, Item Validation, Team Shops & More
Introduction
[A quick note: Using this method prevents the "inventory manipulation - unit BUYS item" event from working. However, you can still use unit gains/loses item. ]
Shops have been discussed a lot in the SC2 Comunity. Typically they use a train order command to purchase items. This tutorial isnt going to cover making an item or a shop. That has already been extensivly discussed in other topics. Instead, what we're going to be focusing on is new methods to use for item buying, selling, and using validators to control what's allowed or not when purchasing our items (ex. Limit 1 item type in inventory, Selling items with multiple charges, combining items, etc)
I'm going to assume you already have created some items and a shop and just need help limiting how a player can buy them. Lets start from there.
First, the Ability
Ignore what people have told you about the train ability. We do NOT want to train an item. We want to CREATE it. So, lets get started.
Create a new ability, type: Effect - Instant. Set the cost to what you want your item to cost. Leave the effect field blank for now. we'll get back to it. (You can check the Stats: Flags: Transient if you want units to purchase while moving, but I dont recommend it) Lets name this ability "Purchase Rareity Item".
Now lets go to effects.
Create a new effect, type issue order. Name it "Purchase Item - Add to inventory". Set the "Ability:" field to your hero's inventory ability, and the Ability command to 2. This will order our unit to pick up the item when its created. Set Effect: Unit to caster, Effect: Player to caster, and Effect: Target to Target Unit.
Create a new effect, type create unit. Lets name it "Create Rare item". Set the "Unit" field to the item you want to create. Set Effect: Spawn to the effect we just created, purchase item - add to inventory. Set Effect: Select Unit to "Caster", and the effect in that field to "purchase item - add item to inventory". Uncheck the "placement" and "offset by radius" flags. We dont want our created unit to have a footprint, nor do we want it to collide with the unit thats creating the item. Set the spawn owner to caster, and target location to caster unit. For good measure set the spawn range to 0, and the offset to (0,0).
Validator
Now go over to our validators tab. Create a new validator, type "unit inventory contains item". Name it "Has Rare Item". Set the "Item" field to our item. Set Validator: Find to disabled (Enabled means its in our inventory, disabled means its not). Set the Validator unit to caster.
Go back to the create unit effect and add our new validator to its Effect: validation field.
Goto our ability and add our create unit effect.
Now goto your shop, add the ability to your unit's Abilities, then set up a command card button for it and you're done. You can now purchase your unit, and it will only let you buy one of that kind of item.
Additional validators
- If you want your shop's items to always be visible, but only purchasable within a certain radius, add a "Location Range" validator to your create unit (item) effect and set the shop's interact ability range to 500. For the Range validator, youll want to set the target location to "target" and leave the location value at caster.
- If your item is part of a group of unique units (example, you have several weapon items, but a hero can only have 1 weapon at any time), use a Combine validator. First, add a normal compare inventory unit validator for each of your units, then add a combine validator and add each item validator to the combine. Set the Type to "And".
- Want to have items with prerequisite items? Simply use the previously discussed validator "unit has inventory item".
If you want to combine items, youll need to use a series of effects and validators for the prerequisite items in order to destroy the old ones and create the new one.
Team Shops
If you want to have a NON NEUTRAL team shop, its pretty simple. You need one simple trigger, and a computer player to act as a host (otherwise things get tricky). First, add a new trigger on map initilization to set alliance one way. Tell Player (shop owner) to treat player (team player) as allied with shared control, vision, and spending. Set alliance one way to tell player (team player) to treat player (shop owner) as ally.
This lets the computer spend your resources to purchase items. The bought items will appear in your units inventory, and will cost you money. However, you wont be able to spend the shop owners money. Pretty cool huh?
Consumables
There has long thought to be a problem with pawning consumable items. This is not the case. People are accustom to setting the pawn fraction to 1 in the pawn ability. However, THIS IS NOT THE CASE WITH CONSUMABLES! In your pawn ability, youll notice it has about 20-30 fields. There is a REASON for this!
About consumables
Typically if your item is consumable, youll have a maximum # of charges. However, when the item is sold, the fraction is based on the MAXIMUM number of charges the consumable can hold. If you have a pawn fraction of 1, and your consumable can have 5 charges and starts with 1 charge when being bought, then when you pawn it youll only get back 1/5th of the amount you bought it for. In order to correct it, we need to utilize the excluded and required fields in the pawn ability
Pawn 01
- Set the refund fraction to 1 for all fields. This allows your typical items to be sold for their normal amount. - At the bottom, set the classes excluded field to exclude "consumables" (or whatever class your consumable items use)
Pawn 02
- Set the Refund fraction to the MAXIMUM # of charges you item can use. In my case, My items start with 1 charge, and have a max stack count of 255. So here I set my refund fraction to 255. - At the bottom, set class required to "consumables" (or whatever class your consumables is) Using this method, youd get a full refund for every charge. In this case, if your item cost 25 minerals, youd get 25 minerals per charge back.
Using this method, you can have items with different classes and different stack counts, and control how items are refunded.