User Tag List

Results 1 to 2 of 2

Thread: How to save online time after change

  1. #1
    Member
    Join Date
    Oct 2016
    Posts
    1
    XP
    183
    Level
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to save online time after change

    Code:
    bool OnGossipSelect(Player* player, Creature* creature, uint32 sender, uint32 action)
    	{
    		player->PlayerTalkClass->ClearMenus();
    
    		QueryResult result = CharacterDatabase.PQuery("SELECT totaltime FROM characters WHERE guid=%u;", player->GetGUID());
    		Field *fields = result->Fetch();
    		uint32 totaltime = fields[0].GetUInt32();
    
    		switch (action)
    		{
    		case 101:
    			if (player->GetTotalPlayedTime() >60)
    			{				
    				CharacterDatabase.PExecute("UPDATE characters SET totaltime = (totaltime - 60), leveltime = (leveltime - 60) WHERE guid = %u", player->GetGUIDLow()); //I updated the database characters
    				player->AddItem(60000, 10);
    				player->GetSession()->SendAreaTriggerMessage("test");
    			}
    			else
    			{
    				player->GetSession()->SendAreaTriggerMessage("test");
    			}
    			player->CLOSE_GOSSIP_MENU();
    			break;
    After doing so, the database is changed, but after a while the database is restored.
    I would like to ask how to preserve here?
    I tried a variety of ways will not work.
    Thank you again.
    Last edited by slp13at420; 01-11-2017 at 06:11 PM.
    Achievements:
    31 days registered Member Level II

  2. #2
    Moderator / Eluna Dev <span style='color: #FF0000'><span class='glow_8B0000'>Rochet2</span></span>'s Avatar
    Join Date
    Apr 2013
    Location
    Finland
    Posts
    1,871
    XP
    13,718
    Level
    35
    Thanks
    95
    Thanked 595 Times in 421 Posts
    As a rule of thumb you should never edit existing database tables when the server is running.
    You must use the core functions to alter what is stored in the memory of the server so it will be saved correctly by the server.

    If you look at how totaltime is used in core, you can see that it is stored to a field for the player.
    Simply edit that field instead of editing the DB. Look for m_Played_time
    Awards:
    Support LOL Scripter Facepalm! Raffle Winner
    rochet2.github.io - Home of great codes

  3. The Following User Says Thank You to Rochet2 For This Useful Post:


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •