SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Thread Tools Display Modes
Old 26/03/2020, 05:32 PM   #1
Little Clucker
Join Date: Mar 2020
Posts: 2
Reputation: 0
Question What about Moving-Object Timers?

This is my first thread, I hope everything is fine!

Well... I don't know if anyone came up with this, but I discovered it myself.

Is it a good idea to make timers (including repetitive timers) based on MoveObject and OnObjectMoved? By making an object to move from (let's say) 0.00 / 0.00 / 0.00 towards 0.00 / 0.00 / 1.00 with a set speed of 1.00 units per second, OnObjectMoved is called after one second. Then you can make the object move back to 0.00 / 0.00 / 0.00 with the same speed when OnObjectMoved is called, so you got a nice 1 second repetitive timer. Also, you can set a very small interval by just calculating the distance you want it to travel within the given speed.
From 0.00 towards 1.00, for one second to pass, you need to set the speed to 1.00 units per second.
From 0.00 towards 1.00, for 100 milliseconds to pass, you need to set the speed to 10.00. units/s.
From 0.00 towards 1.00, for 100 microsecond to pass, you need to set the speed to 10000.0 units/s.

Of course, you can do per-player timers using MovePlayerObject and OnPlayerObjectMoved.

Are these timers a good idea for optimization and can they remain accurate when are 700+ players connected? I think normal timers are using much more resources to run compared to these which are just moving objects. Please, let me know your opinion!

Sorry for my English mistakes, I'm not a native-speaker.
Ryhx is offline   Reply With Quote
Old 27/03/2020, 11:39 AM   #2
NaS's Avatar
Join Date: Mar 2008
Location: 🇩🇪
Posts: 1,785
Reputation: 635
Default Re: What about Moving-Object Timers?

Theoretically you can, but you would waste object slots. They also do not remain as accurate as timers if the server is under stress - objects will start to move slightly slower than on the client side.

Also I don't think they use less resources. They seem to be processed on every server tick, similar to how timers are iterated on every server tick. Additionally to that, objects and player objects are synced with players, so it creates network traffic for no good reason (which doesn't happen for timers).

If the default timers are not precise enough, there are plugins to solve this issue. Those usually use less resources than samp timers as well (for example this plugin, but there are a few more).
NaS is offline   Reply With Quote

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Timers and Objets moving Showzs Scripting Help 0 15/05/2019 04:02 PM
Why my Object not Moving ? Plz Anyone ? Adarsh007 Scripting Help 2 28/10/2014 04:33 AM
Bug with the moving object[++rep!] Chris_Morrison Scripting Help 18 04/03/2012 03:16 PM
Moving several object down? phil_lendon Help Archive 4 05/08/2011 08:27 AM
Moving object Onyx09 Help Archive 2 31/03/2010 08:24 AM

All times are GMT. The time now is 04:40 PM.

Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.