Raised This Month: $ Target: $400
 0% 

Making a "wait" function


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Desikac
Senior Member
Join Date: Apr 2010
Location: Serbia
Old 07-03-2012 , 09:18   Making a "wait" function
Reply With Quote #1

Is there any way to make a function that will pause the code for a specified amount of time?

For example:
PHP Code:
public plugin_init()
    
register_clcmd("say /test""test")

public 
test(id) {
    new 
name[32]
    
get_user_name(idname31)
    
    
wait(2.0//wait func
    
client_print(0print_chat"Your name is: %s"name//This should execute after 2 seconds

I tried to make an include that adds this function:
PHP Code:
#if defined _engine_included
    
#else 
    #include <engine>
#endif

new created
new Float:ttimer

public TimerThink(iEnt)
{
        
ttimer+= 0.1
        entity_set_float
(iEntEV_FL_nextthinkget_gametime() + 0.1)
}

wait(Float:wtime) {
    if(!
created) {
        
register_think("timer","TimerThink")
        new 
iEnt create_entity("info_target")
        
entity_set_string(iEntEV_SZ_classname"timer")
        
entity_set_float(iEntEV_FL_nextthinkget_gametime() + 0.1)
    }
    
ttimer 0.0
    
if(wtime <= 0)
        return -
1

    
while(wtime ttimer) { }
    return 
1

But it crashes the server.
When I put an "infinite" loop in c++ to count it goes on forever so I thought it might work here too
Is there any way to make this? Like, for example, call a function that needs 0.1s to execute 20 times for a 2 second wait?
Desikac is offline
Send a message via MSN to Desikac Send a message via Skype™ to Desikac
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 07-03-2012 , 09:29   Re: Making a "wait" function
Reply With Quote #2

set_task
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
Desikac
Senior Member
Join Date: Apr 2010
Location: Serbia
Old 07-03-2012 , 09:37   Re: Making a "wait" function
Reply With Quote #3

Quote:
Originally Posted by YamiKaitou View Post
set_task
PHP Code:
while(set_task(2.0) > wtime) { } 


I know that there is set_task but I want to know if it's possible to do it like this.
Desikac is offline
Send a message via MSN to Desikac Send a message via Skype™ to Desikac
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 07-03-2012 , 09:42   Re: Making a "wait" function
Reply With Quote #4

http://www.amxmodx.org/funcwiki.php?...task&go=search set_task is the timer.
__________________
Arkshine is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 07-03-2012 , 09:42   Re: Making a "wait" function
Reply With Quote #5

set_task calls another function. Entity thinks call another function. You cannot add a pause into a current function without a while loop.
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
Desikac
Senior Member
Join Date: Apr 2010
Location: Serbia
Old 07-03-2012 , 09:52   Re: Making a "wait" function
Reply With Quote #6

Quote:
Originally Posted by YamiKaitou View Post
You cannot add a pause into a current function without a while loop.
And how can I add it WITH a while loop?
Desikac is offline
Send a message via MSN to Desikac Send a message via Skype™ to Desikac
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 07-03-2012 , 09:56   Re: Making a "wait" function
Reply With Quote #7

PHP Code:
new 0;
while (
50000); 
Replace 50000 with the correct number that equals the amount of time you want to wait.
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 07-03-2012 , 10:23   Re: Making a "wait" function
Reply With Quote #8

Quote:
Originally Posted by YamiKaitou View Post
PHP Code:
new 0;
while (
50000); 
Replace 50000 with the correct number that equals the amount of time you want to wait.
oh dear god no. Use set_task
__________________
What an elegant solution to a problem that doesn't need solving....
Liverwiz is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 07-03-2012 , 10:27   Re: Making a "wait" function
Reply With Quote #9

Quote:
Originally Posted by Liverwiz View Post
oh dear god no. Use set_task
Hey, he asked me how to. I, by no means, recommend the while loop method
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).

Last edited by YamiKaitou; 07-03-2012 at 10:27.
YamiKaitou is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 07-03-2012 , 10:28   Re: Making a "wait" function
Reply With Quote #10

Quote:
Originally Posted by YamiKaitou View Post
Hey, he asked me how to. I, by no means, recommend the while loop method
Oh i know you know. My skin just crawled when i saw that....
__________________
What an elegant solution to a problem that doesn't need solving....
Liverwiz is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:21.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode