ID:137837
 
I've been trying to work out how to make shops. I've gotten buying working perfectly (thanks to Seto-Strife's demo) but I don't have a clue how to go about making a Sell verb. Don't get me wrong, I can understand the buy demo, but I just don't have aclue where to start when it comes to selling. Also, I tried to seach for sselling references in the forums, but couldn't find anything of use. Cheers.
On 7/7/01 9:26 am Botman wrote:
I've been trying to work out how to make shops. I've gotten buying working perfectly (thanks to Seto-Strife's demo) but I don't have a clue how to go about making a Sell verb. Don't get me wrong, I can understand the buy demo, but I just don't have aclue where to start when it comes to selling. Also, I tried to seach for sselling references in the forums, but couldn't find anything of use. Cheers.

Well, your average sell verb would need to be set up such that it would identify the buyer (that's the store you're selling to), the seller, and the object to sell. Presumably you'd want the syntax to sell a sword to a weapons shop to be "sell sword". So first off, you've got to figure out how you're going to identify all these things. The player who's using the sell verb is going to be the verb's "usr" variable, so we don't need to worry about identifying him. Since presumably you've got more than one type of object that can be sold, you want players to be able to specify objects, so the object is probably going to be specified as an argument on the verb. That's 2 out of 3--now you've got to figure out how to make the verb identify the merchant you're selling to. The quick way would be to make your sell verb belong to your merchant mob instead of your player mob. Since it's the merchant's verb, he'd be the "src" variable. But if it's the merchant's verb, players won't be able to use it! So, now would be a good time to look up "src setting (verb)" in the reference. It explains how you make a verb belong to an object but still let players use it under certain conditions. Your condition would probably be being inside a store, or even more specifically, next to a merchant. If you've got a traditional RPG, your merchants live their entire lives behind a countertop, so players can't get immediately adjacent. You'd better make it accessible from 2 or 3 spaces away. Besides which, it's just plain more convenient that way.

So, putting it all together, an example (note that this will almost definitely give you errors if you copy and paste it):


/mob
 player    //This is just included for completeness


 merchant
   verb
    sell(obj/saleitem as obj in usr.contents) //Players must specify an object in their inventory to use the verb
     set src = view(2); //Players must be within 2 squares and able to see the merchant in order to sell to him
     saleitem.loc = src; //Moves the specified item to the merchant's inventory
     usr.money += saleitem.value; //Neither "money" nor "value" has been defined in this sample code, but you get the idea.
     usr << "Here are [saleitem.value] coins for your [saleitem]. Now git outta my store, ye knave!" //Customer service is down lately

In response to Leftley
Mmmmmm... knowledgeable help :)

Thanks (the non-sarcastic type). Now I'm off to spend a few hours to work this out. Nah I'm just kidding... I'd never get it done that fast. But thanks. I think I know what to do now. :)
In response to Botman
Wow, I got it working already. HUGE thanks!