Raised This Month: $ Target: $400
 0% 

Making a "wait" function


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
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
 



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 15:23.


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