ID:2199512
 
I've been trying to think of a way to do this all day now and I feel like I must be overthinking it so I felt like it was time to ask for help.

I need to find a way to create a new obj in-game without defining the type path of that obj.

Basically the code is coming down to asking the player to input the name of an item in the game, and then creating a copy of that item for them. The items having multiple obj paths.

obj/item/weapon/sword/longsword
obj/item/weapon/sword/greatsword
obj/item/weapon/polearm/spear
obj/item/shield/round
obj/item/armor/chest/leather

things like that.

I'm using an input, that asks them to input a line of text, then search the items for one who's name var matches, then create that item for the player. I've tried a few different ways and I'm just drowning in a sea of "Undefined type path" errors.
var/raw_input = input("What do you want to spawn?") as text
var/obj/O
for(var/path in typesof(/obj)) //or /atom/movable or whatever
O = path
if(initial(O.name) == raw_input)
new path(loc)


You could ask them to just type the path itself or build a list of valid names and ask them to choose one, though.
That's not really an option.

Think of this like a Genie granting a wish. You tell them what you wish for and they give it to you, but if you don't know the item exists, how are you suppose to wish for it?

I just found a way to do what I needed. It's simple enough. Never realized .type was a thing up until now.

var/obj/item/iwish = new X.type

seems to be doing the job I need.

var/list/Granted=list("Items")//You can add more

mob/proc/Granted()
if(Not_granted)
return
if(src.Granted)
src.Wish=pick(Granted)
alert("You got [src.Wish]'s!")
switch(src.Wish)
if("Item")//this can be change
var/obj/Weights/B = new/obj/item/
B.loc = usr

I think you would make a list of the stuff like this, just add a little twick to it and you might get what you want.
In response to IceFire2050
IceFire2050 wrote:
Think of this like a Genie granting a wish. You tell them what you wish for and they give it to you, but if you don't know the item exists, how are you suppose to wish for it?

Do you actually want them to type in what they want, instead of selecting from an input of all the item names?

I wrote some simple code up in either case if you wish to look at it.
var list/genie_wishes
obj/item
icon = 'items.dmi'
item_1
icon_state = "item_1"
item_2
icon_state = "item_2"
swords
sword_1
icon_state = "item_1"
sword_2
icon_state = "item_2"

mob/verb
genie_wish()
if(!genie_wishes||!genie_wishes.len)
. = typesof(/obj/item)
genie_wishes = list()
var obj/item/tmp_item
for(var/i in .)
tmp_item = new i
if(tmp_item.icon_state)
// This will not add any item which doesn't have a proper icon_state, which i assume any item should
// This will remove the initial path child paths, such as /obj/item and /obj/item/swords
genie_wishes[tmp_item.name] = tmp_item.type
var item = input("Which item do you desire?", "Wish") as null|text
/*
This is for selecting items from a list, instead of typing in your desired item
var item = input("Which item would you like to wish for?!", "Wish") as null|anything in genie_wishes
*/

if(!item)
src << "You may wish later."
else
if(!genie_wishes[item])
src << "What you wish for is unknown."
else
var item_type = genie_wishes[item]
contents += new item_type
// You seem to not be able to use a list index with new?? byond bug..?