Modcraft - The community dedicated to quality WoW modding!
Wrath of the Lich King Modding => Serverside Modding => Topic started by: jar0fair on July 19, 2015, 05:21:23 pm
-
Hiya,
I have been trying to figure a way to have the server add a certain amount of gold for every hour of time played. For example. Let's say that I have been playing a character for 3 hours. Every hour I play, A gold coin is added to my currency. If I play for 45 minutes, and log off, and log back on for 15 minutes, I would receive another gold coin.
Are there any guides that might help me achieve this?
Thanks so much.
-
Inside the CHARACTERS DATABASE, there's a TABLE called CHARACTERS. Inside, there's a ROW holding the information about every player played time, called TOTALTIME, that column have time played measured in SECONDS.
You can make a script that will check the TOTALTIME and give players a gold coin.
No I cannot help you with the script.
-
One possible implementation:
New column in characters table (or new table with char DB GUID and new column) that stores accumulated time.
Have a function called every minute server side that increments accumulated time. When accumulated time is > 60 then add a coin and set it to 0.
The more efficient method of implementing this would be to have a HashMap of player low GUID to accumulated time that is updated each minute for players online. Dump this HashMap to the database on server shutdown (or periodically for backup).
-
It's quite easy for Trinity. Use Player::Update() function.
void Player::Update(uint32 p_time)
{
.
.
.
// Played time
if (now > m_Last_tick)
{
uint32 elapsed = uint32(now - m_Last_tick);
m_Played_time[PLAYED_TIME_TOTAL] += elapsed; // Total played time
m_Played_time[PLAYED_TIME_LEVEL] += elapsed; // Level played time
m_Last_tick = now;
// Your hour system
if (GetTotalPlayedTime() % 3600 == 0)
{
ChatHandler(GetSession()).PSendSysMessage("You played an hour!");
ModifyMoney(10000); // One gold coin is added
}
// END
}
.
.
.
-
if (GetTotalPlayedTime() % 3600 == 0)
implies that it always rounds up to exact minutes. You may want to
if (uint32 hours_more_played = ((m_Played_time[PLAYED_TIME_TOTAL] % 3600) - ((m_Played_time[PLAYED_TIME_TOTAL] - elapsed) % 3600)) != 0)
{
ModifyMoney (hours_more_played * GOLD);
}