Adding functionality

master
Jean 2019-03-12 14:22:13 +01:00
parent 1ea4746b35
commit 0f99849808
3 changed files with 71 additions and 1 deletions

View File

@ -1 +1,8 @@
minetest_ads
# Mintest Mod: ads
This Mod shows messages you can define in a defined interval (default: 15 Minutes). It can be configured in different languages. Suitable for servers
# Configuring:
In the `init.lua` file you can define the languages, messages and the interval between the messages. The changes will apear after an restart of the server.
with `/ads_language <language>` every player can decide in which language your configured ads will be shown. The default is the second one (english) *you will understand that better, when you look in the init.lua file*

60
init.lua Normal file
View File

@ -0,0 +1,60 @@
-- If you want only use one language, then use the second language (ads_table_2) This is the default one
local FIRST_LANGAUGE = "de"
local SECOND_LANGUAGE = "en"
local INTERVAL = 900 -- In Seconds
-- Here you can define your ads. Of course you can define more as three messages. Just duplicat the second line ;)
local ads_table_1 = {"Erste Werbeanzeige!",
"Zweite Werbeanzeige!",
"Dritte Werbeanzeige!"}
local ads_table_2 = {"Your first ad",
"Your second ad!",
"Your third ad!"}
local counter = 0
local delta = 0
-- define language command Command
minetest.register_chatcommand("ads_language", {
func = function(name, param)
local player = minetest.get_player_by_name(name)
local meta = player:get_meta()
-- Change here the languages of the messages!
if param == FIRST_LANGAUGE then
meta:set_string("ads_language", param)
minetest.chat_send_player(name, "Sprache wurde erfolgreich gesetzt. Nicht alle Inhalte sind aber leider in deutsch!")
elseif param == SECOND_LANGUAGE then
meta:set_string("ads_language", param)
minetest.chat_send_player(name, "Language successfully defined")
else
-- Here you can change the "not found" message:
minetest.chat_send_player(name, "Language not found! Available Languages: de, en")
end
end
})
minetest.register_globalstep(function(dtime)
if delta > INTERVAL then
counter = counter + 1
if counter > tablelength(ads_table_2) then
counter = 1
end
-- minetest.chat_send_player("LinuxGuides", counter)
for _, player in pairs(minetest.get_connected_players()) do
pmeta = player:get_meta()
if pmeta:get_string("ads_language") == FIRST_LANGAUGE then
minetest.chat_send_player(player:get_player_name(), ads_table_1[counter])
else
minetest.chat_send_player(player:get_player_name(), ads_table_2[counter])
end
end
delta = 0
else
delta = delta + dtime
end
end)
-- Helper:
function tablelength(T)
local count = 0
for _ in pairs(T) do count = count + 1 end
return count
end

3
mod.conf Normal file
View File

@ -0,0 +1,3 @@
name = ads
description = Minetest Ad-Mod for minetest servers with language support.
depends = default