ID:144827
 
1)How do I make a list containing all objects of one type?
var/list/weplist = list(obj/wep/,"Cancel")


2)How do I make a list containing all of the items in the user's inventory?
var/list/selllist = list(usr.contents)//This doesn't work.


3)How do I make it so it creates a new whatever you bought in your inventory without making a bunch of if statments.
    usr.contents += new /obj/wep/

The var for choosing what to buy is defined like this:
    var/obj/B = input("Buy which Weapon?","SHOP")in weplist


This is just a small amount of my code but this is all I need help with.

Much appreciated as always.
-Hellsing4-
1)
var/list/weplist = list(new typesof(/obj/wep),"Cancel"

Use 'typesof' for one type of something.

2)
var/list/sell = list()
for(var/obj/I in usr.contents)
sell += I

Add items to the list using a for() statement then access that list when selling.

3)
usr.content += new B
In response to Pyro_dragons
1.) This wouldn't even compile. You should also never add a "Cancel" option that way. It's better to use null|anything if using an input statement.

#define childtypes(t) typesof(t) - t
proc/NewType( type )
if( childtypes(type))
. = new/list
for( var/i in childtypes(type) )
. += new(i)


2.) This is unecessary. You can just set a list equal to the contents and it'll be good. You can NOT, however, set contents equal to a list.

3.) I'm fairly certain you cannot add a type path to contents. After stating that, you should be able to just remove it from weplist, then add it to your contents. Unless you want to leave it in the shopkeeper, of course, then you should be able to do:

var/obj/B = input(src, "Buy which Weapon?","SHOP")in weplist
src.content += new B.type
Problem Solved

Thanks
-Hellsing4-