IPB

Welcome Guest ( Log In | Register )

[Python] Is there a way to detect headshots?
wilson212
post Jan 10 2016, 09:57 PM
Post #1


The Accolade
****

Group: Soldiers
Posts: 115
Joined: 23-June 08
From: Fort Campbell, KY
Member No.: 5,228



As the title says, is there a reliable way to detect whether a soldier died to a head-shot? I have seen through AIX 2.0's scoringCommon.py that they used this line:

CODE
if victim.isManDown() == 0:
    hitregiontext = "headshot"


Does this code work for all weapons, like pistols or just weapons that can one shot you if they hit you in the head? Is there a better way to detect this or is that all we have?

This post has been edited by wilson212: Jan 10 2016, 09:58 PM


--------------------
Go to the top of the page
 
+Quote Post
2 Pages V   1 2 >  
Start new topic
Replies (1 - 14)
MasterChiefRulZ
post Jan 10 2016, 10:28 PM
Post #2


You know the drill...
Group Icon

Group: Mr. Admin
Posts: 10,194
Joined: 31-December 03
From: Home
Member No.: 48



I'm not certain but I think alot of that data they used for scoring came from "Wookie Sniper Mod."


http://www.moddb.com/mods/wookiesnipermod


--------------------
Go to the top of the page
 
+Quote Post
bobthedinosaur
post Jan 11 2016, 11:37 PM
Post #3


Dictator
******

Group: Soldiers
Posts: 2,202
Joined: 4-March 11
From: A Cold Place
Member No.: 7,896



Who did the python coding for AIX?
Go to the top of the page
 
+Quote Post
Gilgamesh
post Jan 13 2016, 08:28 AM
Post #4


Captain
***

Group: Soldiers
Posts: 65
Joined: 24-August 14
From: The High Heavens
Member No.: 10,296



QUOTE (wilson212 @ Jan 10 2016, 10:57 PM) *
As the title says, is there a reliable way to detect whether a soldier died to a head-shot? I have seen through AIX 2.0's scoringCommon.py that they used this line:

CODE
if victim.isManDown() == 0:
    hitregiontext = "headshot"


Does this code work for all weapons, like pistols or just weapons that can one shot you if they hit you in the head? Is there a better way to detect this or is that all we have?


there is a headshot script which is from wookiemod but toned down (i was searching for 2 days trying to find a link "that wasn't dead"), but it crashes for me maybe im doing something wrong... but idk if its mod compatible a lot of the coding is for vbf2

CODE
##########################################
# Module: head_shot.py
# Author: Dean Peternelj, dean.peternelj@gmail.com
# Date: 2008/23/01
# Version: 1.30 Beta

'''
Script is written by permission of "Scouty", a member of Wookie Clan (http://www.wookie-clan.co.uk/),
who wrote the original script.
Thanks also to e-Gor, a member of Project Reality team (http://www.realitymod.com/) and other guys
from "battlefield 2 editor" forums (http://www.bfeditor.org/forums/),
BF2 Technical Information Wiki (http://bf2.fun-o-matic.org/index.php/Main_Page ),
and to Alan Gauld for his python tutorial (http://www.freenetpages.co.uk/hp/alan.gauld/).

This script is made for Battlefield 2 game and it's intention is to inform player,
if he hit the head of the killed enemy character. When head-shot happens,
message is displayed.
'''
##########################################
#CHANGE LOG

#1.30 Beta - 2008/25/01
#-fixed head-shot messages on some stationary weapons

#1.25 Beta - 2008/23/01
#-fixed head-shot messages

#1.2 Beta - 2008/22/1
#added option "one bullet for head-shot"
#fixed "head-shot message on artillery kill" bug

#1.1 Beta - 2008/21/01
#added option "can be revived after head-shot"
#bullet damage is set back to original
#server performance improved

#1.0 Beta - 2008/17/01
#first version of script released

##########################################

import bf2
import host

##########################################
#Defaults:
c_msgStyle= 0
c_canBeRevived= 1
c_oneBulletForHS = 0
##########################################
try:
from head_shot_CONF import c_msgStyle,c_canBeRevived,c_oneBulletForHS

except: print "Can not locate c_msgStyle,c_canBeRevived,c_oneBulletForHS vars, proceeding with default values"

def init():
#register event
host.registerHandler('PlayerKilled', onPlayerKilled, 1)
host.registerGameStatusHandler(onGameStatusChanged)
print "###"
print "Head-shot module initialised"
print "Configuration is:"
print "c_msgStyle %s\nc_canBeRevived %s\nc_oneBulletForHS %s" % (c_msgStyle,c_canBeRevived,c_oneBulletForHS)
print "###"

#============================================================================
#"CAN BE REVIVED ON KILL" LOGIC
if c_canBeRevived == 1:
if c_oneBulletForHS == 1:
def onGameStatusChanged(status):
templateChange(damageMod=6)

else:#classic Bf2 bullet damage
def onGameStatusChanged(status):
templateChange()

else: #can not be revied
def onGameStatusChanged(status):
templateChange(damageMod=25)
#============================================================================
def templateChange(damageMod=3):
host.rcon_invoke("MaterialManager.createCell 38 25")
host.rcon_invoke('MaterialManager.damageMod '+str(damageMod))
host.rcon_invoke("MaterialManager.setEffectTemplate 0 e_bhit_s_sold_head")
host.rcon_invoke("MaterialManager.setSoundTemplate 0 S_Impact_Flesh")
host.rcon_invoke("""
MaterialManager.createCell 38 77
MaterialManager.damageMod 0.707
MaterialManager.setEffectTemplate 0 e_bhit_s_sold_bodyarmor
MaterialManager.setSoundTemplate 0 S_Impact_Flesh
MaterialManager.createCell 38 24

MaterialManager.createCell 38 23
MaterialManager.damageMod 0.667
MaterialManager.setEffectTemplate 0 e_bhit_s_sold_bodyarmor
MaterialManager.setSoundTemplate 0 S_Impact_Kevlar_Vest

MaterialManager.createCell 38 24
MaterialManager.damageMod 1.007
MaterialManager.setEffectTemplate 0 e_bhit_s_sold_limb
MaterialManager.setSoundTemplate 0 S_Impact_Flesh

MaterialManager.createCell 39 23
MaterialManager.setEffectTemplate 0 e_bhit_s_sold_bodyarmor
MaterialManager.setSoundTemplate 0 S_Impact_Kevlar_Vest

MaterialManager.createCell 39 24
MaterialManager.setEffectTemplate 0 e_bhit_s_sold_limb
MaterialManager.setSoundTemplate 0 S_Impact_Flesh

MaterialManager.createCell 39 25
MaterialManager.damageMod 1.5
MaterialManager.setEffectTemplate 0 e_bhit_s_sold_head
MaterialManager.setSoundTemplate 0 S_Impact_Flesh

MaterialManager.createCell 39 77
MaterialManager.damageMod 0.325
MaterialManager.setEffectTemplate 0 e_bhit_s_sold_bodyarmor
MaterialManager.setSoundTemplate 0 S_Impact_Flesh

MaterialManager.createCell 41 23
MaterialManager.damageMod 0.527
MaterialManager.setEffectTemplate 0 e_bhit_s_sold_bodyarmor
MaterialManager.setSoundTemplate 0 S_Impact_Kevlar_Vest

MaterialManager.createCell 41 24
MaterialManager.damageMod 1.007
MaterialManager.setEffectTemplate 0 e_bhit_s_sold_limb
MaterialManager.setSoundTemplate 0 S_Impact_Flesh

MaterialManager.createCell 41 77
MaterialManager.damageMod 0.707
MaterialManager.setEffectTemplate 0 e_bhit_s_sold_bodyarmor
MaterialManager.setSoundTemplate 0 S_Impact_Flesh """)

#print "damage mod set to %s" % damageMod

#============================================================================
#CREATE LOWER-CASE WEAPON LIST
try:

from hs_weapon_list import allowedWeaponList as tempList
print "handheldList imported successfully"

weaponList=[]

#LOWER-CASE HANDHELD WEAPON NAMES
for weapon in tempList:
weapon=weapon.lower()
weaponList.append(weapon)
else: print "Handheld weapons lower-cased"

except:
print "hs_weapon_list can not be found"
#============================================================================


#SERVER MESSAGE STYLE LOGIC
#depending on serve-message-style choice, one function is defined.I did this here to avoid branching
#in events

if c_msgStyle == 0:
def message(attacker="unknownAttacker",victim="unknownVictim"):
attackerName=attacker.getName()
victimName=victim.getName()
#
message='"'+70*" "+str(attackerName)+" C1001[HEADSHOT]C1001 "+str(victimName)+'"'
host.rcon_invoke('game.sayAll '+message)
else:
def message(attacker="unknownAttacker",victim="unknownVictim"):
attackerName=attacker.getName()
victimName=victim.getName()
#
message='"'+str(attackerName)+" C1001[HEADSHOT]C1001 "+str(victimName)+'"'
host.rcon_invoke('game.sayAll '+message)


if c_canBeRevived == 1:
def onPlayerKilled(victim, attacker, weapon, assists, object):

#all 3 objects are needed, othervise we can't get hs
if attacker and victim and weapon == None:
#print "attacker and victim and weapon are None, returning"
return

#attacker must be "on foot",vehicle kills excluded - This filter can vary, if player gives a kill with vehicle
#and he jumped out before projectile killed enemy
if attacker.getVehicle() != attacker.getDefaultVehicle():
#print "Attacker is in vehicle,returning"
return

#if team-kill happens, head shot isnt valid
if victim.getTeam() == attacker.getTeam():
#print "team-kill happened,returning"
return

#check if suicide happened
if attacker == victim:
#print "suicide happened, returning"
return

weaponName=weapon.templateName
weaponName=weaponName.lower()

#check if weapon is allowed
for weaponStr in weaponList:
if weaponName == weaponStr:
#print "weapon is allowed, proceeding to head-shot"
break

else: #gets executed if weapon is not found (if "break" isnt executed)
#print "no allowed weapon found, hs not valid,returning"
return


victimDamage=victim.getDefaultVehicle().getDamage()
delta=0.1
alwaysTrigger=1
data=[victim, attacker,weapon,victimDamage]

#timer needed because isManDown() would return false on player killed event
bf2.Timer(headShot, delta, alwaysTrigger,data)


def headShot(data):

victim=data[0]
attacker=data[1]
weapon=data[2]
victimDmgBeforeKill=data[3]

try:
victimDmgAfterKill=(victim.getDefaultVehicle().getDamage())*10.0
except AttributeError:
#print "Can not get victimDmgAfterKill, it seems victim is in vehicle,returning"
return
except:
#print "Can not get victimDmgAfterKill,returning"
return

deltaDamage = abs(victimDmgBeforeKill) + abs(victimDmgAfterKill)
deltaDamage = round(deltaDamage,3)

if deltaDamage % 3 == 0.0:
message(attacker,victim)

else:
def onPlayerKilled(victim, attacker, weapon, assists, object):


#all 3 objects are needed, othervise we can't get hs
if attacker and victim and weapon == None:
#print "attacker and victim and weapon are None, returning"
return

#attacker must be "on foot",vehicle kills excluded - This filter can vary, if player gives a kill with vehicle
#and he jumped out before projectile killed enemy
if attacker.getVehicle() != attacker.getDefaultVehicle():
#print "Attacker is in vehicle,returning"
return

#if team-kill happens, head shot isnt valid
if victim.getTeam() == attacker.getTeam():
#print "team-kill happened,returning"
return

#check if suicide happened
if attacker == victim:
#print "suicide happened, returning"
return

weaponName=weapon.templateName
weaponName=weaponName.lower()

#check if weapon is allowed
for weaponStr in weaponList:
if weaponName == weaponStr:
#print "weapon is allowed, proceeding to head-shot"
break

else: #gets executed if weapon is not found (if "break" isnt executed)
#print "no allowed weapon found, hs not valid,returning"
return

delta=0.1
alwaysTrigger=1
data=[victim, attacker,weapon]

#timer needed because isManDown() would return false on player killed event
bf2.Timer(headShot, delta, alwaysTrigger,data)


def headShot(data):
victim=data[0]
attacker=data[1]
weapon=data[2]

victimStatus=victim.isManDown()

if victimStatus == 0:
message(attacker,victim)


--------------------

.All Hail The King..
..My City.. My Secret..
...Your Demise Is Inedible..

....Oblivion Is Your Only Escape..
Go to the top of the page
 
+Quote Post
bobthedinosaur
post Jan 13 2016, 08:35 PM
Post #5


Dictator
******

Group: Soldiers
Posts: 2,202
Joined: 4-March 11
From: A Cold Place
Member No.: 7,896



Yup. wookie sniper wasnt really intended to be a SP or coop mod, it has a ton of extra scripts, and it might be made for version pre 1.5 ?
Go to the top of the page
 
+Quote Post
WarmongerX
post Jan 14 2016, 07:54 AM
Post #6


Bayan o Sarili?
***

Group: Soldiers
Posts: 64
Joined: 14-January 16
From: Pilipinas
Member No.: 11,128



well i had downloaded a script from some website i forgot the name of the website , it will display on the top center screen the "playername [HEADSHOT] playername" and the soldier that is being headshot is not revivable but you can configure it.. give it a try.. i forgot if this is complete but still give it a try

This post has been edited by WarmongerX: Jan 14 2016, 07:57 AM
Attached File(s)
Attached File  game.rar ( 5.27K ) Number of downloads: 9
 
Go to the top of the page
 
+Quote Post
wilson212
post Jan 14 2016, 12:52 PM
Post #7


The Accolade
****

Group: Soldiers
Posts: 115
Joined: 23-June 08
From: Fort Campbell, KY
Member No.: 5,228



Hey thank you for finding this script! after looking through it, isManDown() really does appear to be the way to check for headshots. Thanks again!


--------------------
Go to the top of the page
 
+Quote Post
bobthedinosaur
post Jan 14 2016, 10:53 PM
Post #8


Dictator
******

Group: Soldiers
Posts: 2,202
Joined: 4-March 11
From: A Cold Place
Member No.: 7,896



according to that script it looks for a large amount of damage done in one hit, from specific hand held weapons, and assumes a head shot.
Go to the top of the page
 
+Quote Post
bad_santa12345
post Jan 15 2016, 01:03 AM
Post #9


Captain
***

Group: Soldiers
Posts: 63
Joined: 15-January 12
Member No.: 8,670



I once made a script which detected headshots by checking if the damage inflicted by the killing shot was equal to the killers' weapon damage times the projectile->head material damage multiplier. It also accounted for the damage decreasing over distance. It calculated the exact damage with minDamage, distToStartLoseDamage, distToMinDamage etc. It was more generic and at least in theory more reliable than the wookie/AIX mod approach (which only checks whether the damage is exactly divisible by 3 or very high damage in case the non revivable setting was enabled). I hope this made sense:D

I will search through my hard drives for the script and post it here if i find it.

Go to the top of the page
 
+Quote Post
bobthedinosaur
post Jan 15 2016, 09:56 PM
Post #10


Dictator
******

Group: Soldiers
Posts: 2,202
Joined: 4-March 11
From: A Cold Place
Member No.: 7,896



sounds impressive. is the script resource intensive when running?
Go to the top of the page
 
+Quote Post
ZJU_Railgun
post Jan 16 2016, 10:49 AM
Post #11


Enlisted
*

Group: Soldiers
Posts: 3
Joined: 15-January 16
From: where you think I come from
Member No.: 11,129



Isn't there a variate in BF2's 'kill' event data packet indicating whether a kill is headshot? I have been working on Counter Strike 1.6 scripts before and there's a mark bit in CS1.6's kill event data packet which can identify headshot. Isn't there a similar thing in BF2's system?
I don't think identifying headshot by damage threshold is the best way,because I remember sometimes I got headshot or long sniper shot in AIX2 mod but the system didn't give out a headshot or longshot information.

This post has been edited by ZJU_Railgun: Jan 16 2016, 10:55 AM
Go to the top of the page
 
+Quote Post
bad_santa12345
post Jan 17 2016, 02:05 PM
Post #12


Captain
***

Group: Soldiers
Posts: 63
Joined: 15-January 12
Member No.: 8,670



QUOTE (ZJU_Railgun @ Jan 16 2016, 06:49 PM) *
Isn't there a variate in BF2's 'kill' event data packet indicating whether a kill is headshot? I have been working on Counter Strike 1.6 scripts before and there's a mark bit in CS1.6's kill event data packet which can identify headshot. Isn't there a similar thing in BF2's system?
I don't think identifying headshot by damage threshold is the best way,because I remember sometimes I got headshot or long sniper shot in AIX2 mod but the system didn't give out a headshot or longshot information.


Unlike Counter Strike 1.6, BF2 stat/scoring system doesn't track headshots so DICE had no reason to add such information to the kill event data.


Here is my hit damage/material based script for detecting headshots. It should be saved to "$modpath$/python/game/scoringCommon.py"
CODE
# common scoring
# headshot detection added by Bad_santa12345

import host
import bf2
import math
from bf2.stats.constants import *
from bf2 import g_debug

SCORE_KILL = 2
SCORE_TEAMKILL = -4
SCORE_SUICIDE = -2
SCORE_REVIVE = 2
SCORE_TEAMDAMAGE = -2
SCORE_TEAMVEHICLEDAMAGE = -1
SCORE_DESTROYREMOTECONTROLLED = 1
SCORE_DESTROYVEHICLE = 2

SCORE_KILLASSIST_DRIVER = 1
SCORE_KILLASSIST_PASSENGER = 0
SCORE_KILLASSIST_TARGETER = 1
SCORE_KILLASSIST_DAMAGE = 1
SCORE_HEADSHOT = 1

REPAIR_POINT_LIMIT = 100
HEAL_POINT_LIMIT = 100
GIVEAMMO_POINT_LIMIT = 100
TEAMDAMAGE_POINT_LIMIT = 50
TEAMVEHICLEDAMAGE_POINT_LIMIT = 50

REPLENISH_POINT_MIN_INTERVAL = 30 # seconds

# sub score
NORMAL = 0
SKILL = 1
RPL = 2
CMND = 3



def init():

# set limits for how many repair HPs etc are needed to get a callback
bf2.gameLogic.setHealPointLimit(HEAL_POINT_LIMIT)
bf2.gameLogic.setRepairPointLimit(REPAIR_POINT_LIMIT)
bf2.gameLogic.setGiveAmmoPointLimit(GIVEAMMO_POINT_LIMIT)
bf2.gameLogic.setTeamDamagePointLimit(TEAMDAMAGE_POINT_LIMIT)
bf2.gameLogic.setTeamVehicleDamagePointLimit(TEAMVEHICLEDAMAGE_POINT_LIMIT)

host.registerGameStatusHandler(onGameStatusChanged)

if g_debug: print "scoring common init"



def onGameStatusChanged(status):
if status == bf2.GameStatus.Playing:
host.registerHandler('PlayerKilled', onPlayerKilled)
host.registerHandler('PlayerDeath', onPlayerDeath)
host.registerHandler('PlayerRevived', onPlayerRevived)
host.registerHandler('PlayerHealPoint', onPlayerHealPoint)
host.registerHandler('PlayerRepairPoint', onPlayerRepairPoint)
host.registerHandler('PlayerGiveAmmoPoint', onPlayerGiveAmmoPoint)
host.registerHandler('PlayerTeamDamagePoint', onPlayerTeamDamagePoint)
host.registerHandler('VehicleDestroyed', onVehicleDestroyed)

elif status == bf2.GameStatus.EndGame:

giveCommanderEndScore(bf2.playerManager.getCommander(1), bf2.gameLogic.getWinner())
giveCommanderEndScore(bf2.playerManager.getCommander(2), bf2.gameLogic.getWinner())



# give commander score for every player score
def addScore(player, points, subScore = NORMAL, subPoints = -1):

# commander doesnt get score for regular actions, only for pure commander tasks. he also gets punishing points.
if not player.isCommander() or subScore == CMND or points < 0:
player.score.score += points
if subPoints == -1:
subPoints = points

# sub score
if subScore == RPL:
player.score.rplScore += subPoints
if subScore == SKILL:
player.score.skillScore += subPoints
if subScore == CMND:
player.score.cmdScore += subPoints

# commander score
commander = bf2.playerManager.getCommander(player.getTeam())
if commander != None and commander.isValid() and subScore != CMND and player != commander and points > 0:
preScore = commander.score.score
numPlayers = bf2.playerManager.getNumberOfAlivePlayersInTeam(commander.getTeam())
if numPlayers > 0:
commander.score.score += float(points) / numPlayers
scoreGotten = commander.score.score - preScore
if scoreGotten > 0:
commander.score.cmdScore += scoreGotten



def giveCommanderEndScore(player, winningTeam):
if player == None: return
if player.getTeam() != winningTeam: return

# double the commander score and add to regular score
player.score.score = (player.score.score + player.score.fracScore - player.score.cmdScore) + player.score.cmdScore * 2
player.score.cmdScore = player.score.cmdScore * 2


def onPlayerKilled(victim, attacker, weapon, assists, object):
killedByEmptyVehicle = False
countAssists = False

# killed by unknown, no score
if attacker == None:

# check if killed by vehicle in motion
if weapon == None and object != None:
if hasattr(object, 'lastDrivingPlayerIndex'):
attacker = bf2.playerManager.getPlayerByIndex(object.lastDrivingPlayerIndex)
killedByEmptyVehicle = True


if attacker == None:
if g_debug: print "No attacker found"
pass

victimVehicle = victim.getVehicle()


# killed by remote controlled vehicle, no score awarded in this game
if object and object.isPlayerControlObject and object.getIsRemoteControlled():
pass

# no attacker, killed by object
elif attacker == None:
pass

# killed by self
elif attacker == victim:

# no suicides from own wreck
if killedByEmptyVehicle and object.getIsWreck():
return

attacker.score.suicides += 1
addScore(attacker, SCORE_SUICIDE, RPL)

# killed by own team
elif attacker.getTeam() == victim.getTeam():

# no teamkills from wrecks
if object != None and object.getIsWreck():
return

# no teamkills from artillery
if weapon:
attackerVehicle = bf2.objectManager.getRootParent(weapon)
if attackerVehicle.isPlayerControlObject and attackerVehicle.getIsRemoteControlled():
return

#HF Start
if weapon == None and object != None:
victimVehicle = victim.getVehicle()
victimRootVehicle = bf2.objectManager.getRootParent(victimVehicle)
victimVehicleType = getVehicleType(victimRootVehicle.templateName)
attackerVehicle = attacker.getVehicle()
attackerRootVehicle = bf2.objectManager.getRootParent(attackerVehicle)
attackerVehicleType = getVehicleType(attackerRootVehicle.templateName)
#No tk on roadkill from airplane and helo
if attackerVehicleType == VEHICLE_TYPE_AVIATOR and victimVehicleType == VEHICLE_TYPE_SOLDIER:
return
#HF Stop

attacker.score.TKs += 1
addScore(attacker, SCORE_TEAMKILL, RPL)

countAssists = True

# killed by enemy
else:
attacker.score.kills += 1
addScore(attacker, SCORE_KILL, SKILL)

countAssists = True

#HEADSHOT DETECTION
if weapon != None:
attackerPos = attacker.getDefaultVehicle().getPosition()
victimPos = victim.getDefaultVehicle().getPosition()
distance = getDistance3D(attackerPos, victimPos)

dmgBeforeDeath = victim.getVehicle().getDamage()
data = [victim, attacker, weapon, dmgBeforeDeath, distance]
timer = bf2.Timer(hitMaterialDetection, 0.1, 1, data)

# kill assist
if countAssists and victim:

for a in assists:
assister = a[0]
assistType = a[1]

if assister.getTeam() != victim.getTeam():

# passenger
if assistType == 0:
assister.score.passengerAssists += 1
addScore(assister, SCORE_KILLASSIST_PASSENGER, RPL)
# targeter
elif assistType == 1:
assister.score.targetAssists += 1
addScore(assister, SCORE_KILLASSIST_TARGETER, RPL)
# damage
elif assistType == 2:
assister.score.damageAssists += 1
addScore(assister, SCORE_KILLASSIST_DAMAGE, RPL)
# driver passenger
elif assistType == 3:
assister.score.driverAssists += 1
addScore(assister, SCORE_KILLASSIST_DRIVER, RPL)
else:
# unknown kill type
pass


def calculateDamageAtDistance(maxDamage, minDamage, distToStartLoseDamage, distToMinDamage, distance):
damage = 0.0

if distToMinDamage != 0.0:
damage = maxDamage + (minDamage - maxDamage) * ((distance - distToStartLoseDamage) / (distToMinDamage - distToStartLoseDamage))
damage = min(damage, maxDamage)
damage = max(damage, minDamage)
else:
damage = maxDamage

return damage

#HEADSHOT DETECTION
def hitMaterialDetection(data):

victim = data[0]
attacker = data[1]
weapon = data[2]
dmgBeforeDeath = data[3]
distance = data[4]
dmgAfterDeath = 0
dmgInflicted = 0
try:
dmgAfterDeath = victim.getVehicle().getDamage() * 10
except AttributeError:
print "Can not get victimDmgAfterKill, it seems victim is in vehicle,returning"
return
except:
print "Can not get victimDmgAfterKill,returning"
return

Invoke('ObjectTemplate.active ' + str(weapon.templateName))
projectileTemplate = Invoke('ObjectTemplate.projectileTemplate')

Invoke('ObjectTemplate.active ' + projectileTemplate)
maxDamage = float(Invoke('ObjectTemplate.damage'))
minDamage = float(Invoke('ObjectTemplate.mindamage'))
distToStartLoseDamage = float(Invoke('ObjectTemplate.distToStartLoseDamage'))
distToMinDamage = float(Invoke('ObjectTemplate.distToMinDamage'))
projectileMaterial = Invoke('ObjectTemplate.material')

projectileDamage = calculateDamageAtDistance(maxDamage, minDamage, distToStartLoseDamage, distToMinDamage, distance)

dmgInflicted = dmgBeforeDeath - dmgAfterDeath

dmgRatio = dmgInflicted / float(projectileDamage)

Invoke('materialManager.attMaterial ' + projectileMaterial)

Invoke('materialManager.defMaterial 77')
dmgMod_humanLimbs = float(Invoke('materialManager.damageMod'))

Invoke('materialManager.defMaterial 25')
dmgMod_humanHead = float(Invoke('materialManager.damageMod'))

Invoke('materialManager.defMaterial 24')
dmgMod_humanBody = float(Invoke('materialManager.damageMod'))

Invoke('materialManager.defMaterial 23')
dmgMod_humanBodyArmor = float(Invoke('materialManager.damageMod'))

#create a list of possible hit materials
possibleHitMaterials = []
if abs(dmgRatio - dmgMod_humanHead) <= 0.01:
possibleHitMaterials.append("HEAD")
if abs(dmgRatio - dmgMod_humanLimbs) <= 0.01:
possibleHitMaterials.append("LIMB")
if abs(dmgRatio - dmgMod_humanBody) <= 0.01:
possibleHitMaterials.append("BODY")
if abs(dmgRatio - dmgMod_humanBodyArmor) <= 0.01:
possibleHitMaterials.append("BODYARMOR")

#if there is only one material and it is head then give headshot score
#decided to make it like this because some materials have conflicting damage modifiers and it is impossible to detect headshots
if len(possibleHitMaterials) == 1:
if possibleHitMaterials[0] == "HEAD":
bf2.gameLogic.sendGameEvent(attacker, 9, 1)
addScore(attacker, SCORE_HEADSHOT, RPL)

#Invoke('Game.sayall "' + possibleHitMaterials[0] + '"')
Invoke('Game.sayall "' + ', '.join(possibleHitMaterials) + '"')

timer.Destroy()

def onPlayerDeath(victim, vehicle):
victim.score.deaths += 1



def onPlayerRevived(victim, attacker):
if attacker == None or victim == None or attacker.getTeam() != victim.getTeam():
return

attacker.score.revives += 1
addScore(attacker, SCORE_REVIVE, RPL)

bf2.gameLogic.sendGameEvent(attacker, 10, 4) #10 = Replenish, 4 = Revive



# prevent point-exploiting by replenishing same player again
def checkGrindBlock(player, object):

if object.isPlayerControlObject:
defPlayers = object.getOccupyingPlayers()
if len(defPlayers) > 0:
defPlayer = defPlayers[0]

if not hasattr(player, 'lastReplenishPointMap'):
player.lastReplenishPointMap = {}
else:
if defPlayer.index in player.lastReplenishPointMap:
if player.lastReplenishPointMap[defPlayer.index] + REPLENISH_POINT_MIN_INTERVAL > host.timer_getWallTime():
return True

player.lastReplenishPointMap[defPlayer.index] = host.timer_getWallTime()

return False


def onPlayerHealPoint(player, object):
if checkGrindBlock(player, object):
return

player.score.heals += 1
addScore(player, 1, RPL)
bf2.gameLogic.sendGameEvent(player, 10, 0) # 10 = Replenish, 0 = Heal

giveDriverSpecialPoint(player)



def onPlayerRepairPoint(player, object):
if checkGrindBlock(player, object):
return

player.score.repairs += 1
addScore(player, 1, RPL)
bf2.gameLogic.sendGameEvent(player, 10, 1) # 10 = Replenish, 1 = Repair

giveDriverSpecialPoint(player)



def onPlayerGiveAmmoPoint(player, object):
if checkGrindBlock(player, object):
return

player.score.ammos += 1
addScore(player, 1, RPL)
bf2.gameLogic.sendGameEvent(player, 10, 2) # 10 = Replenish, 2 = Ammo

giveDriverSpecialPoint(player)



def giveDriverSpecialPoint(player):
# special point given to driver, if someone in vehicle gets an abilitypoint
vehicle = player.getVehicle()
if vehicle:
rootVehicle = bf2.objectManager.getRootParent(vehicle)
plrs = rootVehicle.getOccupyingPlayers()
# Protect against empty tuple, which seems to occur.
if len(plrs) == 0: return
driver = plrs[0]
if driver != None and driver != player and driver.getVehicle() == rootVehicle:
driver.score.driverSpecials += 1
addScore(driver, 1, RPL)
bf2.gameLogic.sendGameEvent(driver, 10, 3) #10 = Replenish, 3 = DriverAbility



def onPlayerTeamDamagePoint(player, object):
vehicleType = getVehicleType(object.templateName)

if not player.isCommander():
if vehicleType == VEHICLE_TYPE_SOLDIER:
player.score.teamDamages += 1
addScore(player, SCORE_TEAMDAMAGE, RPL)
else:
player.score.teamVehicleDamages += 1
addScore(player, SCORE_TEAMVEHICLEDAMAGE, RPL)

def onVehicleDestroyed(vehicle, attacker):
if attacker != None and vehicle.getTeam() != 0 and vehicle.getTeam() != attacker.getTeam():
vehicleType = getVehicleType(vehicle.templateName)
if vehicleType == 0 or vehicleType == 1 or vehicleType == 2 or vehicleType == 3 or vehicleType == 4 or vehicleType == 6:
addScore(attacker, SCORE_DESTROYVEHICLE, RPL)
bf2.gameLogic.sendGameEvent(attacker, 10, 5) #10 = Replenish, 5 = DestroyStrategic

def Invoke(command):
return host.rcon_invoke(command)

def getDistance3D(pos1,pos2):
x = pos2[0]-pos1[0]
y = pos2[2]-pos1[2]
z = pos2[1]-pos1[1]
distance = math.sqrt(x*x+y*y+z*z)
return distance


This post has been edited by bad_santa12345: Jan 17 2016, 02:09 PM
Go to the top of the page
 
+Quote Post
wilson212
post Jan 24 2016, 06:22 PM
Post #13


The Accolade
****

Group: Soldiers
Posts: 115
Joined: 23-June 08
From: Fort Campbell, KY
Member No.: 5,228



How intense is this script? I usually play with 64 bots, do you think this will work ok?


--------------------
Go to the top of the page
 
+Quote Post
bad_santa12345
post Jan 27 2016, 10:54 AM
Post #14


Captain
***

Group: Soldiers
Posts: 63
Joined: 15-January 12
Member No.: 8,670



QUOTE (wilson212 @ Jan 25 2016, 02:22 AM) *
How intense is this script? I usually play with 64 bots, do you think this will work ok?
It will work fine no matter how many players. The code is only executed when a player dies and it is only a few simple lines.
Go to the top of the page
 
+Quote Post
Supaflow
post Dec 20 2016, 08:35 AM
Post #15


Captain
***

Group: Soldiers
Posts: 44
Joined: 24-November 07
From: On the battlefield
Member No.: 4,178



Is it possible to implement this in BF2142 somehow? I looked at the code but couldn't get it to work sad.gif
Go to the top of the page
 
+Quote Post

2 Pages V   1 2 >
Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 20th January 2017 - 10:16 PM