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

[SOLVED] SaveToDB "Dupliacate" entry

Status
Not open for further replies.

Reloac

BETA Tester
Hey

I've recently been having some weird problems, using a proffession NPC, all works ok, except when the person learns a proffession a error shows up in the TC world window (doesnt cause a crash) when im guessing its trying to save the player, but failing... dont really know why...

Error :

Code:
 INSERT INTO characters (guid, account, name, race, class, gender, level, xp, money, playerBytes, playerBytes2, playerFlags, map, instance_id, instance_mode_mask, position_x, position_y, position_z, orientation, taximask, cinematic, totaltime, leveltime, rest_bonus, logout_time, is_logout_resting, resettalents_cost, resettalents_time, extra_flags, stable_slots, at_login, zone, death_expire_time, taxi_path, arenaPoints, totalHonorPoints, todayHonorPoints, yesterdayHonorPoints, totalKills, todayKills, yesterdayKills, chosenTitle, knownCurrencies, watchedFaction, drunk, health, power1, power2, power3, power4, power5, power6, power7, latency, speccount, activespec, exploredZones, equipmentCache, ammoId, knownTitles, actionBars, grantableLevels) VALUES (66,1,'Mirk',11,7,1,90,0,96723762,50397445,33554432,0,530,0,0,-317.033,1106.84,41.6933,4.05176,'0 0 536870912 8 0 0 1048576 0 0 0 0 0 0 0 ',1,63471,63471,0,1375350421,0,0,0,4,0,0,3483,1375306453,'',0,3780,0,1400,27,0,10,143,4096,4294967295,0,844808192,1267206528,0,0,100,0,0,0,0,1,0,'0 0 0 67108864 0 544 0 0 0 0 4 0 0 0 16777216 0 0 0 0 0 0 0 0 16 32768 524288 0 0 0 0 0 0 0 0 0 134217728 2048 0 0 0 0 0 38 0 0 0 16777216 4 32 33554432 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 33554432 0 0 0 0 0 0 0 0 268500992 4096 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ','600007 0 600009 0 600006 0 23345 0 600005 0 600002 0 600001 0 600000 0 600004 0 600003 0 0 0 0 0 600011 0 600011 0 600008 0 600014 0 600013 0 0 0 130008 0 130006 0 130006 0 130006 0 130006 0 ',0,'0 0 0 0 32768 0 ',0,0)
 [ERROR]: [1062] Duplicate entry

any ideas? i dont know why the core doesnt use REPLACE or UPDATE instead of INSERT :/
 

Reloac

BETA Tester
can we see the profession NPC script u are using ?

Code:
#include "ScriptPCH.h"
#include "Language.h"

class Professions_NPC : public CreatureScript
{
    public:
        Professions_NPC () : CreatureScript("Professions_NPC") {}
                
		void CreatureWhisperBasedOnBool(const char *text, Creature *_creature, Player *pPlayer, bool value)
		{
			if (value)
				_creature->MonsterWhisper(text, pPlayer->GetGUID());
		}

		uint32 PlayerMaxLevel() const
		{
			   return sWorld->getIntConfig(CONFIG_MAX_PLAYER_LEVEL);
		}

		bool PlayerHasItemOrSpell(const Player *plr, uint32 itemId, uint32 spellId) const
		{
			   return plr->HasItemCount(itemId, 1, true) || plr->HasSpell(spellId);
		}

		bool OnGossipHello(Player *pPlayer, Creature* _creature)
		{
			pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "|TInterface\\icons\\trade_alchemy:30|t Alchemy", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+1);
			pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "|TInterface\\icons\\trade_blacksmithing:30|t Blacksmithing", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+2);
			pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "|TInterface\\icons\\inv_misc_armorkit_17:30|t Leatherworking", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+3);
			pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "|TInterface\\icons\\trade_tailoring:30|t Tailoring", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+4);
			pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "|TInterface\\icons\\trade_engineering:30|t Engineering", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+5);
			pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "|TInterface\\icons\\trade_engraving:30|t Enchanting", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+6);
			pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "|TInterface\\icons\\inv_misc_gem_01:30|t Jewelcrafting", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+7);
			pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "|TInterface\\icons\\inv_inscription_tradeskill01:30|t Inscription", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+8);
			pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "|TInterface\\icons\\inv_misc_food_15:30|t Cooking", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+9);
			pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "|TInterface\\icons\\spell_holy_sealofsacrifice:30|t First Aid", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+10);
			pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "|TInterface\\icons\\inv_misc_flower_02:30|t Herbalism", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+11);
			pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "|TInterface\\icons\\inv_misc_pelt_wolf_01:30|t Skinning", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+12);
			pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "|TInterface\\icons\\trade_mining:30|t Mining", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+13);
			pPlayer->PlayerTalkClass->SendGossipMenu(907, _creature->GetGUID());
			return true;
		}
		
		bool PlayerAlreadyHasTwoProfessions(const Player *pPlayer) const
		{
			uint32 skillCount = 0;

			if (pPlayer->HasSkill(SKILL_MINING))
				skillCount++;
			if (pPlayer->HasSkill(SKILL_SKINNING))
				skillCount++;
			if (pPlayer->HasSkill(SKILL_HERBALISM))
				skillCount++;

			if (skillCount >= 6)
				return true;

			for (uint32 i = 1; i < sSkillLineStore.GetNumRows(); ++i)
			{
				SkillLineEntry const *SkillInfo = sSkillLineStore.LookupEntry(i);
				if (!SkillInfo)
					continue;

				if (SkillInfo->categoryId == SKILL_CATEGORY_SECONDARY)
					continue;

				if ((SkillInfo->categoryId != SKILL_CATEGORY_PROFESSION) || !SkillInfo->canLink)
					continue;

				const uint32 skillID = SkillInfo->id;
				if (pPlayer->HasSkill(skillID))
					skillCount++;

				if (skillCount >= 2)
					return true;
			}
			return false;
		}

		bool LearnAllRecipesInProfession(Player *pPlayer, SkillType skill)
		{
			ChatHandler handler(pPlayer->GetSession());
			char* skill_name;

			SkillLineEntry const *SkillInfo = sSkillLineStore.LookupEntry(skill);
			skill_name = SkillInfo->name[handler.GetSessionDbcLocale()];

			if (!SkillInfo)
			{
				sLog->outInfo(LOG_FILTER_GENERAL,"Profession NPC: received non-valid skill ID (LearnAllRecipesInProfession)");
				return false;
			}       

			LearnSkillRecipesHelper(pPlayer, SkillInfo->id);

			pPlayer->SetSkill(SkillInfo->id, pPlayer->GetSkillStep(SkillInfo->id), 450, 450);
			handler.PSendSysMessage(LANG_COMMAND_LEARN_ALL_RECIPES, skill_name);
	
			return true;
		}

		void LearnSkillRecipesHelper(Player *player, uint32 skill_id)
		{
			uint32 classmask = player->getClassMask();

			for (uint32 j = 0; j < sSkillLineAbilityStore.GetNumRows(); ++j)
			{
				SkillLineAbilityEntry const *skillLine = sSkillLineAbilityStore.LookupEntry(j);
				if (!skillLine)
					continue;

				// wrong skill
				if (skillLine->skillId != skill_id)
					continue;

				// not high rank
				if (skillLine->forward_spellid)
					continue;

				// skip racial skills
				if (skillLine->racemask != 0)
					continue;

				// skip wrong class skills
				if (skillLine->classmask && (skillLine->classmask & classmask) == 0)
					continue;

				SpellInfo const * spellInfo = sSpellMgr->GetSpellInfo(skillLine->spellId);
				if (!spellInfo || !SpellMgr::IsSpellValid(spellInfo, player, false))
					continue;
				
				player->learnSpell(skillLine->spellId, false);
			}
		}

		bool IsSecondarySkill(SkillType skill) const
		{
			return skill == SKILL_COOKING || skill == SKILL_FIRST_AID;
		}

		void CompleteLearnProfession(Player *pPlayer, Creature *pCreature, SkillType skill)
		{
			if (PlayerAlreadyHasTwoProfessions(pPlayer) && !IsSecondarySkill(skill))
				pCreature->MonsterWhisper("You already know 2 professions!", pPlayer->GetGUID());
			else
			{
				if (!LearnAllRecipesInProfession(pPlayer, skill))
					pCreature->MonsterWhisper("Internal error occured!", pPlayer->GetGUID());
			}
		}

		bool OnGossipSelect(Player* pPlayer, Creature* _creature, uint32 uiSender, uint32 uiAction)
		{ 
			pPlayer->PlayerTalkClass->ClearMenus();

			if (uiSender == GOSSIP_SENDER_MAIN)
			{			
				switch (uiAction)
				{
					case 196:
						pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "|TInterface\\icons\\trade_alchemy:30|t Alchemy", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+1);
						pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "|TInterface\\icons\\trade_blacksmithing:30|t Blacksmithing", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+2);
						pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "|TInterface\\icons\\inv_misc_armorkit_17:30|t Leatherworking", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+3);
						pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "|TInterface\\icons\\trade_tailoring:30|t Tailoring", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+4);
						pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "|TInterface\\icons\\trade_engineering:30|t Engineering", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+5);
						pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "|TInterface\\icons\\trade_engraving:30|t Enchanting", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+6);
						pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "|TInterface\\icons\\inv_misc_gem_01:30|t Jewelcrafting", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+7);
						pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "|TInterface\\icons\\inv_inscription_tradeskill01:30|t Inscription", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+8);
						pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "|TInterface\\icons\\inv_misc_food_15:30|t Cooking", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+9);
						pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "|TInterface\\icons\\spell_holy_sealofsacrifice:30|t First Aid", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+10);
						pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "|TInterface\\icons\\inv_misc_flower_02:30|t Herbalism", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+11);
						pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "|TInterface\\icons\\inv_misc_pelt_wolf_01:30|t Skinning", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+12);
						pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "|TInterface\\icons\\trade_mining:30|t Mining", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+13);
						break;

					case GOSSIP_ACTION_INFO_DEF+1:
						if(pPlayer->HasItemCount(150003,1,true))
						{
						CompleteLearnProfession(pPlayer, _creature, SKILL_ALCHEMY);
						pPlayer->DestroyItemCount(150003, 1, true);
						pPlayer->SaveToDB(true);
						pPlayer->PlayerTalkClass->SendCloseGossip();
						}
						else
						ChatHandler(pPlayer->GetSession()).PSendSysMessage("To get this proffession maxed, please sure a Profession Token or use the trainers to level it by hand.");
						pPlayer->PlayerTalkClass->SendCloseGossip();
						break;

					case GOSSIP_ACTION_INFO_DEF+2:
						if(pPlayer->HasItemCount(150003,1,true))
						{
						CompleteLearnProfession(pPlayer, _creature, SKILL_BLACKSMITHING);
						pPlayer->DestroyItemCount(150003, 1, true);
						pPlayer->SaveToDB(true);
						pPlayer->PlayerTalkClass->SendCloseGossip();
						}
						else
						ChatHandler(pPlayer->GetSession()).PSendSysMessage("To get this proffession maxed, please sure a Profession Token or use the trainers to level it by hand.");
						pPlayer->PlayerTalkClass->SendCloseGossip();
						break;

					case GOSSIP_ACTION_INFO_DEF+3:
						if(pPlayer->HasItemCount(150003,1,true))
						{
						CompleteLearnProfession(pPlayer, _creature, SKILL_LEATHERWORKING);
						pPlayer->DestroyItemCount(150003, 1, true);
						pPlayer->SaveToDB(true);
						pPlayer->PlayerTalkClass->SendCloseGossip();
						}
						else
						ChatHandler(pPlayer->GetSession()).PSendSysMessage("To get this proffession maxed, please sure a Profession Token or use the trainers to level it by hand.");
						pPlayer->PlayerTalkClass->SendCloseGossip();
						break;

					case GOSSIP_ACTION_INFO_DEF+4:
						if(pPlayer->HasItemCount(150003,1,true))
						{
						CompleteLearnProfession(pPlayer, _creature, SKILL_TAILORING);
						pPlayer->DestroyItemCount(150003, 1, true);
						pPlayer->SaveToDB(true);
						pPlayer->PlayerTalkClass->SendCloseGossip();
						}
						else
						ChatHandler(pPlayer->GetSession()).PSendSysMessage("To get this proffession maxed, please sure a Profession Token or use the trainers to level it by hand.");
						pPlayer->PlayerTalkClass->SendCloseGossip();
						break;

					case GOSSIP_ACTION_INFO_DEF+5:
						if(pPlayer->HasItemCount(150003,1,true))
						{
						CompleteLearnProfession(pPlayer, _creature, SKILL_ENGINEERING);
						pPlayer->DestroyItemCount(150003, 1, true);
						pPlayer->SaveToDB(true);
						pPlayer->PlayerTalkClass->SendCloseGossip();
						}
						else
						ChatHandler(pPlayer->GetSession()).PSendSysMessage("To get this proffession maxed, please sure a Profession Token or use the trainers to level it by hand.");
						pPlayer->PlayerTalkClass->SendCloseGossip();
						break;

					case GOSSIP_ACTION_INFO_DEF+6:
						if(pPlayer->HasItemCount(150003,1,true))
						{
						CompleteLearnProfession(pPlayer, _creature, SKILL_ENCHANTING);
						pPlayer->DestroyItemCount(150003, 1, true);
						pPlayer->SaveToDB(true);
						pPlayer->PlayerTalkClass->SendCloseGossip();
						}
						else
						ChatHandler(pPlayer->GetSession()).PSendSysMessage("To get this proffession maxed, please sure a Profession Token or use the trainers to level it by hand.");
						pPlayer->PlayerTalkClass->SendCloseGossip();
						break;

					case GOSSIP_ACTION_INFO_DEF+7:
						if(pPlayer->HasItemCount(150003,1,true))
						{
						CompleteLearnProfession(pPlayer, _creature, SKILL_JEWELCRAFTING);
						pPlayer->DestroyItemCount(150003, 1, true);
						pPlayer->SaveToDB(true);
						pPlayer->PlayerTalkClass->SendCloseGossip();
						}
						else
						ChatHandler(pPlayer->GetSession()).PSendSysMessage("To get this proffession maxed, please sure a Profession Token or use the trainers to level it by hand.");
						pPlayer->PlayerTalkClass->SendCloseGossip();
						break;

					case GOSSIP_ACTION_INFO_DEF+8:
						if(pPlayer->HasItemCount(150003,1,true))
						{
						CompleteLearnProfession(pPlayer, _creature, SKILL_INSCRIPTION);
						pPlayer->DestroyItemCount(150003, 1, true);
						pPlayer->SaveToDB(true);
						pPlayer->PlayerTalkClass->SendCloseGossip();
						}
						else
						ChatHandler(pPlayer->GetSession()).PSendSysMessage("To get this proffession maxed, please sure a Profession Token or use the trainers to level it by hand.");
						pPlayer->PlayerTalkClass->SendCloseGossip();
						break;

					case GOSSIP_ACTION_INFO_DEF+9:
						if(pPlayer->HasItemCount(150003,1,true))
						{
						CompleteLearnProfession(pPlayer, _creature, SKILL_COOKING);
						pPlayer->DestroyItemCount(150003, 1, true);
						pPlayer->SaveToDB(true);
						pPlayer->PlayerTalkClass->SendCloseGossip();
						}
						else
						ChatHandler(pPlayer->GetSession()).PSendSysMessage("To get this proffession maxed, please sure a Profession Token or use the trainers to level it by hand.");
						pPlayer->PlayerTalkClass->SendCloseGossip();
						break;

					case GOSSIP_ACTION_INFO_DEF+10:
						if(pPlayer->HasItemCount(150003,1,true))
						{
						CompleteLearnProfession(pPlayer, _creature, SKILL_FIRST_AID);
						pPlayer->DestroyItemCount(150003, 1, true);
						pPlayer->SaveToDB(true);
						pPlayer->PlayerTalkClass->SendCloseGossip();
						}
						else
						ChatHandler(pPlayer->GetSession()).PSendSysMessage("To get this proffession maxed, please sure a Profession Token or use the trainers to level it by hand.");
						pPlayer->PlayerTalkClass->SendCloseGossip();
						break;

					case GOSSIP_ACTION_INFO_DEF+11:
						if(pPlayer->HasItemCount(150003,1,true))
						{
						CompleteLearnProfession(pPlayer, _creature, SKILL_HERBALISM);
						pPlayer->DestroyItemCount(150003, 1, true);
						pPlayer->SaveToDB(true);
						pPlayer->PlayerTalkClass->SendCloseGossip();
						}
						else
						ChatHandler(pPlayer->GetSession()).PSendSysMessage("To get this proffession maxed, please sure a Profession Token or use the trainers to level it by hand.");
						pPlayer->PlayerTalkClass->SendCloseGossip();
						break;

					case GOSSIP_ACTION_INFO_DEF+12:
						if(pPlayer->HasItemCount(150003,1,true))
						{
						CompleteLearnProfession(pPlayer, _creature, SKILL_SKINNING);
						pPlayer->DestroyItemCount(150003, 1, true);
						pPlayer->SaveToDB(true);
						pPlayer->PlayerTalkClass->SendCloseGossip();
						}
						else
						ChatHandler(pPlayer->GetSession()).PSendSysMessage("To get this proffession maxed, please sure a Profession Token or use the trainers to level it by hand.");
						pPlayer->PlayerTalkClass->SendCloseGossip();
						break;

					case GOSSIP_ACTION_INFO_DEF+13:
						if(pPlayer->HasItemCount(150003,1,true))
						{
						CompleteLearnProfession(pPlayer, _creature, SKILL_MINING);
						pPlayer->DestroyItemCount(150003, 1, true);
						pPlayer->SaveToDB(true);
						pPlayer->PlayerTalkClass->SendCloseGossip();
						}
						else
						ChatHandler(pPlayer->GetSession()).PSendSysMessage("To get this proffession maxed, please sure a Profession Token or use the trainers to level it by hand.");
						pPlayer->PlayerTalkClass->SendCloseGossip();
						break;
				}
			}
	return true;
	}
};

void AddSC_Professions_NPC()
{
    new Professions_NPC();
}

Im thinking its just something general with TC, since i updated a section of the SavetoDB funcitoon, to UPD from INS and it fixed that, but broke char creation, so im guessing its something with char creation 0.0
 

Reloac

BETA Tester
Fixed, i should never edit code when sleepy.... it was because player->SaveToDB(true); should have been (); - to not make a new entry :p
 

Tommy

Founder
Fixed, i should never edit code when sleepy.... it was because player->SaveToDB(true); should have been (); - to not make a new entry :p

Alright, marking as solved! Wish I could've been here to solve this earlier! :(
 
Status
Not open for further replies.
Top