[Cs:s] How to block kill command in console

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] How to block kill command in console

Postby cssbestrpg » Sat Oct 15, 2022 11:04 am

Hi, i have issues to block kill command, whem you type it in console, it suppose to block, but it allows still kill yourself in console, it doesn't send the message in chat.
Here is the code i tried:

Syntax: Select all

from commands.client import ClientCommand
from commands import CommandReturn
from colors import GREEN, LIGHT_GREEN
from messages import SayText2

@ClientCommand('kill')
def kill_command(command, index):
SayText2(f"{GREEN}[ZR] » {LIGHT_GREEN}You can't {GREEN}suicide!").send(index)
return CommandReturn.BLOCK
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: [Cs:s] How to block kill command in console

Postby L'In20Cible » Sun Oct 16, 2022 4:30 am

kill is technically a server command, not a client one. Using ServerCommand should work. However, you cannot access the index of the player issuing it because GetCommandIndex don't seem to be currently exported to Python.

EDIT: GetCommandIndex has been exported as commands.get_command_index into 3422d53. With this commit, you can do the following:

Syntax: Select all

from colors import GREEN, LIGHT_GREEN
from commands import get_command_index
from commands.server import ServerCommand
from commands import CommandReturn
from messages import SayText2

YOU_CANT_SUICIDE_MSG = SayText2(
f"{GREEN}[ZR] » {LIGHT_GREEN}You can't {GREEN}suicide!"
)

@ServerCommand('kill')
def kill_command(command):
YOU_CANT_SUICIDE_MSG.send(get_command_index())
return CommandReturn.BLOCK
User avatar
Ayuto
Project Leader
Posts: 2193
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: [Cs:s] How to block kill command in console

Postby Ayuto » Sat Oct 22, 2022 11:19 am

Just wanted to let you now that a new build is now available that includes get_command_index().
cssbestrpg
Senior Member
Posts: 287
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

Re: [Cs:s] How to block kill command in console

Postby cssbestrpg » Sat Oct 22, 2022 11:30 am

Ayuto wrote:Just wanted to let you now that a new build is now available that includes get_command_index().

Thanks for let me know of new build, but i already did compile myself the build few days ago that includes get_command_index()
Btw does the get_command_index() get index of ther user who executed the server command or just from console ones?

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 28 guests