1. I want to use the onTick hook to create a task to run 4 times every second. However, I cannot find a way to get the server's tickrate so I know how many iterations of this hook to ignore.

    Code:
    int tickCount = 0;void OnTick() {
        int tickRate = ??? //dont know how to get server's tickrate    if (tickCount % (tickRate / 4) != 0) {
            tickCount++;
            return;
        }
        tickCount = 0;    Puts("OnTick works!");
    }
     
  2. Yeah, I saw the timer library shortly after posting this thread. While that pretty much covers my use-case, the question remains unanswered. I'm still curious how to get the server's tickrate? I will be using the timer library, but knowing how to get the server tickrate (or anything else for that matter) could prove to be beneficial to me, if at minimum it helps me understand more about how to get to the information I am looking for in Rust.
     
  3. It's contained in ConVar.Server, which contains all the other native server configuration as well.
    This stuff is provided by Rust, so the preferred way to learn about this stuff is to fire up your decompiler and read the decompiled source code.
    You shouldn't rely on OnTick really being called with its tickrate, though, so if the timer library didn't exist you shouldn't write it like that.
    Rust uses MonoBehaviour.InvokeRepeating to run ticks, and I'm betting my ass that it isn't deterministic: The OS process scheduler affects it, the OS thread scheduler affects it, the assembly implementation (or even C#, depends on the C# implementation) for timers affects it, the C# garbage collector affects it, I bet Unity also affects it in some way, ...
    All of these are nondeterministic, and your approach relies on determinism, which is nonexistent on every platform that isn't embedded real time (ergo: code for submarines and such ;)).
    If you're curious about how to roughly implement something like this yourself, check out the source code of the Oxide timer library. It isn't perfect but it's worth a read and is definetly good enough for the job.
    I've pointed out some stuff regarding timers here: Plugins known to cause lag? | Oxide
     
    Last edited by a moderator: May 21, 2016
  4. This is what I thought. But my server keeps outputting the value of 10. I keep reading the value is defaulted to 30, while 10 is the minimum and 100 is the maximum. So, I thought maybe this was the wrong thing I was looking for. Seems the default isn't 30 like I expected, though.
     
  5. I'm pretty sure 10 is the default, not 30. Atleast the last time I checked.
     
  6. See, this is where the disconnect between us is. I'm not sure the ConVar.Server.tickrate is the thing I'm looking for. Maybe its under a different name in code. What I'm looking for is the value fed to the server at startup for the command/argument "server.tickrate" as seen here in this wiki:

    Rust Dedicated Server - Valve Developer Community
     
  7. The Convar.Server.tickrate is the thing you're looking for.
    Code:
    namespace ConVar
    {
        [ConsoleSystem.Factory("server")]
        public class Server : ConsoleSystem
        {
            // ...
            [ConsoleSystem.Admin]
            public static int tickrate = 10;
            // ...
        }
    }
    
    What's more likely to be outdated, the dll you downloaded for the most recent version or a wiki that gets updated once in a blue moon?

    When you aren't sure if something is really what you're looking for, check how it's used.
     
  8. Good words to live by. ^_^