Kick menu->reason: other->text input

Please post any questions about developing your plugin here. Please use the search function before posting!
Banz
Junior Member
Posts: 10
Joined: Tue Sep 06, 2016 3:40 pm

Kick menu->reason: other->text input

Postby Banz » Fri Sep 09, 2016 9:35 pm

Lets say that we have kick menu with reason selection. One of the reasons is "other" how can we ask for the reason to be typed through text input after player selects "other"? Then after that we want to be able to print both player and the reason.
Also this is for csgo
Thanks in advance! :)
User avatar
iPlayer
Developer
Posts: 590
Joined: Sat Nov 14, 2015 8:37 am
Location: Moscow
Contact:

Re: Kick menu->reason: other->text input

Postby iPlayer » Fri Sep 09, 2016 10:20 pm

The only and the most obvious text input area in CS:S is its chat area.
You can go with something like selecting the player in your popup menu, but entering the reason through chat just after that.
!kr Stop voice spamming

Would kick selected in a popup player with the proper reason.

also, motd
Image /id/its_iPlayer
My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam

Hail, Companion. [...] Hands to yourself, sneak thief. Image
Banz
Junior Member
Posts: 10
Joined: Tue Sep 06, 2016 3:40 pm

Re: Kick menu->reason: other->text input

Postby Banz » Fri Sep 09, 2016 10:53 pm

iPlayer wrote:The only and the most obvious text input area in CS:S is its chat area.
You can go with something like selecting the player in your popup menu, but entering the reason through chat just after that.
!kr Stop voice spamming

Would kick selected in a popup player with the proper reason.

also, motd


Well the problem is that I don't know how can I pass the option.value to @Saycommands function or whatever is the way to do that.
User avatar
Ayuto
Project Leader
Posts: 2193
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: Kick menu->reason: other->text input

Postby Ayuto » Sat Sep 10, 2016 8:43 am

You need to store them in a dict or something like that.

I made a small example how it could look like:

Syntax: Select all

# =============================================================================
# >> IMPORTS
# =============================================================================
from filters.players import PlayerIter
from messages import SayText2
from players.entity import Player

from menus import PagedMenu
from menus import PagedOption

from commands.say import SayCommand
from commands.say import SayFilter

from listeners import OnClientDisconnect


# =============================================================================
# >> CONSTANTS
# =============================================================================
KICK_NO_REASON = 0
KICK_WITH_REASON = 1


# =============================================================================
# >> GLOBAL VARIABLES
# =============================================================================
class Info(object):
def __init__(self, userid, name, wait_for_reason=False):
self.userid = userid
self.name = name
self.wait_for_reason = wait_for_reason

info_dict = {}


# =============================================================================
# >> KICK MENU
# =============================================================================
kick_menu = PagedMenu()
kick_menu.append(PagedOption('Kick without reason', KICK_NO_REASON))
kick_menu.append(PagedOption('Kick with reason', KICK_WITH_REASON))

@kick_menu.register_select_callback
def on_menu_select(menu, index, option):
info = info_dict[index]
try:
player_to_kick = Player.from_userid(info.userid)
except ValueError:
del info_dict[index]
SayText2('{} is not on the server anymore.'.format(info.name))
return

if option.value == KICK_NO_REASON:
player_to_kick.kick()
elif option.value == KICK_WITH_REASON:
info.wait_for_reason = True
SayText2('Enter a reason for kicking {}.'.format(info.name)).send(index)


# =============================================================================
# >> PLAYER MENU
# =============================================================================
player_menu = PagedMenu('Select a player to kick:')

@player_menu.register_build_callback
def on_player_menu_build(menu, index):
menu.clear()
for player in PlayerIter():
menu.append(PagedOption(player.name, player.userid))

@player_menu.register_select_callback
def on_player_menu_select(menu, index, option):
userid = option.value
try:
player_to_kick = Player.from_userid(userid)
except ValueError:
SayText2('{} is not on the server anymore.'.format(option.text))
else:
info_dict[index] = Info(userid, option.text)
kick_menu.send(index)


# =============================================================================
# >> KICK COMMAND
# =============================================================================
@SayCommand('!kick')
def on_kick(command, index, team_only):
player_menu.send(index)


# =============================================================================
# >> REASON FILTER
# =============================================================================
@SayFilter
def on_say(command, index, team_only):
info = info_dict.pop(index, None)
if info is None or not info.wait_for_reason:
return

try:
player_to_kick = Player.from_userid(info.userid)
except ValueError:
SayText2('{} is not on the server anymore.'.format(info.name))
else:
player_to_kick.kick(command.command_string)


# =============================================================================
# >> CLIENT DISCONNECT
# =============================================================================
@OnClientDisconnect
def on_client_disconnect(index):
# Cleanup if existant
info_dict.pop(index, 0)
Banz
Junior Member
Posts: 10
Joined: Tue Sep 06, 2016 3:40 pm

Re: Kick menu->reason: other->text input

Postby Banz » Sat Sep 10, 2016 6:43 pm

Ayuto wrote:You need to store them in a dict or something like that.

I made a small example how it could look like:

Syntax: Select all

# =============================================================================
# >> IMPORTS
# =============================================================================
from filters.players import PlayerIter
from messages import SayText2
from players.entity import Player

from menus import PagedMenu
from menus import PagedOption

from commands.say import SayCommand
from commands.say import SayFilter

from listeners import OnClientDisconnect


# =============================================================================
# >> CONSTANTS
# =============================================================================
KICK_NO_REASON = 0
KICK_WITH_REASON = 1


# =============================================================================
# >> GLOBAL VARIABLES
# =============================================================================
class Info(object):
def __init__(self, userid, name, wait_for_reason=False):
self.userid = userid
self.name = name
self.wait_for_reason = wait_for_reason

info_dict = {}


# =============================================================================
# >> KICK MENU
# =============================================================================
kick_menu = PagedMenu()
kick_menu.append(PagedOption('Kick without reason', KICK_NO_REASON))
kick_menu.append(PagedOption('Kick with reason', KICK_WITH_REASON))

@kick_menu.register_select_callback
def on_menu_select(menu, index, option):
info = info_dict[index]
try:
player_to_kick = Player.from_userid(info.userid)
except ValueError:
del info_dict[index]
SayText2('{} is not on the server anymore.'.format(info.name))
return

if option.value == KICK_NO_REASON:
player_to_kick.kick()
elif option.value == KICK_WITH_REASON:
info.wait_for_reason = True
SayText2('Enter a reason for kicking {}.'.format(info.name)).send(index)


# =============================================================================
# >> PLAYER MENU
# =============================================================================
player_menu = PagedMenu('Select a player to kick:')

@player_menu.register_build_callback
def on_player_menu_build(menu, index):
menu.clear()
for player in PlayerIter():
menu.append(PagedOption(player.name, player.userid))

@player_menu.register_select_callback
def on_player_menu_select(menu, index, option):
userid = option.value
try:
player_to_kick = Player.from_userid(userid)
except ValueError:
SayText2('{} is not on the server anymore.'.format(option.text))
else:
info_dict[index] = Info(userid, option.text)
kick_menu.send(index)


# =============================================================================
# >> KICK COMMAND
# =============================================================================
@SayCommand('!kick')
def on_kick(command, index, team_only):
player_menu.send(index)


# =============================================================================
# >> REASON FILTER
# =============================================================================
@SayFilter
def on_say(command, index, team_only):
info = info_dict.pop(index, None)
if info is None or not info.wait_for_reason:
return

try:
player_to_kick = Player.from_userid(info.userid)
except ValueError:
SayText2('{} is not on the server anymore.'.format(info.name))
else:
player_to_kick.kick(command.command_string)


# =============================================================================
# >> CLIENT DISCONNECT
# =============================================================================
@OnClientDisconnect
def on_client_disconnect(index):
# Cleanup if existant
info_dict.pop(index, 0)

Thank you this was exactly what I was looking for.
battleweaver
Member
Posts: 43
Joined: Mon Oct 02, 2017 7:57 am
Location: Moscow
Contact:

Re: Kick menu->reason: other->text input

Postby battleweaver » Tue Nov 28, 2017 12:44 pm

What if I want to show reason to a player after I kicked him? player.kick("reason") shows reason only in console.
I mean, something else than "You were kicked from server" popup window.

Sourcemod version is: KickClient(client, "You were kicked");
User avatar
Ayuto
Project Leader
Posts: 2193
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: Kick menu->reason: other->text input

Postby Ayuto » Tue Nov 28, 2017 5:04 pm

The reason isn't only shown in the console. A popup als appears that displays your reason.
User avatar
iPlayer
Developer
Posts: 590
Joined: Sat Nov 14, 2015 8:37 am
Location: Moscow
Contact:

Re: Kick menu->reason: other->text input

Postby iPlayer » Wed Nov 29, 2017 3:19 am

If I remember correctly, CS:GO popup will always display the default text regardless of our reason. CS:S definitely displays your own reason - that's true, but CS:GO will just tell something like "Kicked by server" or something.
Image /id/its_iPlayer
My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • AdPurge • Bot Damage • PLRBots • Entity AntiSpam

Hail, Companion. [...] Hands to yourself, sneak thief. Image
battleweaver
Member
Posts: 43
Joined: Mon Oct 02, 2017 7:57 am
Location: Moscow
Contact:

Re: Kick menu->reason: other->text input

Postby battleweaver » Wed Nov 29, 2017 8:00 am

Sourcemod KickClient(client, "Game ended");
https://ibb.co/mmQpkG
SourcePython player.kick("End of game")
https://ibb.co/eLmjKb

As you can see, everybody is right somehow :)
User avatar
Ayuto
Project Leader
Posts: 2193
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: Kick menu->reason: other->text input

Postby Ayuto » Wed Nov 29, 2017 8:22 am

Well, then it's probably due to the fact that they call client->Disconnect(<reason>) on the client. I will test that today, when I get home.
User avatar
Ayuto
Project Leader
Posts: 2193
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: Kick menu->reason: other->text input

Postby Ayuto » Wed Nov 29, 2017 7:01 pm

A quick test has shown that calling client->Disconnect() properly shows the reason in CS:GO. The next build will fix this issue:
https://github.com/Source-Python-Dev-Te ... 37e4c50d10
battleweaver
Member
Posts: 43
Joined: Mon Oct 02, 2017 7:57 am
Location: Moscow
Contact:

Re: Kick menu->reason: other->text input

Postby battleweaver » Fri Dec 01, 2017 8:15 pm

Checked new build. Now the message appears in popup window. Thank you!

Return to “Plugin Development Support”

Who is online

Users browsing this forum: Bing [Bot] and 25 guests