ID:163117
 
I need to create a utility for myself, I want to import a rather.. LARGE text file containing rows of information handled in another format. I want to include it and organize it just like any other thing. some of you may actually be aware of what file this is and what its used for. Here's an example of the top.

// Items Database
//
// Structure of Database:
// ID,AegisName,Name,Type,Buy,Sell,Weight,ATK,DEF,Range,Slots,Job,Upper,Gender,Loc,wLV,eLV,Refineable,View,{ Script },{ OnEquip_Script },{ OnUnequip_Script }
//
// Healing Items
//=============================================================
0,DEFAULT,Default,0,,10,10,,,,,0xFFFFFFFF,7,2,,,,,,{},{},{}
501,Red_Potion,Red Potion,0,50,,70,,,,,0xFFFFFFFF,7,2,,,,,,{ itemheal rand(45,65),0; },{},{}
502,Orange_Potion,Orange Potion,0,200,,100,,,,,0xFFFFFFFF,7,2,,,,,,{ itemheal rand(105,145),0; },{},{}
503,Yellow_Potion,Yellow Potion,0,550,,130,,,,,0xFFFFFFFF,7,2,,,,,,{ itemheal rand(175,235),0; },{},{}
504,White_Potion,White Potion,0,1200,,150,,,,,0xFFFFFFFF,7,2,,,,,,{ itemheal rand(325,405),0; },{},{}
505,Blue_Potion,Blue Potion,0,5000,,150,,,,,0xFFFFFFFF,7,2,,,,,,{ itemheal 0,rand(40,60); },{},{}
506,Green_Potion,Green Potion,0,40,,70,,,,,0xFFFFFFFF,7,2,,,,,,{ sc_end SC_Poison; sc_end SC_Silence; sc_end SC_Blind; sc_end SC_Confusion; },{},{}
507,Red_Herb,Red Herb,0,18,,30,,,,,0xFFFFFFFF,7,2,,,,,,{ itemheal rand(18,28),0; },{},{}
508,Yellow_Herb,Yellow Herb,0,40,,50,,,,,0xFFFFFFFF,7,2,,,,,,{ itemheal rand(38,58),0; },{},{}
509,White_Herb,White Herb,0,120,,70,,,,,0xFFFFFFFF,7,2,,,,,,{ itemheal rand(75,115),0; },{},{}
510,Blue_Herb,Blue Herb,0,60,,70,,,,,0xFFFFFFFF,7,2,,,,,,{ itemheal 0,rand(15,30); },{},{}
511,Green_Herb,Green Herb,0,10,,30,,,,,0xFFFFFFFF,7,2,,,,,,{ sc_end SC_Poison; },{},{}
512,Apple,Apple,0,15,,20,,,,,0xFFFFFFFF,7,2,,,,,,{ itemheal rand(16,22),0; },{},{}
513,Banana,Banana,0,15,,20,,,,,0xFFFFFFFF,7,2,,,,,,{ itemheal rand(17,21),0; },{},{}
514,Grape,Grape,0,200,,20,,,,,0xFFFFFFFF,7,2,,,,,,{ itemheal 0,rand(10,15); },{},{}
515,Carrot,Carrot,0,15,,20,,,,,0xFFFFFFFF,7,2,,,,,,{ itemheal rand(18,20),0; },{},{}
516,Sweet_Potato,Potato,0,15,,20,,,,,0xFFFFFFFF,7,2,,,,,,{ itemheal rand(15,23),0; if(rand(1000)<15) sc_start SC_Stun,3000,0; },{},{}
517,Meat,Meat,0,50,,150,,,,,0xFFFFFFFF,7,2,,,,,,{ itemheal rand(70,100),0; },{},{}
518,Honey,Honey,0,500,,100,,,,,0xFFFFFFFF,7,2,,,,,,{ itemheal rand(70,100),rand(20,40); },{},{}
519,Milk,Milk,0,25,,30,,,,,0xFFFFFFFF,7,2,,,,,,{ itemheal rand(27,37),0; },{},{}
520,Leaflet_Of_Hinal,Hinalle Leaflet,0,150,,10,,,,,0xFFFFFFFF,7,2,,,,,,{ itemheal rand(175,235),0; },{},{}
521,Leaflet_Of_Aloe,Aloe Leaflet,0,360,,20,,,,,0xFFFFFFFF,7,2,,,,,,{ itemheal rand(325,405),0; },{},{}
522,Fruit_Of_Mastela,Mastela Fruit,0,8500,,30,,,,,0xFFFFFFFF,7,2,,,,,,{ itemheal rand(400,600),0; },{},{}
523,Holy_Water,Holy Water,0,20,,30,,,,,0xFFFFFFFF,7,2,,,,,,{ sc_end SC_Curse; },{},{}
525,Panacea,Panacea,0,500,,100,,,,,0xFFFFFFFF,7,2,,,,,,{ sc_end SC_Poison; sc_end SC_Silence; sc_end SC_Blind; sc_end SC_Confusion; sc_end SC_Curse; sc_end SC_Hallucination; },{},{}
526,Royal_Jelly,Royal Jelly,0,7000,,150,,,,,0xFFFFFFFF,7,2,,,,,,{ itemheal rand(325,405),rand(40,60); sc_end SC_Poison; sc_end SC_Silence; sc_end SC_Blind; sc_end SC_Confusion; sc_end SC_Curse; sc_end SC_Hallucination; },{},{}
528,Monster's_Feed,Monster Food,0,60,,150,,,,,0xFFFFFFFF,7,2,,,,,,{ itemheal rand(72,108),0; },{},{}
529,Candy,Candy,0,10,,30,,,,,0xFFFFFFFF,7,2,,,,,,{ itemheal rand(45,65),0; },{},{}
530,Candy_Striper,Candy Cane,0,20,,40,,,,,0xFFFFFFFF,7,2,,,,,,{ itemheal rand(105,145),0; },{},{}
531,Apple_Juice,Apple Juice,0,20,,40,,,,,0xFFFFFFFF,7,2,,,,,,{ itemheal rand(25,35),0; },{},{}
532,Banana_Juice,Banana Juice,0,20,,40,,,,,0xFFFFFFFF,7,2,,,,,,{ itemheal rand(26,34),0; },{},{}
533,Grape_Juice,Grape Juice,0,250,,40,,,,,0xFFFFFFFF,7,2,,,,,,{ itemheal 0,rand(15,25); },{},{}
534,Carrot_Juice,Carrot Juice,0,20,,40,,,,,0xFFFFFFFF,7,2,,,,,,{ itemheal rand(27,33),0; },{},{}
535,Pumpkin,Pumpkin,0,15,,20,,,,,0xFFFFFFFF,7,2,,,,,,{ itemheal 19,0; },{},{}
536,Ice_Cream,Ice Cream,0,150,,80,,,,,0xFFFFFFFF,7,2,,,,,,{ itemheal rand(105,145),0; if(rand(1000)<25) sc_start SC_Freeze,10000,0; },{},{}
537,Pet_Food,Pet Food,0,1000,,10,,,,,0xFFFFFFFF,7,2,,,,,,{ itemheal rand(50,90),0; },{},{}
538,Well_Baked_Cookie,Well-baked Cookie,0,1000,,30,,,,,0xFFFFFFFF,7,2,,,,,,{ itemheal rand(160,200),0; },{},{}
539,Piece_Of_Cake,Piece of Cake,0,3000,,100,,,,,0xFFFFFFFF,7,2,,,,,,{ itemheal rand(270,330),0; },{},{}
540,Falcon's_Feed,Falcon food,0,2000,,50,,,,,0xFFFFFFFF,7,2,,,,,,{ itemheal rand(185,225),0; },{},{}
541,Pecopeco's_Feed,Peco Peco food,0,3000,,50,,,,,0xFFFFFFFF,7,2,,,,,,{ itemheal rand(325,405),0; },{},{}
//542,Festive_Cookie,Festival Cookie,0,10,,10,,,,,0xFFFFFFFF,7,2,,,,,,{ itemheal rand(325,405),0; },{},{}
//543,Festive_Rainbow_Cake,Festival Rainbow Cake,0,10,,10,,,,,0xFFFFFFFF,7,2,,,,,,{ itemheal rand(325,405),0; },{},{}
544,Fish_Slice,Raw Fish,0,20,,30,,,,,0xFFFFFFFF,7,2,,,,,,{ itemheal rand(25,60),0; },{},{}
545,Red_Slim_Potion,Condensed Red Potion,0,150,,20,,,,,0xFFFFFFFF,7,2,,,,,,{ itemheal rand(45,65),0; },{},{}
546,Yellow_Slim_Potion,Condensed Yellow Potion,0,600,,30,,,,,0xFFFFFFFF,7,2,,,,,,{ itemheal rand(175,235),0; },{},{}
547,White_Slim_Potion,Condensed White Potion,0,1650,,50,,,,,0xFFFFFFFF,7,2,,,,,,{ itemheal rand(325,405),0; },{},{}
548,Cheese,Cheese,0,2800,,50,,,,,0xFFFFFFFF,7,2,,,,,,{ itemheal 0,rand(10,15); },{},{}
549,Nice_Sweet_Potato,Yam,0,180,,80,,,,,0xFFFFFFFF,7,2,,,,,,{ itemheal rand(50,100),0; },{},{}
550,Popped_Rice,Rice Cake,0,10,,10,,,,,0xFFFFFFFF,7,2,,,,,,{ itemheal rand(10,15),0; },{},{}
551,Shusi,Sushi,0,1,,50,,,,,0xFFFFFFFF,7,2,,,,,,{ itemheal rand(50,60),0; },{},{}
552,KETUPAT,Ketupat,0,1,,10,,,,,0xFFFFFFFF,7,2,,,,,,{ itemheal rand(70,90),rand(20,30); },{},{}
553,Bun,Bao,0,1,,50,,,,,0xFFFFFFFF,7,2,,,,,,{ itemheal rand(35,70),0; },{},{}
554,Mojji,Mochi,0,100,,80,,,,,0xFFFFFFFF,7,2,,,,,,{ itemheal rand(105,145),0; if(rand(1000)<10) sc_start SC_Stun,3000,0; if(rand(1000)<15) sc_start SC_Blind,2000,0; },{},{}
555,Rice_Cake,Traditional Rice Cake,0,100,,20,,,,,0xFFFFFFFF,7,2,,,,,,{ itemheal rand(105,145),0; },{},{}

Many thanks apreaciated. If you know an alternate method like in PHP I'd like that too.
Make lists
var
list
ID=(0,1,2)
name=("Red_Potion","Orange_Potion","Yellow_Potion")
//and so on
I highly recommend Deadron's XML library for this. Unless you are strict about using text files, that'd be the way to go.

IF you are strict, you'd want to parse the text file. Here are the barebones:
var/const
POTION_DATABASE_FILE = 'potions.txt' // Direct to the potion database that potions are parsed from.

//Convert a text string to a list. Each item in the string is separated
//from the next by the separator.
proc
text2list(text,separator=",")
. = list()
var/pos = 1
var/find = findtext(text,separator)
while(find)
find = findtext(text,separator,pos)
. += copytext(text,pos,find)
pos = length(separator)+find


// The potion template.
obj
potion
var
ID
effect

// Reading the text file:
client
var
list/potions

New()
. = ..()
potions = new()

verb
GiveMePotions()
var/file_text = file2text(POTION_DATABASE_FILE) // First we convert the database into text from a file...
var/seperate_potions[] = text2list(file_text,";") // Each semi-colon (;) indicates the end of a parsing line, hence the end\
of a potion definition.

for(var/potion_string in seperate_potions)
var/obj/potion/potion = new()
var/list/parse_potion_string = text2list(potion_string,",") // A comma seperates the parsed string's data.
potion.ID = parse_potion_string[1] // First variable indicates a potion's ID.
potion.name = parse_potion_string[2] // Second indicates its name.
potion.effect = parse_potion_string[3] // Third, its effect.
potions += potion

ShowMyPotions()
src << "ID Name Effect"
for(var/obj/potion/potion in potions)
src << "[potion.ID] [potion.name] [potion.effect]"


The code assumes your text file format is similar to this:
1,Potion of Healing,Heals you!;
2,Potion of Death,Kills you!;
3,Potion of Undeath,Revives you!;
49,Special potion,Special


Edit: Oh, in-case you follow my example, you'd want to import the potions into a global list and reuse it at server startup, instead of re-importing potions for every client every time.
In response to DivineO'peanut (#2)
DivineO'peanut wrote:
I highly recommend Deadron's XML library for this. Unless you are strict about using text files, that'd be the way to go.

IF you are strict, you'd want to parse the text file. Here are the barebones:
> var/const
> POTION_DATABASE_FILE = 'potions.txt' // Direct to the potion database that potions are parsed from.
>
> //Convert a text string to a list. Each item in the string is separated
> //from the next by the separator.
> proc
> text2list(text,separator=",")
> . = list()
> var/pos = 1
> var/find = findtext(text,separator)
> while(find)
> find = findtext(text,separator,pos)
> . += copytext(text,pos,find)
> pos = length(separator)+find
>
>
> // The potion template.
> obj
> potion
> var
> ID
> effect
>
> // Reading the text file:
> client
> var
> list/potions
>
> New()
> . = ..()
> potions = new()
>
> verb
> GiveMePotions()
> var/file_text = file2text(POTION_DATABASE_FILE) // First we convert the database into text from a file...
> var/seperate_potions[] = text2list(file_text,";") // Each semi-colon (;) indicates the end of a parsing line, hence the end\
> of a potion definition.

> for(var/potion_string in seperate_potions)
> var/obj/potion/potion = new()
> var/list/parse_potion_string = text2list(potion_string,",") // A comma seperates the parsed string's data.
> potion.ID = parse_potion_string[1] // First variable indicates a potion's ID.
> potion.name = parse_potion_string[2] // Second indicates its name.
> potion.effect = parse_potion_string[3] // Third, its effect.
> potions += potion
>
> ShowMyPotions()
> src << "ID Name Effect"
> for(var/obj/potion/potion in potions)
> src << "[potion.ID] [potion.name] [potion.effect]"
>


The code assumes your text file format is similar to this:
> 1,Potion of Healing,Heals you!;
> 2,Potion of Death,Kills you!;
> 3,Potion of Undeath,Revives you!;
> 49,Special potion,Special
>


Edit: Oh, in-case you follow my example, you'd want to import the potions into a global list and reuse it at server startup, instead of re-importing potions for every client every time.

they aren't really a potion text file, But Ill try and see what happens.
In response to DivineO'peanut (#2)
// ID,AegisName,Name,Type,Buy,Sell,Weight,ATK,DEF,Range,Slots,Job,Upper,Gender,Loc,wLV,eLV,Refineable,View,{ Script },{ OnEquip_Script },{ OnUnequip_Script }

This is the format.
In response to DivineO'peanut (#2)
var/const
POTION_DATABASE_FILE = 'Item_db.txt' // Direct to the potion database that potions are parsed from.

//Convert a text string to a list. Each Item in the string is separated
//from the next by the separator.
proc
text2list(text,separator=",")
. = list()
var/pos = 1
var/find = findtext(text,separator)
while(find)
find = findtext(text,separator,pos)
. += copytext(text,pos,find)
pos = length(separator)+find
// The potion template.
obj
Item
var
ID
AegisName
Name
Type
Buy
Sell
Wieght
ATK
DEF
Range
Slots
Job
Upper
Gender
Loc
wLV
eLV
Refineable
View
Script
OnEquip_Script
OnUnEquip_Script

// Reading the text file:
client
var
list/Items

New()
. = ..()
Items = new()

verb
GiveMePotions()
var/file_text = file2text(POTION_DATABASE_FILE) // First we convert the database into text from a file...
var/seperate_potions[] = text2list(file_text,";") // Each semi-colon (;) indicates the end of a parsing line, hence the end of a potion definition.
for(var/potion_string in seperate_potions)
var/obj/Item/Item = new()
var/list/parse_potion_string = text2list(potion_string,",")
Item.ID = parse_potion_string[1]
Item.AegisName = parse_potion_string[2]
Item.Name = parse_potion_string[3]
Item.Type = parse_potion_string[4]
Item.Buy = parse_potion_string[5]
Item.Sell = parse_potion_string[6]
Item.Wieght = parse_potion_string[7]
Item.ATK = parse_potion_string[8]
Item.DEF = parse_potion_string[9]
Item.Range = parse_potion_string[10]
Item.Slots = parse_potion_string[11]
Item.Job = parse_potion_string[12]
Item.Upper = parse_potion_string[13]
Item.Gender = parse_potion_string[14]
Item.Loc = parse_potion_string[15]
Item.wLV = parse_potion_string[16]
Item.eLV = parse_potion_string[17]
Item.Refineable = parse_potion_string[18]
Item.View = parse_potion_string[19]
Item.Script = parse_potion_string[20]
Item.OnEquip_Script = parse_potion_string[21]
Item.OnUnEquip_Script = parse_potion_string[22]
Items += Item

ShowMyPotions()
var/html = null
html = "VALUE<BR>"
for(var/obj/Item/Item in Items)
//src << browse(html)
html += "[Item.ID]"
src << browse(html)

This is my edit, apparently it doesn't want to work to well.

(I found my problem :D Silly me.) EDIT
You shouldn't really rip other's hard work.

I can clearly tell that's Gravity's Ragnarok Online stuff.
In response to LucifersHellion (#6)
LucifersHellion wrote:
You shouldn't really rip other's hard work.

I can clearly tell that's Gravity's Ragnarok Online stuff.

IF you didn't read. IM using it for personal reasons, I need a tool to organize and search through this massive text file. I'ts not going to be used as a game or no others are using it. It's just a utility I need to use.

On side not this is a piece of a server emulation and no the real thing. however the original concept and creation does goto Gravity.
In response to Fusioneko (#7)
Gravity is far from the first group to make a database using text strings, there's no such thing as copyrighting the format of text, you don't need to give anyone credit.
In response to Keeth (#8)
Keeth wrote:
Gravity is far from the first group to make a database using text strings, there's no such thing as copyrighting the format of text, you don't need to give anyone credit.

I understand that. IT is their work and many others for storing such data into a text file. But my current objective at the moment is to solve my issue with my current script, each line is handled and dealt with but I have nothing to stop them. the ';' as suggested would not work.

var/const
POTION_DATABASE_FILE = 'Item_db.txt' // Direct to the potion database that potions are parsed from.

//Convert a text string to a list. Each Item in the string is separated
//from the next by the separator.
proc
text2list(text,separator=",")
. = list()
var/pos = 1
var/find = findtext(text,separator)
while(find)
find = findtext(text,separator,pos)
. += copytext(text,pos,find)
pos = length(separator)+find
// The potion template.
obj
Item
var
ID
AegisName
Name
Type
Buy
Sell
Wieght
ATK
DEF
Range
Slots
Job
Upper
Gender
Loc
wLV
eLV
Refineable
View
Script
OnEquip_Script
OnUnEquip_Script

// Reading the text file:
client
var
list/Items

New()
. = ..()
Items = new()

verb
GiveMePotions()
var/file_text = file2text(POTION_DATABASE_FILE) // First we convert the database into text from a file...
var/seperate_potions[] = text2list(file_text,";") // Each semi-colon (;) indicates the end of a parsing line, hence the end of a potion definition.
for(var/potion_string in seperate_potions)
var/obj/Item/Item = new()
var/list/parse_potion_string = text2list(potion_string,",")
Item.ID = parse_potion_string[1]
Item.AegisName = parse_potion_string[2]
Item.Name = parse_potion_string[3]
Item.Type = parse_potion_string[4]
Item.Buy = parse_potion_string[5]
Item.Sell = parse_potion_string[6]
Item.Wieght = parse_potion_string[7]
Item.ATK = parse_potion_string[8]
Item.DEF = parse_potion_string[9]
Item.Range = parse_potion_string[10]
Item.Slots = parse_potion_string[11]
Item.Job = parse_potion_string[12]
Item.Upper = parse_potion_string[13]
Item.Gender = parse_potion_string[14]
Item.Loc = parse_potion_string[15]
Item.wLV = parse_potion_string[16]
Item.eLV = parse_potion_string[17]
Item.Refineable = parse_potion_string[18]
Item.View = parse_potion_string[19]
Item.Script = parse_potion_string[20]
Item.OnEquip_Script = parse_potion_string[21]
Item.OnUnEquip_Script = parse_potion_string[22]
Items += Item

ShowMyPotions()
var/html = null
html = "VALUE<BR>"
for(var/obj/Item/Item in Items)
//src << browse(html)
html += "[Item.ID],[Item.AegisName],[Item.Name],[Item.Type],[Item.Buy],[Item.Sell],[Item.Wieght],[Item.ATK],[Item.DEF],[Item.Range],[Item.Job],[Item.Upper],[Item.Gender],[Item.Loc],[Item.wLV],[Item.eLV],[Item.Refineable],[Item.View],[Item.Script],[Item.OnEquip_Script],[Item.OnUnEquip_Script]"
src << browse(html)