[OR] Diversity 1.2 
13 comments ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
Versions
Overview
Diversity is a simple tool to control languages. You want to use multiple languages in your script? Use Diversity!
Example
Documentation
This is the section where you can learn how to add your own languages and how to use them.
First, let's take a look of the configurations.cfg file. There're several configurations you can set on your liking. First is loaddirectory configuration, is to set the load directory of your languages. Second is officiallanguages configuration, is to set the official languages of your script, so if these official languages aren't available, there will be an error.
Second, is to understand how to add your own languages. You need to insert your languages inside the loaddirectory configuration directory. Your language files must be in text (*.txt) form. A new line is to end a line of your languages' lines, just like the usual. There's a symbol that used to manipulate the strings of the languages, that is '$'. '$' is used for subtitution. Example of a complete language:
Third, is to understand how to use the languages. You need to understand how to use functions, that's it. First load Diversity to your script by requiring it, and save it to a variable:
Then to use the languages, use the used variable for Diversity with format of:
Rules
• You are allowed to use this script in your server.
• You are allowed to edit this script for your server.
• You are not allowed to copy any part of this script without permission.
• You are not allowed to say this script is yours.
Installation
1. Download the file and then extract it anywhere in your CS2D directory.
2. Connect your script with this script using require.
3. Use Diversity to control your languages!
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬


Diversity is a simple tool to control languages. You want to use multiple languages in your script? Use Diversity!

Code:
1
2
2
Welcome, $1!
Enjoy your stay!
Enjoy your stay!
Code:
1
2
2
Selamat datang, $1!
Bersenang-senanglah!
Bersenang-senanglah!
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
local language = require("sys/lua/diversity")
local currentlanguage = {}
for id = 1, 32 do
currentlanguage[id] = "English"
end
function serveractionhook(id, action)
if (action == 1) then
currentlanguage[id] = currentlanguage[id] == "English" and "Indonesian" or "English"
end
end
function joinhook(id)
msg2(id, language(currentlanguage[id], 1, player(id, "name")) .. "@C")
msg2(id, language(currentlanguage[id], 2) .. "@C")
end
addhook("serveraction", "serveractionhook")
addhook("join", "joinhook")
local currentlanguage = {}
for id = 1, 32 do
currentlanguage[id] = "English"
end
function serveractionhook(id, action)
if (action == 1) then
currentlanguage[id] = currentlanguage[id] == "English" and "Indonesian" or "English"
end
end
function joinhook(id)
msg2(id, language(currentlanguage[id], 1, player(id, "name")) .. "@C")
msg2(id, language(currentlanguage[id], 2) .. "@C")
end
addhook("serveraction", "serveractionhook")
addhook("join", "joinhook")

This is the section where you can learn how to add your own languages and how to use them.
First, let's take a look of the configurations.cfg file. There're several configurations you can set on your liking. First is loaddirectory configuration, is to set the load directory of your languages. Second is officiallanguages configuration, is to set the official languages of your script, so if these official languages aren't available, there will be an error.
Second, is to understand how to add your own languages. You need to insert your languages inside the loaddirectory configuration directory. Your language files must be in text (*.txt) form. A new line is to end a line of your languages' lines, just like the usual. There's a symbol that used to manipulate the strings of the languages, that is '$'. '$' is used for subtitution. Example of a complete language:
Code:
1
2
2
You've been attacked by $1!
Are you sure to replace $1 with $2?
Are you sure to replace $1 with $2?
Third, is to understand how to use the languages. You need to understand how to use functions, that's it. First load Diversity to your script by requiring it, and save it to a variable:
Code:
1
local language = require("sys/lua/diversity")
Then to use the languages, use the used variable for Diversity with format of:
Code:
1
<variable>(<language-name>, <language-line>,[ <line-subtitution-1>, <line-subtitution-2>, ...])
Code:
1
2
3
2
3
language("English", 1) -- You've been attacked by $1
language("English", 1, "Ortimh") -- You've been attacked by Ortimh
language("English", 2, "null", "nil") -- Are you sure to replace null with nil?
language("English", 1, "Ortimh") -- You've been attacked by Ortimh
language("English", 2, "null", "nil") -- Are you sure to replace null with nil?

• You are allowed to use this script in your server.
• You are allowed to edit this script for your server.
• You are not allowed to copy any part of this script without permission.
• You are not allowed to say this script is yours.

1. Download the file and then extract it anywhere in your CS2D directory.
2. Connect your script with this script using require.
3. Use Diversity to control your languages!
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
edited 9×, last 16.06.16 08:39:25 am

Comments
13 comments



Log in!
You need to log in to be able to write comments!Log in

I will use it soon
Error in your example. Change your code to this below:
Error in your example. Change your code to this below:
Code:
1
2
3
4
2
3
4
function joinhook(id)
msg2(id, language(currentlanguage[id], 1, player(id, "name")) .. "@C")
msg2(id, language(currentlanguage[id], 2) .. "@C")
end
msg2(id, language(currentlanguage[id], 1, player(id, "name")) .. "@C")
msg2(id, language(currentlanguage[id], 2) .. "@C")
end
edited 1×, last 13.06.16 05:39:04 pm
@
MikuAuahDark: That works? Well I might change that. Anyway the checking is not that performance-heavy.


Looks like you're checking if the CS2D version is less than 1.0.0.2 right? Here are single-line CS2D version checking.
It's possible to check the version that way instead of converting everything to number which can gives little performance overhead.
Code:
assert((_CS2DVERSION or "1.0.0.0") < "1.0.0.2","Requires CS2D v1.0.0.2")
It's possible to check the version that way instead of converting everything to number which can gives little performance overhead.
@
MikuAuahDark: Yeah, I've been thinking about that. Will do as soon as I can.


It's looks useful for Citylife script which I rewrite from stratch due to messy code.
However, it might be useful if there's function which allows the values to be passed and then used as $1, $2, ...
Example:
However, it might be useful if there's function which allows the values to be passed and then used as $1, $2, ...
Example:
Code:
format_language("English", 2, "Test", "Null") -- Are you sure to replace Test with Null?

Truly impressive! Was thinking about an idea similarly to this several days ago although I couldn't come up with a working, flexible step algorithm to show up different languages. Definitely a honest like should be given.
@
_Yank: Calling directly from the table is simpler than calling from a function, well in terms of typing and performance.


You could do a function to simplify the querying process so it could be used like, for example,
But yeah, good job!
Code:
1
dictionary(currentlanguage[id], 1, player(id, "name"))
But yeah, good job!



