Various changes and improvements (#2)

- Short and improve the code
- Use `mod.conf` for description
    - Deletes deprecated `description.txt`.
- Improve `readme.md`.
This commit is contained in:
David Leal 2019-11-17 02:16:21 -06:00 committed by SmallJoker
parent fb65f03201
commit a39f4f9482
4 changed files with 107 additions and 121 deletions

View File

@ -1 +0,0 @@
A mod which allows players to change the colour of their nametags

162
init.lua
View File

@ -1,132 +1,80 @@
local colors = {
green = {r = 0, g = 255, b = 0},
blue = {r = 0, g = 0, b = 255},
red = {r = 255, g = 0, b = 0},
purple = {r = 200, g = 0, b = 200},
yellow = {r = 255, g = 255, b = 0},
cyan = {r = 0, g = 255, b = 255},
white = {r = 255, g = 255, b = 255},
orange = {r = 255, g = 165, b = 0},
black = {r = 0, g = 0, b = 0},
}
-- Register command to allow players to colour their nametag
minetest.register_chatcommand("nametag",{
params = "<New Colour>",
description = "Alows a player to set a coloured nametag! This can either have a new colour as a param, or it can be used by itself to bring up a formspec.",
params = "<color>",
description = "Allows players to colour their nametag. Type /nametag to see available colors",
privs = {shout = true},
func = function(user, param)
local player = minetest.get_player_by_name(user)
param = param:lower()
if param == "" then
minetest.chat_send_player(user, "Showing formspec...")
minetest.after(1, function()
minetest.show_formspec(user, "name-colours",
"size[8.5,4.5]"..
"label[0.25,0.5;Please select the colour you want your nametag to be:]"..
"button_exit[0.25,1.5;2.5,0.5;green;Green]"..
"button_exit[3,1.5;2.5,0.5;blue;Blue]"..
"button_exit[5.75,1.5;2.5,0.5;red;Red]"..
"button_exit[0.25,2.5;2.5,0.5;purple;Purple]"..
"button_exit[3,2.5;2.5,0.5;yellow;Yellow]"..
"button_exit[5.75,2.5;2.5,0.5;cyan;Cyan]"..
"button_exit[0.25,3.5;2.5,0.5;white;White]"..
"button_exit[3,3.5;2.5,0.5;orange;Orange]"..
"button_exit[5.75,3.5;2.5,0.5;black;Black]"
)
end)
elseif param == "green" then
minetest.after(1, minetest.show_formspec, user, "name-colours",
"size[8.5,4.5]"..
"label[0.25,0.5;Choose a color:]"..
"button_exit[0.25,1.5;2.5,0.5;green;Green]"..
"button_exit[3,1.5;2.5,0.5;blue;Blue]"..
"button_exit[5.75,1.5;2.5,0.5;red;Red]"..
"button_exit[0.25,2.5;2.5,0.5;purple;Purple]"..
"button_exit[3,2.5;2.5,0.5;yellow;Yellow]"..
"button_exit[5.75,2.5;2.5,0.5;cyan;Cyan]"..
"button_exit[0.25,3.5;2.5,0.5;white;White]"..
"button_exit[3,3.5;2.5,0.5;orange;Orange]"..
"button_exit[5.75,3.5;2.5,0.5;black;Black]"
)
elseif colors[param] then
local player = minetest.get_player_by_name(user)
player:set_nametag_attributes({
color = {r = 0, g = 255, b = 0}
color = colors[param]
})
minetest.chat_send_player(user, "Your nametag colour has been set to " ..param)
elseif param == "blue" then
player:set_nametag_attributes({
color = {r = 0, g = 0, b = 255}
})
minetest.chat_send_player(user, "Your nametag colour has been set to " ..param)
elseif param == "red" then
player:set_nametag_attributes({
color = {r = 255, g = 0, b = 0}
})
minetest.chat_send_player(user, "Your nametag colour has been set to " ..param)
elseif param == "purple" then
player:set_nametag_attributes({
color = {r = 200, g = 0, b = 200}
})
minetest.chat_send_player(user, "Your nametag colour has been set to " ..param)
elseif param == "yellow" then
player:set_nametag_attributes({
color = {r = 255, g = 255, b = 0}
})
minetest.chat_send_player(user, "Your nametag colour has been set to " ..param)
elseif param == "cyan" then
player:set_nametag_attributes({
color = {r = 0, g = 255, b = 255}
})
minetest.chat_send_player(user, "Your nametag colour has been set to " ..param)
elseif param == "white" then
player:set_nametag_attributes({
color = {r = 255, g = 255, b = 255}
})
minetest.chat_send_player(user, "Your nametag colour has been set to " ..param)
elseif param == "orange" then
player:set_nametag_attributes({
color = {r = 255, g = 165, b = 0}
})
minetest.chat_send_player(user, "Your nametag colour has been set to " ..param)
elseif param == "black" then
player:set_nametag_attributes({
color = {r = 0, g = 0, b = 0}
})
minetest.chat_send_player(user, "Your nametag colour has been set to " ..param)
else
minetest.chat_send_player(user, "Incorrect Color! If you don't know what colours are avalible, just use /nametag without an option after it.")
return true, "Your nametag color has been set to: " .. param
end
return false, "Invalid usage, see /help nametag"
end
})
minetest.register_chatcommand("nametag-custom", {
params = "<Red Value> <Green Value> <Blue Value>",
description = "Change the colour of a nametage to a custom colour (in RGB Format)",
-- Customized RGB-format color
minetest.register_chatcommand("custom-nametag", {
params = "<red> <green> <blue>",
description = "Customizable-nametag color",
privs = {nametag = true},
func = function(user, param)
local found, _, redValue, greenValue, blueValue = param:find("^([^%s]+)%s+(.+)%s+(.+)$")
if not found then
minetest.chat_send_player(user, "Not enough Arguments!")
return
return false, "Invalid usage, see /help custom-nametag"
end
local player = minetest.get_player_by_name(user)
player:set_nametag_attributes({
color = {r = redValue, g = greenValue, b = blueValue}
})
minetest.chat_send_player(user, "Your nametag colour has been set to the RBG value of " ..redValue .. ", " .. greenValue .. ", " .. blueValue)
return true, "Your nametag color has been set to the value of: " ..
redValue .. ", " .. greenValue .. ", " .. blueValue
end
})
minetest.register_on_player_receive_fields(function(player, formname, fields)
if formname ~= "name-colours" then return end
if fields.green then
player:set_nametag_attributes({
color = {r = 0, g = 255, b = 0}
})
elseif fields.blue then
player:set_nametag_attributes({
color = {r = 0, g = 0, b = 255}
})
elseif fields.red then
player:set_nametag_attributes({
color = {r = 255, g = 0, b = 0}
})
elseif fields.purple then
player:set_nametag_attributes({
color = {r = 200, g = 0, b = 200}
})
elseif fields.yellow then
player:set_nametag_attributes({
color = {r = 255, g = 255, b = 0}
})
elseif fields.cyan then
player:set_nametag_attributes({
color = {r = 0, g = 255, b = 255}
})
elseif fields.white then
player:set_nametag_attributes({
color = {r = 255, g = 255, b = 255}
})
elseif fields.orange then
player:set_nametag_attributes({
color = {r = 255, g = 165, b = 0}
})
elseif fields.black then
player:set_nametag_attributes({
color = {r = 0, g = 0, b = 0}
})
end
for key, value in pairs(colors) do
if fields[key] then
player:set_nametag_attributes({
color = colors[key]
})
end
end
end)
-- Log
if minetest.settings:get_bool("log_mods") then
minetest.log("action", ("[MOD] Coloured nametag loaded"))
end

View File

@ -1 +1,2 @@
name = coloured_nametag
description = Allows players to change the colour of their nametags.

View File

@ -1,23 +1,61 @@
##Coloured Nametag: A mod for Minetest!
This mod allows players to set their nametag to a colour of their choice.
# Coloured Nametag
####Usage and effects:
The usage of this mod is very simple. Once it has been installed, players on the server can use the /nametag command to bring up a formspec, on which they can select a colour, out of red, green, blue, purple, yellow, cyan, white, orange and black. The player's nametag then gets set to that colour! However, this has to be done on every log in, I still need to find a simple way of preserving the nametag colour between logins.
This mod allows players to set their nametag to a color of their choice.
If you prefer, you can add the colour you want (out of the ones listed above) as a param to the /nametag command, which dispenses with the need to use the formspec.
## Getting started
If you want to get creative, you can use the command /nametag-custom with three values (RGB) between 1 and 255 to set your nametag to any colour you like!
**Warning:** This mod is useless in singleplayer (even with F7, nametag isn't visible).
Just to warn you: This mod is totally and utterly useless in singleplayer! (Even with f7, the nametag isn't visible.)
Use `/nametag` to change your nametag color.
A formspec will be opened, so, you can choose a color.
####ToDo:
You can use parameters to set a color, too.
For example, use
/nametag blue
to set your nametag to color blue.
Players can also change their color to their like using `/custom-nametag` in the RGB format (between 1 and 255).
## Requirements
Latest commit of Coloured Nametag requires MT 5.0.0+ to work.
[`fb65f03`](https://github.com/minetest-mods/coloured_nametag/commit/fb65f032011230974e36713d24a51c821c0df68d) is the latest commit supporting MT/MTG 0.4.14+.
## Dependencies
None yet.
### Optional dependencies
None yet.
## Installation
- Unzip the archive, rename the folder to `coloured_nametag` and
place it in .. minetest/mods/
- GNU/Linux: If you use a system-wide installation place
it in ~/.minetest/mods/.
- If you only want this to be used in a single world, place
the folder in .. worldmods/ in your world directory.
For further information or help, see:
https://wiki.minetest.net/Installing_Mods
## Issues, suggestions, features & bugfixes.
Report bugs or suggest ideas by [creating an issue](https://github.com/minetest-mods/coloured_nametag/issues/new).
If you know how to fix an issue, or want something to be added, consider opening a [pull request](https://github.com/minetest-mods/coloured_nametag/compare).
## Credits:
Special thanks to Chanku/Sapein.
## To Do:
* Make the nametag colours preserve over reboot.
* Make the mod more customisable.
* Maybe make the formspec a little more colourful.
* Maybe make a second page of colours?
###Credits:
Thanks to Chanku/Sapein for the option of using a param to set the colour, and for the custom colour nametag command.
###License:
Everything in this mod is licensed under MIT.
## License:
Copyright (C) Amaz1 2015-2016.
See [`license.txt`](/license.txt) for more information.