revengertmt 50 Posted February 10, 2018 Share Posted February 10, 2018 (edited) For starters hello!I'd like to be able to hide the Shop Search Icon and 2 I have a problem with vouchers ... that is, I want to save myself in the log table from navicatthe code looks like this:char.cpp bool CHARACTER::SetCoins(long coins) { SQLMsg *msg; msg = DBManager::instance().DirectQuery("UPDATE account.account SET coins = coins + '%ld' WHERE id = '%d'", coins, GetAID()); if (msg->uiSQLErrno != 0) { sys_err("[MD] Nu pot fi predate!(a aparut o eroare)"); return false; } return true; } char_item.cpp switch (item->GetVnum()) { //Vnums case 80014: // 100 DR/Coins case 80015: // 500 DR/Coins case 80016: // 1000 DR/Coins case 80017: // 50 DR/Coins int idx[4]; idx[0] = 100; idx[1] = 500; idx[2] = 1000; idx[3] = 50; int idax; if (item->GetVnum() == 80014) idax = 0; if (item->GetVnum() == 80015) idax = 1; if (item->GetVnum() == 80016) idax = 2; if (item->GetVnum() == 80017) idax = 3; long val; val = idx[idax]; if (SetCoins(val)) { ChatPacket(CHAT_TYPE_INFO, "Ai Primit %ld Monede Dragon.", val); // {0} item->SetCount(item->GetCount() - 1); } else { ChatPacket(CHAT_TYPE_INFO, "A aparut o eroare. Contactati administratorul."); } return 1; break; default: break; } my table log tablesvoucher_log Target Server Type : MYSQL Target Server Version : 50533 File Encoding : 65001 Date: 2018-02-10 16:01:15 */ SET FOREIGN_KEY_CHECKS=0; -- ---------------------------- -- Table structure for voucher_log -- ---------------------------- DROP TABLE IF EXISTS `voucher_log`; CREATE TABLE `voucher_log` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `account_id` int(10) unsigned NOT NULL, `item_vnum` int(11) NOT NULL, `coins` int(10) unsigned NOT NULL, `data` datetime NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; -- ---------------------------- -- Records of voucher_log -- ---------------------------- Sorry for my bad English Edited August 20, 2022 by Metin2 Dev Core X - External 2 Internal Link to comment Share on other sites More sharing options...
Developer Ikarus_ 2426 Posted February 10, 2018 Developer Share Posted February 10, 2018 5 hours ago, revengertmt said: bool CHARACTER::SetCoins(long coins) { SQLMsg *msg; msg = DBManager::instance().DirectQuery("UPDATE account.account SET coins = coins + '%ld' WHERE id = '%d'", coins, GetAID()); if (msg->uiSQLErrno != 0) { sys_err("[MD] Nu pot fi predate!(a aparut o eroare)"); return false; } return true; } I suggest you change with this bool CHARACTER::ChangeCoins(DWORD dwVnum) { int iCount = 0; for(int i = 0 ; i < VOUCHER_NUM ; i++) { if(dwVnum == cdwVoucherVnum[i]) { iCount = ciVoucherCountDR[i]; break; } } if(iCount ==0) return false; SQLMsg* pMsg = AccountDB::instance().DirectQuery("UPDATE account.account SET coins = coins + '%ld' WHERE id = '%d'", iCount,GetAID()); bool bSucc = (pMsg->uiSQLErrno == 0); delete(pMsg); if (!bSucc) { sys_err("[MD] Nu pot fi predate!(a aparut o eroare)"); } else { LogManager::instance().CoinsLog(GetAID() , GetPlayerID() , dwVnum , iCount); ChatPacket(CHAT_TYPE_INFO,"<SYSTEM> You received [%d]DR ",iCount); } return bSucc; } if you don't delete pMsg you get memory leak... change in char_item (UseItem / UseItemEx) your's script with this switch (item->GetVnum()) { //Vnums case 80014: // 100 DR/Coins case 80015: // 500 DR/Coins case 80016: // 1000 DR/Coins case 80017: if (ChangeCoins(item->GetVnum())) { item->SetCount(item->GetCount() - 1); } else { ChatPacket(CHAT_TYPE_INFO, "A aparut o eroare. Contactati administratorul."); } return 1; break; default: break; } add in constants.cpp and constants.h //constants.cpp (end of file) const DWORD cdwVoucherVnum[VOUCHER_NUM] = { 80014, 80015, 80016, 80017 } const int ciVoucherCountDR[VOUCHER_NUM] = { 100, 500, 1000, 50 } //constants.h (end of file) #define VOUCHER_NUM 4 extern const DWORD cdwVoucherVnum[VOUCHER_NUM]; extern const int ciVoucherCountDR[VOUCHER_NUM]; add in log.cpp and log.h //log.cpp void LogManager::CoinsLog( DWORD dwAID , dwPlayerID , DWORD dwVnum , int iCount) { Query("INSERT INTO voucher_log (id , account_id , item_vnum , coins , data) VALUES('%u' , '%u' , '%u' , '%u' , NOW() )",dwPlayerID , dwAID , dwVnum , iCount ); } log.h //under public CoinsLog(DWORD dwAID , dwPlayerID , DWORD dwVnum , int iCount); Let me know if you have problems... I have not tested it but should do everything you ask for Fixed the chat packet error * My youtube channel on which you can see my works here Link to comment Share on other sites More sharing options...
revengertmt 50 Posted February 11, 2018 Author Share Posted February 11, 2018 bro you are amazing!:X tnx can you help me improve this??? char.cpp void CHARACTER::ChangeGold(long gold) { DBManager::instance().SendMoneyLog(MONEY_LOG_QUEST, GetPlayerID(), gold); PointChange(POINT_GOLD, gold, true); } char.h void ChangeGold(long gold = 0); char_item.cpp switch (item->GetVnum()) { case 80003: // 50kk case 80004: // 100kk case 80005: // 250kk case 80006: // 500kk??? case 80007: // 1kkk??? int idx[5]; idx[0] = 50000000; idx[1] = 100000000; idx[2] = 250000000; idx[3] = 500000000; idx[4] = 1000000000; int idax; if (item->GetVnum() == 80003) idax = 0; if (item->GetVnum() == 80004) idax = 1; if (item->GetVnum() == 80005) idax = 2; if (item->GetVnum() == 80006) idax = 3; if (item->GetVnum() == 80007) idax = 4; long val; val = idx[idax]; ChangeGold(val); item->SetCount(item->GetCount() - 1); return 1; break; default: break; } I have yang type long long Link to comment Share on other sites More sharing options...
Developer Ikarus_ 2426 Posted February 11, 2018 Developer Share Posted February 11, 2018 usually, when you put the full yang system with the value type long long, you don't use PointChange because the points are an array of long type....I hope you haven't changed the value type of the character point array just to put the full yang.... you would lose a lot of efficiency at all If you did it... You usually add an extra long long member to the packet update point and assign the long long m_dlGold value (e. g..). If you just want me to optimize what you've posted using character points arrays, I can do it... how you want to do it. My youtube channel on which you can see my works here Link to comment Share on other sites More sharing options...
revengertmt 50 Posted February 11, 2018 Author Share Posted February 11, 2018 about the same problem ....I want to save myself in the log table when using one of: vnum, written above Link to comment Share on other sites More sharing options...
Developer Ikarus_ 2426 Posted February 11, 2018 Developer Share Posted February 11, 2018 I preface that even this code is only written and posted, I have not compilled it and not tested it. //UseItem / UseItemEx part switch (item->GetVnum()) { case 80003: // 50kk case 80004: // 100kk case 80005: // 250kk case 80006: // 500kk??? case 80007: // 1kkk??? { if(ChangeBars(item->GetVnum()) item->SetCount(item->GetCount() - 1); else ChatPacket(CHAT_TYPE_INFO , "<SYSTEM> An error occurred while the exchange happened."); return 1; } default: break; } //constantsc.cpp const DWORD cdwBarsItems[ITEM_BARS_NUM] = { 80003, 80004, 80005, 80006, 80007, } const long long cdlBarsValue[ITEM_BARS_NUM] = { 50000000, 100000000, 250000000, 500000000, 1000000000, } //constants.h #define ITEM_BARS_NUM 5 extern const DWORD cdwBarsItems[ITEM_BARS_NUM]; extern const long long cdlBarsValue[ITEM_BARS_NUM]; //new methods to add in char.cpp or char_item.cpp bool CHARACTER::ChangeBars(DWORD dwVnum) { long long dlCount = 0; for(int i = 0; i < ITEM_BARS_NUM; i++) { if(cdwBarsItems[i] == dwVnum) { dlCount = cdlBarsValue[i]; break; } } if(dlCount == 0) return false; ChangeGold(dlCount); TItemTable* pItemTable = ITEM_MANAGER::instance().GetTable(dwVnum); if(pItemTable) ChatPacket(CHAT_TYPE_INFO , "<SYSTEM> You received [%d] yang for changing [%s]", dlCount,pItemTable->szLocaleName ); LogManager::instance().BarsLog(GetAID() , GetPlayerID() , dwVnum , dlCount); } //into char.h (under public) bool ChangeBars(DWORD dwVnum); //in log.cpp void LogManager::BarsLog(DWORD dwAID , DWORD dwPlayerID , DWORD dwVnum , long long dlCount) { Query("INSERT INTO bars_log (account_id , id , item_vnum , yang_count , time_stamp ) VALUES('%u', '%u' , '%u' , '%u' , NOW() )" , dwAID , dwPlayerID , dwVnum , dlCount); } //in log.h (under public) void BarsLog(DWORD dwAID , DWORD dwPlayerID , DWORD dwVnum , long long dlCount); it is necessary to add the table in the log database "bars_log" account_id (unsigned int) id (unsigned int) item_vnum (unsigned int) yang_count (unsigned big int) time_stamp (datetime) not knowing if you are using bars or cheques I preferred to use the word bars in the code (and for the table) but you can replace it anywhere (you are sure to have replaced it everywhere) with what you want. 1 My youtube channel on which you can see my works here Link to comment Share on other sites More sharing options...
Premium Speachless 759 Posted February 11, 2018 Premium Share Posted February 11, 2018 You should use auto_ptr in query to avoid memory leak. Link to comment Share on other sites More sharing options...
Developer Ikarus_ 2426 Posted February 11, 2018 Developer Share Posted February 11, 2018 5 minutes ago, Dobrescu Sebastian said: You should use auto_ptr in query to avoid memory leak. If you use SQLMsg* and after using delete you don't get memory leak... My youtube channel on which you can see my works here Link to comment Share on other sites More sharing options...
Premium Speachless 759 Posted February 11, 2018 Premium Share Posted February 11, 2018 43 minutes ago, riku11 said: If you use SQLMsg* and after using delete you don't get memory leak... But, isn't it better with auto_ptr ? http://en.cppreference.com/w/cpp/memory/auto_ptr Link to comment Share on other sites More sharing options...
Developer Ikarus_ 2426 Posted February 11, 2018 Developer Share Posted February 11, 2018 I apologise, but your statement suggests that mine is a mistake, so I would like to clarify something. the use or not of auto_ptr is at the discretion of the programmer.... the auto_ptr is not better than a normal pointer, it is only safer. But I hate to see it used if the pointer's life is only 5 lines of code.... it doesn't make much sense. The use of the auto_ptr instead of a normal pointer in my code would have no advantage. SQLMsg* pMsg = AccountDB::instance().DirectQuery("UPDATE account.account SET coins = coins + '%ld' WHERE id = '%d'", iCount,GetAID()); bool bSucc = (pMsg->uiSQLErrno == 0); delete(pMsg); as you can see there is no way the pointer could be deleted without deleting the object which he points to... the use of auto_ptr (which has been deprecated and replaced with unique_ptr IF YOU ARE INTERESTED IN KNOWING IT) is especially recommended when the pointer life is durable, not if you only use it for 2 lines of code.... I don't want to seem bad or attack you, but better say things really as they are:) My youtube channel on which you can see my works here Link to comment Share on other sites More sharing options...
revengertmt 50 Posted February 11, 2018 Author Share Posted February 11, 2018 wtf? char.cpp:7545: error: 'ChangeGold' was not declared in this scope Link to comment Share on other sites More sharing options...
Developer Ikarus_ 2426 Posted February 11, 2018 Developer Share Posted February 11, 2018 You did not put ChangeGold in char.h i think.. My youtube channel on which you can see my works here Link to comment Share on other sites More sharing options...
revengertmt 50 Posted February 11, 2018 Author Share Posted February 11, 2018 (edited) 6 minutes ago, riku11 said: You did not put ChangeGold in char.h i think.. Edited August 24, 2022 by Metin2 Dev Core X - External 2 Internal Link to comment Share on other sites More sharing options...
Developer Ikarus_ 2426 Posted February 11, 2018 Developer Share Posted February 11, 2018 I thought I understood that you already had the method ChangeGold in your code If you don't hold it, replace it with what is used in your code to give/remove yang My youtube channel on which you can see my works here Link to comment Share on other sites More sharing options...
revengertmt 50 Posted February 11, 2018 Author Share Posted February 11, 2018 1 hour ago, riku11 said: I thought I understood that you already had the method ChangeGold in your code If you don't hold it, replace it with what is used in your code to give/remove yang I have edited! bool CHARACTER::ChangeGoldBars(DWORD dwVnum) { long long dlCount = 0; for(int i = 0; i < GOLD_BARS_NUM; i++) { if(GoldBarsItems[i] == dwVnum) { dlCount = GoldBarsValue[i]; break; } } if(dlCount ==0) return false; SQLMsg* pMsg = DBManager::instance().DirectQuery("UPDATE player.player SET gold = gold + '%lld' WHERE id = '%d'", dlCount,GetPlayerID()); bool bSucc = (pMsg->uiSQLErrno == 0); delete(pMsg); if (!bSucc) { sys_err("[GOLD] Nu poate fi predat!(a aparut o eroare)"); } else { LogManager::instance().GoldBarsLog(GetAID(), GetPlayerID(), dwVnum, dlCount); ChatPacket(CHAT_TYPE_INFO,"<SYSTEM> You received [%d] Yang",dlCount); } return bSucc; } Link to comment Share on other sites More sharing options...
Developer Ikarus_ 2426 Posted February 11, 2018 Developer Share Posted February 11, 2018 no you don't have to do this..... take up my method... You just have to replace the ChangeGold with the method used in your code to give the yang.... you don't have to go to replace the information in the database, this would not be able to a real change in game because the information is already into game cache.... understand? Possible methods that are used in your code to give yang: ChangeMoney SetGold If the method is SetGold, you need to replace in my method "ChangeGold (dlCount)" with "SetGold (GetGold () + dlCount)" My youtube channel on which you can see my works here Link to comment Share on other sites More sharing options...
revengertmt 50 Posted March 3, 2018 Author Share Posted March 3, 2018 How i can combine this 2 sys???? switch (item->GetVnum()) { case 80003: case 80004: case 80005: case 80006: case 80007: { static const int sGold[5] = { 50000, ///< 80003 100000, ///< 80004 500000, ///< 80005 1000000, ///< 80006 2000000 ///< 80007 }; if (IsOpenSafebox() || GetExchange() || GetMyShop() || IsCubeOpen()) { ChatPacket(CHAT_TYPE_INFO, "Nu poti folosi lingouri in timp ce negociezi."); return false; } const int amount = sGold[item->GetVnum() - 80003]; if ((GOLD_MAX - amount) <= GetGold()) { ChatPacket(CHAT_TYPE_INFO, "Nu poti detine mai mult de 2kkk Yang."); return false; } item->SetCount(item->GetCount() - 1); PointChange(POINT_GOLD, amount, true); } break; default: break; } Link to comment Share on other sites More sharing options...
revengertmt 50 Posted March 4, 2018 Author Share Posted March 4, 2018 up! Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now