HL2DM color text

A place for requesting new Source.Python plugins to be made for your server.

Please request only one plugin per thread.
User avatar
daren adler
Senior Member
Posts: 328
Joined: Sat May 18, 2019 7:42 pm

HL2DM color text

Postby daren adler » Wed Oct 28, 2020 8:49 pm

Hello scripters :cool: , I am looking for a color text for chat, every sourcemod or eventscript that ive used has errors or dont work at all, was wondering if someone could make a sp for somthing like that. Like this picture in the bottom left. https://steamuserimages-a.akamaihd.net/ ... 00EBE2D65/ heres the one i use to use https://forums.alliedmods.net/showthread.php?p=2362842 but has errors :mad: :mad:
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: HL2DM color text

Postby satoon101 » Thu Oct 29, 2020 3:01 pm

This might not be exactly what you're looking for, but it's at least a good start:

Syntax: Select all

from random import choice
import colors
from cvars import ConVar
from listeners.tick import Delay
from messages import SayText
from messages.hooks import HookUserMessage
from players.entity import Player


CHAT_STRINGS = {
'HL2MP_Chat_All': '{color}{data.param1}\x01 : {data.param2}',
'HL2MP_Chat_Team': '\x01(Team) {color}{data.param1}\x01 : {data.param2}',
}

# Add any colors not represented in the 'colors' package
CONFIG_COLOR_CHOICES = [
'87CEEB',
]


COLOR_CHOICES = [
str(getattr(colors, color))
for color in dir(colors)
if isinstance(getattr(colors, color), colors.Color)
] + [f'\07{color}' for color in CONFIG_COLOR_CHOICES]


@HookUserMessage('SayText2')
def _saytext2_hook(recipients, data):
if int(ConVar('mp_teamplay')):
return

key = data.message
if key not in CHAT_STRINGS:
return

Delay(
0,
_send_new_message,
(key, data.index, list(recipients)),
{
'data': data,
'color': choice(COLOR_CHOICES)
}
)
recipients.remove_all_players()


def _send_new_message(key, index, *ply_indexes, **tokens):
"""Send the message to the given players."""
message = SayText(
message=CHAT_STRINGS[key],
index=index,
)
message.send(*ply_indexes, **tokens)
Image
User avatar
daren adler
Senior Member
Posts: 328
Joined: Sat May 18, 2019 7:42 pm

Re: HL2DM color text

Postby daren adler » Thu Oct 29, 2020 3:43 pm

OK, Thank you :grin: I will give it a try :cool: Just tryed it and got this

Code: Select all

2020-10-29 10:46:35 - sp   -   MESSAGE   [SP] Loading plugin 'colors'...
2020-10-29 10:46:35 - sp   -   EXCEPTION   
[SP] Caught an Exception:
Traceback (most recent call last):
  File "..\addons\source-python\packages\source-python\plugins\command.py", line 164, in load_plugin
    plugin = self.manager.load(plugin_name)
  File "..\addons\source-python\packages\source-python\plugins\manager.py", line 180, in load
    spec = find_spec(plugin.import_name)

AttributeError: module 'colors' has no attribute '__path__'
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: HL2DM color text

Postby satoon101 » Thu Oct 29, 2020 3:55 pm

Don't call the plugin 'colors'. There's a package called 'colors' inside SP itself, which is what is imported and causing that error.
Image
User avatar
daren adler
Senior Member
Posts: 328
Joined: Sat May 18, 2019 7:42 pm

Re: HL2DM color text

Postby daren adler » Thu Oct 29, 2020 4:52 pm

satoon101 wrote:Don't call the plugin 'colors'. There's a package called 'colors' inside SP itself, which is what is imported and causing that error.

works :smile: :smile: . thank you :cool:
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: HL2DM color text

Postby Ayuto » Fri Oct 30, 2020 8:23 am

satoon101 wrote:Don't call the plugin 'colors'. There's a package called 'colors' inside SP itself, which is what is imported and causing that error.

I thought we would have a check for that in the plug-in loading logic :confused:
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: HL2DM color text

Postby L'In20Cible » Fri Oct 30, 2020 9:41 am

Ayuto wrote:
satoon101 wrote:Don't call the plugin 'colors'. There's a package called 'colors' inside SP itself, which is what is imported and causing that error.

I thought we would have a check for that in the plug-in loading logic :confused:

We do, but it will only catch packages not modules because we internally lookup the spec of colors.colors instead of colors so importlib tries to resolve the colors module from the colors package but since colors is a module it fails to retrieve its __path__ which produce the exception above. For example, os is a module:

Syntax: Select all

sp plugin load os
[SP] Loading plugin 'os'...

[SP] Caught an Exception:
Traceback (most recent call last):
File "..\addons\source-python\packages\source-python\plugins\command.py", line 164, in load_plugin
plugin = self.manager.load(plugin_name)
File "..\addons\source-python\packages\source-python\plugins\manager.py", line 180, in load
spec = find_spec(plugin.import_name)

AttributeError: module 'os' has no attribute '__path__'


And asyncio is a package:

Syntax: Select all

sp plugin load asyncio
[SP] Loading plugin 'asyncio'...
[SP] Cannot load plugin 'asyncio'. Plugin name cannot be name of a built-in module


An easy fix would be to replace ../plugins/manager.py#L180-L184 with something such as:

Syntax: Select all

spec = find_spec(plugin_name)
if spec is not None and (
spec.origin != 'namespace' and
Path(spec.origin).parent != plugin.file_path.parent):
raise PluginHasBuiltInName(
'Plugin "{}" has the name of a built-in module.'.format(
plugin_name))
User avatar
daren adler
Senior Member
Posts: 328
Joined: Sat May 18, 2019 7:42 pm

Re: HL2DM color text

Postby daren adler » Sun Nov 01, 2020 3:51 am

I get this error on here, it dont say culurs (colors) script, but if i remove the culurs i get no errors, sorry if i am wrong.

Code: Select all

2020-10-31 22:32:46 - sp   -   MESSAGE   [SP] Loading plugin 'alpha_props'...
2020-10-31 22:32:46 - sp   -   MESSAGE   [SP] Successfully loaded plugin 'alpha_props'.
2020-10-31 22:32:46 - sp   -   MESSAGE   [SP] Loading plugin 'culurs'...
2020-10-31 22:32:46 - sp   -   MESSAGE   [SP] Successfully loaded plugin 'culurs'.
2020-10-31 22:32:46 - sp   -   MESSAGE   [SP] Loading plugin 'fiery_bolts'...
2020-10-31 22:32:46 - sp   -   MESSAGE   [SP] Successfully loaded plugin 'fiery_bolts'.
2020-10-31 22:32:46 - sp   -   MESSAGE   [SP] Loading plugin 'npc_points'...
2020-10-31 22:32:46 - sp   -   MESSAGE   [SP] Successfully loaded plugin 'npc_points'.
2020-10-31 22:32:46 - sp   -   MESSAGE   [SP] Loading plugin 'sawblade_trail'...
2020-10-31 22:32:46 - sp   -   MESSAGE   [SP] Successfully loaded plugin 'sawblade_trail'.
2020-10-31 22:32:46 - sp   -   MESSAGE   [SP] Loading plugin 'silent_hill'...
2020-10-31 22:32:46 - sp   -   MESSAGE   [SP] Successfully loaded plugin 'silent_hill'.
2020-10-31 22:32:46 - sp   -   MESSAGE   [SP] Loading plugin 'temp_scanner'...
2020-10-31 22:32:46 - sp   -   MESSAGE   [SP] Successfully loaded plugin 'temp_scanner'.
2020-10-31 22:32:46 - sp   -   MESSAGE   [SP] Loading plugin 'throwables'...
2020-10-31 22:32:46 - sp   -   MESSAGE   [SP] Successfully loaded plugin 'throwables'.
2020-10-31 22:44:54 - sp   -   EXCEPTION   
[SP] Caught an Exception:
Traceback (most recent call last):
  File "..\addons\source-python\packages\source-python\messages\hooks.py", line 273, in _pre_message_end
    data = impl.read(buffer_read)
  File "..\addons\source-python\packages\source-python\messages\impl.py", line 112, in read
    return cls.read_bitbuffer(buffer)
  File "..\addons\source-python\packages\source-python\messages\impl.py", line 159, in read_bitbuffer
    param2=buffer.read_string(),

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe2 in position 21: invalid continuation byte

Return to “Plugin Requests”

Who is online

Users browsing this forum: No registered users and 21 guests