Created
May 20, 2017 18:42
-
-
Save SpencerSharkey/e5635ffc6605a90be3b1ff34ac7b9fef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Work only for camp_gibraltar gpm_nv 16, but you can add the other spawnpoint coordonates for the other maps! | |
import bf2 | |
import host | |
import bf2.PlayerManager | |
import bf2.GameLogic | |
import bf2.Timer | |
import math | |
import time | |
#PARAMETERS YOU CAN CHANGE | |
protectedTime = 4 #Time during the player is protected | |
maxBulletFired = 4 #The maximum bullets can fired a spawned player | |
distanceSpawnKill = 10 #Maximum distance treated as spawnkill | |
maxSpawnKill = 3 #Maximum spawnkill before apply the punishment! | |
punishSpawnKiller = -5 #Punishment : number of points lost | |
maxRulesBroken = 2 | |
#SPAWNPOINTS, YOU CAN ADD THE OTHER SPAWNPOINTS OF THE OTHER MAPS HERE | |
suez_canal = {'name' : 'SUEZ_CANAL', 'mode' : 'gpm_coop', 'size' : '16', | |
'601' : [(-559.0,51.0,-9.3),(-560.4,51.0,-1.0), (-571.5,51.0,-3.2)], | |
'602' : [(-379.700,50.000,8.472), (-406.682,50.000,-59.026), (-351.933,50.000,-55.709), (-373.000,49.996,-62.000), | |
(-356.715,50.000,-12.917), (-359.927,50.000,-63.514), (-345.289,50.000,-4.027)]} | |
camp_gibraltar = {'name' : 'CAMP_GIBRALTAR', 'mode' : 'gpm_nv', 'size' : '16', | |
'301' : [(26.628,15.319,266.877),(19.325,15.319,279.746),(39.810,23.767,299.127),(32.354,15.319,265.938),(31.297,15.319,251.898), | |
(48.720,15.319,237.688),(82.690,15.319,243.538),(96.133,15.319,255.587),(88.061,15.319,255.562)], | |
'304' : [(84.656,15.449,99.529),(103.087,15.630,97.319),(72.641,15.108,86.945),(113.061,15.611,97.302),(113.237,15.257,84.728),(102.858,15.373,82.430)], | |
'305' : [(103.815,22.197,147.061),(35.791,19.461,142.448),(106.547,15.319,167.910),(103.475,15.339,166.334),(104.738,15.538,143.509), | |
(109.831,15.557,139.313),(29.002,15.405,161.332),(28.430,15.445,139.201),(42.089,15.320,165.240)], | |
'401' : [(187.262,22.242,38.253),(188.605,15.678,49.746),(186.557,15.115,13.899),(177.058,14.923,13.795),(186.046,15.212,4.805), | |
(165.548,17.855,3.858),(161.874,17.965,4.234)]} | |
camp_gibraltar_32 = {'name' : 'CAMP_GIBRALTAR', 'mode' : 'gpm_nv', 'size' : '32', | |
'201' :[(-85.029/6.672/340.896),(-124.463/2.671/414.905),(-46.103/3.084/379.401 ),(-43.854/4.242/374.185 ),(-116.468/3.305/402.964),(-49.063/4.966/371.534), | |
(-88.914/4.766/332.882),(-81.077/2.776/363.740),(-108.414/2.690/418.489),(-67.819/7.553/305.070),(-58.891/4.939/371.148)], | |
'202' :[(-2.932/15.717/282.435),(10.057/15.319/265.110),(-11.420/15.699/284.521),(-14.383/24.085/295.755),(-6.507/15.319/296.584),(-6.378/15.330/269.890), | |
(21.521/15.570/313.771),(28.423/15.579/312.836),(29.529/15.600/306.320)], | |
'203' :[(35.798/19.461/142.394),(30.893/15.389/168.429),(105.638/15.319/135.392),(103.453/15.356/166.194),(106.357/15.319/167.915),(103.771/22.197/147.081), | |
(44.935/15.319/173.955),(34.817/15.449/139.844),(71.331/15.327/206.190),(76.336/15.319/206.237)], | |
'204' :[(113.088/15.285/84.440),(113.153/15.604/97.215),(84.704/15.588/84.693),(103.321/15.472/98.811),(84.933/15.522/99.595),(103.482/15.370/82.519), | |
(72.575/15.108/87.322),(72.754/15.108/84.976)], | |
'205' :[(180.927/15.313/46.836),(195.854/15.183/25.131),(176.204/17.095/-1.706),(185.148/21.644/6.534), | |
(192.823/15.220/4.751),(195.513/15.646/44.326),(205.016/15.529/41.940),(177.284/21.667/6.422),(204.634/15.319/30.071),(186.869/22.230/42.071)], | |
'207' :[(110.108/15.251/-47.598),(71.124/15.226/-22.567),(71.042/15.461/0.457),(71.436/22.059/-9.697),(74.484/15.119/-19.733),(66.127/15.444/-10.142), | |
(74.033/22.061/-33.880)]} | |
tunis_harbor = {'name' : 'TUNIS_HARBOR', 'mode' : 'gpm_nv', 'size' : '16', | |
'301' : [()], | |
'302' : [()], | |
'303' : [()], | |
'304' : [()]} | |
#ADD THE NAME_MAP HERE | |
mapList = [suez_canal, camp_gibraltar, tunis_harbor, camp_gibraltar_32] | |
#LIST, DON'T TOUCH PLZ! | |
g_controlPoints = [] | |
rulesBreaker = [] | |
def init(): | |
host.registerGameStatusHandler(onGameStatusChanged) | |
host.registerHandler('PlayerConnect', onPlayerConnect, 1) | |
host.registerHandler('PlayerSpawn', onPlayerSpawn) | |
host.registerHandler('PlayerKilled', onPlayerKilled) | |
def onGameStatusChanged(status): | |
global g_controlPoints | |
global rulesBreaker | |
if status == bf2.GameStatus.Playing: | |
g_controlPoints = bf2.objectManager.getObjectsOfType('dice.hfe.world.ObjectTemplate.ControlPoint') | |
if status == bf2.GameStatus.EndGame: | |
g_controlPoints = [] | |
rulesBreaker = [] | |
for p in bf2.playerManager.getPlayers(): | |
p.flagId = '0' | |
p.timeProtectedAfterSpawn = 99999999999999999999999999999 | |
p.afkKills = 0 | |
p.rulesBroken = 0 | |
def onPlayerConnect(player): | |
player.flagId = '0' | |
player.timeProtectedAfterSpawn = 99999999999999999999999999999 | |
player.afkKills = 0 | |
player.rulesBroken = 0 | |
def onPlayerSpawn(player, soldier): | |
if player.getSquadId() > 0: | |
pos1 = player.getVehicle().getPosition() | |
squadLeader = bf2.playerManager.getSquadLeader(player.getTeam(), player.getSquadId()) | |
pos2 = squadLeader.getVehicle().getPosition() | |
dist = getVectorDistance(pos1, pos2) | |
if dist < 5: | |
return | |
player.bulletsFired = getBulletsFired(player) | |
player.timeProtectedAfterSpawn = time.time() + protectedTime | |
testIfEnnemyNear(player, None) #Teleport the player at the farthest spawnpoint if this one is occupied by an enemy | |
def onPlayerKilled(victim, attacker, weapon, assists, object): | |
global rulesBreaker | |
if attacker == None: return | |
if victim.timeProtectedAfterSpawn >= time.time() and victim.getTeam() != attacker.getTeam(): | |
bullets = getBulletsFired(victim) | |
if bullets < (victim.bulletsFired + maxBulletFired): | |
for p in bf2.playerManager.getPlayers(): | |
if p.getTeam() == victim.getTeam() and p != victim: | |
kit = p.getKit() | |
if 'ASSAULT' in kit.templateName.upper(): | |
pPos = p.getVehicle().getPosition() | |
victim.getVehicle().setPosition(pPos) | |
attacker.score.score -= 1 | |
attacker.afkKills += 1 | |
attacker.score.kills -= 1 | |
victim.score.deaths -= 1 | |
host.sgl_sendTextMessage(attacker.index, 14, 4, 'RESPECT THE RULES : NO SPAWNKILL' , 0) | |
host.rcon_invoke('game.sayall "|C1001Rules :|C1001 '+ attacker.getName() +' don\'t spawnkill! ['+ str(attacker.afkKills) +'/'+ str(maxSpawnKill) +']"') | |
if attacker.afkKills >= maxSpawnKill: | |
attacker.score.score += punishSpawnKiller | |
attacker.afkKills = 0 | |
attacker.rulesBroken += 1 | |
host.sgl_sendGameLogicEvent(attacker.index, 20, 1) | |
if attacker.rulesBroken >= maxRulesBroken: | |
rulesBreaker.append(attacker) | |
flou() | |
def flou(): | |
bf2.Timer(flou2, 0.1, 1) | |
def flou2(data): | |
for p in rulesBreaker: | |
bf2.gameLogic.sendGameEvent(p, 13, 1) #Flouette l'écran du joueur. | |
flou() | |
def getBulletsFired(player): | |
bulletsFired = player.score.bulletsFired | |
nr = 0 | |
for b in bulletsFired: | |
nr += b[1] | |
return nr | |
def testIfEnnemyNear(player, searchInList): | |
global g_controlPoints | |
playerPos = player.getVehicle().getPosition() #Don't replace its by player.playerPos!!! | |
teams = [[],[]] | |
for flag in g_controlPoints: | |
id = 0 | |
if player.getTeam() != int(flag.cp_getParam('team')): | |
id = 1 | |
teams[id].append(flag) # id: 0 = Same team that the player, 1 = team different (Neutral or Enemy) | |
#Get the nearest flag | |
keep = min([(getVectorDistance(flag.getPosition(), playerPos), flag) for flag in teams[0]])[1:] | |
for flag in keep: | |
try: | |
player.flagId = flag.getTemplateProperty('controlPointId') | |
except: | |
'Player' | |
noobs = [] | |
dist = 9999 | |
for p in bf2.playerManager.getPlayers(): | |
if p.getTeam() != player.getTeam() and p.isAlive() and not p.isManDown(): | |
pPos = p.getVehicle().getPosition() | |
dist = getVectorDistance(pPos,playerPos) | |
if dist < distanceSpawnKill: #If an enemy is near | |
noobs.append(p) | |
if len(noobs) > 0: | |
findOtherSpawnPointMoreFar(player, noobs, searchInList) | |
def findOtherSpawnPointMoreFar(player, noobs, searchInList): | |
spList = [] | |
if searchInList == None: #Triggered at spawn | |
id = int(host.rcon_invoke('maplist.currentMap' )) | |
mL = host.rcon_invoke('maplist.list' ) | |
nML = mL.split(':') | |
for map in mapList: | |
if bf2.gameLogic.getMapName().upper() == map.get('name') and host.ss_getParam('gameMode') == map.get('mode') and map.get('size') in nML[id+1]: #and str(bf2.gameLogic.getWorldSize()) == map.get('size') #bf2.gameLogic.getWorldSize() doesn't work!!! FUCK DICE! | |
for l in map.get(player.flagId): | |
spList.append(l) | |
elif searchInList == []: #Triggered when enemy players are near all the spawnpoints... | |
for noob in noobs: | |
message = noob.getName().upper() +' STOP TO CAMP NEAR THE ENEMI SPAWNPOINTS' | |
host.sgl_sendTextMessage(noob.index, 14, 4, message , 0) | |
host.sgl_sendGameLogicEvent(noob.index, 20, 1) | |
return | |
else: #The player has been teleported near another enemy, the script have to find the farthest spawnpoint excepted the precedent spawnpoints. | |
for l in searchInList: | |
spList.append(l) | |
keep = max([(getVectorDistance(sp, player.getVehicle().getPosition()), sp) for sp in spList])[1:] | |
for obj in keep: | |
try: | |
test = obj.getName() | |
'Filter' | |
except: | |
maxPos = obj | |
player.getVehicle().setPosition(maxPos) | |
spList.remove(maxPos) | |
testIfEnnemyNear(player, spList) | |
def getVectorDistance(pos1, pos2): | |
diffVec = [0.0, 0.0, 0.0] | |
diffVec[0] = math.fabs(pos1[0] - pos2[0]) | |
diffVec[1] = math.fabs(pos1[1] - pos2[1]) | |
diffVec[2] = math.fabs(pos1[2] - pos2[2]) | |
return math.sqrt(diffVec[0] * diffVec[0] + diffVec[1] * diffVec[1] + diffVec[2] * diffVec[2]) | |
host.rcon_invoke('echo "BZH-SERVER\'s SpawnManager Script Loaded!"') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment