[Cs:s] Players Chat

Please post any questions about developing your plugin here. Please use the search function before posting!
cssbestrpg
Senior Member
Posts: 287
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

[Cs:s] Players Chat

Postby cssbestrpg » Tue Mar 14, 2023 3:29 pm

Hi, i have plugin that modifies players chat, but i noticed small issue with it.
Sometimes when use non english letters like: ö ä å, sometimes the chat changes like:
[New] playername: miss ä sä sit oot töissä but it suppose to show: [New] playername: missä sä sit oot töissä, only appers happens when use once the letter in same word.

The chat modifer uses SayFilter

Syntax: Select all

@SayFilter
def say_filter(command, index, teamonly):
userid = None
if index:
try:
userid = rpglib.useridFromIndex(index)
except ValueError:
userid = None

if userid and command:
text = command[0].replace('!', '', 1).replace('/', '', 1).lower()
args = command.arg_string

name = rpglib.get_name(userid)
return ratinghandler.modified_chat(name, rpglib.getTeam(userid), stattrack.get_player_rating(userid), command[0] + ' ' + args, text)


Ratinghandler code:

Syntax: Select all

import rpglib

# ========================================
# COLORS
# ========================================
if rpglib.gamename() == 'csgo':
team_colors = {
2: '\x0F',
3: '\x0B'
}
else:
team_colors = {
2: '\x07FF3D3D',
3: '\x079BCDFF'
}

title_colors = {
0: 'pale_green',
10: 'green',
255: 'grey',
1115: 'yellow',
3365: 'light_blue',
6785: 'red',
13055: 'orange',
21750: 'white',
40000: 'purple'
}

# ========================================
# RATING TITLES
# ========================================

titles = {
0: 'new',
10: 'trainee',
255: 'silver',
1115: 'gold',
3365: 'diamond',
6785: 'master',
13055: 'insane',
21750: 'heroic',
40000: 'olympic'
}

# ========================================
# METHODS
# ========================================

"""
Chat modifier
"""
def modified_chat(name, team, rating, text, text_command):
chat_string = '{}[{}] {}{}:\x01 {}'.format(get_title_color(rating), get_title(rating), get_team_color(team), name, text)

for i in rpglib.getUseridList():
rpglib.tell(i, chat_string, False, True)

return False


"""
Returns team color
"""
def get_team_color(team):
if team in team_colors:
return team_colors[team]
if rpglib.gamename() == 'csgo':
return '\x08'
else:
return '\x07CDCDCD'

"""
Returns title from given rating
"""
def get_title(rating):
title = 'new'

for i in sorted(titles):
if rating >= i:
title = titles[i]

return title.capitalize()

"""
Returns title color from given rating
"""
def get_title_color(rating):
if rpglib.gamename() == 'csgo':
_color = '\x08'
else:
_color = '\x07CDCDCD'

for i in sorted(title_colors):
if rating >= i:
_color = title_colors[i]

return rpglib.get_chat_color(_color)


Do you have any clue why it splits sometimes a letter when use those certain letters?
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: [Cs:s] Players Chat

Postby L'In20Cible » Wed Mar 15, 2023 10:05 am

Into the following line:
cssbestrpg wrote:

Syntax: Select all

return ratinghandler.modified_chat(name, rpglib.getTeam(userid), stattrack.get_player_rating(userid), command[0] + ' ' + args, text)

This:

Syntax: Select all

command[0] + ' ' + args

Should be:

Syntax: Select all

command.command_string

The engine's tokenizer does not work well with non-ascii characters and will treat any escaped sequences as new arguments. For example:

Syntax: Select all

from commands import Command

c = Command()
c.tokenize('missä sä sit oot töissä')
print('Command.tokenize:', list(c))

"""
Command.tokenize: ['miss', '', '', 's', '', '', 'sit', 'oot', 't', '', 'iss', '', '']
"""

Consider using the core.Tokenize class instead. Example:

Syntax: Select all

from core import Tokenize

print('Tokenize:', list(Tokenize('missä sä sit oot töissä')))

"""
Tokenize: ['missä', 'sä', 'sit', 'oot', 'töissä']
"""
cssbestrpg
Senior Member
Posts: 287
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

Re: [Cs:s] Players Chat

Postby cssbestrpg » Wed Mar 15, 2023 8:21 pm

The core.Tokenize class did the trick.

Is there anything else that can improve of the SayFilter code?
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: [Cs:s] Players Chat

Postby L'In20Cible » Thu Mar 16, 2023 8:09 am

cssbestrpg wrote:Is there anything else that can improve of the SayFilter code?

A lot could be said about your current code, but I won't expand upon it because I don't think a SayFilter is appropriate for the purpose of adding titles to players. I would rather recommend you use a SayText2 hook and override the format with your own while making use of the unused param4 parameter for your titles. For example:

Syntax: Select all

from messages.colors.saytext2 import DARK_BLUE
from messages.hooks import HookUserMessage

CHAT_OVERRIDES = {
'Cstrike_Chat_CT_Loc': '\x01(Counter-Terrorist) %s4 \x03%s1\x01 @ \x04%s3\x01 : %s2',
'Cstrike_Chat_CT': '\x01(Counter-Terrorist) %s4 \x03%s1\x01 : %s2',
'Cstrike_Chat_T_Loc': '\x01(Terrorist) %s4 \x03%s1\x01 @ \x04%s3\x01 : %s2',
'Cstrike_Chat_T': '\x01(Terrorist) %s4 \x03%s1\x01 : %s2',
'Cstrike_Chat_CT_Dead': '\x01*DEAD*(Counter-Terrorist) %s4 \x03%s1\x01 : %s2',
'Cstrike_Chat_T_Dead': '\x01*DEAD*(Terrorist) %s4 \x03%s1\x01 : %s2',
'Cstrike_Chat_Spec': '\x01(Spectator) %s4 \x03%s1\x01 : %s2',
'Cstrike_Chat_All': '\x01%s4 \x03%s1\x01 : %s2',
'Cstrike_Chat_AllDead': '\x01*DEAD* %s4 \x03%s1\x01 : %s2',
'Cstrike_Chat_AllSpec': '\x01*SPEC* %s4 \x03%s1\x01 : %s2'
}

@HookUserMessage('SayText2')
def _(recipients, data):
try:
data.message = CHAT_OVERRIDES[data.message]
except KeyError:
return

# player = Player(data.index)
# username = data.param1
# text = data.param2
# location = data.param3
data.param4 = f'{DARK_BLUE}[TITLE]'

Image

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 39 guests