Initial commit with working implementation

This commit is contained in:
Zenon Seth 2023-11-01 02:51:19 +00:00
commit 8ba3f0db78
4 changed files with 134 additions and 0 deletions

49
LICENSE Normal file
View File

@ -0,0 +1,49 @@
License of source code
----------------------
GNU Lesser General Public License, version 2.1
Copyright (C) 2023-2023 Zenon Seth
This program is free software; you can redistribute it and/or modify it under the terms
of the GNU Lesser General Public License as published by the Free Software Foundation;
either version 2.1 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details:
https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
Licenses of media (textures)
----------------------------
Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0)
Copyright (C) 2023-2023 Zenon Seth
You are free to:
Share — copy and redistribute the material in any medium or format.
Adapt — remix, transform, and build upon the material for any purpose, even commercially.
The licensor cannot revoke these freedoms as long as you follow the license terms.
Under the following terms:
Attribution — You must give appropriate credit, provide a link to the license, and
indicate if changes were made. You may do so in any reasonable manner, but not in any way
that suggests the licensor endorses you or your use.
ShareAlike — If you remix, transform, or build upon the material, you must distribute
your contributions under the same license as the original.
No additional restrictions — You may not apply legal terms or technological measures that
legally restrict others from doing anything the license permits.
Notices:
You do not have to comply with the license for elements of the material in the public
domain or where your use is permitted by an applicable exception or limitation.
No warranties are given. The license may not give you all of the permissions necessary
for your intended use. For example, other rights such as publicity, privacy, or moral
rights may limit how you use the material.
For more details:
http://creativecommons.org/licenses/by-sa/3.0/

76
init.lua Normal file
View File

@ -0,0 +1,76 @@
local shown = {}
local settings = minetest.settings
local MSG_BUBBLE_LIFETIME = tonumber(settings:get("message_bubbles_lifetime")) or 10
local MAX_MSG_BUBBLE_LENGTH = tonumber(settings:get("message_bubbles_char_limit")) or 40
local MSG_BUBBLE_PREFIX = settings:get("message_bubbles_prefix") or "Says: "
local cumulativeTime = 0
local function trim(msg)
if not msg or not type(msg) == "string" then return "" end
if string.len(msg) > MAX_MSG_BUBBLE_LENGTH then
return string.sub(msg, 1, MAX_MSG_BUBBLE_LENGTH)
else
return msg
end
end
minetest.register_on_chat_message(function(name, origMessage)
if minetest.get_player_privs(name).shout then
local player = minetest.get_player_by_name(name)
if not player then return end
local msg = "\n"..MSG_BUBBLE_PREFIX..trim(origMessage)
local nametag = player:get_nametag_attributes()
local nametagText = nametag.text
local hadToAddName = false
if shown[name] then
local currText = shown[name].text
if shown[name].wasEmpty then
shown[name].text = name..msg
shown[name].addedMsg = msg
else
shown[name].text = string.gsub(nametagText, currText, msg)
shown[name].addedMsg = msg
end
shown[name].time = minetest.get_gametime()
else
local addedMsg = msg
if not nametagText or nametagText == "" then
msg = name..msg
hadToAddName = true
end
shown[name] = {
text = msg,
addedMsg = addedMsg,
time = minetest.get_gametime(),
wasEmpty = hadToAddName,
}
end
nametag.text = shown[name].text
player:set_nametag_attributes(nametag)
end
end)
minetest.register_globalstep(function(dtime)
cumulativeTime = cumulativeTime + dtime
if cumulativeTime > 1 then
cumulativeTime = 0
local currTime = minetest.get_gametime()
for playerName, info in pairs(shown) do
if currTime - info.time > MSG_BUBBLE_LIFETIME then
local player = minetest.get_player_by_name(playerName)
if player then
local nametag = player:get_nametag_attributes()
if info.wasEmpty then
nametag.text = ""
else
nametag.text = string.gsub(nametag.text, info.addedMsg, "")
end
player:set_nametag_attributes(nametag)
end
shown[playerName] = nil
end
end
end
end)

5
mod.conf Normal file
View File

@ -0,0 +1,5 @@
name = message_bubbles
min_minetest_version = 5.0
author = ZenonSeth
description = Shows chat messages above player heads
title = Message Bubbles

4
settingtypes.txt Normal file
View File

@ -0,0 +1,4 @@
message_bubbles_lifetime (Lifetime for message bubbles, in seconds) int 10 1 600
message_bubbles_char_limit (Max number of characters to display per message bubble) int 40 5 500
message_bubbles_prefix (Prefix to show before user message bubble) string Says: