This is a read only copy without any forum functionality of the old Modcraft forum.
If there is anything that you would like to have removed, message me on Discord via Kaev#5208.
Big thanks to Alastor for making this copy!

Menu

Author Topic: [Question] Add gold to a player for each hour played?  (Read 1139 times)

jar0fair

  • Registred Member
  • Race Changer
  • *****
  • Posts: 30
    • View Profile
[Question] Add gold to a player for each hour played?
« 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.
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

Krang Stonehoof

  • Contributors
  • Wiki Incarnate
  • *****
  • Posts: 164
    • View Profile
Re: [Question] Add gold to a player for each hour played?
« Reply #1 on: July 19, 2015, 05:35:01 pm »
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.
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

stoneharry

  • Contributors
  • Creator of Worlds
  • *****
  • Posts: 617
    • View Profile
Re: [Question] Add gold to a player for each hour played?
« Reply #2 on: July 19, 2015, 06:59:59 pm »
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).
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

Daweo

  • Registred Member
  • Race Changer
  • *****
  • Posts: 39
    • View Profile
Re: [Question] Add gold to a player for each hour played?
« Reply #3 on: July 20, 2015, 04:11:56 pm »
It's quite easy for Trinity. Use Player::Update() function.

Code: [Select]
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
    }
.
.
.
« Last Edit: January 01, 1970, 01:00:00 am by Admin »

schlumpf

  • Administrator
  • Creator of Worlds
  • *****
  • Posts: 2967
    • View Profile
Re: [Question] Add gold to a player for each hour played?
« Reply #4 on: July 20, 2015, 06:45:18 pm »
Code: [Select]
   if (GetTotalPlayedTime() % 3600 == 0)
implies that it always rounds up to exact minutes. You may want to

Code: [Select]
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);
}
« Last Edit: January 01, 1970, 01:00:00 am by Admin »