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!"); }
Solved How to get server tickrate?
Discussion in 'Rust Development' started by BillyGalbreath, May 21, 2016.
-
Use the timer library: Oxide/Timer.cs at master · OxideMod/Oxide · GitHub
-
-
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? | OxideLast edited by a moderator: May 21, 2016 -
-
I'm pretty sure 10 is the default, not 30. Atleast the last time I checked.
-
Rust Dedicated Server - Valve Developer Community -
Code:namespace ConVar { [ConsoleSystem.Factory("server")] public class Server : ConsoleSystem { // ... [ConsoleSystem.Admin] public static int tickrate = 10; // ... } }
When you aren't sure if something is really what you're looking for, check how it's used. -