Advertisement
404Verified

old update played time

Sep 16th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. #include "ScriptMgr.h"
  2. #include "Chat.h"
  3. #include "ObjectAccessor.h"
  4. #include "Player.h"
  5.  
  6. #define UPDATE_TIME_EVERY 600 // updates every 1 minute i recommend you this not less than 60 seconds
  7. #define EQUIRED_ONLINE_TIME 7200 // in seconds '3600' = 1hour
  8. #define REWARD_AMOUNT 2 // how much vp gives if player meets online time
  9.  
  10. // database config
  11. #define DATABASE "webdb"
  12. #define TABLE "account_data"
  13.  
  14. struct sPlayerExtention
  15. {
  16. sPlayerExtention() : online_time(0) {}
  17. uint32 online_time;
  18. };
  19.  
  20. typedef std::map<uint64, sPlayerExtention> PlayerExtention;
  21.  
  22. static PlayerExtention m_PlayerExtention;
  23.  
  24. class Online_Time_VP : public WorldScript
  25. {
  26. public:
  27. Online_Time_VP() : WorldScript("Online_Time_VP") { }
  28.  
  29. static const uint32 m_SaveTimer = UPDATE_TIME_EVERY * IN_MILLISECONDS;
  30.  
  31. uint32 m_Timer;
  32.  
  33. void OnUpdate(uint32 diff)
  34. {
  35. m_Timer += diff;
  36. if (m_Timer > m_SaveTimer)
  37. {
  38. m_Timer = 0;
  39.  
  40. SessionMap const& smap = sWorld->GetAllSessions();
  41. for (SessionMap::const_iterator iter = smap.begin(); iter != smap.end(); ++iter)
  42. {
  43. if (Player* player = iter->second->GetPlayer())
  44. {
  45. uint32 player_id = player->GetGUIDLow();
  46.  
  47. sPlayerExtention extention = m_PlayerExtention[player_id];
  48.  
  49. m_PlayerExtention[player_id].online_time += UPDATE_TIME_EVERY;
  50.  
  51. if(extention.online_time >= EQUIRED_ONLINE_TIME)
  52. {
  53. // first add VP then erase "reset" for that player
  54. LoginDatabase.PExecute("UPDATE `%s`.`%s` SET `vp`=`vp`+%u WHERE `id`='%u'", DATABASE, TABLE, REWARD_AMOUNT, player->GetSession()->GetAccountId());
  55. // now reset his online time
  56. m_PlayerExtention.erase(player_id);
  57. ChatHandler(player->GetSession()).PSendSysMessage("Congratulations your online that has been reached, you have got %u vp", REWARD_AMOUNT);
  58. }
  59. }
  60. }
  61. }
  62. }
  63. };
  64.  
  65. class PlayerLogs : public PlayerScript
  66. {
  67. public:
  68. PlayerLogs() : PlayerScript("PlayerLogs"){}
  69.  
  70. void OnLogout(Player* player)
  71. {
  72. // reset online time
  73. m_PlayerExtention.erase(player->GetSession()->GetAccountId());
  74. }
  75.  
  76. };
  77.  
  78. void AddSC_Online_Time_VP()
  79. {
  80. new Online_Time_VP();
  81. new PlayerLogs;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement