Page 1 of 1
HL2DM color text
Posted: Wed Oct 28, 2020 8:49 pm
by daren adler
Hello scripters

, 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

Re: HL2DM color text
Posted: Thu Oct 29, 2020 3:01 pm
by satoon101
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)
Re: HL2DM color text
Posted: Thu Oct 29, 2020 3:43 pm
by daren adler
OK, Thank you

I will give it a try

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__'
Re: HL2DM color text
Posted: Thu Oct 29, 2020 3:55 pm
by satoon101
Don't call the plugin 'colors'. There's a package called 'colors' inside SP itself, which is what is imported and causing that error.
Re: HL2DM color text
Posted: Thu Oct 29, 2020 4:52 pm
by daren adler
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

. thank you

Re: HL2DM color text
Posted: Fri Oct 30, 2020 8:23 am
by Ayuto
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

Re: HL2DM color text
Posted: Fri Oct 30, 2020 9:41 am
by L'In20Cible
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

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))
Re: HL2DM color text
Posted: Sun Nov 01, 2020 3:51 am
by daren adler
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