ID:267080
 
mob/electshopkeeper
icon='shopkeepers.dmi'
verb/Buy()
set src in oview(1)
if(usr.wanted==0)
var/totalprice
for(var/obj/eitemsdmi/O in usr.scart)
totalprice+=O.price
usr<<"That will be [totalprice] dollars"
if(usr.cash>=totalprice)
usr.cash-=totalprice
for(var/obj/eitemsdmi/O in usr.scart)
if(O.parent_type==/obj/eitemsdmi/cd)
new/obj/eitemsdmi/cd(usr)
if(O.parent_type==/obj/eitemsdmi/cdplayer)
new/obj/eitemsdmi/cd(usr)
if(O.parent_type==/obj/eitemsdmi/scouter)
new/obj/eitemsdmi/cd(usr)
else
usr<<"You do not have enough money"
switch(input("What will you do?","Do?")in list("Put back Items","Run"))
if("Put back Items")
for(var/obj/eitemsdmi/O in usr.scart)
del(O)
if("Run")
world<<"[usr] has just robbed the electronic store 300 Zeni reward!"
usr.wanted=1
bounty=300
usr.overlays+='wanted.dmi'
else
usr<<"GET OUT OF MY STORE!!!"
usr<<"The shopkeeper takes out a shotgun"
usr.hp-=rand(1,5)


Here is my code. Is there an easier way to transfer something from a list as in scart to the users contents easier then what I have up there in the area around


for(var/obj/eitemsdmi/O in usr.scart)
if(O.parent_type==/obj/eitemsdmi/cd)
new/obj/eitemsdmi/cd(usr)
if(O.parent_type==/obj/eitemsdmi/cdplayer)
new/obj/eitemsdmi/cd(usr)
if(O.parent_type==/obj/eitemsdmi/scouter)
new/obj/eitemsdmi/cd(usr)?
for(var/obj/eitemsdmi/O in usr.scart)
O.Move(usr)
In response to Xooxer
I'm so stupid...I can't believe that I didn't notice it.
DBZ Kidd wrote:
Here is my code. Is there an easier way to transfer something from a list as in scart to the users contents easier then what I have up there in the area around


for(var/obj/eitemsdmi/O in usr.scart)
if(O.parent_type==/obj/eitemsdmi/cd)
new/obj/eitemsdmi/cd(usr)
if(O.parent_type==/obj/eitemsdmi/cdplayer)
new/obj/eitemsdmi/cd(usr)
if(O.parent_type==/obj/eitemsdmi/scouter)
new/obj/eitemsdmi/cd(usr)?

Question here: Did you intend for later players to be able to buy merchandise?

If you want to be able to buy the same thing later in infinite supply, Xooxer's suggestion to use Move() won't work out for you; you will in fact need to create new items as above.

However, there are a few problems in the code as it stands:

  • parent_type is not the correct var to use; type is.
  • All the items you create are type /obj/eitemsdmi/cd; I don't think this is intentional.

    You don't need to use all those if() statements, however; all that's redundant. Instead try this:
for(var/obj/eitemsdmi/O in usr.scart)
new O.type(usr)
The trick is, you should verify before this loop that the usr can afford the prices of these items. You could do that check during the loop, but that's not really a great idea for interface purposes because a player could accidentally buy too many of the first item(s) and miss out on the last things on the list.

Lummox JR
In response to DBZ Kidd
After reading LummoxJR's reply, I'll ditto that! :)

~X