adjgam 4 Posted August 19, 2016 почему пишет? *** File "", line 99, in _onHealthChanged*** File "", line 99, in _onHealthChanged*** File "", line 99, in _onHealthChanged*** File "", line 99, in _onHealthChanged*** File "", line 99, in _onHealthChanged*** File "", line 99, in _onHealthChanged*** File "", line 99, in _onHealthChanged*** File "", line 99, in _onHealthChanged*** File "", line 99, in _onHealthChanged*** File "", line 99, in _onHealthChanged*** File "", line 99, in _onHealthChanged*** File "", line 99, in _onHealthChanged*** File "", line 99, in _onHealthChanged*** File "", line 99, in _onHealthChanged*** File "", line 99, in _onHealthChanged*** File "", line 99, in _onHealthChanged*** RuntimeError: maximum recursion depth exceeded while calling a Python object *** File "", line 120, in _onLeaveWorld*** File "", line 120, in _onLeaveWorld*** File "", line 120, in _onLeaveWorld*** File "", line 120, in _onLeaveWorld*** File "", line 120, in _onLeaveWorld*** File "", line 120, in _onLeaveWorld*** File "", line 120, in _onLeaveWorld*** File "", line 120, in _onLeaveWorld*** File "", line 120, in _onLeaveWorld*** File "", line 120, in _onLeaveWorld*** File "", line 120, in _onLeaveWorld*** File "", line 120, in _onLeaveWorld*** File "", line 120, in _onLeaveWorld*** File "", line 120, in _onLeaveWorld*** File "", line 120, in _onLeaveWorld*** File "", line 120, in _onLeaveWorld*** File "", line 120, in _onLeaveWorld*** File "", line 120, in _onLeaveWorld*** RuntimeError: maximum recursion depth exceeded while calling a Python object import BigWorld import os import json import httplib, urllib2 from Avatar import PlayerAvatar from items import vehicles from Vehicle import Vehicle import Math url = '' LastHP = 0 # read GameSense url def Gamesense_ReadUrl(): with open(os.getenv('PROGRAMDATA')+'/SteelSeries/SteelSeries Engine 3/coreProps.json', 'r') as f: data = json.load(f) global url url = 'http://' + data['address'] # register game def Gamesense_RegisterGame(): data = {"game":"WOT","game_display_name":"World Of Tanks","icon_color_id":11} req = urllib2.Request(url+'/game_metadata') req.add_header('Content-Type', 'application/json') response = urllib2.urlopen(req, json.dumps(data)) # delete game def Gamesense_DeleteGame(): data = {"game":"WOT"} req = urllib2.Request(url+'/remove_game') req.add_header('Content-Type', 'application/json') response = urllib2.urlopen(req, json.dumps(data)) # register HP event def Gamesense_RegisterHpEvent(): data = { "game":"WOT", "event":"HP", "min_value":1, "max_value":100, "icon_id":1, "handlers": [{"zone":"headset", "color": {"gradient":{ "zero": {"red":255,"green":0,"blue":0}, "hundred": {"red":0,"green":255,"blue":0} } }, "mode":"percent", "device-type":"rgb-1-zone" }]} req = urllib2.Request(url+'/bind_game_event') req.add_header('Content-Type', 'application/json') response = urllib2.urlopen(req, json.dumps(data)) # delete game event def Gamesense_DeleteEvent(EventName): data = {"game":"WOT","event":"+EventName+"} req = urllib2.Request(url+'/remove_game_event') req.add_header('Content-Type', 'application/json') response = urllib2.urlopen(req, json.dumps(data)) # post HP change event 0..100 def HpChange(n): data = {"game":"WOT","event":"HP","data":{"value": n}} req = urllib2.Request(url+'/game_event') req.add_header('Content-Type', 'application/json') response = urllib2.urlopen(req, json.dumps(data)) # change color def Gamesense_SetRgb(r, g, b): data = {"game":"WOT","event":"SETRGB","data":{"r": r, "g": g, "b": b}} req = urllib2.Request(url+'/game_event') req.add_header('Content-Type', 'application/json') response = urllib2.urlopen(req, json.dumps(data)) # post Keepalive Event def Gamesense_PostHearBeat(): data = {"game":"WOT"} req = urllib2.Request(url+'/game_heartbeat') req.add_header('Content-Type', 'application/json') response = urllib2.urlopen(req, json.dumps(data)) # gamesense hearbeat 15s = set default def _loop(): Gamesense_PostHearBeat() BigWorld.callback(10, _loop) # on battle loaded set green def new_onInitStepCompleted(self): # update url Gamesense_ReadUrl() Gamesense_SetRgb(0,255,0) old_onInitStepCompleted = PlayerAvatar._PlayerAvatar__onInitStepCompleted PlayerAvatar._PlayerAvatar__onInitStepCompleted = new_onInitStepCompleted # on hp change def _onHealthChanged(self, newHealth, attackerID, attackReasonID): orig_onHealthChanged(self, newHealth, attackerID, attackReasonID) playerVehicle = BigWorld.entity(BigWorld.player().playerVehicleID) global LastHP if playerVehicle is not None and playerVehicle.isStarted and playerVehicle.isPlayerVehicle: HP = playerVehicle.health MaxHP = playerVehicle.typeDescriptor.maxHealth if LastHP == HP: return LastHP = HP if HP>0: # playerVehicle.isAlive() HPPercent = math.trunc(HP*100/MaxHP) HpChange(HPPercent) else: Gamesense_SetRgb(0 ,0, 0) return return orig_onHealthChanged = Vehicle.onHealthChanged Vehicle.onHealthChanged = _onHealthChanged def _onLeaveWorld(self): orig_onLeaveWorld(self) Gamesense_SetRgb(0,0,0) orig_onLeaveWorld = PlayerAvatar.onLeaveWorld PlayerAvatar.onLeaveWorld = _onLeaveWorld Gamesense_ReadUrl() Gamesense_SetRgb(0, 0, 0) # set color (0,0,0) on game init _loop() вывод.txt Quote Share this post Link to post Short link Share on other sites
SkepticalFox 1,445 #348484 Posted August 19, 2016 @adjgam, а кто будет потоки использовать? Игра повиснет к хренам от такого скрипта. Quote Share this post Link to post Short link Share on other sites
adjgam 4 #348488 Posted August 19, 2016 тоесть в new_onInitStepCompleted запустить поток, и в потоке по таймеру выполнять то, что я делаю в _onHealthChanged? Quote Share this post Link to post Short link Share on other sites
SkepticalFox 1,445 #348498 Posted August 19, 2016 @adjgam, ну примерно так: http://www.koreanrandom.com/forum/topic/30746-/ Quote Share this post Link to post Short link Share on other sites
adjgam 4 #348950 Posted August 21, 2016 так? import BigWorld import os import json import httplib, urllib2 from Avatar import PlayerAvatar from items import vehicles from Vehicle import Vehicle import Math import math import threading print "gamesense loaded" url = '' LastHP = 0 # read GameSense url def Gamesense_ReadUrl(): with open(os.getenv('PROGRAMDATA')+'/SteelSeries/SteelSeries Engine 3/coreProps.json', 'r') as f: data = json.load(f) global url url = 'http://' + data['address'] # register game def Gamesense_RegisterGame(): data = {"game":"WOT","game_display_name":"World Of Tanks","icon_color_id":11} req = urllib2.Request(url+'/game_metadata') req.add_header('Content-Type', 'application/json') response = urllib2.urlopen(req, json.dumps(data)) # delete game def Gamesense_DeleteGame(): data = {"game":"WOT"} req = urllib2.Request(url+'/remove_game') req.add_header('Content-Type', 'application/json') response = urllib2.urlopen(req, json.dumps(data)) # register HP event def Gamesense_RegisterHpEvent(): data = { "game":"WOT", "event":"HP", "min_value":1, "max_value":100, "icon_id":1, "handlers": [{"zone":"headset", "color": {"gradient":{ "zero": {"red":255,"green":0,"blue":0}, "hundred": {"red":0,"green":255,"blue":0} } }, "mode":"percent", "device-type":"rgb-1-zone" }]} req = urllib2.Request(url+'/bind_game_event') req.add_header('Content-Type', 'application/json') response = urllib2.urlopen(req, json.dumps(data)) # delete game event def Gamesense_DeleteEvent(EventName): data = {"game":"WOT","event":"+EventName+"} req = urllib2.Request(url+'/remove_game_event') req.add_header('Content-Type', 'application/json') response = urllib2.urlopen(req, json.dumps(data)) # post HP change event 0..100 def HpChange(n): data = {"game":"WOT","event":"HP","data":{"value": n}} req = urllib2.Request(url+'/game_event') req.add_header('Content-Type', 'application/json') response = urllib2.urlopen(req, json.dumps(data)) # change color def Gamesense_SetRgb(r, g, b): data = {"game":"WOT","event":"SETRGB","data":{"r": r, "g": g, "b": b}} req = urllib2.Request(url+'/game_event') req.add_header('Content-Type', 'application/json') response = urllib2.urlopen(req, json.dumps(data)) # post Keepalive Event def Gamesense_PostHearBeat(): data = {"game":"WOT"} req = urllib2.Request(url+'/game_heartbeat') req.add_header('Content-Type', 'application/json') response = urllib2.urlopen(req, json.dumps(data)) def threadDecorate(object): def decorate(*args, **kwargs): th = threading.Thread(target=object, args=args, kwargs=kwargs) th.setName = object.func_name th.setDaemon = True th.start() return decorate # gamesense hearbeat 15s = set default @threadDecorate def _loop(): Gamesense_PostHearBeat() BigWorld.callback(10, _loop) # on battle loaded set green def _onInitStepCompleted(self): orig_onInitStepCompleted(self) Gamesense_SetRgb(0,255,0) orig_onInitStepCompleted = PlayerAvatar._PlayerAvatar__onInitStepCompleted PlayerAvatar._PlayerAvatar__onInitStepCompleted = _onInitStepCompleted # on hp change @threadDecorate def OnHp(): playerVehicle = BigWorld.entity(BigWorld.player().playerVehicleID) global LastHP if playerVehicle is not None and playerVehicle.isStarted and playerVehicle.isPlayerVehicle: HP = playerVehicle.health MaxHP = playerVehicle.typeDescriptor.maxHealth if LastHP == HP: return LastHP = HP if HP>0: # playerVehicle.isAlive() HPPercent = math.trunc(HP*100/MaxHP) HpChange(HPPercent) else: Gamesense_SetRgb(0 ,0, 0) return return def _onHealthChanged(self, newHealth, attackerID, attackReasonID): orig_onHealthChanged(self, newHealth, attackerID, attackReasonID) OnHp() orig_onHealthChanged = Vehicle.onHealthChanged Vehicle.onHealthChanged = _onHealthChanged def _onLeaveWorld(self): orig_onLeaveWorld(self) Gamesense_SetRgb(0,0,0) orig_onLeaveWorld = PlayerAvatar.onLeaveWorld PlayerAvatar.onLeaveWorld = _onLeaveWorld Gamesense_ReadUrl() Gamesense_SetRgb(0, 0, 0) # set color (0,0,0) on game init _loop() Quote Share this post Link to post Short link Share on other sites
SkepticalFox 1,445 #348961 Posted August 21, 2016 (edited) @adjgam, всё сетевое нужно вынести в поток и прописать timeout на запрос. И я не уверен, что urllib2 будет потокобезопасен. Edited August 21, 2016 by ShadowHunterRUS Quote Share this post Link to post Short link Share on other sites