RP Caching

Legend

https://habda.sh/
Jun 17, 2015
86
20
Has anyone released (or coded) a system which caches RP timers? I.e., how it does with prison time.

I'm looking to implement a system like this for learning and working. I guess I could copy the system that workout uses but I feel as though that would be a pain in the ass. Or I could take a look at the code for imprisonment, I just don't want to break anything, lol. I'm super new to C# as well.

Any help or tips would be phenomenal - thanks in advance.
 

JayC

Always Learning
Aug 8, 2013
5,493
1,398
I avoid using separate timers in the emulator I am coding for FluxRP.

I have 1 main timer that runs the habbo class and rp class (Thanks to @Damien for recoding parts of this timer)

But I have a long variable set to a Unix Timestamp (Which gets stored in the database when the user disconnects), and then I compare that to the current timestamp in my 1 loop.
This handles ALL of my loops. It gets called every second (On it's own thread because it's on it's own loop so the game doesn't lagg...)
 

Legend

https://habda.sh/
Jun 17, 2015
86
20
I avoid using separate timers in the emulator I am coding for FluxRP.

I have 1 main timer that runs the habbo class and rp class (Thanks to @Damien for recoding parts of this timer)

But I have a long variable set to a Unix Timestamp (Which gets stored in the database when the user disconnects), and then I compare that to the current timestamp in my 1 loop.
This handles ALL of my loops. It gets called every second (On it's own thread because it's on it's own loop so the game doesn't lagg...)
That's a lot more simple and cleaner. But like I said, I'm a super noob when it comes to C#. I'll look further into the prison time cache.
 

TheGeneral

Active Member
Dec 27, 2016
135
152
I avoid using separate timers in the emulator I am coding for FluxRP.

I have 1 main timer that runs the habbo class and rp class (Thanks to @Damien for recoding parts of this timer)

But I have a long variable set to a Unix Timestamp (Which gets stored in the database when the user disconnects), and then I compare that to the current timestamp in my 1 loop.
This handles ALL of my loops. It gets called every second (On it's own thread because it's on it's own loop so the game doesn't lagg...)
I don't quite understand this. If you already know beforehand when you have to execute something (as you know the end timestamp say 10 minute jail time), why call it every second (assuming to compare etc). Why not use some kind of scheduled task, and cancel that scheduled task when someone logs out? Makes everything more event based, async and most likely faster. On top of that it is easier to add in new 'timers' / deadlines without having to modify your 'core loop' thus making it easier to maintain your code and build on it.

Just a thought, no need to flame me. Here to give you suggestions about implementations you might want to try.
 

JayC

Always Learning
Aug 8, 2013
5,493
1,398
I don't quite understand this. If you already know beforehand when you have to execute something (as you know the end timestamp say 10 minute jail time), why call it every second (assuming to compare etc). Why not use some kind of scheduled task, and cancel that scheduled task when someone logs out? Makes everything more event based, async and most likely faster. On top of that it is easier to add in new 'timers' / deadlines without having to modify your 'core loop' thus making it easier to maintain your code and build on it.

Just a thought, no need to flame me. Here to give you suggestions about implementations you might want to try.
Right so you don't know exactly when for everything. Doing it in this one loop that is already readibly available in the habbo class I found to be the most beneficial because all of my timers, loops, updating is done in one location. So when the loop triggers it says, is the user jailed. Then it checks how long remaining they have jailed, if it's equivalent to a 30 second interval it pops up and says you have 1 min 30 seconds left in jail, etc.

Each action is controlled separately by a Boolean check, and then a timestamp check, so all of the code is easy to adjust.

I wouldn't flame you for voicing your opinion, everyone has a different coding style but I will share my idea behind why I did it this way, and I still believe this is the best way I have found so far.
 

Jaden

not so active
Aug 24, 2014
886
263
I don't quite understand this. If you already know beforehand when you have to execute something (as you know the end timestamp say 10 minute jail time), why call it every second (assuming to compare etc). Why not use some kind of scheduled task, and cancel that scheduled task when someone logs out? Makes everything more event based, async and most likely faster. On top of that it is easier to add in new 'timers' / deadlines without having to modify your 'core loop' thus making it easier to maintain your code and build on it.

Just a thought, no need to flame me. Here to give you suggestions about implementations you might want to try.
I'm guessing he does it the same way Sledmore implemented it into his Plus Emulator (ProcessComponent) which was inspired by Matty from his Mango server. RP emulator's rarely have anything going on under the hood of it's timers besides maybe a simple alert, coin update, etc. it would be considered a waste of resources imo to create Tasks also because the user could stop and restart their timer at any minute just by a simple interaction and the emulator would then have to stop and schedule a new Task. Using 1 timer per session that's literally a pooled Thread and just using creating a ticker in the "core loop" (since it's necessary yet rarely has anything going on under the hood anyways) seems much more efficient.

No way could I possibly see someone replacing the core loop (pooled Thread with a loop) for Task(s), but I can see you replacing the ticker with a Task for more strenuous timers not ones that just play with integers and booleans.
 

Users who are viewing this thread

Top