[TUTORIAL]INI Databases...

Started by NicusorN5, Mar 27, 2018, 06:17 PM

Previous topic - Next topic

NicusorN5

    We all know that INI databases are the easiest to use. (And the laggiest ofc)

    When reading some values in a for() statement in a large file( ~2000+ values or more) , it freezes the server, then the players will experience an INSANE delay.

    Some people will still continue using INIParser plugin, because SQL languages are so confusing for them.

    There are some short,obvious tips for using the INI plugin:
   
  • Use it as less as possible : For example saving a pickup using INI is a bad idea. Use MySQL/SQLite dbs or some CreatePickup() functions.
  • You can only use ReadIniString() and WriteIniString(): You can convert the values if you need to.
  • Save less entries as possible : If you still don't want to use the SQL language, save less values as you can.
   A example:
Bad example:
WriteIniInteger("cars.ini",player.Vehicle.ID+"","model",player.Vehicle.Model);
WriteIniNumber("cars.ini",player.Vehicle.ID+"","x",player.Vehicle,Pos.x);
WriteIniNumber("cars.ini",player.Vehicle.ID+"","y",player.Vehicle.Pos.y);
WriteIniNumber("cars.ini",player.Vehicle.ID+"","z",player.Vehicle.Pos.z);
WriteIniNumber("cars.ini",player.Vehicle.ID+"","rx",player.Vehicle.Rotation.x);
WriteIniNumber("cars.ini",player.Vehicle.ID+"","ry",player.Vehicle.Rotation.y);
WriteIniNumber("cars.ini",player.Vehicle.ID+"","rz",player.Vehicle.Rotation.z);
WriteIniNumber("cars.ini",player.Vehicle.ID+"","rw",player.Vehicle.Rotation.w);
WriteIniInteger("cars.ini",player.Vehicle.ID+"","c1",player.Vehicle.Colour1);
WriteIniInteger("cars.ini",player.Vehicle.ID+"","c2",player.Vehicle.Colour2);

Good example:
local data = player.Vehicle.Model+" "+player.Vehicle.Pos.x+" "+player.Vehicle.Pos.y+" "+player.Vehicle.Pos.z+" "+player.Vehicle.Rotation.x+" "+player.Vehicle.Rotation.y+" "+player.Vehicle.Rotation.z+" "+player.Vehicle.Rotation.w+" "+player.Vehicle.Colour1+" "+player.Vehicle.Colour2+"";
WriteIniString("cars.ini","vehicles",player.Vehicle.ID+"",data);


Why? Because this method of writing (one string value per item(car/pickup/object/player/etc)) reduces the size of saved data. So hopefully the lag will be more rare and smaller ^_^ .
   
  • If saving players stats, find a way to convert the equal symbols to something else : A equal sign from a player name will break the INI database. There's a example on how to relpace the = sign to a letter that won't break the server. Use GetTok or some Squirrel functions to split the string, and remove somehow the = letters.
  • NEVER USE A SINGLE INI FILE AS A DATABASE : I said before that large INI files create a large delay for the players.
  • If there's a value that changes every minute or less, like car fuel, nitrous, health , save it at specific moments, not when it is changes : For example when a player's health is saved, it should only be saved when the player quits. An other simpler example is the car's NOS. Read it when the car is created, and save it when the server closes, or every half an hour. It's a GREAT idea to store values in a array.
   
Thanks for reading. Hope you will use these tips if you use IniParser in your server. (ofc this tutorial is made for newbs)