Imported from trollstream "ContentDB"

master
OldCoder 2022-09-04 22:01:39 -07:00
commit 44ce6b18dc
7 changed files with 139 additions and 0 deletions

43
README.md Normal file
View File

@ -0,0 +1,43 @@
Title mod
This is a mod inspired by the Minecraft /title command
Install it from the source or from content.minetest.net
---
# Commands
- [/title {playername} set {title/subtitle} {text}](#set command)
- [/title {playername} clear](#clear command)
- [/title {playername} times {time}](#times command)
---
## set command
> params = {playername} set {title/subtitle} {text}
- playername = name of online player you want to show it
- title/subtitle = or title (middle screen) or subtitle (above inv)
- text = the text you want to show
---
## clear command
> params = {playername} clear
- playername = name of online player you want to show it
- clear = remove all
---
## times command
> params = {playername} times {time}
- playername = name of online player you want to show it
- time = the time it needs to stay in miliseconds
---

1
author.txt Normal file
View File

@ -0,0 +1 @@
Miniontoby

5
changelog.txt Normal file
View File

@ -0,0 +1,5 @@
Version 1.1
I created this.
all cmds included

1
depends.txt Normal file
View File

@ -0,0 +1 @@

1
description.txt Normal file
View File

@ -0,0 +1 @@
A mod that shows an HUD Title. Made by "Miniontoby". More info check README.md

66
functions.lua Normal file
View File

@ -0,0 +1,66 @@
local idx = {}
title.clear_hud = function(playername)
local player = minetest.get_player_by_name(playername)
if idx[playername] then
player:hud_remove(idx[playername])
idx[playername] = nil
end
end
title.set_title = function(playername, method, text)
local player = minetest.get_player_by_name(playername)
if not idx[playername] then
if method == "title" then
idx[playername] = player:hud_add({
hud_elem_type = "text",
position = {x = 0.5, y = 0.53},
offset = {x = 0, y = 0},
text = text,
alignment = {x = 0, y = 0},
scale = {x = 100, y = 100},
number = 0x00FF00,
})
elseif method == "subtitle" then
idx[playername] = player:hud_add({
hud_elem_type = "text",
position = {x = 0.5, y = 0.7},
offset = {x = 0, y = 0},
text = text,
alignment = {x = 0, y = 0},
number = 0xFF0000,
})
else
minetest.chat_send_player(playername, "param does not match")
end
end
end
title.set_times = function(playername, stay)
minetest.after(stay, function()
local player = minetest.get_player_by_name(playername)
if idx[playername] then
player:hud_remove(idx[playername])
idx[playername] = nil
end
end)
end
title.decode = function(var)
local t = {}
local test = " "
for i in string.gmatch(var, "%S+") do
test = test .. " " .. i
end
for str in string.gmatch(test, "%S+") do
table.insert(t, str)
end
local username = t[1]
local command = t[2]
local text = " "
local a = 3
while a < #t or a == #t do
text = text .. " " .. t[a]
a = a + 1
end
return username, command, text
end

22
init.lua Normal file
View File

@ -0,0 +1,22 @@
--title mod
title = {}
dofile(minetest.get_modpath("title").."/functions.lua")
minetest.register_chatcommand("title", {
params = "<player> <command> | <player> <method> <text> | <player> <command> <stay>", -- clear | <title¦subtitle> <titleText> | times <fadeIn> <stay> <fadeOut>
description = "shows a title in a players HUD",
func = function(name, param)
local wordsinparam = {}
for word in string.gmatch(param, "[^%s]+") do
table.insert(wordsinparam, word)
end
if wordsinparam[2] == "clear" then
title.clear_hud(wordsinparam[1])
elseif wordsinparam[2] == "times" then
title.set_times(wordsinparam[1], wordsinparam[3])
else
local playername, method, text = title.decode(param)
title.set_title(playername, method, text)
end
end,
})