Inflikted's Idiot Guide to .txt Manipulation

Inflikted

LOMCN Veteran
Veteran
Aug 4, 2003
256
7
114
so i seen alot of people have incorporated SQL scripting onto their servers, which is great.
However, sometimes it is easier to use a more simple method. I noticed there was no posted tutorial on this
so I figured I would make one, it might help some of you make more simple scripts that allow things to be saved
without resorting to make a table in SQL.

First off, what can a .txt file store? It can basically store 2 unique columns of data, they can be numbers
or words. You can add, subtract, update, edit, load things from text files. Unfortunately with that limitation
you can't store 3+ columns of data in a text file (to my knowledge, correct me if i am wrong :)) However, you can
seperate columns out, so in retrospect you can actually store alot more data then you think.. I'll explain below :)



Lets start off with some terms to no, i think you no probably in general what these things do. so lets start off
with an example on how to use them.


SaveValue

Loadvalue

addnamelist

checknamelist

!CheckNameList


now lets start a script in 00default.txt that check's if its a new player or not, and then gives the user a custom welcome message

Code:
#IF
!CheckNameList newplayers.txt   ;if the name isnt in the newplayers list
#ACT
AddNameList newplayers.txt    ;then we add the name to the list
SaveValue "QuestDiary\newplayermessage.txt" Main %USERNAME noob       ;notice we use a new text file to save this data. name searching must be in a seperate
									text file from the data entry. Notice the format of saving. Main tell's the category
									Username tell's us the player name, noob is the message.
goto @@changemessage
#ELSEACT
LoadValue A1 "QuestDiary\newplayermessage.txt" Main %USERNAME
#SAY
Welcome back <$OUTPUT(A1)>\
<Change Message/@@changemessage>\
<Close/@Exit>\

[@@changemessage]
#ACT
Mov A2 %INPUTSTR
SaveValue A2 "QuestDiary\newplayermessage.txt" Main %USERNAME
#SAY
Next time you login, your welcome message will say\\
Welcome back <$OUTPUT(A1)>\\
<Close/@Exit>\


If this is done properly, you can go into newplayermessage.txt
and you should see something like this...

Code:
[Main]
Inflikted=noob
Noname=you idiot

Now as I mentioned earlier, you can indeed save multiple categories in the same text file, I won't draw out another example for it
but say we want to add another category that saves numbers. Unlike SQL we would have to go back and make a new table. Not with .txt files
Mir3 should simply add in the category for you.

Say I want to store a certain number along with their username in the same text file to save space. I could do something like..

Code:
SaveValue "QuestDiary\newplayermessage.txt" Main2 %USERNAME 89

and when we want to call up data from Main2 we simply specify in the LoadValue prompt which category we want to load from

Code:
LoadValue D1 "QuestDiary\newplayermessage.txt" Main2 %USERNAME

So ya hopefully this gives you guys an idea how text files work, and how you can store data in it. In alot of ways its more simple and easier to use
than SQL tables, since it can create its own categories on the fly. Also notice its only the right column of data that can be searched and edited, the left column stays permanent.

When you think about it, you probably can create more sophisticated data entries
with text files than with SQL, and read them must quicker. something like...

Code:
#ACT
LoadValue D1 "QuestDiary\newplayermessage.txt" Main2 %USERNAME
LoadValue D2 "QuestDiary\newplayermessage.txt" Main3 %USERNAME
LoadValue D3 "QuestDiary\newplayermessage.txt" Main4 %USERNAME
LoadValue D4 "QuestDiary\newplayermessage.txt" Main5 %USERNAME
LoadValue D5 "QuestDiary\newplayermessage.txt" Main6 %USERNAME

Enjoy :) and please let me no if i made an error's. I don't own a server anymore, so I can only go off my head if this stuff is valid anymore lol :)
 
Last edited:

idaBigA

Holley Mir 3!!
VIP
Oct 28, 2003
1,966
110
310
Stoke, UK
Nice post.. a lot of people overlook text files now that SQL is being used more and more.

After looking at the VE files, I think thats all they used, and they have system's Equal in complexity to the ones using SQL. I suppose its just a matter on which one you prefer.

I dunno about how much resources it uses to update SQL as compared to the file handler that the server uses.. in fact, I would have no idea how to ever go about check it lol.. I am gonna shut up now..

Anyway.. Good Post.. Rep Up!
 
Upvote 0

Inflikted

LOMCN Veteran
Veteran
Aug 4, 2003
256
7
114
for me it was actually kyeron who triggered the idea to do this. since everything he has done can be created with text file database and its much easier for a new scripter. but i guess if you notice in alot of the chinese scripts that no one bothers to translate, they rely heavily on .txt storage aswell, rather than SQL. i suppose the only benefit you get with the SQL storage is adding multiple entries at the same time, while you can't do that with text files. and generally speaking.. i think resource wise it probably won't be a big difference unless you heavily mod your server with alot SQL scripting.. but i doubt anyone here has done this so its not a big deal
 
Last edited:
Upvote 0

idaBigA

Holley Mir 3!!
VIP
Oct 28, 2003
1,966
110
310
Stoke, UK
for me it was actually kyeron who triggered the idea to do this. since everything he has done can be created with text file database and its much easier for a new scripter. but i guess if you notice in alot of the chinese scripts that no one bothers to translate, they rely heavily on .txt storage aswell, rather than SQL. i suppose the only benefit you get with the SQL storage is adding multiple entries at the same time, while you can't do that with text files. and generally speaking.. i think resource wise it probably won't be a big difference unless you heavily mod your server with alot SQL scripting.. but i doubt anyone here has done this so its not a big deal


Oops.. :)

I have all my Quests, Pot Storage, Booty Storage, Events, and a few more items all use SQL..

Saying that I also, use quite a bit of Text storage as well, i.e. When people die, it adds to a text doc so I can tell exactly how many times everyone has died.. Sabuk War Deaths recorded.. and random other stuff..

There is a quite a bit you can do with the files, but unless someone makes an open source server we will always be stopped short of making masterpieces.

I don't notice any server lag at all, so I suppose either way is good.
 
Upvote 0

Cricket1650

Dedicated Member
Dedicated Member
Apr 25, 2008
66
0
52
Nice thanks man.. didn't know how to do this before.. but than again that's what tutorials/guides are for.
 
Upvote 0

Geordiehc

Mad Dog Geo
VIP
Jul 4, 2007
2,827
49
195
Redditch, UK
Sorry that im noob been so long since i messed with mir lol
#ACT
LoadValue D1 "QuestDiary\guildpoints.txt" Main %Guildname
Inc %D1 1
SaveValue "QuestDiary\guildpoints.txt" Main %Guildname %D1
#SAY
%GUILDNAME now has <OUTPUT(D1)> point('s)\
Something like that would work instead of Using SQL for guild points?

EDIT: dont know what im doing wrong but im having real problems with guild calling, sometimes it works with <$GUILD> sometimes it doesnt and it woont work at all with %GUILD any ideasplease im totally stuck other than that iv got a .txt version of guild points that i can release when finished lol
 
Last edited:
Upvote 0

Cricket1650

Dedicated Member
Dedicated Member
Apr 25, 2008
66
0
52
Hey so say I wanted to check the script to see if the username is there and if it is the script will end. If its not there i want it to continue the script and save their name to the script. How would i do that?
 
Upvote 0

Inflikted

LOMCN Veteran
Veteran
Aug 4, 2003
256
7
114
read my tutorial cricket, the thing your asking for is already in there :)

and geo... you should use %GUILDNAME in the ACT part of the script and i believe <$GUILD> or <$GUILDNAME> for the SAY part's of the script. i cant confirm this though, since i dont have a server.
 
Upvote 0

Cricket1650

Dedicated Member
Dedicated Member
Apr 25, 2008
66
0
52
i read it and put it in the script but even with the name in the .txt the script would still continue
 
Upvote 0

Inflikted

LOMCN Veteran
Veteran
Aug 4, 2003
256
7
114
try to use
#IF
CheckNameList thetext.txt
#ACT
break
#ELSEACT
Addnamelist thetext.txt


try that out. though the other way should work fine also i think.
 
Upvote 0

idaBigA

Holley Mir 3!!
VIP
Oct 28, 2003
1,966
110
310
Stoke, UK
Its exactly the same as using USERNAME, just replace USERNAME with GUILDNAME..

Here..

Code:
#ACT
   Mov A0 %GUILDNAME
   Mov A1 "Value A to Save"
   Mov A2 "Value B to Save"
   Mov A3 "Value C to Save"
   Mov A4 "Value D to Save"
   SaveValue "QuestDiary\System\TextDoc.txt" [%A0] SectionA %A1
   SaveValue "QuestDiary\System\TextDoc.txt" [%A0] SectionB %A2
   SaveValue "QuestDiary\System\TextDoc.txt" [%A0] SectionC %A3
   SaveValue "QuestDiary\System\TextDoc.txt" [%A0] SectionD %A4

This will save the following in the files TextDoc.txt

Code:
[GUILDNAME1]
SectionA=Value A to Save
SectionB=Value B to Save
SectionC=Value C to Save
SectionD=Value D to Save
[GUILDNAME2]
SectionA=Value A to Save
SectionB=Value B to Save
SectionC=Value C to Save
SectionD=Value D to Save
etc

To get the info back out.. putting whichever item you want.. into a Variable (in this case A1)

Code:
#ACT
   Mov A0 %GUILDNAME
   LoadValue A1 "QuestDiary\System\TextDoc.txt" [%A0] SectionA

To check if the Guild already exists in this file.. A1 will return no value if SectionA does not exist (or is empty, if this is not acceptable, see below). So it must not exist

Code:
#ACT
   Mov  A1  ""
   Mov A0 %GUILDNAME
   LoadValue A1 "QuestDiary\System\TextDoc.txt" [%A0] SectionA
#IF
   Equal  A1 ""
#SAY
This guild does not exist...

If "SectionA" can be empty then you need to setup another variable to say it exists.. i.e. one that you will not use for any other purpose than checking it is available.

Code:
#ACT
   Mov A0 %GUILDNAME
   SaveValue "QuestDiary\System\TextDoc.txt" [%A0] GuildExists 1
And then to check it..
Code:
#ACT
   Mov D1 0
   Mov  A1  ""
   Mov A0 %GUILDNAME
   LoadValue D1 "QuestDiary\System\TextDoc.txt" [%A0] GuildExists
#IF
   Equal D1 0
#SAY
Guild does not exist..

And.. almost ANYTHING is possible, if it isn't capable of being done internally with Mir, just make a small add on App that will check things, or manipulate data for you to then grab from text docs or SQL.. :)
 
Upvote 0

Inflikted

LOMCN Veteran
Veteran
Aug 4, 2003
256
7
114
yup ida summed it up nicely :)

i might correct my tutorial a bit later. i think people are getting a bit confused with the first part of the script, and assuming you can't check a name on a list any other way. the method ida described is a bit longer, but accurate for guild's or anything else you want to check. the username check that i had is just a more simplified version that saves a few lines of text, but obviously it can't be used everywhere.
 
Last edited:
Upvote 0

budyniowski

Dedicated Member
Dedicated Member
Dec 16, 2007
149
0
63
Warsaw, Poland
I have 1 question: .txt file can store only 255 names/guilds/IDs/etc. or more than 255? its important for me because we rewrite integral system on ower serwer from database to txt files (its save integral value in txt files).
Someone know?
thanks.
 
Upvote 0

idaBigA

Holley Mir 3!!
VIP
Oct 28, 2003
1,966
110
310
Stoke, UK
I don't "think" there is a limit. Only way to test is to run it, although I would recommend using SQL, I find it easier to search and update many users at once..
 
Upvote 0

Amenovis

Golden Oldie
Golden Oldie
Loyal Member
Jan 9, 2006
1,105
0
143
Germany
i miss something in that script. I know addnamelist and checknamelist from woool server files. there is also the command DelNameList for delete a name from a list. Before i read that post i have not known that on Lomservers that 3 Commands work also *lol

A nice example for use it, is in that way quests what you normal do with flags but as all from us know that work longer with lom flags are only some available and it have a limit. txt files never have a limit!

ScriptExample:

[@main]
#if
Checknamelist finished.txt ;;Here is a check if the user allread had done that quest
#say
You have done the Quest!
#elseact goto @queststart

[@queststart]
#say
hi m8 you wanna make a quest?
<yes/@yes>\
<No/@exit>\

[@yes]
#if
checknamelist start.txt ;;Here check"the user had allready start so he will bring questitems"
#say
You bring me what i told you to ?
<Yes/@yes2>
#elsesay
If you wanna help me bring me 20 X items
<Exit/@exit>
#elseact
addnamelist start.txt
break
[@yes2]
#if
Checkitem X 20
#say
Nice that you had survive it and bring me what i need!
<exit/@exit>
#act
take item x 20
delnamelist start.txt ,,had get reward
addnamelist finished.txt ;;had finished quest for check in first part
give "Reward"
#elsesay
something is missing you have not the items!
<Exit/@exit>

only a small example. that it work you must create for sure that both txt files (start.txt and finished.txt)
and now for the once that are better in that as me.

How does a command in writeline (chatline) can start a script?
i mean now example:

someone write as example @adduser "Name" (i have seen on Hasekura server)

how can than a popup window come and ask :"You wanna add that member to guild?"


//i will not copy that part but i think it usefull cause than also commands like that can have a much deeper use as example for events guildevent quests and more
 
Last edited:
Upvote 0