Scripts:SayKick

From BF2 Technical Information Wiki
Jump to: navigation, search

Introduction

First of all, a warning: Don't use this script on your server! It works, but it's incomplete and crazily insecure. This is meant more as a springboard for people with more Python experience than I have. I hope that someone will get this working in a secure way and make other improvements to it.

Usage

Copy and paste. Call it saykick.py. Add this to your __init__.py:

import saykick
saykick.init()

Change "BILLY_THE_KID" or "SCRUMPYLICIOUS" to your player name.

Run the server, jump in, and use your global chat key to say:
> kickplayer "somePlayerName" for saying mean stuff

The server will kick the player and say:
>>> somePlayerName kicked for saying mean stuff

Warnings

  • This script does no checking for valid player names. If you use an incorrect name, it'll still tell you the player has been kicked, even if the player never existed.
  • This also won't work if you try to use it while you're dead.
  • Oh, and the biggest problem with it? If someone logs in with your name, they suddenly have kicking priveleges. I told you not to use it on your server, right?

Anyway, here it is. Have at it:

import bf2
import host
from bf2 import g_debug

def init():
	if g_debug: print 'initialising saykick script'
	host.registerHandler('ChatMessage', onChatMessage, 1)
	host.rcon_invoke('echo "saykick.py loaded"')
	
def onChatMessage(player_id, text, channel, flags):
	player = bf2.playerManager.getPlayerByIndex(player_id)
	if player.getName() == 'BILLY_THE_KID' or player.getName() == 'SCRUMPYLICIOUS':
		if text.find('kickplayer') != -1:
			cmdList = text.split('"')
			if len(cmdList) > 1:
				cmdList[0:1] = []
				kickPlayer = cmdList[0]
				cmdList[0:1] = []
				reason = '"'.join(cmdList)
				host.rcon_invoke('game.sayAll "' + kickPlayer + ' kicked' + reason + '"')
				host.rcon_invoke('admin.kickPlayer "' + kickPlayer + '"')
				if g_debug: print kickPlayer + ' kicked' + reason
Greeze 07:51, 1 Jul 2005 (MDT)
Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox