Page 1 of 1

Kick menu->reason: other->text input

Posted: Fri Sep 09, 2016 9:35 pm
by Banz
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! :)

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

Posted: Fri Sep 09, 2016 10:20 pm
by iPlayer
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

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

Posted: Fri Sep 09, 2016 10:53 pm
by Banz
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.

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

Posted: Sat Sep 10, 2016 8:43 am
by Ayuto
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)

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

Posted: Sat Sep 10, 2016 6:43 pm
by Banz
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.

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

Posted: Tue Nov 28, 2017 12:44 pm
by battleweaver
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");

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

Posted: Tue Nov 28, 2017 5:04 pm
by Ayuto
The reason isn't only shown in the console. A popup als appears that displays your reason.

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

Posted: Wed Nov 29, 2017 3:19 am
by iPlayer
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.

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

Posted: Wed Nov 29, 2017 8:00 am
by battleweaver
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 :)

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

Posted: Wed Nov 29, 2017 8:22 am
by Ayuto
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.

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

Posted: Wed Nov 29, 2017 7:01 pm
by Ayuto
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

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

Posted: Fri Dec 01, 2017 8:15 pm
by battleweaver
Checked new build. Now the message appears in popup window. Thank you!