Raised This Month: $23 Target: $400
 5% 

Timers: Wiki misunderstanding


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
St00ne
Veteran Member
Join Date: Jan 2011
Location: Annecy - France
Old 05-27-2020 , 21:49   Timers: Wiki misunderstanding
Reply With Quote #1

Hi, I'm using timers very often, and try to avoid handles as far as possible.
But I'm having troubles with the callback of a one-time timer using client serial (or user id) because the English wiki and RU wiki don't say the exact same.

I also searched here: https://sm.alliedmods.net/new-api/timers/Timer
Concerning the callback return, it says "Plugin_Stop to stop a repeating timer, any other value for default behavior."

So I'd like to know what to write at the end of such a timer:
PHP Code:
public void OnClientPutInServer(int client)
{
    
CreateTimer(15.0WelcomePlayerGetClientSerial(client)); // You could also use GetClientUserId(client)
}
 
public 
Action WelcomePlayer(Handle timerint serial)
{
    
int client GetClientFromSerial(serial); // Validate the client serial
 
    
if (client == 0// The serial is no longer valid, the player must have disconnected
    
{
        return 
Plugin_Stop;
    }
 
    
PrintToConsole(client"Welcome to the server!");
 
    return 
Plugin_Continue// <- ??? I am pretty sure I used to read return Plugin_Handled in that wiki and they changed it. Are they both working?

Thx for your advice.
St00ne
__________________

*** *** ***
-My plugins-

Last edited by St00ne; 05-27-2020 at 21:52.
St00ne is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 05-27-2020 , 23:54   Re: Timers: Wiki misunderstanding
Reply With Quote #2

The documentation for the API page should be correct. (If it's not, file a bug report with code to reproduce and an explanation of what it is doing and what you think it should be doing.)

Since your example doesn't have a repeating timer, it doesn't actually matter what you return.
Fyren is offline
St00ne
Veteran Member
Join Date: Jan 2011
Location: Annecy - France
Old 05-28-2020 , 01:46   Re: Timers: Wiki misunderstanding
Reply With Quote #3

Thx for your answer. The logic of a repeated timer is well explained. I am wondering about a one-time timer situation, like in the example.
__________________

*** *** ***
-My plugins-
St00ne is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 05-28-2020 , 03:36   Re: Timers: Wiki misunderstanding
Reply With Quote #4

You are not using a repeating timer, so you can return any value or nothing, it doesn't matter for one time timers.
If you use a repeating timer, return Plugin_Continue will make the timer to repeat again, Plugin_Handled or Plugin_Stop will stop it.

You can use this without problems:
PHP Code:

public Action WelcomePlayer(Handle timerint serial)
{
    
int client GetClientFromSerial(serial); // Validate the client serial
    
if (client == 0)
    {
        return 
Plugin_Continue;
    }
 
    
PrintToConsole(client"Welcome to the server!");
    return 
Plugin_Continue;

__________________
Ilusion9 is offline
St00ne
Veteran Member
Join Date: Jan 2011
Location: Annecy - France
Old 05-28-2020 , 07:23   Re: Timers: Wiki misunderstanding
Reply With Quote #5

Mmh ok, so "continue" or "handled" doesn't have a consequence here. Thx for your answers. I'll put this as solved if there are no more answers for a couple of days.
__________________

*** *** ***
-My plugins-

Last edited by St00ne; 05-28-2020 at 07:24.
St00ne is offline
Tilex
Junior Member
Join Date: May 2020
Old 05-29-2020 , 20:38   Re: Timers: Wiki misunderstanding
Reply With Quote #6

You are working with defines/enums, which are defined in sourcemod\scripting\include\core.inc
PHP Code:
/**
 * Specifies what to do after a hook completes.
 */
enum Action
{
    
Plugin_Continue 0,    /**< Continue with the original action */
    
Plugin_Changed 1,     /**< Inputs or outputs have been overridden with new values */
    
Plugin_Handled 3,     /**< Handle the action at the end (don't call it) */
    
Plugin_Stop 4         /**< Immediately stop the hook chain and handle the original */
}; 
So you might as well use these numbers as return values, if you want your code look obscure.

I bet that the timers would just have an if like: "if(bla == Plugin_Stop) ... else...", so it's possible that any other value than 4 might serve your needs.
Tilex 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 12:58.


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