mob/NPC
icon='mob.dmi'
npc=1
Resource_trader
icon_state="trader"
DblClick()
if(usr.oz)
if(usr.oz==6)
var/a=input("Would you like to buy resources?") in list ("Yes","No")
switch(a)
if("Yes")
for(var/obj/consoles/ships_computer/S in world)
if(S.z==usr.oz)
if(c1slots.len==0)
for(var/obj/slots/cargo/cargo1/c in world)
if(c.z==S.z&&c.contents.len==0)
c1slots.Add(c)
if(c2slots.len==0)
for(var/obj/slots/cargo/cargo2/c in world)
if(c.z==S.z&&c.contents.len==0)
c2slots.Add(c)
if(c3slots.len==0)
for(var/obj/slots/cargo/cargo3/c in world)
if(c.z==S.z&&c.contents.len==0)
c3slots.Add(c)
if(c4slots.len==0)
for(var/obj/slots/cargo/cargo4/c in world)
if(c.z==S.z&&c.contents.len==0)
c4slots.Add(c)
var/b=input("Which resource do you want to buy?") in list ("plastic level 1","plastic level 2","plastic level 3","steel","aluminum","tungsten","carbon fiber","coolant","fuel","oil","uranium","rubber")
switch(b)
if("plastic level 1")
var/c=input("How much of the resource do you want to buy?") in list ("One cargo bay","Two cargo bays","Three cargo bays","Cancel")
switch(c)
if("One cargo bay")
if(c1slots.len>=1)
if(c1contents.len==0)
for(var/obj/slots/cargo/cargo1/c1 in c1slots)
//text2path
var/string=b
var/replace="_"
var/find=" "
var/length = lentext(find)
var/pos = findtextEx(string, find)
string = copytext(string, 1, pos)+replace+copytext(string, pos+length)
length = lentext(find)
pos = findtextEx(string, find)
string = copytext(string, 1, pos)+replace+copytext(string, pos+length)
string=text2path(string)
var/P
P=text2path("/obj/items/resources/[string]/")
if(ispath(P,/obj/items/resources/plastic_level_1/))
usr<<"Path true."
c1contents.Add(P)
else
usr<<"Not a path"
//var/obj/items/resources/plastic_level_1/P = new /obj/items/resources/plastic_level_1
usr<<"Thank you for purchasing [b]."
Problem description:
I'm trying to simplify my resource system with text2path and it isn't producing valid paths. I've been working on it for a while and nothing seems to be working. I got the replace text code from another thread, [link] , and tweaked it to my needs. The replacement works. It changes the spaces into underscores. However, the variable is not outputted as a valid path. I followed the example of text2path from the DM reference. I pasted much more code than was needed, but I have had major problems in the past from only posting snippets and the thread gets out of hand fast. The commented out part at the end was the old way I was doing it, and it required a ton of copy and pasting for every resource. So I wanted to simplify it.
Then, solicit input from the list. resource_names[input] will then give you the type path of the selection.