ID:148084
 
Ok well I can make a shop that sells things but currently I do not know how to make it buy things, can someone please help me? This is my code so far:

// The following Click() proc is the shop. When buying items,
// The proc converts the entire cost of the item to Copper,
// and all of the users money into Copper, subtracts the cost
// and removes all money from the user. Then it gives back
// the left over amount and gives the item to the user.
Click()
var/list/menu = new()
for (var/I = 1; I < 20; I++)
if (Item_Name[I] != null)
menu += "[Item_Name[I]] - [Item_CostGold[I]] Gold, [Item_CostSilver[I]] Silver, [Item_CostCopper[I]] Copper"
menu += "Cancel"
var/Choice = alert("What do you want to do?", "Shop", "Buy", "Sell", "Item Info")
switch(Choice)
if ("Item Info")
var/Result = input("What item do you want info on?", "Item Info", null) in menu
for (var/I = 1; I < 20; I++)
if (Result == "[Item_Name[I]] - [Item_CostGold[I]] Gold, [Item_CostSilver[I]] Silver, [Item_CostCopper[I]] Copper")
usr.DisplayItemInfo(Item_Name[I])

if ("Sell")
var/Result = input("What do you want to sell?", "Sell Item",null) in menu
if (Result == "Cancel")
return

if ("Buy")
var/Result = input("What do you want to buy?", "Buy Item", null) in menu
if (Result == "Cancel")
return
// Run a check on all the possible results
for (var/I = 1; I < 20; I++)
// We found one that matches, so buy the item.
if (Result == "[Item_Name[I]] - [Item_CostGold[I]] Gold, [Item_CostSilver[I]] Silver, [Item_CostCopper[I]] Copper")

// This converts the item cost into Copper
var/FinalCost = 0
FinalCost += Item_CostGold[I] * 100
FinalCost += Item_CostSilver[I] * 10
FinalCost += Item_CostCopper[I]

// This converts the player's money into Copper
var/PlayerMoney = 0
var/obj/Money/Gold/G1
var/obj/Money/Silver/S1
var/obj/Money/Copper/C1
for (G1 in usr)
PlayerMoney += G1.Amount * 100
for (S1 in usr)
PlayerMoney += S1.Amount * 10
for (C1 in usr)
PlayerMoney += C1.Amount

// Check if the player has enough money
if (FinalCost > PlayerMoney)
usr << "You require more money to buy \an [Item_Name[I]]."
return

// Remove all the players money for the time being
for (var/obj/Money/M in usr)
del (M)
// Subtract the cost of the item
PlayerMoney -= FinalCost

// This gives all the left over money back
while(PlayerMoney > 99)
PlayerMoney -= 100
var/obj/Money/Gold/G
var/Has_Type = 0
for (G in usr)
G.Amount += 1
G.suffix = "([G.Amount])"
Has_Type = 1
if (!Has_Type)
new /obj/Money/Gold(usr)
while(PlayerMoney > 9)
PlayerMoney -= 10
var/obj/Money/Silver/S
var/Has_Type = 0
for (S in usr)
S.Amount += 1
if (S.Amount < 10)
S.suffix = "([S.Amount])"
else
var/obj/Money/Gold/G
var/obj/Has_Type2 = 0
for (G in usr)
G.Amount += 1
G.suffix = "([G.Amount])"
Has_Type2 = 1
if (!Has_Type2)
new /obj/Money/Gold(usr)
Has_Type = 1
if (!Has_Type)
new /obj/Money/Silver(usr)
while(PlayerMoney > 0)
PlayerMoney -= 1
var/obj/Money/Copper/C
var/Has_Type = 0
for (C in usr)
C.Amount += 1
if (C.Amount < 10)
C.suffix = "([C.Amount])"
else
var/obj/Money/Silver/S
var/Has_Type2 = 0
for (S in usr)
S.Amount += 1
if (S.Amount < 10)
S.suffix = "([S.Amount])"
else
var/obj/Money/Gold/G
var/Has_Type3 = 0
for (G in usr)
G.Amount += 1
G.suffix = "([G.Amount])"
Has_Type3 = 1
if (!Has_Type3)
new /obj/Money/Gold(usr)
Has_Type2 = 1
if (!Has_Type2)
new /obj/Money/Silver(usr)
Has_Type = 1
if (!Has_Type)
new /obj/Money/Copper(usr)

// Gives the item to the player and informs him
// of it.
var/obj/O = Item_Data[I]
new O (usr)
usr << "You bought \an [Item_Name[I]]."</10></20></20></20>
Well, if I understand you right, you want a shop to buy things from the player?

That's fairly simple. Display a list of all the objects in a user contents + "Cancel". If cancel, do nothing.
Otherwise, remove the item from the players inventory, and add it to the shop's inventory. (I suggest that each item have a price value. Shop sells at this value, and buys at value*0.75 (Or whatever.))
In response to Nova2000
Ty very much that helped me greatly :).