Raised This Month: $32 Target: $400
 8% 

A wait function instead of CreateTimer?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Facksy
Senior Member
Join Date: Apr 2017
Location: +2+2
Old 11-17-2017 , 16:05   A wait function instead of CreateTimer?
Reply With Quote #1

Hey guys, I'd like to know if its possible to create a "wait function" or something like that to use it instead of CreateTimer? Exemple:

Can this be possible?
PHP Code:
public Action:Cmd_In(clientargs);
{
    
EmitSoundToClient(clientANNOUNCER_THREEclient_2);
    
//Wait 1.0 second
    
EmitSoundToClient(clientANNOUNCER_TWOclient_2);
    
//Wait 1.0 second
    
EmitSoundToClient(clientANNOUNCER_ONEclient_2);

Instead of that?
PHP Code:
public Action:Cmd_In(clientargs);
{
    
EmitSoundToClient(clientANNOUNCER_THREEclient_2);
    
CreateTimer(1.0TwoSecondsclient);
    
CreateTimer(2.0OneSecondclient);
}

public 
Action:TwoSeconds(Handle Timerclient)
{
    
EmitSoundToClient(clientANNOUNCER_TWOclient_2);
}

public 
Action:OneSecond(Handle Timerclient)
{
    
EmitSoundToClient(clientANNOUNCER_ONEclient_2);

Facksy is offline
shavit
AlliedModders Donor
Join Date: Dec 2011
Location: Israel
Old 11-17-2017 , 16:39   Re: A wait function instead of CreateTimer?
Reply With Quote #2

I don't think SourceMod supports that. If you'd wait 1 second per call, your server's thread would be blocked for 1 second each time.
__________________
retired
shavit is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 11-19-2017 , 16:59   Re: A wait function instead of CreateTimer?
Reply With Quote #3

This is not possible in Pawn. You have to do it as per your second example.

Below I've converted your code to the new syntax.

Code:
public Action Cmd_In(int client, int args); 
{
    EmitSoundToClient(client, ANNOUNCER_THREE, client, _, 2); 
    CreateTimer(1.0, OneSecond, GetClientUserId(client)); 
    CreateTimer(2.0, TwoSeconds, GetClientUserId(client));
    return Plugin_Continue;
} 

public Action OneSecond(Timer timer, int userid) 
{
    int client = GetClientOfUserId(userid);
    if (client==0)
        return Plugin_Continue;

    EmitSoundToClient(client, ANNOUNCER_ONE, client, _, 2);
    return Plugin_Continue;
}

public Action TwoSeconds(Timer timer, int userid) 
{
    int client = GetClientOfUserId(userid);
    if (client==0)
        return Plugin_Continue;

    EmitSoundToClient(client, ANNOUNCER_TWO, client, _, 2);
    return Plugin_Continue;
}
Note: Never send a client index through a timer. If a client disconnects during the timer you may receive an error. Send a UserId instead as GetClientOfUserId will return 0 if the client has disconnected.
__________________
Neuro Toxin is offline
fakuivan
Senior Member
Join Date: Nov 2015
Old 11-21-2017 , 09:32   Re: A wait function instead of CreateTimer?
Reply With Quote #4

As shavit said, you'd block the server if you wanted to do that. Command callbacks run on the main thread, other processes will have to wait until you return.
__________________
fakuivan is offline
Reply


Thread Tools
Display Modes

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 16:24.


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