ID:139752
 
Code:
mob/NPC/MerchantNPCs//Merchant System in developement
icon='HakumeiGetsu.dmi'
icon_state="NPC"//Just so you know where they are on the map.
verb/Command()
set src in oview(1)
set name="Command"
set hidden=1
var/Count=0
for(var/obj/BuyableThings/A in src.InventorySet)//For all the obj/Buyable things in the source or its Inventory Set.
Count++
A.ObjectNumber=Count
var/obj/C=new
C=A
var/StartingX=2
var/StartingY=15
StartingX+=Count
if(Count>13)
StartingX=3
StartingY-=1
if(Count>26)
StartingX=3
StartingY-=1
if(Count>39)
StartingX=3
StartingY-=1
if(Count>52)//Maximum amount of items a seller can sell.
StartingX=3
StartingY-=1
C.screen_loc="[StartingX],[StartingY]"
usr.client.screen+=C
usr<<"Found something."//Just to make sure the objects are still there?
var
list/InventorySet=list("")//The list of things they're selling you.
//Do not go over 52 objects.
obj/BuyableThings
icon='wskillcards.dmi'
layer=MOB_LAYER+5
var
Price=100//Price you buy it at.
ObjectNumber=1//DO NOT edit this. This is used for designing.
//When the objects come up after shopping it allows them to be tiled next
//to each other.
Cancel
icon_state="Cancel"
Click()
usr<<sound('click1.wav',0)
for(var/obj/BuyableThings/Clothing/A in usr.client.screen)
del(A)
for(var/obj/BuyableThings/Weapons/A in usr.client.screen)
del(A)
for(var/obj/BuyableThings/Scrolls/A in usr.client.screen)
del(A)
del(src)
Clothing//Clothing category
//1500 is the maximum any normal clothing wear will cost in Yen.
Black_Shirt
icon_state="BlackShirt"
Price=200
Click()
usr<<sound('click1.wav',0)
switch(input(usr,"The [src.name] costs [y2k_Uncondense_Num(src.Price)] Ryo. Do you want to buy it?", text) in list ("Yes","No."))
if("Yes")
if(usr.Yen>=src.Price)
usr<<sound('click1.wav',0);usr<<sound('Cash.wav');usr<<"You bought a [src.name]!";usr.Yen-=src.Price
var/blue=0;var/red=0;var/green=0
var/obj/Clothes/Shirt/B=new();B.shirtblue=blue;B.shirtgreen=green;B.shirtred=red;B.loc=usr
usr<<sound('Cash.wav')
return
else
usr<<"Not enough money!";usr<<sound('click2.wav',0)
if("No")
usr<<sound('click2.wav',0)
return


Problem description:
I really don't know how to ask it. The point basically is, I'm making a Merchant based systems thus the items you'd buy would pop up on whoever is purchasing's client.screen as objects. That way you can click them and it'd make it easier to make Merchants without all these large amounts of code.

Now I did get it to work. The problem was that I wasn't too sure about the C=A. Because everytime I canceled, which simply deleted all the objects belonging to /obj/BuyableThings/ whenever I tried to buy again it wouldn't work unless there was another NPC. I think the new created C actually are the objects in A and thus deleting them.

Um, I really don't even know if I'm asking this correctly. Could someone help?
When removing them from your screen, don't delete them, because that's deleting the actual object. Just remove them from the screen using the -= operator.

Additionally, your C=A line is silly. Just get rid of that.
In response to Garthor (#1)
Garthor wrote:
When removing them from your screen, don't delete them, because that's deleting the actual object. Just remove them from the screen using the -= operator.

Additionally, your C=A line is silly. Just get rid of that.

But a merchant should be available for multiple people at a time. The point of that code was to make new objects that were based off of the objects in the merchant's inventory. Right now as it is, the objects in the merchant's inventory is just going straight to the user's client screen. It's not suppose to do it, it's suppose to create an object just like A and put in on the usr.client.screen.

That's why the C=A. But if I get rid of that it won't work because it'll merely make objects. I've tried several variations but I don't know how to make C's type the same as A's type.
In response to Zack101 (#2)
Zack101 wrote:
I've tried several variations but I don't know how to make C's type the same as A's type.

var/obj/C = new A.type()


http://www.byond.com/members/?command=reference&path=proc/ new
In response to Zack101 (#2)
Adding something to a client's screen does not move the object. The object is still in the shopkeepers inventory or whatever. You can have the same object on multiple screens at the same time.
In response to Skyspark (#3)
Skyspark wrote:
Zack101 wrote:
I've tried several variations but I don't know how to make C's type the same as A's type.

> var/obj/C = new A.type()
>


http://www.byond.com/members/?command=reference&path=proc/ new

Thanks I was looking for this.
In response to Garthor (#4)
Garthor wrote:
Adding something to a client's screen does not move the object. The object is still in the shopkeepers inventory or whatever. You can have the same object on multiple screens at the same time.

Ah I understand what you mean now then.