Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- import os
- import GUI
- import Math
- import BigWorld
- from json import loads
- from ResMgr import openSection
- from gui import g_guiResetters
- from gui import DEPTH_OF_GunMarker
- from constants import ARENA_PERIOD
- from messenger import MessengerEntry
- from PlayerEvents import g_playerEvents
- from gui.Scaleform.Battle import Battle
- from gui.shared.utils.sound import Sound
- AppName = 'GameOver_Notify'
- AppFile = AppName + '.json'
- g_text = None
- g_other_team = 0
- g_onetime = 0
- g_my_team = 0
- def DefaultConfig():
- return {'ArenaPanel': {
- 'posX': 0,
- 'posY': 100,
- 'hcentered': True,
- 'vcentered': True,
- 'font': 'default_small'},
- 'TimeOut': {
- 'Chat': {'enabled': True,
- 'message': u'Время вышло',
- 'color': '#4CFF47'},
- 'Arena': {'enabled': True,
- 'message': u'Время вышло',
- 'color': '#4cff47',
- 'time': 3.0},
- 'Sound': {'enabled': True,
- 'paths': 'ingame_voice/notifications_VO/target_unlocked'}},
- 'TeamBasePoints': {
- 'Chat': {
- '50': {'enabled': True,
- 'message': u'База захвачена на 50%',
- 'color': '#FFFF47',
- 'sound': 'GUI/dynamic_platoon/starting_dynamic_platoon'},
- '70': {'enabled': True,
- 'message': u'База захвачена на 70%',
- 'color': '#FF9F34',
- 'sound': 'GUI/dynamic_platoon/starting_dynamic_platoon'},
- '90': {'enabled': True,
- 'message': 'База захвачена на 90%',
- 'color': '#FF0000',
- 'sound': 'GUI/dynamic_platoon/starting_dynamic_platoon'}},
- 'Arena': {
- '50': {'enabled': True,
- 'message': u'База захвачена на 50%',
- 'time': 3.0,
- 'color': '#FFFF47',
- 'sound': 'GUI/dynamic_platoon/starting_dynamic_platoon'},
- '70': {'enabled': True,
- 'message': u'База захвачена на 70%',
- 'time': 3.0,
- 'color': '#FF9F34',
- 'sound': 'GUI/dynamic_platoon/starting_dynamic_platoon'},
- '90': {'enabled': True,
- 'message': 'База захвачена на 90%',
- 'time': 3.0,
- 'color': '#FF0000',
- 'sound': 'GUI/dynamic_platoon/starting_dynamic_platoon'}}},
- 'TeamBaseCaptured': {
- 'Chat': {'enabled': True,
- 'message': u'База захвачена',
- 'color': '#CC0006'},
- 'Arena': {'enabled': True,
- 'message': u'База захвачена',
- 'color': '#CC0006',
- 'time': 3.0},
- 'Sound': {'enabled': True,
- 'paths': 'ingame_voice/notifications_VO/target_unlocked'}},
- 'VehicleKilled': {
- 'enabled': True,
- 'allies': u'Союзники',
- 'opponents': u'Противники',
- 'Colors': {
- 'color1': '#83FF79',
- 'color2': '#FF0000',
- 'color3': '#FFFF93'},
- 'MyTeamDestroyed': {
- 'Chat': {'enabled': True,
- 'message': u'Ваша команда уничтожена',
- 'color': '#FF0000'},
- 'Arena': {'enabled': True,
- 'message': u'Ваша команда уничтожена',
- 'color': '#FF0000',
- 'time': 3.0},
- 'Sound': {'enabled': True,
- 'paths': 'ingame_voice/notifications_VO/target_unlocked'}},
- 'TheEnemyTeamDestroyed': {
- 'Chat': {'enabled': True,
- 'message': u'Команда противника уничтожена',
- 'color': '#4CFF47'},
- 'Arena': {'enabled': True,
- 'message': u'Команда противника уничтожена',
- 'color': '#4CFF47',
- 'time': 3.0},
- 'Sound': {'enabled': True,
- 'paths': 'ingame_voice/notifications_VO/target_unlocked'}}
- }
- }
- def FixPath(path):
- a = path.split('/')
- restore = False
- if not a[0]:
- a[0] = '_'
- restore = True
- path = os.path.join(*a)
- if restore:
- return path[1:]
- return path
- def PythonInfo(text):
- try:
- return text.encode('windows-1251')
- except:
- return text
- def PrintError(*args):
- Error = PythonInfo('[' + AppName + ']: ' + str(*args))
- print Error
- def Comments(string, strip_space = True):
- tokenizer = re.compile('"|(/\*)|(\*/)|(//)|\n|\r')
- end_slashes_re = re.compile(r'(\\)*$')
- in_string = False
- in_multi = False
- in_single = False
- new_str = []
- index = 0
- for match in re.finditer(tokenizer, string):
- if not (in_multi or in_single):
- tmp = string[index:match.start()]
- if not in_string and strip_space:
- tmp = re.sub('[ \t\n\r]+', '', tmp)
- new_str.append(tmp)
- index = match.end()
- val = match.group()
- if val == '"' and not (in_multi or in_single):
- escaped = end_slashes_re.search(string, 0, match.start())
- if not in_string or (escaped is None or len(escaped.group()) % 2 == 0):
- in_string = not in_string
- index -= 1
- elif not (in_string or in_multi or in_single):
- if val == '/*':
- in_multi = True
- elif val == '//':
- in_single = True
- elif val == '*/' and in_multi and not (in_string or in_single):
- in_multi = False
- elif val in '\r\n' and not (in_multi or in_string) and in_single:
- in_single = False
- elif not ((in_multi or in_single) or (val in ' \r\n\t' and strip_space)):
- new_str.append(val)
- new_str.append(string[index:])
- return ''.join(new_str)
- def ConfigSection(directory):
- return openSection(FixPath('../paths.xml'))['Paths'].values()[0].asString + FixPath('/' + directory)
- def GameOver_Notify_Cfg():
- global Cfg
- Cfg = None
- conf_file = None
- try:
- conf_file = ConfigSection('scripts/client/mods/' + AppFile)
- file = open(conf_file)
- Cfg = loads(Comments(file.read()))
- file.close()
- print ''
- print '-------------------------------------------------------------------------'
- print PythonInfo(u'[' + AppName + u']: [' + AppName + u' by Ekspoint & waza123, Pepto_]')
- print PythonInfo(u'[' + AppName + u']: Конфиг файл [' + AppFile + u'] Успешно загрузился.')
- print '-------------------------------------------------------------------------'
- print ''
- except Exception as err:
- print ''
- print '-----------------------------------------------------------------------------------------------------------'
- print PythonInfo(u'[' + AppName + u']: [' + AppName + u' by Ekspoint & waza123, Pepto_]')
- PrintError(err)
- print PythonInfo(u'[' + AppName + u']: Конфиг файл [' + AppFile + u'] не правильно настроен или не найден.')
- print PythonInfo(u'[' + AppName + u']: Загружаю из мода встроенный конфиг' + ' ' + '[' + AppFile + ']')
- print '-----------------------------------------------------------------------------------------------------------'
- print ''
- Cfg = DefaultConfig()
- return
- GameOver_Notify_Cfg()
- def PeriodChange(period, *args):
- global g_onetime
- arena = BigWorld.player().arena
- if arena is not None:
- if arena.period == ARENA_PERIOD.AFTERBATTLE and g_onetime != 1:
- g_onetime = 1
- if Cfg['TimeOut']['Chat']['enabled']:
- nst_logs(Cfg['TimeOut']['Chat']['message'], Cfg['TimeOut']['Chat']['color'])
- if Cfg['TimeOut']['Arena']['enabled']:
- nst_text(Cfg['TimeOut']['Arena']['message'], Cfg['TimeOut']['Arena']['time'], Cfg['TimeOut']['Arena']['color'], Cfg['ArenaPanel']['font'])
- if Cfg['TimeOut']['Sound']['enabled']:
- Sound('/' + Cfg['TimeOut']['Sound']['paths']).play()
- return
- def nst_logs(message, color = '#FF0000'):
- MessengerEntry.g_instance.gui.addClientMessage('<font color="' + color + '">' + message + '</font>')
- def nst_text(message, time, color = '#FFFFFF', font = 'hpmp_panel'):
- global g_text
- if g_text is not None:
- GUI.delRoot(g_text)
- g_text = None
- g_text = GUI.Text('')
- g_text.verticalAnchor = 'TOP' #выравнивание элемента по оси Y (top, center, bottom).
- g_text.horizontalAnchor = 'CENTER' #выравнивание элемента по оси Х (left, center, right).
- g_text.widthMode = 'PIXEL'
- g_text.heightMode = 'PIXEL'
- g_text.verticalPositionMode = 'PIXEL'
- g_text.horizontalPositionMode = 'PIXEL'
- g_text.colourFormatting = True
- color = '\\c' + re.sub('[^A-Za-z0-9]+', '', color) + 'FF;'
- font = font + '.font'
- g_text.font = font
- g_text.text = color + message
- GUI.addRoot(g_text)
- onChangeScreenResolution()
- BigWorld.callback(time, nst_del_text)
- return
- def onChangeScreenResolution():
- sr = GUI.screenResolution()
- if g_text is None:
- return
- x = sr[0] / 2 + Cfg['ArenaPanel']['posX'] if Cfg['ArenaPanel']['hcentered'] else Cfg['ArenaPanel']['posX']
- y = sr[1] / 2 + Cfg['ArenaPanel']['posY'] if Cfg['ArenaPanel']['vcentered'] else Cfg['ArenaPanel']['posY']
- g_text.position = (x, y, DEPTH_OF_GunMarker)
- return
- g_guiResetters.add(onChangeScreenResolution)
- def Setup():
- global g_onetime
- global g_other_team
- global g_my_team
- g_other_team = 0
- g_onetime = 0
- g_my_team = 0
- def new_Battle_afterCreate(self):
- Setup()
- old_Battle_afterCreate(self)
- old_Battle_afterCreate = Battle.afterCreate
- Battle.afterCreate = new_Battle_afterCreate
- def nst_del_text():
- global g_text
- if g_text is not None:
- GUI.delRoot(g_text)
- g_text = None
- return
- def TeamBasePointsUpdate(team, baseID, points, capturingStopped):
- if g_onetime != 1:
- if points == 50:
- if Cfg['TeamBasePoints']['Chat']['50']['enabled']:
- nst_logs(Cfg['TeamBasePoints']['Chat']['50']['message'], Cfg['TeamBasePoints']['Chat']['50']['color'])
- Sound('/' + Cfg['TeamBasePoints']['Chat']['50']['sound']).play()
- if Cfg['TeamBasePoints']['Arena']['50']['enabled']:
- nst_text(Cfg['TeamBasePoints']['Arena']['50']['message'], Cfg['TeamBasePoints']['Arena']['50']['time'], Cfg['TeamBasePoints']['Arena']['50']['color'], Cfg['ArenaPanel']['font'])
- Sound('/' + Cfg['TeamBasePoints']['Arena']['50']['sound']).play()
- if points == 70:
- if Cfg['TeamBasePoints']['Chat']['70']['enabled']:
- nst_logs(Cfg['TeamBasePoints']['Chat']['70']['message'], Cfg['TeamBasePoints']['Chat']['70']['color'])
- Sound('/' + Cfg['TeamBasePoints']['Chat']['70']['sound']).play()
- if Cfg['TeamBasePoints']['Arena']['70']['enabled']:
- nst_text(Cfg['TeamBasePoints']['Arena']['70']['message'], Cfg['TeamBasePoints']['Arena']['70']['time'], Cfg['TeamBasePoints']['Arena']['70']['color'], Cfg['ArenaPanel']['font'])
- Sound('/' + Cfg['TeamBasePoints']['Arena']['70']['sound']).play()
- if points == 90:
- if Cfg['TeamBasePoints']['Chat']['90']['enabled']:
- nst_logs(Cfg['TeamBasePoints']['Chat']['90']['message'], Cfg['TeamBasePoints']['Chat']['90']['color'])
- Sound('/' + Cfg['TeamBasePoints']['Chat']['90']['sound']).play()
- if Cfg['TeamBasePoints']['Arena']['90']['enabled']:
- nst_text(Cfg['TeamBasePoints']['Arena']['90']['message'], Cfg['TeamBasePoints']['Arena']['90']['time'], Cfg['TeamBasePoints']['Arena']['90']['color'], Cfg['ArenaPanel']['font'])
- Sound('/' + Cfg['TeamBasePoints']['Arena']['90']['sound']).play()
- def TeamBaseCaptured(team, baseID):
- global g_onetime
- if g_onetime != 1:
- g_onetime = 1
- if Cfg['TeamBaseCaptured']['Chat']['enabled']:
- nst_logs(Cfg['TeamBaseCaptured']['Chat']['message'], Cfg['TeamBaseCaptured']['Chat']['color'])
- if Cfg['TeamBaseCaptured']['Arena']['enabled']:
- nst_text(Cfg['TeamBaseCaptured']['Arena']['message'], Cfg['TeamBaseCaptured']['Arena']['time'], Cfg['TeamBaseCaptured']['Arena']['color'], Cfg['ArenaPanel']['font'])
- if Cfg['TeamBaseCaptured']['Sound']['enabled']:
- Sound('/' + Cfg['TeamBaseCaptured']['Sound']['paths']).play()
- def VehicleKilled(victimID, killerID, equipmentID, reason):
- global g_onetime
- global g_other_team
- global g_my_team
- arena = BigWorld.player().arena
- if arena is not None:
- total_other_team_players = len(BigWorld.player().arena.vehicles) / 2
- if total_other_team_players != 0:
- if BigWorld.player().team == BigWorld.player().arena.vehicles[victimID]['team']:
- g_my_team = g_my_team + 1
- c = Cfg['VehicleKilled']['Colors']['color2']
- if g_my_team > g_other_team:
- c = Cfg['VehicleKilled']['Colors']['color2']
- if g_my_team < g_other_team:
- c = Cfg['VehicleKilled']['Colors']['color1']
- if g_my_team == g_other_team:
- c = Cfg['VehicleKilled']['Colors']['color3']
- if Cfg['VehicleKilled']['enabled']:
- nst_logs(Cfg['VehicleKilled']['allies'] + ' ' + str(total_other_team_players - g_my_team) + ' ' + str(total_other_team_players - g_other_team) + ' ' + Cfg['VehicleKilled']['opponents'], c)
- if total_other_team_players == g_my_team and g_onetime != 1:
- g_onetime = 1
- if Cfg['VehicleKilled']['MyTeamDestroyed']['Chat']['enabled']:
- nst_logs(Cfg['VehicleKilled']['MyTeamDestroyed']['Chat']['message'], Cfg['VehicleKilled']['MyTeamDestroyed']['Chat']['color'])
- if Cfg['VehicleKilled']['MyTeamDestroyed']['Arena']['enabled']:
- nst_text(Cfg['VehicleKilled']['MyTeamDestroyed']['Arena']['message'], Cfg['VehicleKilled']['MyTeamDestroyed']['Arena']['time'], Cfg['VehicleKilled']['MyTeamDestroyed']['Arena']['color'], Cfg['ArenaPanel']['font'])
- if Cfg['VehicleKilled']['MyTeamDestroyed']['Sound']['enabled']:
- Sound('/' + Cfg['VehicleKilled']['MyTeamDestroyed']['Sound']['paths']).play()
- if BigWorld.player().team != BigWorld.player().arena.vehicles[victimID]['team']:
- g_other_team = g_other_team + 1
- c = Cfg['VehicleKilled']['Colors']['color2']
- if g_my_team > g_other_team:
- c = Cfg['VehicleKilled']['Colors']['color2']
- if g_my_team < g_other_team:
- c = Cfg['VehicleKilled']['Colors']['color1']
- if g_my_team == g_other_team:
- c = Cfg['VehicleKilled']['Colors']['color3']
- if Cfg['VehicleKilled']['enabled']:
- nst_logs(Cfg['VehicleKilled']['allies'] + ' ' + str(total_other_team_players - g_my_team) + ' ' + str(total_other_team_players - g_other_team) + ' ' + Cfg['VehicleKilled']['opponents'], c)
- if total_other_team_players == g_other_team and g_onetime != 1:
- g_onetime = 1
- if Cfg['VehicleKilled']['TheEnemyTeamDestroyed']['Chat']['enabled']:
- nst_logs(Cfg['VehicleKilled']['TheEnemyTeamDestroyed']['Chat']['message'], Cfg['VehicleKilled']['TheEnemyTeamDestroyed']['Chat']['color'])
- if Cfg['VehicleKilled']['TheEnemyTeamDestroyed']['Arena']['enabled']:
- nst_text(Cfg['VehicleKilled']['TheEnemyTeamDestroyed']['Arena']['message'], Cfg['VehicleKilled']['TheEnemyTeamDestroyed']['Arena']['time'], Cfg['VehicleKilled']['TheEnemyTeamDestroyed']['Arena']['color'], Cfg['ArenaPanel']['font'])
- if Cfg['VehicleKilled']['TheEnemyTeamDestroyed']['Sound']['enabled']:
- Sound('/' + Cfg['VehicleKilled']['TheEnemyTeamDestroyed']['Sound']['paths']).play()
- return
- def avatarReady():
- arena = BigWorld.player().arena
- if arena is not None:
- arena.onTeamBasePointsUpdate += TeamBasePointsUpdate
- arena.onTeamBaseCaptured += TeamBaseCaptured
- arena.onVehicleKilled += VehicleKilled
- arena.onPeriodChange += PeriodChange
- return
- g_playerEvents.onAvatarReady += avatarReady
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement