In game chat
#1
Dear people,

I use this addon -> Permission plugin now what I want is that when it detects that you are an Admin in the server the chat color is red, when it detects it's a moderator the chat color is blue. If it is possible at all what I ask it would be cool if you can make something like this too [Mod] Playername: text here

I've no idea if this is possible but if you could create this it would be amazing!!
Reply

#2
Don't think it'll be possible just do ^5/4 for talking as a moderator and ^1 as an admin. Not so hard.
Do not take life too seriously. You will never get out of it alive.
[Image: UGPjFJa.jpg]
Reply

#3
[code=csharp]
using System;
using System.Collections.Generic;
using Addon;
using System.Text;

namespace ClassLibrary1
{
public class Class1:CPlugin
{
List<string> Admins = new List<string>();
List<string> Moderators = new List<string>();

public override void OnServerLoad()
{
ServerPrint("ChatPlugin by 8Q4S8 loaded!");

string admin = GetServerCFG("Permission", "Admin_xuids", "");
string[] admins = admin.Split(',');

string mod = GetServerCFG("Permission", "Moderator_xuids", "");
string[] mods = mod.Split(',');

foreach (string xuid in admins)
{
Admins.Add(xuid);
}
foreach (string xuid in mods)
{
Moderators.Add(xuid);
}
}
public override ChatType OnSay(string Message, ServerClient Client)
{
if (!Message.StartsWith("!"))
{
if (Admins.Contains(Client.XUID))
{
ServerSay("^1[Admin] ^8" + Client.Name + "^7:^1 " + Message, true);
return ChatType.ChatNone;
}
if (Moderators.Contains(Client.XUID))
{
ServerSay("^1[Mod] ^7" + Client.Name + "^7:^4 " + Message, true);
return ChatType.ChatNone;
}
}
return ChatType.ChatContinue;
}
}
}
[/code]

I was too lazy to add sv_config stuff, feel free to edit the code.


Attached Files
.zip   ChatPlugin.zip (Size: 2.19 KB / Downloads: 44)
Reply

#4
Thank you soo much! (:
Reply

#5
There's a little bug in the plugin but I couldn't find a fix. The problem is that the chat doesn't get hid if a mod talks, for admins it's working fine. I use the code that I posted above so if you find the bug please tell me.
Reply

#6
(04-24-2013, 19:03)8q4s8 Wrote: There's a little bug in the plugin but I couldn't find a fix. The problem is that the chat doesn't get hid if a mod talks, for admins it's working fine. I use the code that I posted above so if you find the bug please tell me.

Try to add 'else'.
C++/Obj-Cdeveloper. Neko engine wip
Steam: Click
Reply

#7
(04-24-2013, 19:14)SailorMoon Wrote:
(04-24-2013, 19:03)8q4s8 Wrote: There's a little bug in the plugin but I couldn't find a fix. The problem is that the chat doesn't get hid if a mod talks, for admins it's working fine. I use the code that I posted above so if you find the bug please tell me.

Try to add 'else'.

I already tried it, it doesn't work
Reply

#8
Try to use Dictionary?

Also try to make sleeping between two foreaches, problem may be there.
C++/Obj-Cdeveloper. Neko engine wip
Steam: Click
Reply

#9
Ok I finally found the bug! It wasn't in my plugin actually, it was in the permission plugin:

[code=csharp]
if (userIsInGroup != "Admin")
{
if (!lowMsg.StartsWith("!"))
return ChatType.ChatAll;
[/code]

return ChatType.ChatAll;

I replaced it with ChatContinue and it worked! Also I added a few more functions:

!chat - disable all the tags
!toggletag - enables/disables your tag

[code=csharp]
using System;
using System.Collections.Generic;
using Addon;
using System.Text;

namespace ClassLibrary1
{
public class Class1:CPlugin
{
Dictionary<string, string> xuids = new Dictionary<string, string>();
bool togglechat = false;
Dictionary<string, bool> chat = new Dictionary<string, bool>();

public override void OnServerLoad()
{
ServerPrint("ChatPlugin by 8Q4S8 loaded!");

string admin = GetServerCFG("Permission", "Admin_xuids", "");
string[] admins = admin.Split(',');

string mod = GetServerCFG("Permission", "Moderator_xuids", "");
string[] mods = mod.Split(',');

foreach (string xuid in mods)
{
xuids.Add(xuid, "Mod");
}

foreach (string xuidz in admins)
{
xuids.Add(xuidz, "Admin");
}
}
public override ChatType OnSay(string Message, ServerClient Client)
{
if (!Message.StartsWith("!") && togglechat == false && chat[Client.XUID] == false)
{
if (xuids.ContainsKey(Client.XUID))
{
ServerSay("^1[" + xuids[Client.XUID]+ "] ^8" + Client.Name + "^7:^1 " + Message, true);
return ChatType.ChatNone;
}
}
if (Message.ToLower() == "!chat")
{
togglechat = !togglechat;
return ChatType.ChatNone;
}
if (Message.ToLower() == "!toggletag")
{
chat[Client.XUID] = !chat[Client.XUID];
return ChatType.ChatNone;
}
return ChatType.ChatContinue;
}
public override void OnPlayerConnect(ServerClient Client)
{
chat.Add(Client.XUID, false);
}
public override void OnPlayerDisconnect(ServerClient Client)
{
chat.Remove(Client.XUID);
}
}
}
[/code]

You can also change the code back to the version with List<>, it should work too.
I also attached the edited permission plugin, credits for that go obviously to @Pozzuh


Attached Files
.zip   ChatPlugin.zip (Size: 5.5 KB / Downloads: 52)
Reply

#10
[code=csharp]
if (xuids.ContainsKey(Client.XUID))
{
ServerSay("^1[" + xuids[Client.XUID]+ "] ^8" + Client.Name + "^7:^1 " + Message, true);
return ChatType.ChatNone;
}
}
if (Message.ToLower() == "!chat")
{
togglechat = !togglechat;
return ChatType.ChatNone;
}[/code]

I still can't figure it out why the first return ChatType.ChatNone; does not work under ServerSay("^1[" + xuids[Client.XUID]+ "] ^8" + Client.Name + "^7:^1 " + Message, true);

but the second return ChatType.ChatNone; works fine..
8q4s8 told me that another plugin might cause the problem, but I removed all the plugins and tested it, it still does not work - anyone that can help me out? I really don't know what is wrong :/
Reply



Possibly Related Threads…
Thread Author Replies Views Last Post
  What game have you bought in the last week? RaZ 12 12,271 12-05-2013, 16:29
Last Post: Nekochan
  [GAME]The Letter Game Bandarigoda123 65 43,055 08-08-2013, 21:05
Last Post: AZUMIKKEL
  [Release] AntiRage for Infected Game Mode yokai134 17 19,842 08-04-2013, 22:22
Last Post: yokai134
  ESTRANGED best indie game I've seen so far Arteq 0 3,842 08-03-2013, 14:03
Last Post: Arteq
  how to remove commands in the chat ExoGamer* 6 6,572 07-20-2013, 09:24
Last Post: Pozzuh
  [HELP] bo2 - FD1 - dis-attach the console from the game masis 8 7,976 07-17-2013, 23:01
Last Post: surtek
Smile [Release] Map & Game Type Changer Plugin (Fixed) 30mba 31 28,993 07-10-2013, 16:27
Last Post: 26hz
  [Request] Names, Chat and Scoreboard Mibbix 6 6,606 06-21-2013, 22:16
Last Post: Mibbix
  Selling steam account for a game! Strentin 3 5,729 06-18-2013, 07:49
Last Post: xfxtroll
  Help Using chat outside in game Bandarigoda123 1 4,176 06-09-2013, 12:46
Last Post: Nekochan

Forum Jump:


Users browsing this thread:
1 Guest(s)

Forum Powered By MyBB, Theme by © 2002-2026 Melroy van den Berg.