Page 1 of 2

mod to highlight when a player joins or leaves?

PostPosted: Tue Jul 03, 2018 01:02
by Joseph16
Is there a mod that will show in highlighted text when a player joins or leaves? I joinded a random MT server earlier and It has that feature. I already look on the forums for a mod but no luck. Any help would be awesome! Thanks!
Screenshot:
Image

Re: mod to highlight when a player joins or leaves?

PostPosted: Tue Jul 03, 2018 08:28
by AspireMint
You can try this powerful csm: https://github.com/doyousketch2/friendly_chat
But might not work correctly on some servers that already has colored chat.

Re: mod to highlight when a player joins or leaves?

PostPosted: Tue Jul 03, 2018 08:35
by Krock
That's IhrFussel's server with custom mods which aren't public. I don't know any mod which currently does this, but implementing it yourself is quite easy:

Solution for Minetest 5.0.0-dev or newer: Overwrite minetest.send_join_message in a new mod
Solution for Minetest 0.4.x (hacky): Edit the builtin code
Local solution for Minetest >= 0.4.16: Write or use a CSM that checks whether the chat line has the default join message format and colorize it locally.

Here you can find the documentation of "minetest.colorize", which makes colorizing messages very easy.

Re: mod to highlight when a player joins or leaves?

PostPosted: Tue Jul 03, 2018 14:36
by Joseph16
Thanks for these answers! I’ll look into them soon.

Re: mod to highlight when a player joins or leaves?

PostPosted: Tue Jul 03, 2018 15:08
by Joseph16
Krock wrote:Local solution for Minetest >= 0.4.16: Write or use a CSM that checks whether the chat line has the default join message format and colorize it locally..

But that wouldn't apply for all clients. Just my client. I'm running a server for my family and some of them are on phones so they can't install CSM's.

Re: mod to highlight when a player joins or leaves?

PostPosted: Tue Jul 03, 2018 16:33
by stormchaser3000
Joseph13 wrote:
Krock wrote:Local solution for Minetest >= 0.4.16: Write or use a CSM that checks whether the chat line has the default join message format and colorize it locally..

But that wouldn't apply for all clients. Just my client. I'm running a server for my family and some of them are on phones so they can't install CSM's.


as far as i know it should be possible to install CSMs on android phones when using the official client. but just to be sure i will do some testing and then edit this post

Re: mod to highlight when a player joins or leaves?

PostPosted: Tue Jul 03, 2018 16:40
by Joseph16
stormchaser3000 wrote:
as far as i know it should be possible to install CSMs on android phones when using the official client. but just to be sure i will do some testing and then edit this post

But they are playing on iOS devices- so as I said CSM’s won’t work. Is there any way to take a CSM mod and put it on the server mods list? Or is that physically impossible?

Re: mod to highlight when a player joins or leaves?

PostPosted: Tue Jul 03, 2018 16:47
by Krock
Joseph13 wrote:
Krock wrote:Local solution for Minetest >= 0.4.16

But that wouldn't apply for all clients. Just my client.

Hence, local solution. Because it only applies to your client.

Joseph13 wrote:But they are playing on iOS devices- so as I said CSM’s won’t work. Is there any way to take a CSM mod and put it on the server mods list? Or is that physically impossible?

They should update to 0.4.16 or newer to make it work. Sending CSMs by the server is yet not possible (not even in 5.0.0-dev, surprise!), so consider using one of the other solutions by writing a SSM (regular mod).

Re: mod to highlight when a player joins or leaves?

PostPosted: Tue Jul 03, 2018 16:52
by Joseph16
Krock wrote: by writing a SSM (regular mod).


I looked into doing it as a normal mod, tried this:
Image
but it gave me an error:
Image
I know I did this completely wrong but is it as simple as this code or is it much harder to make work properly?

Re: mod to highlight when a player joins or leaves?

PostPosted: Tue Jul 03, 2018 16:57
by stormchaser3000
Joseph13 wrote:
stormchaser3000 wrote:
as far as i know it should be possible to install CSMs on android phones when using the official client. but just to be sure i will do some testing and then edit this post

But they are playing on iOS devices- so as I said CSM’s won’t work. Is there any way to take a CSM mod and put it on the server mods list? Or is that physically impossible?


ah i see the problem. also i asked on #minetest on freenode and one of the developers said it is not possible to send CSMs to clients from the server yet. i am sorry to say but minetest is no officially supported on IOS because of the licensing restrictions on the apple app store which would prevent minetest from being put on that store because of the license minetest is licensed under (if i understand correctly). the versions of minetest on the IOS appstore are usually not legal because they break the terms of the LGPL 2.1 (which minetest is licensed under) by not releasing their modified versions of the minetest source code. I am not sure if these IOS clients will ever work with CSMs for 1) because of the restrictions placed on IOS users from apple and 2) because these IOS apps are unofficial and might not properly support CSMs anyway. i wish i could be of better help however i would wait a while to see if anyone else who knows more than me could help.

EDIT: previous edit deleted because i should read everything before posting

Re: mod to highlight when a player joins or leaves?

PostPosted: Tue Jul 03, 2018 17:40
by Joseph16
OK. I already knew about the licensing issues on iOS. And even if it ever did get licensed you couldn't access the file system like you can on android.

Re: mod to highlight when a player joins or leaves?

PostPosted: Tue Jul 03, 2018 17:46
by Joseph16
I guess the main objective is to make a mod that will act very similar to that of IhrFussel's server. Green text, better join/leave message and maybe the time counter(although not really going for that.)
Maybe the owner of IhrFussel's server could PM me and share the details of the mod(maybe even the code? :) )

Re: mod to highlight when a player joins or leaves?

PostPosted: Tue Jul 03, 2018 18:35
by ExeterDad
Joseph... player_list is local to the builtin. So you can't see it with another mod. You need to make your own.
Right before the code posted above add:
Code: Select all
local player_list = {}


I'm at work and unable to test... but I bet it will work for you. But.... it won't override the existing builtin function unless you comment the builtin function out.

Re: mod to highlight when a player joins or leaves?

PostPosted: Tue Jul 03, 2018 18:37
by Joseph16
ExeterDad wrote:Joseph... player_list is local to the builtin. So you can't see it with another mod. You need to make your own.
Right before the code posted above add:
Code: Select all
local player_list = {}


I'm at work and unable to test... but I bet it will work for you. But.... it won't override the existing builtin function unless you comment the builtin function out.

I’ll try it! Thanks!

Re: mod to highlight when a player joins or leaves?

PostPosted: Tue Jul 03, 2018 19:31
by Joseph16
I addd that line and it works - but Minetest still puts the old server messages as well. So when I join my sever it looks like:
Joseph joined the game.
Joseph joined the mod.
The second message being the modded one. I need to disable the old one and change the color of the text. Know how to do both?

Re: mod to highlight when a player joins or leaves?

PostPosted: Tue Jul 03, 2018 20:13
by ExeterDad
Joseph13 wrote:I addd that line and it works - but Minetest still puts the old server messages as well. So when I join my sever it looks like:
Joseph joined the game.
Joseph joined the mod.
The second message being the modded one. I need to disable the old one and change the color of the text. Know how to do both?

This is the hacky part mentioned earlier. You have to disable the code in the builtin file. Not the best way because you will lose your modification when you upgrade. But if you must....
Edit builtin/game/misc.lua
Find:
Code: Select all
core.register_on_joinplayer(function(player)
   local player_name = player:get_player_name()
   player_list[player_name] = player
   if not minetest.is_singleplayer() then
      core.chat_send_all("*** " .. player_name .. " joined the game.")
   end
end)

core.register_on_leaveplayer(function(player, timed_out)
   local player_name = player:get_player_name()
   player_list[player_name] = nil
   local announcement = "*** " ..  player_name .. " left the game."
   if timed_out then
      announcement = announcement .. " (timed out)"
   end
   core.chat_send_all(announcement)
end)

and add a multi line comment to one to stop it from loading.
The second one comments out the announcement, and removes the player from the list that's needed in connected players.
Code: Select all
--[[
core.register_on_joinplayer(function(player)
   local player_name = player:get_player_name()
   player_list[player_name] = player
   if not minetest.is_singleplayer() then
      core.chat_send_all("*** " .. player_name .. " joined the game.")
   end
end)
--]]
core.register_on_leaveplayer(function(player, timed_out)
   local player_name = player:get_player_name()
   player_list[player_name] = nil
--   local announcement = "*** " ..  player_name .. " left the game."
--   if timed_out then
--      announcement = announcement .. " (timed out)"
--   end
--   core.chat_send_all(announcement)
end)

Do not touch the
Code: Select all
local player_list = {}
that's above those two functions. It's needed by core.get_connected_players

Edited to fix my screw up.

Re: mod to highlight when a player joins or leaves?

PostPosted: Tue Jul 03, 2018 20:14
by Joseph16
Tysm!

Re: mod to highlight when a player joins or leaves?

PostPosted: Tue Jul 03, 2018 20:16
by Joseph16
Now to make the text green..

Re: mod to highlight when a player joins or leaves?

PostPosted: Tue Jul 03, 2018 20:16
by ExeterDad
Joseph13 wrote:Tysm!

Wait! Both need not be commented out. I'm editing now.

Re: mod to highlight when a player joins or leaves?

PostPosted: Tue Jul 03, 2018 20:17
by Joseph16
Ok?

Re: mod to highlight when a player joins or leaves?

PostPosted: Tue Jul 03, 2018 20:22
by Joseph16
But it will still show the “player left” messages won’t it?

Re: mod to highlight when a player joins or leaves?

PostPosted: Tue Jul 03, 2018 20:26
by ExeterDad
Joseph13 wrote:But it will still show the “player left” messages won’t it?

No the message part is commented out, but it will still remove their name from the list which must happen.

To change the color to a green, change the needed messages to something like this:
Code: Select all
core.chat_send_all(core.colorize("#2aff00", "*** " .. player_name .. " joined the game100."))
core.chat_send_all(core.colorize("#2aff00", announcement))

In whatever code you posted earlier.

Re: mod to highlight when a player joins or leaves?

PostPosted: Tue Jul 03, 2018 20:29
by Joseph16
Alright! So I can make the “join”messages green and the “leave” messages red or grey!

Re: mod to highlight when a player joins or leaves?

PostPosted: Tue Jul 03, 2018 20:31
by ExeterDad
You can change the color to anything. What's used in my example is hex colors.
https://www.w3schools.com/colors/colors_picker.asp

Re: mod to highlight when a player joins or leaves?

PostPosted: Tue Jul 03, 2018 20:35
by Joseph16
Very good!