Jump to content
  • 0

Sleep a source line


Mikado

Question


  • Group:  Members
  • Topic Count:  13
  • Topics Per Day:  0.00
  • Content Count:  26
  • Reputation:   2
  • Joined:  11/08/12
  • Last Seen:  

Is any way I could delay some code? After I execute an instruction I want to execute another one in about 100ms (but leave the rest of the code go on).

 

I guess I could use the add_timer function, but it looks a bit complicated as it needs a timerFunc variable.

Edited by Mikado
Link to comment
Share on other sites

7 answers to this question

Recommended Posts

  • 1

  • Group:  Members
  • Topic Count:  81
  • Topics Per Day:  0.02
  • Content Count:  1654
  • Reputation:   583
  • Joined:  08/09/12
  • Last Seen:  

Use 'sleep2'

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  13
  • Topics Per Day:  0.00
  • Content Count:  26
  • Reputation:   2
  • Joined:  11/08/12
  • Last Seen:  

That's a script command, I'm talking about source code.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  75
  • Topics Per Day:  0.02
  • Content Count:  2223
  • Reputation:   593
  • Joined:  10/26/11
  • Last Seen:  

There is a sleep function in C that can sleep for seconds. To sleep for less than 1 second, use usleep (microseconds).

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  60
  • Topics Per Day:  0.01
  • Content Count:  562
  • Reputation:   219
  • Joined:  11/22/11
  • Last Seen:  

sleep will also stop server running.

 

-

 

use add_timer or put your setting into somewhere timer (like sc, skill delay, pc loop...etc)

 

you can find some sample in core about how to use add_timer.

Edited by goddameit
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  16
  • Topics Per Day:  0.00
  • Content Count:  737
  • Reputation:   216
  • Joined:  11/29/11
  • Last Seen:  

DONT use "sleep" on the code you'll slow down all other thing. You'll have to understand how we deal with socket to get what I mean but best is to use the add timer wich will call your sub func at appopriate time.

nb : sleep and usleep are different on OS :

#ifdef WIN32
            Sleep(1000);
#else
            sleep(1);
#endif
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  13
  • Topics Per Day:  0.00
  • Content Count:  26
  • Reputation:   2
  • Joined:  11/08/12
  • Last Seen:  

So, as I need to use add_timer with a custom function, anybody can tell me how to use it properly? As it uses TimerFunc variables and I don't know how to pass variables through it.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  16
  • Topics Per Day:  0.00
  • Content Count:  737
  • Reputation:   216
  • Joined:  11/29/11
  • Last Seen:  

let assum my_func = your custom finction.

 

1) Add my_func to timer_func_list :

add_timer_func_list(my_func, "my_func_name");

 

2) Ask a timered call :

x = 200; //suppose we wanna call it in 200ms

otherdata = 25<<16 |  10; //suppose we want to send 2 value 25 and 10

my_func->timer_id = add_timer(gettick() + x, my_func, bl->id, otherdata);

 

3)Function treatement : (exemple)

int my_func(int tid, unsigned int tick, int id, intptr_t data) {
 TBL_PC *sd=map_id2sd(id); //this assum bl was BL_PC (os you can have all info about sd)
 if(sd->sc.data[sC_ASSUMPTIO]) foo; //got assumptio do foo.

 if((data&0x00FF) <= 10) foo; //does my second value was 10 and below ? (eg yes (10))

 else if ((data&0xFF00) > 30) foo2; //does my 1st value was above 30 ? (eg no (25))
}

yes 3rd part may be more hard to understand but without utilisy of my_func I can't give better exemple. Hope rest was clear =)

  • Upvote 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...