Jump to content

Recommended Posts

  • Premium

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

  • Metin2 Dev 1
  • Good 2
  • Love 2
Link to comment
https://metin2.dev/topic/1264-timer-on-python/#findComment-9314
Share on other sites

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
https://metin2.dev/topic/1264-timer-on-python/#findComment-9417
Share on other sites

  • 2 weeks later...
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

  • Love 1

Plain logic saves lives.

Link to comment
https://metin2.dev/topic/1264-timer-on-python/#findComment-10370
Share on other sites

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
https://metin2.dev/topic/1264-timer-on-python/#findComment-10892
Share on other sites

  • 1 month later...

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...

  • Good 1
Link to comment
https://metin2.dev/topic/1264-timer-on-python/#findComment-15016
Share on other sites

Don't use any images from : imgur, turkmmop, freakgamers, inforge, hizliresim... Or your content will be deleted without notice...
Use : https://metin2.download/media/add/

Please use https://metin2.download/ when uploading files smaller than 100MB, otherwise the approval will take longer due to manual upload.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.