ID:142785
 
Code:
mob
icon = 'yourchar.dmi'
shopkeeper
Shopkeeper2
description = "Welcome to Rob's Armory!"
name = "Rob"
icon_state = "shopkeeper"

inventory1 = list(new /obj/weapons/Axe,new /obj/weapons/Axe,new /obj/weapons/Axe,new /obj/weapons/Axe)
inventory2 = list(new /obj/weapons/Axe,new /obj/weapons/Axe,new /obj/weapons/Axe,new /obj/weapons/Axe)
inventory3= list(new /obj/weapons/Axe,new /obj/weapons/Axe)
verb
Buy()
set src in oview(2)
usr.shopkeeper = src
Shopkeeper2(usr)
Sell(var/obj/Item in usr.contents)
set src in oview(2)
if(Item.suffix == "Equipped")
usr << "Un-equip [Item] first!"
return
switch(input("Would you really like to sell this item?")in list ("Yes","No"))
if("Yes")
src.contents+=Item
var/give = round(Item.price / 1.5)
usr.gold += give
usr << "You sell the [Item]."
return
else
return
/*
In the New() is the shopkeepers inventory list.
You can code new items and add them here and it will display them
One of my favorite parts about this.
*/


New()
src.contents += list(new /obj/weapons/Axe,new /obj/weapons/Dagger)

New()
src.restock()
proc
Shopkeeper2()
for(var/mob/I in oview(2))
statpanel("Shop")
stat("[I.description]")
stat(I.contents)


Problem description:
Well i am trying to make it so when using verb buy... you get the statpanel with the shopkeepers inventory, if you need the entire code please reply saying so.

client
//an atom whose Stat() proc will also be called
var/atom/watching

Stat()
//call our default Stat() proc
..()
//if we're watching something, call its Stat() proc too
if(watching)
watching.Stat()

mob/shopkeeper
Stat()
//if we're out of range
if(get_dist(src,usr) > 2)
//close the statpanel
usr.client.watching = null
else
//display our contents on the "Shopkeeper" tab
statpanel("Shopkeeper",contents)
verb
Buy()
set src in oview(2)
//set the usr's client to watch us
usr.client.watching = src
//switch their statpanel to the "Shopkeeper" tab
usr.client.statpanel = "Shopkeeper"
//(not 100% neccessary, try commenting it out)


That's the basic way of doing this.
In response to Garthor
OMG GARTHOR TYSM!!!!! I have been working on this FOREVER. Much thanks, sincerely NateGrant
In response to Nategrant
Ok now onto the next problem
obj
var
description
bought
Click()
if(src.bought == 1)
return
else
usr << "[src.description]"
usr << "Double click to purchase!"
DblClick()
if(bought == 1)
return
else
if(usr.gold >= src.price)
usr << "Enjoy your new item!"
usr.gold -= src.price
src.Move(usr)
src.bought = 1
else
usr << "You do not have that much gold!"







mob
icon = 'yourchar.dmi'
shopkeeper
Shopkeeper2
var
mob/shopkeeper/shopkeeper
description
inventory1
inventory2
inventory3
isshopping = 0
proc
restock()
for(var/A in pick(src.inventory1,src.inventory2,src.inventory3))
src.contents += A
sleep(pick(500,900,1000)) // so he restocks periodically
src.restock()
description = "Welcome to Rob's Armory!"
name = "Rob"
icon_state = "shopkeeper"

inventory1 = list(new /obj/weapons/Axe,new /obj/weapons/Axe,new /obj/weapons/Axe,new /obj/weapons/Axe)
inventory2 = list(new /obj/weapons/Axe,new /obj/weapons/Axe,new /obj/weapons/Axe,new /obj/weapons/Axe)
inventory3= list(new /obj/weapons/Flail,new /obj/weapons/Dagger)

Stat()
//if we're out of range
if(get_dist(src,usr) > 2)
//close the statpanel
usr.client.watching = null
else
//display our contents on the "Shopkeeper" tab
statpanel("Shopkeeper")
stat(description)
stat(contents)
verb
Buy()
set src in oview(2)
//set the usr's client to watch us
usr.client.watching = src
//switch their statpanel to the "Shopkeeper" tab
usr.client.statpanel = "Shopkeeper"
//(not 100% neccessary, try commenting it out)
Shopkeeper2(usr)
Sell(var/obj/Item in usr.contents)
set src in oview(2)
if(Item.suffix == "Equipped")
usr << "Un-equip [Item] first!"
return
switch(input("Would you really like to sell this item?")in list ("Yes","No"))
if("Yes")
src.contents+=Item
var/give = round(Item.price / 1.5)
usr.gold += give
usr << "You sell the [Item]."
return
else
return
/*
In the New() is the shopkeepers inventory list.
You can code new items and add them here and it will display them
One of my favorite parts about this.
*/

proc
Shopkeeper2()
New()
src.contents += list(new /obj/weapons/Axe,new /obj/weapons/Dagger)

New()
src.restock()

Ok I have no idea but I would like it so when you click something in HIS inventory you can buy, right now you can buy your own inventory things and his which is a problem.
In response to Nategrant
This is how i did it in another game
obj/Click()
if(!(src in usr.contents))
switch(alert("Would you like to buy this [src] for [price] money!","Buy","Yes","No"))
if("No")return
var/obj/s=new src.type
usr.contents+=s
s.suffix=null
usr.client.statpanel="Inventory"
In response to Tubutas
Whoever started doing alert()s like that needs to be punched in the face for such a bad idea. Do this instead:
if(alert("Would you like to buy this [src] for [price] money!", "Buy", "Yes", "No") != "No")
//Blah
In response to Popisfizzy
=p this was a while ago cut me some slack.
In response to Tubutas
Thank you, took me a bit to overlook and understand but i finally got it :P ...

Again Thanks!
In response to Tubutas
Note that this will let you buy ANYTHING that you aren't holding. What you might want to do instead is check the second argument to Click(), location. This will be equal to "Shopkeeper" if you're clicking on an obj on the Shopkeeper statpanel.

Or you could check the type of the obj's location, which would be a shopkeeper if you can buy it.
In response to Garthor
I am the other GM for this game and I am good at setting loc, not good at checking for loc. I can't remember how to do this, could you give me a lesson or two?
In response to Garthor
Okay.... Execpt why else would you be looking at someones elses contents.
In response to Tubutas
You are spending 99% of your time looking at something else's contents. You know. Turfs.
In response to Garthor
Turfs contents is whatever happens to be in the same space they are. Mobs aren't the only things that can have contents which brings me to this... can an obj be coded to have contents? That could be useful in some cases. Like when an obj is a bag or small chest.
In response to Nategrant
Yes. Objects can hold other objects. They have a contents section, just like your character does. In the game I am making I have different powers (obj) containing abilities(obj) that I can use. All you have to do is search your contents for the container you want then you can search it's contents.

Here's a BASIC example:

var/obj
>> bag
>> >> //This is the bag that we're using
>> >> //we are also assuming that we have already
>> >> //added the bag to usr.contents
>> key
>> >> //This is our key


In our program we are seeing if we have this key in our bag.

To add an obj to an obj:

for(var/obj/KEY in oview(1,usr)
>> if(KEY && "[KEY]"=="key")//If there's a key in front of us
>> >> for(var/obj/BAG in usr.contents)
>> >> >> if(BAG && "[BAG]"=="bag")//Check that we do have the bag and it is the right bag
>> >> >> >> if(length(BAG.contents)=0)//the bag is empty
>> >> >> >> >> var/AddKey = text2path("/obj/[KEY]")//Adding the key this way is not necessary but I
>> >> >> >> >> >> BAG.contents += new AddKey//did it for debugging reasons as well as ability to use for multiple items


Now to search the bag for our key.

(for(var/obj/BAG in usr.contents)
>> if(BAG && "[BAG]"=="bag")//Check that we do have the bag and it is the right bag
>> >> for(var/obj/KEY in BAG.contents)//If it's the right bag, look for the key in the bag.
>> >> >> if(KEY && "[KEY]"=="key")//Do we have the key and is it the right key
>> >> >> >> usr<<"You have the key."


Like I said, that is a BASIC example but it shows you how to search for an obj in an obj.
In response to Jholder84
That would be some raw code that don't think we will be using since we don't use code we don't understand. We, meaning Nategrant and I. Fair enough? Thanks for lesson anyway though.
In response to Garthor
I know this thread is getting kind of old but one last problem about the contents off turfs.... you can buy anything thats on the ground that is an object I want it so you can buy only the shopkeeper's items but not anything else... I also have like no idea how to do this.

    if(!(src in usr.contents))

has to do with this, i know entirely this makes it so only if not in usr's contents but I want it so it can only work in the shopkeepers contents... so something like this


    if(src in /mob/shopkeeper/Shopkeeper2.contents)

but of course that dosn't work :P
In response to Nategrant
You'd want to use istype() to make sure src.loc is of the correct type (/mob/shopkeeper).
In response to Garthor
istype is kinda new to me... how would I use that?
    var/mob/shopkeeper/M
M = new/mob/shopkeeper/Shopkeeper2()
if(istype(M))
if(src in M.contents)

would I do something like this? I really don't know. If it is suppose to be this, it doesn't work.
In response to Nategrant
No. It's just this:

if(istype(loc, /mob/shopkeeper))
//we're in a shopkeeper
In response to Garthor
then how would i do this line?
        if(src in /mob/shopkeeper.contents)//???

could you just do the double click for me because I am getting vary confused.. I promise I would read over and try and learn how to do lol.
Page: 1 2