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:
C#:
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();
}
}
}
}