Getting a line out of a file
#1

Hey guys,

Lets say i got those lines in a file: (theyre all names, and can be added by a command)
Код:
Henk 
Piet
Klaas
Isabel
Wesley
And if i want to get the name "Klaas" out of this file, and remove it, how would i do this?
Dont really know how to explain this, but tell me if you want more information.
~Wesley
Reply
#2

You better save them in a file and then you can delete them out of the file.
Reply
#3

This was an example, and the names i posted there were in the example file. Im trying to remove one of the lines (in my example this will be klaas), by using a command.
Reply
#4

So wait what are you loading it to a dialog?

Also the easyist way would to be to save names as

a = Henk
b = Piet

With Y_INI or somthing and hen loading it to somthing like you would do with a user

Dont really know what your loading it, explain further along these lines
Reply
#5

Well practicly i got nothing now. Let me try to explain it, using a file as the banned list (example)

Im gonna make a folder in my scriptfiles, with a file inside it named "Banned.ini"(or anything else).
When i do /aban klaas, then it kicks the player klaas out of the game, and add his name to the Banned.ini. Then im gonna use /aban on piet, henk, isable & wesley. Now theyre all in the Banned.ini.
Now i want to remove them with a command, not by removing the name out of the file. So i wanna do /removeban klaas, so klaas will be removed from the banned.ini file, so he can enter the game again.

Hope i explained it well, and you understand what im trying to do.
~Wesley
Reply
#6

Under the scenario of using this method for a banned library, it's OK. However; this isn't normally the method I would suggest to remove a name out of a library.

I would suggest SQLite, SQL and SQLite are kind of designed for this sort of use, here's some code for checking a table for banned users and the tables creation:

*code untested
pawn Код:
new DB:DB;
new DBResult:DBResult;

stock VerifyDatabase()
{
    new bool:remake;
   
    //Verify to see if the database exists
    if(!fexist("BannedDB"))remake=true;
    DB=db_open("BannedDB");
   
    //If database does not exist, create the necessary table
    if(remake)
    {
        print("[Database] Creating database...");
        db_free_result(db_query(DB,"CREATE IF NOT EXISTS `Banned` (`ID` INTEGER PRIMARY KEY, `Name` TEXT)"));
    }
   
    print("[Database] Database opened");
}

stock IsPlayerBanned(playerid)
{
    new tmpstring[64];
    new name[24];
    GetPlayerName(playerid,name,24);

    format(tmpstring,64,"SELECT ROWID FROM Banned WHERE Name='%s'",name);
    DBResult=db_query(DB,tmpstring);

    if(db_num_rows(DBResult))
    {
        db_free_result(DBResult);
        return 1;
    }
    return 0;
}

stock DBBan(playerid)
{
    new name[24];
    GetPlayerName(playerid,name,24);

    if(IsPlayerBanned(playerid))
    {
        printf("[Database] \"%s\" already found in banned database",name);
        return 0;
    }
   
    //Add name into database
    new tmpstring[64];
    format(tmpstring,64,"INSERT INTO Banned (Name) VALUES ('%s')",name);
    db_free_result(db_query(DB,tmpstring));
    printf("[Database] \"%s\" added to banned database",name);
    return 1;
}

stock UnbanName(const name[])
{
    new tmpstring[64];

    format(tmpstring,64,"DELETE FROM Banned WHERE Name='%s'",name);
    db_free_result(db_query(DB,tmpstring));
   
    return 1;
}
VerifyDatabase() would go into OnGameModeInit()
IsPlayerBanned will tell you if the player is banned (OnPlayerConnect is a good place for this)
DBBan(playerid) to ban players
UnbanName("name") to unban

Pretty simple
Reply
#7

Hm thanks, but i dont use SQlite or anything like that.
I might consider using SQlite, or MySQL, but im not sure if i want that.
Another question
Is it possible to have a register system in y_ini, and some other features for SQLite/MySQL? Probably it is, but if its posible, is it fast, or should i convert the register system to SQLite/MySQL aswell then?
Reply
#8

It's better to have everything in one writer / reader. But it's still possible to do it
Reply
#9

But is it faster to have everything in MySQL/SQLite, or just the register system in y_ini, and the ban thing in MySQL/SQLite?
Reply
#10

Well technically speaking, files are the fastest method. But the difference between saving an account's information via SQLite or files is literally within 1 or 2 milliseconds, not noticeable to anyone. However; SQLite is far more organized, you can keep all information including bans, accounts, and server information in a single organized-file. So in the event you need to change servers or create backups, it will be no different than downloading and uploading a file probably no more than 10MB in size.

For a valid example of SQLite account system, take a look at my Assassin's Escape gamemode I publicly released a long time ago.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)