ID:148323
 
Ok I have the following code that allows players to sell items to npcs. But as it is right now it list everything in their contents.

var/obj/s=input("What do you have to sell?") as obj in usr.contents

What I would like to know is how to I take this piece of code and make it to where it just shows certain types of objs like

obj/armor
obj/items
obj/weapons
LordJR wrote:
Ok I have the following code that allows players to sell items to npcs. But as it is right now it list everything in their contents.

var/obj/s=input("What do you have to sell?") as obj in usr.contents

What I would like to know is how to I take this piece of code and make it to where it just shows certain types of objs like

obj/armor
obj/items
obj/weapons

What you have to do is create a list and manually add items to it. The "as" clause won't be able to limit items to anything more specific than objs.

I also suggest you use "as null|anything" once you've made this change. That allows the player to hit Cancel, and then s will be null.

Lummox JR
In response to Lummox JR
Ah a bit more than what I was hoping for.. I think for now I'll just stick with listing everything.

On the Cancel button I've also seen after the "usr.contents + Cancel" being used.. will this work as well???

LJR

Lummox JR wrote:
I also suggest you use "as null|anything" once you've made this change. That allows the player to hit Cancel, and then s will be null.

Lummox JR
In response to LordJR
LordJR wrote:
Ah a bit more than what I was hoping for.. I think for now I'll just stick with listing everything.

Its pretty simple really. All you need to do is create a proc that sorts through a list and extracts a certain type, like this:

<code>proc/ListType(type, where) var/list/list = list() for(var/obj/O in where) if(istype(O, type)) list += O return list</code>

Then you can use that in connection with your regular input:

<code>var/obj/S = input() as null|anything in ListType(/obj/weapon, usr.contents)</code>


On the Cancel button I've also seen after the "usr.contents + Cancel" being used.. will this work as well???

That works, since it basically has the same effect as having null, only it returns "Cancel" when nothing is selected instead of null. But since it adds it to the bottom of the list, it can be a pain to get to the cancel button if the list is long. Besides, its tacky, and usually used by people who don't realize they can use null|anything. :)
In response to Foomer
Wow thanks alot Foomer.. quick, small, efficent!

I'm kinda simple minded at the moment getting back into BYOND coding. I've added this to my code and will compile it later when I get home. I can also see many other possibilites for this proc to come in handy down the line. Thanks!

LJR