• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

TrinityCore 3.3.5 How to save online time after change

jeaskk

Member
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 a moderator:

Rochet2

Moderator / Eluna Dev
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
 
Top