CSS: Moderator, connect/disconnect show

Please post any questions about developing your plugin here. Please use the search function before posting!
yakuza
Junior Member
Posts: 3
Joined: Tue Nov 29, 2022 7:28 am

CSS: Moderator, connect/disconnect show

Postby yakuza » Tue Nov 29, 2022 7:36 am

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()
Last edited by Ayuto on Thu Dec 08, 2022 5:25 pm, edited 1 time in total.
Reason: Syntax highlighting
cssbestrpg
Senior Member
Posts: 259
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

Re: CSS: Moderator, connect/disconnect show

Postby cssbestrpg » Tue Nov 29, 2022 12:59 pm

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()
yakuza
Junior Member
Posts: 3
Joined: Tue Nov 29, 2022 7:28 am

Re: CSS: Moderator, connect/disconnect show

Postby yakuza » Tue Nov 29, 2022 6:46 pm

I checked this option, it doesn't work
User avatar
Articha
Junior Member
Posts: 19
Joined: Tue Sep 21, 2021 12:13 pm
Location: Russia

Re: CSS: Moderator, connect/disconnect show

Postby Articha » Wed Dec 07, 2022 8:31 pm

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
User avatar
Ayuto
Project Leader
Posts: 2184
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: CSS: Moderator, connect/disconnect show

Postby Ayuto » Thu Dec 08, 2022 5:31 pm

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'])?
yakuza
Junior Member
Posts: 3
Joined: Tue Nov 29, 2022 7:28 am

Re: CSS: Moderator, connect/disconnect show

Postby yakuza » Sun Dec 11, 2022 2:02 pm

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!

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 8 guests