<?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%3AAntiBaseRape</id>
	<title>Scripts:AntiBaseRape - 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%3AAntiBaseRape"/>
	<link rel="alternate" type="text/html" href="https://bf2tech.uturista.pt/index.php?title=Scripts:AntiBaseRape&amp;action=history"/>
	<updated>2026-08-06T01:11:04Z</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:AntiBaseRape&amp;diff=112&amp;oldid=prev</id>
		<title>Pireax: Created page with &quot;__TOC__  == Description:  ==  ; Module : &lt;code&gt;AntiBaseRape.py&lt;/code&gt; ; Author : SHAnders ; Version : 1.11  Server side only admin script.  This script will punish players who...&quot;</title>
		<link rel="alternate" type="text/html" href="https://bf2tech.uturista.pt/index.php?title=Scripts:AntiBaseRape&amp;diff=112&amp;oldid=prev"/>
		<updated>2018-06-22T15:30:49Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;__TOC__  == Description:  ==  ; Module : &amp;lt;code&amp;gt;AntiBaseRape.py&amp;lt;/code&amp;gt; ; Author : SHAnders ; Version : 1.11  Server side only admin script.  This script will punish players who...&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;
&lt;br /&gt;
== Description:  ==&lt;br /&gt;
&lt;br /&gt;
; Module&lt;br /&gt;
: &amp;lt;code&amp;gt;AntiBaseRape.py&amp;lt;/code&amp;gt;&lt;br /&gt;
; Author&lt;br /&gt;
: SHAnders&lt;br /&gt;
; Version&lt;br /&gt;
: 1.11&lt;br /&gt;
&lt;br /&gt;
Server side only admin script.&lt;br /&gt;
&lt;br /&gt;
This script will punish players who kill enemy within the area of a safe base. (Control point that can&amp;#039;t be captured.)&lt;br /&gt;
&lt;br /&gt;
The punishment is the following:&lt;br /&gt;
&lt;br /&gt;
# The victims death score will be lowered by 1&lt;br /&gt;
# The attackers kill score will will be lowered by 1&lt;br /&gt;
# The attackers overall score will be lowered by 2 + number of warnings&lt;br /&gt;
# If warnings &amp;gt; 3 then...&lt;br /&gt;
&lt;br /&gt;
## The attackers TKs score will be increased by 1&lt;br /&gt;
## If attacker is on foot, he/she&amp;#039;s health will be lowered to 0&lt;br /&gt;
## If attacker is in a vehicle, its health will be lowered to 1&lt;br /&gt;
&lt;br /&gt;
1 warning will be removed from players history every 2 minutes&lt;br /&gt;
&lt;br /&gt;
The radius for a safe base is set to 40. (Standard controlpoint capture area is 10.)&lt;br /&gt;
&lt;br /&gt;
== Installation as Admin script  ==&lt;br /&gt;
&lt;br /&gt;
# Save this script as &amp;lt;code&amp;gt;AntiBaseRape.py&amp;lt;/code&amp;gt; in your &amp;lt;code&amp;gt;admin/standard_admin&amp;lt;/code&amp;gt; directory.&lt;br /&gt;
# Add the lines &amp;lt;code&amp;gt;import AntiBaseRape&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;AntiBaseRape.init()&amp;lt;/code&amp;gt; to the file &amp;lt;code&amp;gt;admin/standard_admin/__init__.py&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== TODO:  ==&lt;br /&gt;
&lt;br /&gt;
Since not all maps are alike, the requirements for base rape protiction should be able to be altered individualy for each control point. &lt;br /&gt;
&lt;br /&gt;
== The Code  ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt; &amp;lt;/code&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
# Module: AntiBaseRape.py&lt;br /&gt;
# Author: SHAnders&lt;br /&gt;
#&lt;br /&gt;
# Version 1.11&lt;br /&gt;
#&lt;br /&gt;
# Changes:&lt;br /&gt;
#   v1.1 -&amp;gt; 1.11&lt;br /&gt;
#   Fixed the timer to only be started once&lt;br /&gt;
#   v1.0 -&amp;gt; 1.1&lt;br /&gt;
#   Implemted a baseRapeWarning attribute on players to count safe base kills&lt;br /&gt;
#   Implemted allowed amount of safe base kills (3)&lt;br /&gt;
#      up to this amount player only loses kill points + 1 score pr baseRapeWarning&lt;br /&gt;
#      over this amount player is allso killed&lt;br /&gt;
#   Implemtes a timer for removing 1 baseRapeWarning every 2 minutes&lt;br /&gt;
#&lt;br /&gt;
# Description:&lt;br /&gt;
#   Server side only admin script&lt;br /&gt;
#&lt;br /&gt;
#   This script will punish players who kill enemy within the area of a safe base&lt;br /&gt;
#  &lt;br /&gt;
# Requirements:&lt;br /&gt;
#   None.&lt;br /&gt;
#&lt;br /&gt;
# Installation as Admin script:&lt;br /&gt;
#   1: Save this script as &amp;#039;AntiBaseRape.py&amp;#039; in your &amp;lt;bf2&amp;gt;/admin/standard_admin directory.&lt;br /&gt;
#   2: Add the lines &amp;#039;import AntiBaseRape&amp;#039; and &amp;#039;AntiBaseRape.init()&amp;#039; to the file&lt;br /&gt;
#      &amp;#039;&amp;lt;bf2&amp;gt;/admin/standard_admin/__init__.py&amp;#039;.&lt;br /&gt;
#&lt;br /&gt;
# TODO:&lt;br /&gt;
#   Since not all maps are alike, the requirements for base rape protiction&lt;br /&gt;
#   should be able to be altered individualy for each control point.&lt;br /&gt;
#&lt;br /&gt;
# Thanks to:&lt;br /&gt;
#   Battlefield.no for inspiration from their pingkick.py script&lt;br /&gt;
#&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
import host&lt;br /&gt;
import bf2&lt;br /&gt;
import math&lt;br /&gt;
from bf2.stats.constants import *&lt;br /&gt;
from bf2 import g_debug&lt;br /&gt;
&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
# Constants&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
DEFAULT_SAFEBASE_RADIUS = 40 # Default safe area radius (normal commandpoint radius = 10)&lt;br /&gt;
ALLOWED_SAFEBASEKILLS = 3&lt;br /&gt;
SAFEBASEKILL_TIMER_INTERVAL = 120 # Intervals between removing a point from players.baseRapeWarning&lt;br /&gt;
&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
# Variables&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
 &lt;br /&gt;
WarnReduceTimer = None # Timer that reduces the warnings at intervals&lt;br /&gt;
 &lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
# Init&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
 &lt;br /&gt;
def init():&lt;br /&gt;
   if g_debug: print &amp;quot;AntiBaseRape init&amp;quot;&lt;br /&gt;
   host.registerHandler(&amp;#039;PlayerConnect&amp;#039;, onPlayerConnect, 1)  &lt;br /&gt;
   host.registerHandler(&amp;#039;PlayerKilled&amp;#039;, onPlayerKilled)&lt;br /&gt;
 &lt;br /&gt;
   # Start the timer that reduces warnings on the SAFEBASEKILL_TIMER_INTERVAL&lt;br /&gt;
   WarnReduceTimer = bf2.Timer(onSafeBaseKillTimer, SAFEBASEKILL_TIMER_INTERVAL, 1)&lt;br /&gt;
   WarnReduceTimer.setRecurring(SAFEBASEKILL_TIMER_INTERVAL)&lt;br /&gt;
&lt;br /&gt;
   # Connect already connected players if reinitializing&lt;br /&gt;
   for p in bf2.playerManager.getPlayers():&lt;br /&gt;
      onPlayerConnect(p)&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
#  onPlayerConnect&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
def onPlayerConnect(player):&lt;br /&gt;
   resetPlayer(player)&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
# onPlayerKilled&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
def onPlayerKilled(victim, attacker, weapon, assists, object):&lt;br /&gt;
   # killed by self&lt;br /&gt;
   if attacker == victim:&lt;br /&gt;
      pass&lt;br /&gt;
     &lt;br /&gt;
   # killed by enemy&lt;br /&gt;
   elif attacker != None and attacker.getTeam() != victim.getTeam():&lt;br /&gt;
      checkForSafeBase(attacker, victim)&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
# Reset the bfno pingscript variables placed in the player object:&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
def resetPlayer(player):&lt;br /&gt;
   player.baseRapeWarning = 0&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
# Check if victim was killed within safebase area&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
def checkForSafeBase(attacker, victim):&lt;br /&gt;
   victimVehicle = victim.getVehicle()&lt;br /&gt;
   controlPoints = bf2.objectManager.getObjectsOfType(&amp;#039;dice.hfe.world.ObjectTemplate.ControlPoint&amp;#039;)&lt;br /&gt;
   for cp in controlPoints:&lt;br /&gt;
      if cp.cp_getParam(&amp;#039;unableToChangeTeam&amp;#039;) != 0 and cp.cp_getParam(&amp;#039;team&amp;#039;) != attacker.getTeam():&lt;br /&gt;
         distanceTo = getVectorDistance(victimVehicle.getPosition(), cp.getPosition())&lt;br /&gt;
         if DEFAULT_SAFEBASE_RADIUS &amp;gt; float(distanceTo):&lt;br /&gt;
            justify(attacker, victim, cp, distanceTo)&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
# Punish attacker, give victim life back and inform all&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
def justify(attacker, victim, controlPoint, distanceTo):&lt;br /&gt;
   victim.score.deaths += -1&lt;br /&gt;
   attacker.score.kills += -1&lt;br /&gt;
   attacker.score.score += -2 - attacker.baseRapeWarning&lt;br /&gt;
   attacker.baseRapeWarning += 1&lt;br /&gt;
   sendWarning(attacker, controlPoint, distanceTo)&lt;br /&gt;
   if attacker.baseRapeWarning &amp;gt; ALLOWED_SAFEBASEKILLS:&lt;br /&gt;
      attacker.score.TKs += 1&lt;br /&gt;
      if attacker.isAlive():&lt;br /&gt;
         vehicle = attacker.getVehicle()&lt;br /&gt;
         rootVehicle = getRootParent(vehicle)&lt;br /&gt;
         if getVehicleType(rootVehicle.templateName) == VEHICLE_TYPE_SOLDIER:&lt;br /&gt;
            rootVehicle.setDamage(0)&lt;br /&gt;
            # This should kill them !&lt;br /&gt;
         else:&lt;br /&gt;
            rootVehicle.setDamage(1)&lt;br /&gt;
            # a vehicle will likely explode within 1 sec killing entire crew,&lt;br /&gt;
            # not so sure about base defenses though&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
# Send Warning&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
def sendWarning(player, controlPoint, distanceTo):&lt;br /&gt;
   mapName = bf2.gameLogic.getMapName()&lt;br /&gt;
   if player.baseRapeWarning &amp;gt; ALLOWED_SAFEBASEKILLS:&lt;br /&gt;
      sendMsgAll(player.getName() + &amp;quot; is punished for repeated violating of the no kill rules within safe base area&amp;quot;)&lt;br /&gt;
   else:&lt;br /&gt;
      sendMsgAll(player.getName() + &amp;quot; has violated of the no kill rules within safe base area &amp;quot; + str(player.baseRapeWarning) + &amp;quot; times now&amp;quot;)&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
# remove baseRapeWarnings over time&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
def onSafeBaseKillTimer(data):&lt;br /&gt;
   for p in bf2.playerManager.getPlayers():&lt;br /&gt;
      if p.baseRapeWarning &amp;lt;= 0:&lt;br /&gt;
         p.baseRapeWarning = 0&lt;br /&gt;
      else:&lt;br /&gt;
         p.baseRapeWarning += -1&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
# get distance between two positions&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
def getVectorDistance(pos1, pos2):&lt;br /&gt;
   diffVec = [0.0, 0.0, 0.0]&lt;br /&gt;
   diffVec[0] = math.fabs(pos1[0] - pos2[0])&lt;br /&gt;
   diffVec[1] = math.fabs(pos1[1] - pos2[1])&lt;br /&gt;
   diffVec[2] = math.fabs(pos1[2] - pos2[2])&lt;br /&gt;
  &lt;br /&gt;
   # Application of Pythagorean theorem to calculate total distance&lt;br /&gt;
   return math.sqrt(diffVec[0] * diffVec[0] + diffVec[1] * diffVec[1] + diffVec[2] * diffVec[2])&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
# Send message to all on server&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
def sendMsgAll(msg):&lt;br /&gt;
   host.rcon_invoke(&amp;quot;game.sayAll \&amp;quot;&amp;quot; + str(msg) + &amp;quot;\&amp;quot;&amp;quot;)&lt;br /&gt;
# ------------------------------------------------------------------------&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pireax</name></author>
	</entry>
</feed>