Skip to content

Commit 405289b

Browse files
Merge pull request #1 from SpaceBuddy231/improve-welcome-message-6318945189728686045
Improve WelcomeMessage Plugin with Hints, Delay, and Random Messages
2 parents c132cc2 + 3b5c494 commit 405289b

File tree

2 files changed

+81
-54
lines changed

2 files changed

+81
-54
lines changed

SB_WelcomeMessage/Config.cs

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
1-
using System.ComponentModel;
2-
3-
namespace SB_WelcomeMessage
4-
{
5-
public class Config
6-
{
7-
[Description("just de/activates the plugin")]
8-
public bool wlcAct { get; set; } = true;
9-
10-
[Description("Join message delay")]
11-
public int JoinMessageDelay { get; set; } = 5;
12-
13-
[Description("Join Message Text ({name} specifies the name of the joining player). For Rich Text Editing you can use this Guide -> https://sites.google.com/view/scpsl-config/unity-rich-text")]
14-
public string JoinMessage { get; set; } = "<b><color=#E8002A>Welcome on the YOUR COMMUNITY NAME Community</color>,</b> <i><color=#EB0079>{name}</color></i><b>!</b>";
15-
}
16-
}
1+
using System.Collections.Generic;
2+
using System.ComponentModel;
3+
4+
namespace SB_WelcomeMessage
5+
{
6+
public class Config
7+
{
8+
[Description("Is the plugin enabled?")]
9+
public bool IsEnabled { get; set; } = true;
10+
11+
[Description("Delay in seconds before sending the message after the player joins.")]
12+
public float Delay { get; set; } = 2.0f;
13+
14+
[Description("Duration in seconds for the message to be displayed.")]
15+
public ushort Duration { get; set; } = 5;
16+
17+
[Description("If true, sends a Hint instead of a Broadcast.")]
18+
public bool UseHint { get; set; } = false;
19+
20+
[Description("List of Join Messages. One is chosen randomly. ({name} = player name, {userId} = player UserID). For Rich Text Editing see: https://sites.google.com/view/scpsl-config/unity-rich-text")]
21+
public List<string> JoinMessages { get; set; } = new List<string>
22+
{
23+
"<b><color=#E8002A>Welcome to the YOUR COMMUNITY NAME Community</color>,</b> <i><color=#EB0079>{name}</color></i><b>!</b>"
24+
};
25+
}
26+
}

SB_WelcomeMessage/Plugin.cs

Lines changed: 55 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,55 @@
1-
using PluginAPI.Core;
2-
using PluginAPI.Core.Attributes;
3-
using PluginAPI.Enums;
4-
using FormatWith;
5-
6-
namespace SB_WelcomeMessage
7-
{
8-
public class Plugin
9-
{
10-
public static Plugin Singleton;
11-
12-
[PluginConfig] public Config Config;
13-
14-
public const string Version = "1.0.0";
15-
16-
[PluginPriority(LoadPriority.Highest)]
17-
[PluginEntryPoint("JoinMessage-System", Version, "Shows a Broadcast Message in the top of the Screen of the joining player.", "SpaceBuddy")]
18-
void LoadPlugin()
19-
{
20-
Singleton = this;
21-
PluginAPI.Events.EventManager.RegisterEvents(this);
22-
}
23-
24-
[PluginEvent(ServerEventType.PlayerJoined)]
25-
26-
public void OnPlayerJoin(Player player)
27-
{
28-
if (Config.wlcAct)
29-
{
30-
string JoinText = Config.JoinMessage.FormatWith(new
31-
{
32-
name = player.Nickname
33-
});
34-
player.SendBroadcast(JoinText, (ushort)Config.JoinMessageDelay);
35-
}
36-
}
37-
}
38-
}
1+
using PluginAPI.Core;
2+
using PluginAPI.Core.Attributes;
3+
using PluginAPI.Enums;
4+
using FormatWith;
5+
using MEC;
6+
7+
namespace SB_WelcomeMessage
8+
{
9+
public class Plugin
10+
{
11+
public static Plugin Singleton;
12+
13+
[PluginConfig] public Config Config;
14+
15+
public const string Version = "1.1.0";
16+
17+
[PluginPriority(LoadPriority.Highest)]
18+
[PluginEntryPoint("JoinMessage-System", Version, "Shows a Broadcast Message or Hint in the top/bottom of the Screen of the joining player.", "SpaceBuddy")]
19+
void LoadPlugin()
20+
{
21+
Singleton = this;
22+
PluginAPI.Events.EventManager.RegisterEvents(this);
23+
}
24+
25+
[PluginEvent(ServerEventType.PlayerJoined)]
26+
public void OnPlayerJoin(Player player)
27+
{
28+
if (!Config.IsEnabled || Config.JoinMessages == null || Config.JoinMessages.Count == 0)
29+
return;
30+
31+
Timing.CallDelayed(Config.Delay, () =>
32+
{
33+
// Verify player still exists and is connected
34+
if (player == null || !player.GameObject) return;
35+
36+
string rawMessage = Config.JoinMessages[UnityEngine.Random.Range(0, Config.JoinMessages.Count)];
37+
38+
string joinText = rawMessage.FormatWith(new
39+
{
40+
name = player.Nickname,
41+
userId = player.UserId
42+
});
43+
44+
if (Config.UseHint)
45+
{
46+
player.ReceiveHint(joinText, Config.Duration);
47+
}
48+
else
49+
{
50+
player.SendBroadcast(joinText, Config.Duration);
51+
}
52+
});
53+
}
54+
}
55+
}

0 commit comments

Comments
 (0)