redditing Posted November 16, 2020 Share Posted November 16, 2020 I would like to know about two things: 1. Are the server-side and client-side timers dangerous and why? 2. Is it possible to do the function GetTickCount () timer? Link to comment
Moderators IIYAMA Posted November 16, 2020 Moderators Share Posted November 16, 2020 8 hours ago, redditing said: 1. Are the server-side and client-side timers dangerous and why? Timers in general can become never ending, if not programmed correctly. That is why you should use them with care. It is not as if timers are dangerous by themself. But when they become never ending, there is a risk that your code might create a new infinity timer with the same task. Which leads up to creating a memory leak in the form of infinity amount of timers. Each timer uses CPU and memory. But that ain't the biggest issue. The tasks/functions attached to the timers are also becoming infinity. So for example if the task is `setElementData(vehicle, "fuel", <some value>)`, this function is using bandwidth (and CPU) for all clients/players. When this becomes infinity, there is no bandwidth for other things and a network error occurs. (server will die at a given moment if it continues for too long) 8 hours ago, redditing said: 2. Is it possible to do the function GetTickCount () timer? getTickCount is something passive, you need to combine that with an timer/onClientRender, to make it active. Active (timer + getTickCount) https://gitlab.com/IIYAMA12/draw-distance/-/blob/master/scripts/timer_c.lua Passive (getTickCount) https://wiki.multitheftauto.com/wiki/CheckPassiveTimer 1 Link to comment
redditing Posted November 16, 2020 Author Share Posted November 16, 2020 11 minutes ago, IIYAMA said: Timers in general can become never ending, if not programmed correctly. That is why you should use them with care. It is not as if timers are dangerous by themself. But when they become never ending, there is a risk that your code might create a new infinity timer with the same task. Which leads up to creating a memory leak in the form of infinity amount of timers. Each timer uses CPU and memory. But that ain't the biggest issue. The tasks/functions attached to the timers are also becoming infinity. So for example if the task is `setElementData(vehicle, "fuel", <some value>)`, this function is using bandwidth (and CPU) for all clients/players. When this becomes infinity, there is no bandwidth for other things and a network error occurs. (server will die at a given moment if it continues for too long) getTickCount is something passive, you need to combine that with an timer/onClientRender, to make it active. Active (timer + getTickCount) https://gitlab.com/IIYAMA12/draw-distance/-/blob/master/scripts/timer_c.lua Passive (getTickCount) https://wiki.multitheftauto.com/wiki/CheckPassiveTimer And I would also like to know why setElementData is dangerous and can it be replaced somehow with e.g. a table? Link to comment
Moderators IIYAMA Posted November 16, 2020 Moderators Share Posted November 16, 2020 (edited) 34 minutes ago, redditing said: And I would also like to know why setElementData is dangerous and can it be replaced somehow with e.g. a table? Clientside The dangerous part of elementdata is that the programmer might forget that each time it is set (on clientside), it will synchronize with the server and after that it will also synchronize with all other players. The following code is in my opinion to be considered dangerous: addEventHandler("onClientRender", root, function () setElementData(localPlayer, "test", getTickCount()) end) No synchronization steps are skipped (even if the same is the same), therefore if can stack up until no other messages can be send and network error occurs after the buffer is filled for too long. Same goes for serverside: setTimer(function () setElementData(root, "test", getTickCount()) end, 50, 0) --------- Elementdata are be replace-able by tables, that will excluding the synchronization part as well as the event system. You can also disable synchronization: setElementData(root, "test", getTickCount(), false) -- false = disable Edited November 16, 2020 by IIYAMA 1 Link to comment
Scripting Moderators ds1-e Posted November 16, 2020 Scripting Moderators Share Posted November 16, 2020 @redditing You might check out my tutorial which explains data system based on tables - Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now