Really simple and awesome RP cooldown system

Seriosk

Programmer;
Oct 29, 2016
256
105
Lol.. not really awesome BUT..

Hello. Many of you may of seen, or even coded a cool-down for an RP or hotel command. But what happens when the cool-down gets too large, and the user could just reload the client and bypass it? That is where this comes in.. it stores it in the database, so even if the emulator went down, the user would still have a cooldown on their head.

It works via Date Times so it knows exactly when it was added, which results in it knowing exactly when it expires. With this tiny tiny tiny pretty useless library you can set cool downs for hours, days, weeks, anything you like.

I've seen emulators such as Rage, Habbo, Fabbo, Holo all do horrible cooldown systems, but this system actually seems really easy to use, and its amazing how small it is, along with its amazing simplicity of using it.

It's coded in pretty good standards, so it should be fine... It's in my opinion far better than any other cooldown system I have seen released on this forum. And before people starting commenting "its useless", maybe.. but I just coded it for simple usage, I just shared it for people looking for the same thing.

SQL:
Code:
DROP TABLE IF EXISTS `user_roleplay_cooldowns`;
CREATE TABLE `user_roleplay_cooldowns` (
  `user_id` int(11) DEFAULT NULL,
  `cooldown_name` varchar(255) DEFAULT NULL,
  `cooldown_added` varchar(255) DEFAULT NULL,
  `cooldown_duration` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

C#:
Code:
namespace Plus.Roleplay.Handlers
{
    using System;

    internal class RoleplayCooldownHandler
    {
        public bool UserHasCooldown(int userId, string cooldownName)
        {
            using (var databaseConnection = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                databaseConnection.SetQuery("SELECT * FROM `rise_user_roleplay_cooldowns` WHERE `user_id` = @userId AND `cooldown_name` = @cooldownName");
                databaseConnection.AddParameter("userId", userId);
                databaseConnection.AddParameter("cooldownName", cooldownName);

                var cooldownRow = databaseConnection.GetRow();

                if (cooldownRow == null)
                {
                    return false;
                }

                var dateTimeAdded = DateTime.Parse(Convert.ToString(cooldownRow["cooldown_added"]));
                var span = DateTime.Now - dateTimeAdded;
                var duration = Convert.ToInt32(cooldownRow["cooldown_duration"]);

                return !(span.TotalSeconds >= duration);
            }
        }

        public void AddCooldown(int userId, string cooldownName, int cooldownDuration)
        {
            using (var databaseConnection = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
            {
                databaseConnection.SetQuery("INSERT INTO `rise_user_roleplay_cooldowns` (`user_id`, `cooldown_name`, `cooldown_added`, `cooldown_duration`) VALUES (@userId, @cooldownName, @cooldownAdded, @cooldownDuration)");
                databaseConnection.AddParameter("userId", userId);
                databaseConnection.AddParameter("cooldownName", cooldownName);
                databaseConnection.AddParameter("cooldownAdded", DateTime.Now.ToString());
                databaseConnection.AddParameter("cooldownDuration", cooldownDuration);
                databaseConnection.RunQuery();
            }
        }
    }
}
 

Seriosk

Programmer;
Oct 29, 2016
256
105
dose this only work for role play emu?
It works for any C# solution, meaning any emulator, any desktop application, use it how you want...

If you're technically asking if it'll work just on Plus without recoding any part of it, the answer is yes.. It uses Plus's database library structure, which obviously not every C# application has, but if you did want to use it outside Plus just re-code the database actions, which is most of the code tbh lol.
 

Seriosk

Programmer;
Oct 29, 2016
256
105
can uu make tutoral for newbies?
On how to make a class in a C# solution? It's pretty easy.. you right click on your solutions name, click 'Add New Item' then click 'New Class'. I don't really think it requires me to tell you how to make a new class, a new class is merely a new file. (.CS file)
 

Jaden

not so active
Aug 24, 2014
886
263
Dis-gust-ing

Why are you using your database to store simple cooldowns that can be handled using simple caching of 2 int variables (1 const and a user variable) then a simple if-statement to check.

imo: Holo, Habbo, Rage, and even Fabbo had better cooldown implementations then this. Creating a table, then requesting a db connection object from the server every time the user inputs something that can trigger a cooldown, not only is this a resource hog to your system but it is a contention to the server.

Also, why are you using the public access modifier for methods which should be public static? And if you're going to insist on storing cooldowns in the database (no reason to) at least use the proper data types, VARCHAR is the equivalent to a string, they're data types like DATE and DATETIME that you should look into.

It's minor programming mistakes like these which contribute to Plus's decline in performance and other things like that today.
 

Seriosk

Programmer;
Oct 29, 2016
256
105
Dis-gust-ing

Why are you using your database to store simple cooldowns that can be handled using simple caching of 2 int variables (1 const and a user variable) then a simple if-statement to check.

imo: Holo, Habbo, Rage, and even Fabbo had better cooldown implementations then this. Creating a table, then requesting a db connection object from the server every time the user inputs something that can trigger a cooldown, not only is this a resource hog to your system but it is a contention to the server.

Also, why are you using the public access modifier for methods which should be public static? And if you're going to insist on storing cooldowns in the database (no reason to) at least use the proper data types, VARCHAR is the equivalent to a string, they're data types like DATE and DATETIME that you should look into.

It's minor programming mistakes like these which contribute to Plus's decline in performance and other things like that today.
I never said it was perfect, neither did I at all try and make it.. I don't know why you're crying about it, the community's used to horrible coded released (joke there), but anyway.. I put them in a database in case of an emulation restart, its for people who always want the cooldown to apply, even after an emulation system reboot.

If I wanted to code one for real I would use a KeyValuePair dictionary and cache it, but for this.. its just a quick way to do that.
 

Brad

Well-Known Member
Jun 5, 2012
2,319
992
Thread has been cleaned, please stay on topic. Anymore after this will be dealt with accordingly.
 

Users who are viewing this thread

Top