ID:161496
 
How would i make a sell verb??
so far, i have this;
obj
var/value
stone
icon = 'rocks.dmi'
icon_state ="stone"
value = 1
verb
Get()
set src in oview(1)
src.loc = usr
usr<<"You picked up a [src]"
ruby
icon = 'rocks.dmi'
icon_state = "ruby"
value = 50
verb
Get()
set src in oview(1)
src.loc = usr
usr<<"You picked up a [src]"
diamond
icon = 'rocks.dmi'
icon_state = "diamond"
value = 100
verb
Get()
set src in oview(1)
src.loc = usr
usr<<"You picked up a [src]"
emerald
icon = 'rocks.dmi'
icon_state = "emerald"
value = 75
verb
Get()
set src in oview(1)
src.loc = usr
usr<<"You picked up a [src]"
mob
var/money=0
mob
Stat()
statpanel("Player Status")
stat("$$$:",src.money)
stat("inventory:")
stat(src.contents)
mob
Shopman
icon = 'shop.dmi'
verb
sell()
switch(input("What do you want to sell?",text) in list ("Stone","Ruby","Emerald","Diamond","Nothing"))
if("Stone")
usr.money+=1
if("Ruby")
usr.money+=50
if("Emerald")
usr.money+=75
if("Diamond")
usr.money+=100


but, how do i make an if() statment to see if they have the rock @ all, also, i defined value, but cant figure out that either >_<
lol
thx for help u guys
switch(input("What do you want to sell?",text) in list ("Stone","Ruby","Emerald","Diamond","Nothing"))

I would make it:
var/sellitem=input("What do you want to sell?") in usr.contents 
usr.gold+=sellitem.value
del(sellitem)

Not sure about to rest so I'm not going to lead you in the wrong direction.
> obj
> var/value
> verb
> Get()
> set src in oview(1)
> src.loc = usr
> usr<<"You picked up a [src]"
> usr.stonelist += src
> icon = 'rocks.dmi'
> stone
> icon_state ="stone"
> value = 1
> ruby
> icon_state = "ruby"
> value = 50
> diamond
> icon_state = "diamond"
> value = 100
> verb
> emerald
> icon_state = "emerald"
> value = 75
> mob
> var/money=0
> mob
> Stat()
> statpanel("Player Status")
> stat("$$$:",src.money)
> stat("inventory:")
> stat(src.contents)
> mob
> var/list/stonelist = list()
> Shopman
> icon = 'shop.dmi'
> verb
> sell()
> var/K = input("What would you like to sell","",stonelist)
> usr.money += K.value
> usr.stonelist -= K
>

Grah, something like that. You should get the idea.I also cleaned some of the code up, if you don't understand something i'll explain it better if you want.Probably a few mistakes though.
In response to Giantpanda
The stonelist is a bad idea. And when you're picking up, your instantly adding it to stonelist without even checking if it's in fact a stone.
Don't make it hardcoded. You've made a value var for each sellable, that's a start, but you're not even using that value?
Create any variables needed to make a 'shopkeeper system' dynamically, which would be infinitely better. A value for each sellable item is one (though a note, you should really not define this stuff under the "root" /obj, make a subtype for (sellable) items like obj/item and put everything under there) and a list of what a shopkeeper has for sale (which you'd change between shopkeeper instances to change their wares), you could do with using the contents list for that one if you want. You can set the contents list at compile time to a list of new object types.
Then define general Buy() and Sell() verbs under a main shopkeeper subtype (eg mob/shopkeeper and you could use subtypes for different shopkeeprs, like mob/shopkeeper/Bob and mob/shopkeeper/Mary), you could probably do with making shopkeepers actual /objs actually. At any case, don't use pre-defined numbers or checks (switch() etc) there. It should look something like:
obj/shopkeeper
var/list/sellables
verb/Buy()
set src in oview(1)
var/obj/item/O = input("Buy what?") in src.sellables
if(usr.money < O.price) //if he has enough money to pay the item's price
usr << "You don't have enough cash!"
return //stop the verb
usr.money -= O.price //the player pays the price!
//what you do now depends on how you want to implement this. you should probably also use the Move() proc to locate the item in the player as well!
new O.type(usr) //create a new item of the chosen type in the player

^Ideally, you'd use type paths in a custom list instead. Using type paths is in principle the same, but requires some adjustments of course. It is easier to understand like this first, so this is the code I posted (also to leave more work to you :P) Also perhaps you'd want to limit how much item the shopkeeper sells and maybe he can run out and restock later, etc.
Another thing you may or may not want in the Sell() verb is to put the sold object in the shopkeeper's list so he actually puts it for sale, and you may want to give shopkeepers their own money variable to limit how much they can buy etc.
RanEsu wrote:
How would i make a sell verb??
so far, i have this;
> obj
> var/value
> stone
> icon = 'rocks.dmi'
> icon_state ="stone"
> value = 1
> verb
> Get()
> set src in oview(1)
> src.loc = usr
> usr<<"You picked up a [src]"
> ruby
> icon = 'rocks.dmi'
> icon_state = "ruby"
> value = 50
> verb
> Get()
> set src in oview(1)
> src.loc = usr
> usr<<"You picked up a [src]"
> diamond
> icon = 'rocks.dmi'
> icon_state = "diamond"
> value = 100
> verb
> Get()
> set src in oview(1)
> src.loc = usr
> usr<<"You picked up a [src]"
> emerald
> icon = 'rocks.dmi'
> icon_state = "emerald"
> value = 75
> verb
> Get()
> set src in oview(1)
> src.loc = usr
> usr<<"You picked up a [src]"
> mob
> var/money=0
> mob
> Stat()
> statpanel("Player Status")
> stat("$$$:",src.money)
> stat("inventory:")
> stat(src.contents)
> mob
> Shopman
> icon = 'shop.dmi'
> verb
> sell()
> switch(input("What do you want to sell?",text) in list ("Stone","Ruby","Emerald","Diamond","Nothing"))
> if("Stone")
> usr.money+=1
> if("Ruby")
> usr.money+=50
> if("Emerald")
> usr.money+=75
> if("Diamond")
> usr.money+=100
>

but, how do i make an if() statment to see if they have the rock @ all, also, i defined value, but cant figure out that either >_<
lol
thx for help u guys



sorry for no help but..........Shopman XD pwnt name :D

i would hang myself if my parents named me shopman
In response to Kaioken
A sellables list isn't even needed. Just select from the shopkeeper's contents. A simple trick that I like for stocking shopkeepers is to do this:

obj/shopkeeper/New()
..()
for(var/item/I in loc)
I.Move(src)


Then you just place any items that you want a shopkeeper to sell on the turf they're standing on.
In response to Garthor
Garthor wrote:
A sellables list isn't even needed. Just select from the shopkeeper's contents.

If you read my post, you'd have seen I mentioned this anyway. But you can't use the more efficient method of storing type paths instead of actual objects in the list if you use the contents list.

A simple trick that I like for stocking shopkeepers is to do this:

Well, not too robust. At any case you can just set the contents list at compile time and probably in the instance editor on the map too, so that'd be a better "trick".
In response to Kaioken
What are the O.Price and such there for?? if i put them in i get a bit fat error lol
In response to RanEsu
RanEsu wrote:
What are the O.Price and such there for?? if i put them in i get a bit fat error lol

Why did you put "them" in if you don't know what they're for? Don't just copy my code, it was an example. You'd need to implement this into your own game, one apparent obvious difference is that you've got that functionality named as a "value" variable, not "price"... even if you apparently didn't use it anywhere and used hardcoded numbers instead.
Anyway, "they"'re there to... access the object(item, in fact)'s price! So you have it defined dynamically per object and no need to do manual price checking and operating for each item in your game, etc.
In response to Kaioken
Ok, I tried changing the "price" to value, and it diddnt work, im getting errors with the O.Price lines, i know what their SUPPOSED to do, and they dont :( :
test world.dm:199:error:O.price:undefined type: O.price
test world.dm:202:error:O.price:undefined type: O.price
test world.dm:204:error:O.type:undefined type: O.type
test world.dm:198:O :warning: variable defined but not used




also, this isn't an actual game im making, im making a quick refrence to look @ verbs im likly to use in future games

thx ^_^
In response to RanEsu
Should I bother stating again that you weren't supposed to use that code, but to actually study it and the rest of the post so you can make your own system suited for your game, and actually learn as well, rather than fiddling with others' code and trying to get it to work by swapping words? Not to mention if you want others to possibly solve a code problem, they might need to see your code. Of course, again, you shouldn't be using it here either way; it's not even the complete 'system' or what you've asked for originally.
In response to Kaioken
Kaioken wrote:
Garthor wrote:
A sellables list isn't even needed. Just select from the shopkeeper's contents.

If you read my post, you'd have seen I mentioned this anyway. But you can't use the more efficient method of storing type paths instead of actual objects in the list if you use the contents list.

You also can't have a neat little graphical interface without mucking about with instantiating objects all the time. Storing actual objects instead of type paths for the hundred or so things that are sold by shopkeepers isn't going to kill you.

A simple trick that I like for stocking shopkeepers is to do this:

Well, not too robust. At any case you can just set the contents list at compile time and probably in the instance editor on the map too, so that'd be a better "trick".

That sounds like a huge pain in the ass and would be harder to modify things. You'd also need a separate type of shopkeeper for each one on the map that you want to have different items, or you'd need to... I don't know if you can even use the instance editor to modify contents. If you can, then you'd be editing an ugly string of type paths inside a tiny little text box.

Yeah. I'll stick with the GUI.
In response to Garthor
Garthor wrote:
You also can't have a neat little graphical interface without mucking about with instantiating objects all the time. Storing actual objects instead of type paths for the hundred or so things that are sold by shopkeepers isn't going to kill you.

No, creating a new object only whenever a player wants to buy something won't kill you. But if you have a big map with lots of shopkeepers with lots of items, having all of those always initialized is silly. Oh, and unlike my method, it is more likely to "kill" you (well, your game).

That sounds like a huge pain in the ass and would be harder to modify things.

So it can be with your method potentially; also it wouldn't really be any hard. It's probably more convenient to manage actually.

You'd also need a separate type of shopkeeper for each one on the map that you want to have different items, or you'd need to...

It is one method and it depends on your game which one you would prefer to use. If your mobs aren't unique and all have the same name etc, yes, it would be more bother and you should probably use the instance method. But obviously if you're already got unique mobs sticking that into existing subtypes can fit right in.

I don't know if you can even use the instance editor to modify contents.

You can.

If you can, then you'd be editing an ugly string of type paths inside a tiny little text box.

Could you be more relevant? It won't ruin your game and life if you need to endure editing a horrible text box. Chances are, you're already accustomed to such things!

Yeah. I'll stick with the GUI.

Yeah. Surely it's more convenient when you need to add, remove and modify each item in the contents one-by-one with your method and generally being much more hassle (sure, opinions can differ but it will surely take more time) to manage rather than editing one string. But of course, there is more than 1 correct way to do things in programming, use what you want. Just remember to pay attention to what's in the turf you're creating a new shopkeeper on at runtime, etc. :P
In response to Kaioken
Kaioken wrote:
Garthor wrote:
You also can't have a neat little graphical interface without mucking about with instantiating objects all the time. Storing actual objects instead of type paths for the hundred or so things that are sold by shopkeepers isn't going to kill you.

No, creating a new object only whenever a player wants to buy something won't kill you. But if you have a big map with lots of shopkeepers with lots of items, having all of those always initialized is silly. Oh, and unlike my method, it is more likely to "kill" you (well, your game).

BYOND does not operate on likelyhood. A d100 is not rolled for every item in the game to determine effect. It either works, or it doesn't. And no, having an object that any number of players might reference at more or less any time isn't silly. Pissing about with lists of types to achieve some twisted sense of efficiency that amounts to saving yourself a sixth of a percent of your resources is silly. If a simple solution works with negligible drawbacks over a convoluted solution... USE IT.

Oh, and for bonus points: you've used up a list for each of these list of types.

That sounds like a huge pain in the ass and would be harder to modify things.

So it can be with your method potentially; also it wouldn't really be any hard. It's probably more convenient to manage actually.

How? You go into the map editor. You drop anything you want a shopkeeper to sell on the ground below him. If you want to modify anything about them (say, this shopkeeper wants to sell this item for double the price... oh hey, how would you do that with a list of types anyway?) all you have to do is edit that instance of the object. How does this make things harder to modify?

You'd also need a separate type of shopkeeper for each one on the map that you want to have different items, or you'd need to...

It is one method and it depends on your game which one you would prefer to use. If your mobs aren't unique and all have the same name etc, yes, it would be more bother and you should probably use the instance method. But obviously if you're already got unique mobs sticking that into existing subtypes can fit right in.

...It's a goddamn SHOPKEEPER. Change their icon, change their name, and they could fit in anywhere. If you were to look at the "unique" shopkeepers in a game, the differences you'll find will be:

1) Name
2) Icon
3) What they sell

1 and 2 can be changed in the map editor, and I'm presenting a solution to allow you to do the same with 3. You, however, are stuck in some old mentality of EVERYTHING needing to be in the .dm file. Data belongs in data files, not in the executable files.

I don't know if you can even use the instance editor to modify contents.

You can.

And you have the functionality provided by the ever-so-useful newlist() proc. You've used that before, right?

Probably not. It's not very useful.

If you can, then you'd be editing an ugly string of type paths inside a tiny little text box.

Could you be more relevant? It won't ruin your game and life if you need to endure editing a horrible text box. Chances are, you're already accustomed to such things!

Oh, I'm sorry? I'm being off topic? Weren't you arguing just NOW (isn't asynchronous communication great?) about "your" method, "it wouldn't really be any hard. It's probably more convenient to manage actually." Oh, but now when it suits your argument, it's off-topic? Maybe you've just forgotten what you wrote a minute ago?

Now then, if you love text boxes so much, why aren't you using DOS?

Yeah. I'll stick with the GUI.

Yeah. Surely it's more convenient when you need to add, remove and modify each item in the contents one-by-one with your method and generally being much more hassle (sure, opinions can differ but it will surely take more time) to manage rather than editing one string. But of course, there is more than 1 correct way to do things in programming, use what you want. Just remember to pay attention to what's in the turf you're creating a new shopkeeper on at runtime, etc. :P

Excuse me? YOU were the one advocating having to add, remove, and modify each item in an obnoxious list. *I* was advocating PLACING ITEMS ON THE MAP using the MAP EDITOR. This is not an onerous task, and is in fact quite easy to do. You select the item on the left, and then click on the map. Hell, the place you need to click is even pointed out for you: you just need to click on the shopkeeper guy. Isn't that nice?

Yes. There are multiple correct ways to do things. However: my way of doing things is correcter than your way of doing things. As for your silly little criticism, it takes literally one line to prevent that:

if(world.time > 0) return


Your suggestion was bad. Just because you've been around for a while, doesn't mean you are protected from being called out on it. Accept it and move on.