<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://bf2tech.uturista.pt/index.php?action=history&amp;feed=atom&amp;title=Scripts%3ASquadlessKick</id>
	<title>Scripts:SquadlessKick - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://bf2tech.uturista.pt/index.php?action=history&amp;feed=atom&amp;title=Scripts%3ASquadlessKick"/>
	<link rel="alternate" type="text/html" href="https://bf2tech.uturista.pt/index.php?title=Scripts:SquadlessKick&amp;action=history"/>
	<updated>2026-08-06T00:35:39Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.40.1</generator>
	<entry>
		<id>https://bf2tech.uturista.pt/index.php?title=Scripts:SquadlessKick&amp;diff=115&amp;oldid=prev</id>
		<title>Pireax: Created page with &quot;__TOC__ == Introduction  ==  In an effort to learn Python and create something useful, I wrote this script to kick squadless players. It&#039;s a step towards a smoothly running te...&quot;</title>
		<link rel="alternate" type="text/html" href="https://bf2tech.uturista.pt/index.php?title=Scripts:SquadlessKick&amp;diff=115&amp;oldid=prev"/>
		<updated>2018-06-22T15:31:51Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;__TOC__ == Introduction  ==  In an effort to learn Python and create something useful, I wrote this script to kick squadless players. It&amp;#039;s a step towards a smoothly running te...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;__TOC__&lt;br /&gt;
== Introduction  ==&lt;br /&gt;
&lt;br /&gt;
In an effort to learn Python and create something useful, I wrote this script to kick squadless players. It&amp;#039;s a step towards a smoothly running team. &lt;br /&gt;
&lt;br /&gt;
== The Algorithm  ==&lt;br /&gt;
&lt;br /&gt;
Originally, the script performed a check when players died. However, this caused problems with the autobalancing system because the way BF2 triggers events when switching teams. When a player switches teams, he is removed from a squad (if it applies), killed, and switched to the other side. The problem with checking at player death is the autobalance triggers it when switching a player to another team. Of course, he will definitely not be in a squad and be kicked.&lt;br /&gt;
&lt;br /&gt;
A better way of performing the check is on player spawn. This ensures the intention of whether the player wants to work in a squad or not. Combined with Python&amp;#039;s ability to use lists as queues, squadless players can be processed at a specified interval after they spawn squadless.&lt;br /&gt;
&lt;br /&gt;
When the player spawns, we want to perform the check and add the player to the queue if he is squadless. Setting a timer will perform a second check at a specified period after the player spawns.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Player spawns&lt;br /&gt;
    Player is not in a squad or not commanding&lt;br /&gt;
        Player is added to a kick list&lt;br /&gt;
        Player is issued a warning to join a squad&lt;br /&gt;
        Set timer to kick player&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When the kick timer is triggered, we want to double-check that the player is still squadless. It&amp;#039;s like a second chance. What we do is get the first player in the list and perform the check on him. This would be at the specified time after the player has spawned.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Kick timer is triggered&lt;br /&gt;
    Retrieve first player in kick list&lt;br /&gt;
    Player is not in a squad or not commanding&lt;br /&gt;
        Player is kicked from server&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We want to be fair and issue a general warning to all players every so often so they know to join a squad. If this timer is set to half the time of the kick timer, we can be sure that squadless players will see the warning at least once.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Message timer is triggered&lt;br /&gt;
    Display message to all players&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In between games, we want to clean up the message timer and clear the kick list. Everybody starts fresh on a new round!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Game status changes&lt;br /&gt;
    Game status is Playing&lt;br /&gt;
        Set the message timer to trigger at set interval&lt;br /&gt;
    Game status is PreGame&lt;br /&gt;
        Destroy message timer&lt;br /&gt;
        Clear the kick list&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
== Code  ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Squadless Kick System&lt;br /&gt;
&lt;br /&gt;
# Module: squadless_kick_v2.py&lt;br /&gt;
# Author: Sarc&lt;br /&gt;
# Version: 0.3a&lt;br /&gt;
# Description: Players not in a squad will be kicked from the server.&lt;br /&gt;
#            An automated message will issue general warnings at specified intervals.&lt;br /&gt;
#            Squadless player checks are done when the player spawns.&lt;br /&gt;
&lt;br /&gt;
# Installation:&lt;br /&gt;
#    Save this script, &amp;#039;squadless_kick_v2.py&amp;#039;, in your &amp;lt;bf2&amp;gt;/admin/standard_admin directory.&lt;br /&gt;
#    Add &amp;#039;import squadless_kick_v2&amp;#039; and &amp;#039;squadless_kick_v2.init()&amp;#039; to the file &amp;#039;&amp;lt;bf2&amp;gt;/admin/standard_admin/__init__.py&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
import bf2&lt;br /&gt;
import host&lt;br /&gt;
from bf2 import g_debug&lt;br /&gt;
&lt;br /&gt;
#debug flag&lt;br /&gt;
sks_debug = False # for verbose server console messages&lt;br /&gt;
&lt;br /&gt;
#variable settings; intervals are in seconds&lt;br /&gt;
kickInterval = 60 # time before a squadless player is kicked&lt;br /&gt;
msgInterval = 30 # time between warning messages&lt;br /&gt;
warningMsg = &amp;quot;ADMIN: |c1000Squadless players will be kicked!&amp;quot; # the warning message&lt;br /&gt;
&lt;br /&gt;
#timers&lt;br /&gt;
msgTimer = None&lt;br /&gt;
&lt;br /&gt;
#queue lists&lt;br /&gt;
kickList = []&lt;br /&gt;
&lt;br /&gt;
# Initialize the kick system i.e. register game hooks.&lt;br /&gt;
def init():&lt;br /&gt;
    if g_debug: print &amp;quot;initializing squadless_kick script&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
    host.registerHandler(&amp;#039;PlayerSpawn&amp;#039;, onPlayerSpawn)&lt;br /&gt;
    host.registerGameStatusHandler(onGameStatusChanged)&lt;br /&gt;
&lt;br /&gt;
# On spawn, checks if the player is in a squad or commanding.&lt;br /&gt;
# Player is added to kick list if not in a squad or not commanding.&lt;br /&gt;
def onPlayerSpawn(p, vehicle):&lt;br /&gt;
    global sks_debug&lt;br /&gt;
    global kickList, kickInterval&lt;br /&gt;
   &lt;br /&gt;
    if (p.getSquadId() == 0) and not p.isCommander():&lt;br /&gt;
        # Add the player if not in kick list&lt;br /&gt;
        if kickList.count(p.index) == 0:&lt;br /&gt;
            kickList.append(p.index)&lt;br /&gt;
&lt;br /&gt;
            # Set timer for kick&lt;br /&gt;
            bf2.Timer(onKickTimer, kickInterval, 1)&lt;br /&gt;
           &lt;br /&gt;
            if sks_debug: host.rcon_invoke(&amp;quot;echo \&amp;quot;&amp;quot; + p.getName() + &amp;quot; was added to the kick list.\&amp;quot;&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
        if sks_debug: host.rcon_invoke(&amp;quot;echo \&amp;quot;Kick warning issued.\&amp;quot;&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
        # Issue kick warning&lt;br /&gt;
        host.rcon_invoke(&amp;quot;game.sayAll \&amp;quot;ADMIN: |c1000&amp;quot; + p.getName() + &amp;quot; will be kicked for not being in a squad\&amp;quot;&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# Sends out warning messages&lt;br /&gt;
def onMsgTimer(data):&lt;br /&gt;
    global sks_debug&lt;br /&gt;
    global warningMsg&lt;br /&gt;
   &lt;br /&gt;
    host.rcon_invoke(&amp;quot;game.sayAll \&amp;quot;&amp;quot; + warningMsg + &amp;quot;\&amp;quot;&amp;quot;)&lt;br /&gt;
   &lt;br /&gt;
    if sks_debug: host.rcon_invoke(&amp;quot;echo \&amp;quot;Warning message issued.\&amp;quot;&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# Processes the kick list queue. The next player in queue&lt;br /&gt;
# is checked again and kicked if not in a squad or not commanding.&lt;br /&gt;
def onKickTimer(data):&lt;br /&gt;
    global sks_debug&lt;br /&gt;
    global kickList&lt;br /&gt;
&lt;br /&gt;
    if sks_debug: host.rcon_invoke(&amp;quot;echo \&amp;quot;Kick timer triggered.\&amp;quot;&amp;quot;)&lt;br /&gt;
   &lt;br /&gt;
    # Process the next player in queue.&lt;br /&gt;
    p = bf2.playerManager.getPlayerByIndex(kickList.pop(0))&lt;br /&gt;
   &lt;br /&gt;
    # Player is still squadless, kick him.&lt;br /&gt;
    if (p.getSquadId() == 0) and not p.isCommander():&lt;br /&gt;
        host.rcon_invoke(&amp;quot;echo \&amp;quot;&amp;quot; + p.getName() + &amp;quot; was kicked for not being in a squad\&amp;quot;&amp;quot;)&lt;br /&gt;
        host.rcon_invoke(&amp;quot;admin.kickPlayer &amp;quot; + str(p.index))&lt;br /&gt;
&lt;br /&gt;
# Handles clean up and initialization between rounds.&lt;br /&gt;
def onGameStatusChanged(status):&lt;br /&gt;
    global kickList&lt;br /&gt;
    global msgInterval, msgTimer&lt;br /&gt;
&lt;br /&gt;
    if status == bf2.GameStatus.Playing:&lt;br /&gt;
        host.rcon_invoke(&amp;quot;echo \&amp;quot;Game Status: Playing\&amp;quot;&amp;quot;)&lt;br /&gt;
       &lt;br /&gt;
        # Set the warning timer.&lt;br /&gt;
        msgTimer = bf2.Timer(onMsgTimer, msgInterval, 1)&lt;br /&gt;
        msgTimer.setRecurring(msgInterval)&lt;br /&gt;
&lt;br /&gt;
    elif status == bf2.GameStatus.PreGame:&lt;br /&gt;
        host.rcon_invoke(&amp;quot;echo \&amp;quot;Game Status: PreGame\&amp;quot;&amp;quot;)&lt;br /&gt;
       &lt;br /&gt;
        # Destroy any timers&lt;br /&gt;
        msgTimer.destroy()&lt;br /&gt;
        msgTimer = None&lt;br /&gt;
       &lt;br /&gt;
        # Blank the list.&lt;br /&gt;
        kickList = []&lt;br /&gt;
   &lt;br /&gt;
    elif status == bf2.GameStatus.EndGame:&lt;br /&gt;
        host.rcon_invoke(&amp;quot;echo \&amp;quot;Game Status: EndGame\&amp;quot;&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== History  ==&lt;br /&gt;
&lt;br /&gt;
0.1a&lt;br /&gt;
&lt;br /&gt;
- Basic squadless kick functionality at death&lt;br /&gt;
&lt;br /&gt;
- Warning message added&lt;br /&gt;
&lt;br /&gt;
0.2a&lt;br /&gt;
&lt;br /&gt;
- FIX: Players are not kicked when changing teams&lt;br /&gt;
&lt;br /&gt;
- Warning message can be set at a user specified interval&lt;br /&gt;
&lt;br /&gt;
- Kick list checks can be set at a user specified interval&lt;br /&gt;
&lt;br /&gt;
0.3a&lt;br /&gt;
&lt;br /&gt;
- FIX: Compatible with EA&amp;#039;s autobalance script&lt;br /&gt;
&lt;br /&gt;
- Checks are now done when a player spawns&lt;br /&gt;
&lt;br /&gt;
- Message timer is destroyed when game ends and reinstantiated at game start&lt;br /&gt;
&lt;br /&gt;
- Improved kick delay; now works by a queue for consistent kick delays&lt;br /&gt;
&lt;br /&gt;
- Added debug flag for verbose server console messages&lt;/div&gt;</summary>
		<author><name>Pireax</name></author>
	</entry>
</feed>