ID:272735
 
mob
proc
AdminCheck()
var/Admins = file2text("Admins.txt")
if (findtext(Admins,"[usr.ckey]")
usr << "You are a [num] lvl GM.(TESTIN)"
usr.verbs+=typesof(/client/Admin/verb)
usr.verbs+=typesof(/client/GM/verb)
usr.verbs+=typesof(/client/Azziki/verb)
usr.client.GM_Pref = "Warp"

OK, This scans Admins.txt file and retrives Admins just fine, How would I make it where it looks For [usr.ckey] - [num] and makes gm_level = num?
Use an associative list :) I've done this myself to check if a person is of a specific rank ;p
In response to Mizukouken Ketsu
Associative list? What?
In response to World Build
load_admins()
var/ini_reader/IRead = new("lobby/settings.ini", INIREADER_INI)
var/list/names=IRead.ReadSetting("Admins")
if(names.len)
adminss=new/list()
for(var/o in names)
if(!adminss.Find(o))
adminss+=names[o]



var/list/admins=list("testname"=9001,"testname1"=5)
proc/save_admins()
var/savefile/f=file("folder/file.ini")
//write stuff to the ini file
f<<"[ascii2text(BEGINOP_INI)]Admins[ascii2text(ENDOP_INI)]"
for(var/o in admins)
f<<"[o] = [ascii2text(STRINGOP)][admins[o]][ascii2text(STRINGOP)];"

//you get the picture

var/list/admins=list("test1"=9001,"test"=5)

if(ckey in admins)
src << "you are a level [admins[ckey]] gm"

world/del()//<-------- TRY USING THIS BEFORE ALL THE STUFF ABOVE
for(var/x=1 to admins.len)
text2file("[admins[x]]=[admins[admins[x]]]","whatever")
..()


try using some of this
In response to World Build
In response to Purles9000
A little long, complicated, and unnecessary >_>

var/list/Admins[] = list("Key"="Rank")
mob/Login()
..()
if(src.key in Admins[src.key])
switch(Admins[Rank])
if(1) src.verbs += typesof(/mob/GM1/verb)
if(2) src.verbs += typesof(/mob/GM2/verb)
//etc


Not sure if you could use an associative check like that to see what the associating value is, but yeah. That simple <_<;
Once you have your admin file as a string (which is what file2text("Admin.txt") does) then you'll need to parse it to find the values you want. Here's an example; let's say the Admin.txt file looks like this:

worldbuild - Admin
naruto111 - gm2
dbzfan000 - gm1
someotherguy - gm1


To parse it we use text functions (like copytext and findtext) to pull it apart into the pieces we need, but first we need to know what we need. In your case, this is an "AdminCheck" proc, so we don't need all the info, only the info that has to do with the person we're checking.

If the person we're looking for is in the file, then we also want to know what rank they are. So, I'm going to use the findtext() proc (you should look up these procs in the DM reference as we go along). findtext will tell me exactly where the person's name is in the file, so we'll want to put that in a variable so we know where to find his rank, too. If findtext can't find the person's name, then we just return so that it doesn't add any verbs or anything.

var/ckey_location = findtext(Admins, ckey)
if(!ckey_location){ return}


Once we know where the mob's ckey is in the file, we can use that to grab the rank. To grab the rank we're going to use the copytext proc (again, look this up in the reference right now). The copytext proc needs to know where to start copying, and where to stop copying. If the Admin.txt file looks like the example I posted above then the place it should stop copying is going to be the position of the end of the line. We can find that by using findtext and the newline macro "\n". Next we need to tell it where to start copying. We know that the admin rank comes after the hyphen "-" but it doesn't come immediatly after it (at least not in my example, your actual file is probably set up differently). In my example above, the rank start two spaces after the hyphen (because of the space: "- "). So, what we need to find is:

Where (after the ckey) is the hyphen? (we'll then add 2)
Where is the end of the line.

Then we plug those values into copytext():

var/rank_start = findtext(Admins, "-", ckey_location)+2
/* You need to know why ckey_location is the third argument, if you
don't know why, then you need to check the reference right now. */

var/rank_end = findtext(Admins, "\n", rank_start)
var/rank = copytext(Admins, rank_start, rank_end)


The full proc may look something like this:

mob/proc/AdminCheck()
var/Admins = file2text("Admins.txt")
var/ckey_location = findtext(Admins, ckey)
if(!ckey_location){ return}
var/rank_start = findtext(Admins, "-", ckey_location)+2
var/rank_end = findtext(Admins, "\n", rank_start)
var/rank = copytext(Admins, rank_start, rank_end)