Sober 37 Posted May 16, 2014 Share Posted May 16, 2014 Guys i am trying to figure out how to do a timer on metin2 client. i use the function time.sleep(3) but the client freezes for 3 seconds xD Any ideas on how to do it without freezing? Link to comment Share on other sites More sharing options...
Premium Sanchez 2474 Posted May 16, 2014 Premium Share Posted May 16, 2014 time.sleep is equal with thread.sleep in common program languages and that is not equal with timer. For timer you can use the default OnUpdate function or use the official one: https://docs.python.org/release/2.5.2/lib/timer-objects.html 1 2 2 Link to comment Share on other sites More sharing options...
Sober 37 Posted May 16, 2014 Author Share Posted May 16, 2014 global name 'timer' is not defined I get this error when i try these. t = timer(3.0,__hideKillsGuiBg) t.start() I tried: from threading import Timer but i get an error : there isn't any module called threading Link to comment Share on other sites More sharing options...
Premium Sanchez 2474 Posted May 16, 2014 Premium Share Posted May 16, 2014 Are you sure you have threading in your lib folder? Link to comment Share on other sites More sharing options...
Sober 37 Posted May 16, 2014 Author Share Posted May 16, 2014 i don't have anything named threading.pyc or something like that in the libs , how can i import it?? Does it need any change on the binary? Link to comment Share on other sites More sharing options...
Premium Sanchez 2474 Posted May 16, 2014 Premium Share Posted May 16, 2014 Just copy the Lib folder from Python to your client. Link to comment Share on other sites More sharing options...
Sober 37 Posted May 16, 2014 Author Share Posted May 16, 2014 I found a threading.pyc in the lib folder but i get the error bad magic number.I think the lib was for python2.6 but my client uses python2.7 Could someone please give me the threading.pyc for 2.7? Link to comment Share on other sites More sharing options...
ShuzZzle 28 Posted May 16, 2014 Share Posted May 16, 2014 Nvm. You can download the Libs from the Python website Link to comment Share on other sites More sharing options...
Frozen 189 Posted May 16, 2014 Share Posted May 16, 2014 You can use this: if app.GetTime() < timeyouwant: code the part when the timer is running else after timer stopped Link to comment Share on other sites More sharing options...
RatCatcher 77 Posted May 17, 2014 Share Posted May 17, 2014 Guys, what about use new thread for sleep so game will not freeze? xD [codesyntax] import thread import app import chat def test(): app.Sleep(3000) # 3 seconds chat.AppendChat(chat.CHAT_TYPE_INFO, "hello world") thread.start_new_thread(msg, ()) [/codesyntax] Enough is enough Link to comment Share on other sites More sharing options...
Sober 37 Posted May 17, 2014 Author Share Posted May 17, 2014 app.sleep freezes the game, is it tested? Link to comment Share on other sites More sharing options...
Zetsu 78 Posted May 28, 2014 Share Posted May 28, 2014 app.sleep stop the game. In 10 minutes i will come with my timer version I took it from switchbot xD //posted by Aveline... sry Link to comment Share on other sites More sharing options...
Denis 1477 Posted May 28, 2014 Share Posted May 28, 2014 app.sleep just freeze the game,he doesn't want that Link to comment Share on other sites More sharing options...
Aveline™ 555 Posted May 28, 2014 Share Posted May 28, 2014 import time class Wait(ui.ScriptWindow): def __init__(self): ui.ScriptWindow.__init__(self) self.eventTimeOver = lambda * arg: None self.eventExit = lambda * arg: None def __del__(self): ui.ScriptWindow.__del__(self) def Open(self,waitTime): curTime = time.clock() self.endTime = curTime + waitTime self.Show() def Close(self): self.Hide() def Destroy(self): self.Hide() def EmptyFunc(self): pass def SAFE_SetTimeOverEvent(self,event = 0): if(not event): self.eventTimeOver = self.EmptyFunc self.eventTimeOver = ui.__mem_func__(event) def SAFE_SetExitEvent(self,event = 0): if(not event): self.eventExit = self.EmptyFunc self.eventExit = ui.__mem_func__(event) def OnUpdate(self): lastTime = max(0,self.endTime - time.clock()) if(lastTime == 0): self.Close() else: return def OnPressExitKey(self): self.Close() return True ## Example ; self.waitFor = Wait() self.waitFor.Open(20.0) self.waitFor.SAFE_SetTimeOverEvent(self.SecondFinished) self.waitFor.SAFE_SetExitEvent(self.ExitKey) def SecondFinished(self): print "======================================================" print "Second is finished." print "======================================================" def ExitKey(self): print "======================================================" print "Exit Key -- Write Something" print "======================================================" maybe you could work on your business Best Regards Aveline 1 Plain logic saves lives. Link to comment Share on other sites More sharing options...
Frozen 189 Posted June 1, 2014 Share Posted June 1, 2014 import time class Wait(ui.ScriptWindow): def __init__(self): ui.ScriptWindow.__init__(self) self.eventTimeOver = lambda * arg: None self.eventExit = lambda * arg: None def __del__(self): ui.ScriptWindow.__del__(self) def Open(self,waitTime): curTime = time.clock() self.endTime = curTime + waitTime self.Show() def Close(self): self.Hide() def Destroy(self): self.Hide() def EmptyFunc(self): pass def SAFE_SetTimeOverEvent(self,event = 0): if(not event): self.eventTimeOver = self.EmptyFunc self.eventTimeOver = ui.__mem_func__(event) def SAFE_SetExitEvent(self,event = 0): if(not event): self.eventExit = self.EmptyFunc self.eventExit = ui.__mem_func__(event) def OnUpdate(self): lastTime = max(0,self.endTime - time.clock()) if(lastTime == 0): self.Close() else: return def OnPressExitKey(self): self.Close() return True ## Example ; self.waitFor = Wait() self.waitFor.Open(20.0) self.waitFor.SAFE_SetTimeOverEvent(self.SecondFinished) self.waitFor.SAFE_SetExitEvent(self.ExitKey) def SecondFinished(self): print "======================================================" print "Second is finished." print "======================================================" def ExitKey(self): print "======================================================" print "Exit Key -- Write Something" print "======================================================" maybe you could work on your business Best Regards Aveline There is no need to make that, he can simply write this: define a variable for your action, for example you whant to make a timer when you buy. When you buy a thing you define sothing like this: self.buytime = app.GetTime() and then you whant to wait like 30 seconds before you can buy, you can write this: import time if app.GetTime() < self.buytime+30: code the part when the timer is running else: after timer stopped Here you make a action so he can buy again. Link to comment Share on other sites More sharing options...
Denis 1477 Posted June 1, 2014 Share Posted June 1, 2014 You are wrong because with the if statement it's checks only once,you need to use while loop Link to comment Share on other sites More sharing options...
ѕeмa™ 308 Posted June 1, 2014 Share Posted June 1, 2014 You are wrong because with the if statement it's checks only once,you need to use while loop you can put the timer in "onupdate" and work perfectly with app.gettime() https://m2admin.net/ Link to comment Share on other sites More sharing options...
Frozen 189 Posted June 1, 2014 Share Posted June 1, 2014 You are wrong because with the if statement it's checks only once,you need to use while loop But i was talking if he was working with action, like for example chat action, whennever you talk that if executes. Link to comment Share on other sites More sharing options...
pySmith 4 Posted July 16, 2014 Share Posted July 16, 2014 There is a simple way: def myfunction_took_long_to_execute(): for i in range(500000000000000000000000000000000000): print i return i def myfunction_took_long_to_execute_with_yield(): for i in range(500000000000000000000000000000000000): print i yield None return i https://docs.python.org/release/2.5.2/ref/yield.html I would post a better example, but Ymir Client times are long ago... 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now