• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

How to make a function for tfs 1.5?

vexler222

Active Member
Joined
Apr 22, 2012
Messages
714
Solutions
15
Reaction score
46
Hi, i make two language datapack, where i can use Polish or English language, and i have question, its possible to make a function short than my actually storage check?

Actually im using it like that:
if player:getStorageValue(language_storage) == 1 then
MESSAGE IN ENGLISH
else
MESSAGE IN POLISH
end

Its possible to make something like this?

if lang_s then
ENGLISH
else
POLISH
end
 
Solution
Or if you prefer even something shorter (based on Gesior answer, combined with what Xikini wrote)

data/lib/core/player.lua
Lua:
function Player.isEnglish(self)
    return self:getStorageValue(language_storage) == 1
end

-- tm stands for translatedMessage
function Player.tm(self, englishText, polishText)
        self:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, (self:isEnglish() and englishText or polishText))
end

Usage:
Lua:
player:tm("English Text", "Polski tekst")

That's the beauty of code - you can always improve ;)
Hi, i make two language datapack, where i can use Polish or English language, and i have question, its possible to make a function short than my actually storage check?

Actually im using it like that:
if player:getStorageValue(language_storage) == 1 then
MESSAGE IN ENGLISH
else
MESSAGE IN POLISH
end

Its possible to make something like this?

if lang_s then
ENGLISH
else
POLISH
end
Whats the point of it? Its the Same at the end or im confused?
 
Whats the point of it? Its the Same at the end or im confused?
yep, but its easy to remember :D My memory is little broken after few years in nederlands so i wanna try something faster and easy to remember and copy/past to next file
i wanna make so easy script/function what i can, for the future ;p To easy use for other people
 
You can add in data/lib/core/player.lua something like:
Code:
function Player.isEnglish(self)
    return self:getStorageValue(language_storage) == 1
end
and then use it this way:
Code:
if player:isEnglish() then
    -- MESSAGE IN ENGLISH
else
    -- MESSAGE IN POLISH
end
 
You can also use the player's storage table to get or set values for storages.
Example:
Lua:
if player.storage[language_storage] == 1 then
    --ENGLISH
else
    --POLISH
end

You can also set values like this:
Lua:
player.storage[language_storage] = 1
 
Combining with Gesior.pl's answer

Lua:
local englishText = "This is some text."
local polishText = "To prawdopodobnie polski tekst."

player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, (player:isEnglish() and englishText or polishText))
 
Or if you prefer even something shorter (based on Gesior answer, combined with what Xikini wrote)

data/lib/core/player.lua
Lua:
function Player.isEnglish(self)
    return self:getStorageValue(language_storage) == 1
end

-- tm stands for translatedMessage
function Player.tm(self, englishText, polishText)
        self:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, (self:isEnglish() and englishText or polishText))
end

Usage:
Lua:
player:tm("English Text", "Polski tekst")

That's the beauty of code - you can always improve ;)
 
Solution
Back
Top