Forum

> > CS2D > Scripts > Script bridge
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Script bridge

4 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Script bridge

Leonam
User Off Offline

Zitieren
Sorry for my bad English, but I need some help. I just through this new script deal more I translate a script to my language. But I wanted the player to have the freedom to choose the appropriate language for them, I wanted a view of a bridge script that bind scripts more only execute what the player want!

Thanks for help

alt Re: Script bridge

Rainoth
Moderator Off Offline

Zitieren
I'm going to assume that you want to have multiple languages in your script.

Here's how I'd do it:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
languages = {
[1] = {"labas","as esu","krabas"},
[2] = {"hi","I am","a crab"},
["used"] = {}
}

addhook("menu","_m")
function _m(id,t,b)
	if t == "example title A" then
		for k,v in pairs (languages[b]) do
			languages["used"][k] = v
		end
	elseif t == "example title B" then
		menu(id,"Title (can also be a variable)",languages["used"][1], languages["used"][2], languages["used"][3])
	end
end

This is just an example of how it would work. It doesn't actually work because I didn't create appropriate menus and hooks to call them.

alt Example

Leonam
User Off Offline

Zitieren
If the player talk "!English run ingles.lua"
If the player talk "!German run german.lua"

only for the specific player show your language specific

alt Re: Script bridge

Dousea
User Off Offline

Zitieren
I'm being so generous today. I assume that you know the basics of Lua, including string formatting and table, and how the I/O works.

You need to make text files for each language. Here's English.txt:
1
2
3
Language Selection
Welcome, %s!
You pressed button %d!
Here's Indonesian.txt (my language):
1
2
3
Pemilihan Bahasa
Selamat datang, %s!
Anda menekan tombol %d!
They're using the same order for each line. You need to save the text files in the same directory.

Now to load the text files you need to insert the following code.
1
2
3
4
5
6
7
8
9
10
11
12
13
availablelanguages = {"English", "Indonesian"}
languages = {}

for index, language in ipairs(availablelanguages) do
	local file = assert(io.open("<directory-to-your-languages>/" .. language .. ".txt", "r"))
	languages[language] = {}
	local line = 1
	
	for lines in file:lines() do
		languages[language][line] = lines
		line = line + 1
	end
end
You need to replace <directory-to-your-languages> to directory to your languages. By this code you can access each language line by
1
languages["<language>"][<line>]

How do you use the languages? Well, here's an example on how to use the languages.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
local language = {}

for id = 1, 32 do
	language[id] = "English"
end

function joinhook(id)
	msg2(id, languages[language[id]][1]:format(player(id, "name")))
end

function serveractionhook(id, action)
	if (action == 1) then
		menu(id, languages[language[id]][1] .. "," .. table.concat(availablelanguages, ","))
	elseif (action == 2) then
		menu(id, "Menu,1,2,3")
	end
end

function menuhook(id, title, button)
	if (title == languages[language[id]][1]) then
		if (button >= 1 and button <= 9) then
			if (availablelanguages[button]) then
				language[id] = availablelanguages[button]
			end
		end
	if (title == "Menu") then
		if (button >= 1 and button <= 9) then
			msg2(id, languages[language[id]][2]:format(button))
		end
	end
end

for index, hook in ipairs({"join", "serveraction", "menu"}) do
	addhook(hook, hook .. "hook")
end
You can change the language by pressing F2 (default cs2d lua hook serveraction 1) and choose your language. In that example you can only have 9 languages because of CS2D menu limitation.

You can extend them more if you like.
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht