Liberty Unleashed
Scripting => Script Help => Topic started by: IdkanYavuk X on November 20, 2012, 10:45:18 pm
-
Hello
I'm making a language system using an ini file, in this way:
[Test]
esp = "Esto es un test"
eng = "This is a test"
In VRocker's area system, he uses many strings in a single "title", so my ini would be like this:
[Langs]
Test = "Esto es un test", "This is a test"
How to read sections of the same "title"?
Thanks
-
Use a seperator that wont be used in any lines of text, like ; .
You make your ini like this:
[Langs]
Line1="Esto es un test;This is a test"
To get the correct language lines, use this:
local Lang1 = ReadIniString( "Langs.ini", "Langs", "Line1" );
local esp = GetTok( Lang1, ";", 0 ); //This will get the first part of the whole line, untill the first ; is found
local eng = GetTok( Lang1, ";", 1 ); //You can probably fill in what this thing does here..
Hope that helps you out.
-
Thanks! But if I want more languages?
I use this?:
local fra = GetTok( Lang1, ";", 2 );
Another thing: what if I want variables in those messages? for example
"Bienvenido al server, " + plr
"Welcome to the server, " + plr
-
Thanks! But if I want more languages?
I use this?:
local fra = GetTok( Lang1, ";", 2 );
Yeah.
Another thing: what if I want variables in those messages? for example
"Bienvenido al server, " + plr
"Welcome to the server, " + plr
You would just have to extract the text from the ini and then attach the player's name/whatever to it in a callback such as onPlayerJoin.
-
You could use two way.
First:
Store a string that you will place before the player. Something like "Welcome to the server, "
Then store a string you would like to place behind it, in this case it will be nothing.
Then on your signal paste your player name behind the first bit and paste the behind-stuff behind that.
Second:
Store your messages like this:
"Welcome to the server, %plr%"
Then on your join signal you do something like this:
local lang = ReadIniString( "Langs.ini", "Langs", "Line1" );
lang = GetTok( lang, ";", 1 );
lang = Replace( lang, "%plr%", plr.Name );
MessagePlayer( lang, plr );
and the function:
function Replace( szOriginal, szFind, szReplace )
{
local iCharPos = szOriginal.find( szFind );
local iLength = szFind.len();
local szBefore = szOriginal.slice( 0, iCharPos );
local szBehind = szOriginal.slice( ( iCharPos + iLength ) );
return ( szBefore + szReplace + szBehind );
}
You could of course add more variables that way, Just add more %vars% and copy the Replace line.
Function is tested, rest is not. Good luck ;)
-
Wow! nice! thanks Thijn!
Thanks all