ID:180658
 
im trying to make a butcher in my game where you can sell the corpses from the dead animals but i dont know how to get only the corpses which are defined as obj/item/corpse to show up in a list to sell.can anyone help me?
On 4/15/01 3:31 am Haroki wrote:
im trying to make a butcher in my game where you can sell the corpses from the dead animals but i dont know how to get only the corpses which are defined as obj/item/corpse to show up in a list to sell.can anyone help me?

mob/butcher/verb/sell()
set src in oview(usr)
var/L[0]
for(var/obj/item/corpse/X in usr)
L += X
if(!L.len) //if the player doesn't have anything
src.say("Sorry, you don't have anything I'd like.")
return
var/choice = input("What would you like to sell?") in L+"-- Cancel --"

if(choice == "-- Cancel --")
return

//otherwise do selling stuff here

That's basically it. For anything you need to do like that, just make a list, add all possible items to that list, and then ask for a choice (including a cancel option so if people can change their mind, too).

You can adapt it for other shopkeepers, too. For example, an armourer would only have to have var/obj/item/corpse/X changed to your general firearm class (which is why I suggested that you subclass all guns). And the sell code beneath that can operate however you like, because I don't want to go through that part. =)

In response to Spuzzum
this is the selling part of the code that i made but it doesnt recognise the items im trying to sell so there is no money added.Any ideas?

mob/butcher
icon = 'hmerchant.dmi'
verb/sell()
set src in oview(usr)
var/L[0]
for(var/obj/item/corpse/X in usr)
L += X
if(!L.len) //if the player doesn't have anything
src.say("Sorry, you don't have anything I'd like.")
return
var/selling = input("What would you like to sell?") in L+"-- Cancel --"
if(selling == /obj/item/corpse/sheep)
usr.gold += 100
del(src)
if(selling == /obj/item/corpse/wolf)
usr.gold += 10
del(src)
if(selling == "-- Cancel --")
return

obj/item/corpse/sheep
name = "dead sheep"

obj/item/corpse/wolf
name = "dead wolf"


In response to Haroki
On 4/16/01 3:25 pm Haroki wrote:
this is the selling part of the code that i made but it doesnt recognise the items im trying to sell so there is no money added.Any ideas?

mob/butcher
icon = 'hmerchant.dmi'
verb/sell()
set src in oview(usr)
var/L[0]
for(var/obj/item/corpse/X in usr)
L += X
if(!L.len) //if the player doesn't have anything
src.say("Sorry, you don't have anything I'd like.")
return
var/selling = input("What would you like to sell?") in L+"-- Cancel --"
if(selling == /obj/item/corpse/sheep)
usr.gold += 100
del(src)
if(selling == /obj/item/corpse/wolf)
usr.gold += 10
del(src)
if(selling == "-- Cancel --")
return

obj/item/corpse/sheep
name = "dead sheep"

obj/item/corpse/wolf
name = "dead wolf"

The item to be sold is not /obj/item/corpse/sheep, it is an object of type /obj/item/corpse/sheep. The big difference:

new /obj/item/corpse/sheep - object of that type
/obj/item/corpse/sheep - that type

Instead of

if(selling == /obj/item/corpse/sheep)

you need

if(istype(selling,/obj/item/corpse/sheep))


And the cancel option is incorrectly indented. Thought I might point that out, too.

[edited] Oh, and you should del(selling), not del(src). You don't want the butcher to disappear every time something is sold!