Page 1 of 1

CSS: Moderator, connect/disconnect show

Posted: Tue Nov 29, 2022 7:36 am
by yakuza
Good afternoon! I wrote a plugin but it doesn't work, what's my mistake? I'm just learning, please don't swear

Syntax: Select all

# -*- coding: utf-8 -*-
from events import Event
from messages import SayText2

moderator = {'[U:1:81936084]':'МЕДОЕД', 'uniqueid':'test'}

def load():
SayText2('[admin] Plugin loaded successfully!').send()

def unload():
SayText2('[admin] Plugin unloaded successfully!').send()

@Event('player_connect')
def on_player_connect(game_event):
uniqueid = game_event['networkid']
if uniqueid in moderator:
SayText2('[Moderator] Подключился к игре').send()

@Event('player_disconnect')
def on_player_disconnect(game_event):
uniqueid = game_event['networkid']
if uniqueid in moderator:
SayText2('[Moderator] Покинул игру').send()

Re: CSS: Moderator, connect/disconnect show

Posted: Tue Nov 29, 2022 12:59 pm
by cssbestrpg
yakuza wrote:Good afternoon! I wrote a plugin but it doesn't work, what's my mistake? I'm just learning, please don't swear


Your code is incorrect of the part where you have moderator, the code suppose to like something like this:

Syntax: Select all

from events import Event
from messages import SayText2

moderator = '[U:1:81936084]'

def load():
SayText2('[admin] Plugin loaded successfully!').send()

def unload():
SayText2('[admin] Plugin unloaded successfully!').send()

@Event('player_connect')
def on_player_connect(game_event):
# Get the player steamid who connected
uniqueid = game_event['networkid']
# Does the steamid belong to admin
if uniqueid in moderator:
# Steamid belongs to admin, now make a message
SayText2('[Moderator] Подключился к игре').send()

@Event('player_disconnect')
def on_player_disconnect(game_event):
# Get the player steamid who disconnected
uniqueid = game_event['networkid']
# Does the steamid belong to admin
if uniqueid in moderator:
# Steamid belongs to admin, now make a message
SayText2('[Moderator] Покинул игру').send()

Re: CSS: Moderator, connect/disconnect show

Posted: Tue Nov 29, 2022 6:46 pm
by yakuza
I checked this option, it doesn't work

Re: CSS: Moderator, connect/disconnect show

Posted: Wed Dec 07, 2022 8:31 pm
by Articha

Syntax: Select all

from events import Event
from messages import SayText2

moderator = ['[U:1:81936084]']

def load():
SayText2('[admin] Plugin loaded successfully!').send()

def unload():
SayText2('[admin] Plugin unloaded successfully!').send()

@Event('player_connect')
def on_player_connect(game_event):
# Get the player steamid who connected
uniqueid = game_event['networkid']
# Does the steamid belong to admin
if uniqueid in moderator:
# Steamid belongs to admin, now make a message
SayText2('[Moderator] Подключился к игре').send()

@Event('player_disconnect')
def on_player_disconnect(game_event):
# Get the player steamid who disconnected
uniqueid = game_event['networkid']
# Does the steamid belong to admin
if uniqueid in moderator:
# Steamid belongs to admin, now make a message
SayText2('[Moderator] Покинул игру').send()


Square brackets. Moderator variable should be list instead of string, to use "in" in current context

Re: CSS: Moderator, connect/disconnect show

Posted: Thu Dec 08, 2022 5:31 pm
by Ayuto
Actually, a dictionary would also work, because the keys of the dictionary are checked.

Syntax: Select all

>>>moderator = {'[U:1:81936084]':'МЕДОЕД', 'uniqueid':'test'}
>>>'[U:1:81936084]' in moderator
True
>>>'uniqueid' in moderator
True
>>>'something' in moderator
False
This would allow providing moderator specific messages.

So, the initial plugin actually seems correct to me. Have you checked/printed what's inside of your "uniqueid" variable (game_event['networkid'])?

Re: CSS: Moderator, connect/disconnect show

Posted: Sun Dec 11, 2022 2:02 pm
by yakuza
Hello! most likely the problem is that I will never see a message about my connection in my client.. the thing is that at this moment I am actually not yet on the server ..(game_event['networkid']) returns the steamid of the client and it works with other users I checked.

Syntax: Select all

# -*- coding: utf-8 -*-
from events import Event
from colors import WHITE, OLIVE, LIGHT_GREEN
from messages import SayText2

moders = {'[U:1:81936084]':'МЕДОЕД'}

def load():
pass
def unload():
pass

@Event('player_connect')
def on_player_connect(game_event):
name = game_event['name']
uniqueid = game_event['networkid']
if uniqueid in moders:
SayText2(f"{OLIVE}[connect] {WHITE}Модератор {LIGHT_GREEN}{name}{WHITE}:{LIGHT_GREEN}{uniqueid} {WHITE}подключился к игре.").send()

@Event('player_disconnect')
def on_player_disconnect(game_event):
name = game_event['name']
uniqueid = game_event['networkid']
if uniqueid in moders:
SayText2(f"{OLIVE}[connect] {WHITE}Модератор {LIGHT_GREEN}{name}{WHITE}:{LIGHT_GREEN}{uniqueid} {WHITE}покинул игру.").send()


Maybe someone will find it useful, I'll leave it here. Thank you all for your responsiveness!