- Joined
- Feb 19, 2011
- Messages
- 41
- Reaction score
- 14
Pressing V to teleport the system will close the game. Can anyone help or fix the bug? Or give me some directions?
void CDPSrvr::OnSellItem(CAr& ar, DPID dpidCache, DPID dpidUser, LPBYTE lpBuf, u_long uBufSize)
{
BYTE nId;
short nNum;
ar >> nId >> nNum;
if (nNum < 1)
return;
CUser* pUser = g_UserMng.GetUser(dpidCache, dpidUser);
if (IsValidObj(pUser) && IsValidObj(pUser->m_vtInfo.GetOther()))
{
#ifdef __WORLDSERVER_MENU
#ifdef __GAMEMASTER
if (CDPSrvr::GetInstance()->m_bExchange == FALSE && !pUser->IsAuthHigher(AUTH_GAMEMASTER3))
#else // __GAMEMASTER
if (CDPSrvr::GetInstance()->m_bExchange == FALSE)
#endif // __GAMEMASTER
{
pUser->AddText("");
return;
}
#endif // __WORLDSERVER_MENU
if (pUser->m_vtInfo.GetOther()->IsNPC() == FALSE) // vente uniquement sur NPC
return;
if (!CNpcChecker::GetInstance()->IsCloseNpc(MMI_TRADE, pUser->GetWorld(), pUser->GetPos()))
return;
CItemElem* pItemElem = pUser->m_Inventory.GetAtId(nId);
if (IsUsableItem(pItemElem) == FALSE)
return;
ItemProp* pProp = pItemElem->GetProp();
if (pProp->dwItemKind3 == IK3_EVENTMAIN)
return;
if (pItemElem->IsQuest())
return;
if (pUser->m_Inventory.IsEquip(nId))
{
pUser->AddDefinedText(TID_GAME_EQUIPTRADE, "");
return;
}
#if __VER >= 11 // __MA_VER11_05
if (pItemElem->m_dwItemId == II_SYS_SYS_SCR_SEALCHARACTER)
return;
#endif
#if __VER >= 11 // __MA_VER11_02
if (pItemElem->m_dwItemId == II_SYS_SYS_SCR_PERIN)
return;
#endif
if (nNum > pItemElem->m_nItemNum)
nNum = pItemElem->m_nItemNum;
if (nNum < 1)
nNum = 1;
#if __VER >= 12 // __TAX
int nGold = (pItemElem->GetCost() / 4);
#ifdef __SHOP_COST_RATE
nGold = (int)(prj.m_EventLua.GetShopSellFactor() * nGold);
#endif
if (nGold == 0)
nGold = 1;
int nTax = 0;
if (CTax::GetInstance()->IsApplyTaxRate(pUser, pItemElem))
{
nTax = (int)(nGold * CTax::GetInstance()->GetSalesTaxRate(pUser));
#ifdef __BUYBACK
pItemElem->setBuyBackCont(CTax::GetInstance()->GetContinent(pUser));
pItemElem->setBuyBackTaxes(nTax);
#endif
}
nGold -= nTax;
#ifdef __BUYBACK
pItemElem->setBuyBackPrice(nGold + ceil(nGold * (double)((double)__BUYBACK_PERCENT_COST / 100.0f)));
#endif
nGold *= nNum;
nTax *= nNum;
float fTmpGold = (float)(pUser->GetGold() + nGold);
#else
float fTmpGold = pUser->GetGold() + (pItemElem->GetCost() / 4) * nNum;
#endif
if (fTmpGold >= 2100000000)
return;
if (pProp->dwParts == PARTS_RIDE && pProp->dwItemJob == JOB_VAGRANT)
return;
if (pUser->IsUsing(pItemElem))
{
pUser->AddDefinedText(TID_GAME_CANNOT_DO_USINGITEM);
return;
}
LogItemInfo aLogItem;
aLogItem.Action = "S";
aLogItem.SendName = pUser->GetName();
aLogItem.RecvName = pUser->m_vtInfo.GetOther()->GetName();
aLogItem.WorldId = pUser->GetWorld()->GetID();
aLogItem.Gold = pUser->GetGold();
#if __VER >= 12
aLogItem.Gold2 = pUser->GetGold() + nGold;
#else
aLogItem.Gold2 = pUser->GetGold() + (pItemElem->GetCost() / 4) * nNum;
#endif
OnLogItem(aLogItem, pItemElem, nNum);
int nCost = (int)pItemElem->GetCost() / 4;
#if __VER < 8
KarmaProp* pKarmaProp = prj.GetKarmaProp(pUser->m_nSlaughter);
if (pKarmaProp)
{
if (pKarmaProp->nGrade == -6)
return;
if (pKarmaProp->fSellPenaltyRate != 0.0f)
nCost = (int)(nCost * pKarmaProp->fSellPenaltyRate);
}
#endif
if (nCost < 1)
nCost = 1;
#if __VER >= 12
if (nGold < 1)
nGold = 1;
pUser->AddGold(nGold);
if (nTax)
CTax::GetInstance()->AddTax(CTax::GetInstance()->GetContinent(pUser), nTax, TAX_SALES);
#else
pUser->AddGold(nCost * nNum);
#endif
#ifdef __BUYBACK
#ifdef __ZACKS_FIX_BUYBACK
if (pItemElem->m_pPet != NULL || pProp->dwItemKind3 == IK3_PET)
{
pUser->RemoveItem(nId, nNum);
#ifdef __GAMEGUARD
if (pUser->GetWorld())
g_dpDBClient.SavePlayer(pUser, pUser->GetWorld()->GetID(), pUser->GetPos(), pUser->GetLayer());
#endif
return;
}
#endif // __ZACKS_FIX_BUYBACK
if (pUser->m_BuyBack.GetCount() >= pUser->m_BuyBack.GetMax())
{
pUser->m_BuyBack.RemoveAtId(0);
Reorganize(&pUser->m_BuyBack);
pUser->BuyBackRemoveItem(0);
}
CItemElem itemElem = *pItemElem;
itemElem.m_nItemNum = nNum;
#ifdef __ZACKS_FIX_BUYBACK
// ===== Correctif: la copie ne doit PAS poss?er le pet =====
itemElem.m_pPet = NULL; // neutralise la propri??dans la copie
#endif
pUser->m_BuyBack.Add(&itemElem);
pUser->SendBuyBack(&itemElem);
#endif // __BUYBACK
pUser->RemoveItem(nId, nNum);
#ifdef __GAMEGUARD
if (pUser->GetWorld())
g_dpDBClient.SavePlayer(pUser, pUser->GetWorld()->GetID(), pUser->GetPos(), pUser->GetLayer());
#endif
}
}
Minor fix for the crash occurring when selling a pet (however, once sold, pets can no longer be repurchased through the BuyBack system): in the OnSellItem function.
C++:void CDPSrvr::OnSellItem(CAr& ar, DPID dpidCache, DPID dpidUser, LPBYTE lpBuf, u_long uBufSize) { BYTE nId; short nNum; ar >> nId >> nNum; if (nNum < 1) return; CUser* pUser = g_UserMng.GetUser(dpidCache, dpidUser); if (IsValidObj(pUser) && IsValidObj(pUser->m_vtInfo.GetOther())) { #ifdef __WORLDSERVER_MENU #ifdef __GAMEMASTER if (CDPSrvr::GetInstance()->m_bExchange == FALSE && !pUser->IsAuthHigher(AUTH_GAMEMASTER3)) #else // __GAMEMASTER if (CDPSrvr::GetInstance()->m_bExchange == FALSE) #endif // __GAMEMASTER { pUser->AddText(""); return; } #endif // __WORLDSERVER_MENU if (pUser->m_vtInfo.GetOther()->IsNPC() == FALSE) // vente uniquement sur NPC return; if (!CNpcChecker::GetInstance()->IsCloseNpc(MMI_TRADE, pUser->GetWorld(), pUser->GetPos())) return; CItemElem* pItemElem = pUser->m_Inventory.GetAtId(nId); if (IsUsableItem(pItemElem) == FALSE) return; ItemProp* pProp = pItemElem->GetProp(); if (pProp->dwItemKind3 == IK3_EVENTMAIN) return; if (pItemElem->IsQuest()) return; if (pUser->m_Inventory.IsEquip(nId)) { pUser->AddDefinedText(TID_GAME_EQUIPTRADE, ""); return; } #if __VER >= 11 // __MA_VER11_05 if (pItemElem->m_dwItemId == II_SYS_SYS_SCR_SEALCHARACTER) return; #endif #if __VER >= 11 // __MA_VER11_02 if (pItemElem->m_dwItemId == II_SYS_SYS_SCR_PERIN) return; #endif if (nNum > pItemElem->m_nItemNum) nNum = pItemElem->m_nItemNum; if (nNum < 1) nNum = 1; #if __VER >= 12 // __TAX int nGold = (pItemElem->GetCost() / 4); #ifdef __SHOP_COST_RATE nGold = (int)(prj.m_EventLua.GetShopSellFactor() * nGold); #endif if (nGold == 0) nGold = 1; int nTax = 0; if (CTax::GetInstance()->IsApplyTaxRate(pUser, pItemElem)) { nTax = (int)(nGold * CTax::GetInstance()->GetSalesTaxRate(pUser)); #ifdef __BUYBACK pItemElem->setBuyBackCont(CTax::GetInstance()->GetContinent(pUser)); pItemElem->setBuyBackTaxes(nTax); #endif } nGold -= nTax; #ifdef __BUYBACK pItemElem->setBuyBackPrice(nGold + ceil(nGold * (double)((double)__BUYBACK_PERCENT_COST / 100.0f))); #endif nGold *= nNum; nTax *= nNum; float fTmpGold = (float)(pUser->GetGold() + nGold); #else float fTmpGold = pUser->GetGold() + (pItemElem->GetCost() / 4) * nNum; #endif if (fTmpGold >= 2100000000) return; if (pProp->dwParts == PARTS_RIDE && pProp->dwItemJob == JOB_VAGRANT) return; if (pUser->IsUsing(pItemElem)) { pUser->AddDefinedText(TID_GAME_CANNOT_DO_USINGITEM); return; } LogItemInfo aLogItem; aLogItem.Action = "S"; aLogItem.SendName = pUser->GetName(); aLogItem.RecvName = pUser->m_vtInfo.GetOther()->GetName(); aLogItem.WorldId = pUser->GetWorld()->GetID(); aLogItem.Gold = pUser->GetGold(); #if __VER >= 12 aLogItem.Gold2 = pUser->GetGold() + nGold; #else aLogItem.Gold2 = pUser->GetGold() + (pItemElem->GetCost() / 4) * nNum; #endif OnLogItem(aLogItem, pItemElem, nNum); int nCost = (int)pItemElem->GetCost() / 4; #if __VER < 8 KarmaProp* pKarmaProp = prj.GetKarmaProp(pUser->m_nSlaughter); if (pKarmaProp) { if (pKarmaProp->nGrade == -6) return; if (pKarmaProp->fSellPenaltyRate != 0.0f) nCost = (int)(nCost * pKarmaProp->fSellPenaltyRate); } #endif if (nCost < 1) nCost = 1; #if __VER >= 12 if (nGold < 1) nGold = 1; pUser->AddGold(nGold); if (nTax) CTax::GetInstance()->AddTax(CTax::GetInstance()->GetContinent(pUser), nTax, TAX_SALES); #else pUser->AddGold(nCost * nNum); #endif #ifdef __BUYBACK #ifdef __ZACKS_FIX_BUYBACK if (pItemElem->m_pPet != NULL || pProp->dwItemKind3 == IK3_PET) { pUser->RemoveItem(nId, nNum); #ifdef __GAMEGUARD if (pUser->GetWorld()) g_dpDBClient.SavePlayer(pUser, pUser->GetWorld()->GetID(), pUser->GetPos(), pUser->GetLayer()); #endif return; } #endif // __ZACKS_FIX_BUYBACK if (pUser->m_BuyBack.GetCount() >= pUser->m_BuyBack.GetMax()) { pUser->m_BuyBack.RemoveAtId(0); Reorganize(&pUser->m_BuyBack); pUser->BuyBackRemoveItem(0); } CItemElem itemElem = *pItemElem; itemElem.m_nItemNum = nNum; #ifdef __ZACKS_FIX_BUYBACK // ===== Correctif: la copie ne doit PAS poss?er le pet ===== itemElem.m_pPet = NULL; // neutralise la propri??dans la copie #endif pUser->m_BuyBack.Add(&itemElem); pUser->SendBuyBack(&itemElem); #endif // __BUYBACK pUser->RemoveItem(nId, nNum); #ifdef __GAMEGUARD if (pUser->GetWorld()) g_dpDBClient.SavePlayer(pUser, pUser->GetWorld()->GetID(), pUser->GetPos(), pUser->GetLayer()); #endif } }
simply added __ZACKS_FIX_BUYBACK
CItemElem itemElem;
itemElem = *pItemElem;
the pet are sellable but if you buyback no pet in the buyback systemif pets are out and are sellable you can compare the id of the item sold with GetEatPetId or GetPetId to ignore selling the pet.
Otherwise,
C++:CItemElem itemElem; itemElem = *pItemElem;
Part of the crash issue or whatever is because CItemElem(const CItemElem&) constructor copying raw pointer data and because its construction of the object it does the default assumed implementation (copying all the data) rather than doing what's listed in virtual CItemElem& operator = ( CItemElem & ie );
I've literally run all the databases, even the ones in the folders, but the error persists, and when I log in I can't even create a character because it freezes.You need to run the database scripts in order. They are numbered for you. Including ones inside of the folders. Which should be done LAST. Hope this helps.![]()