04-13-2021, 02:22 PM
Simple but working:
DoFuncItem.cpp
First declare a new function which should look like this:
bool do_ItemUse_CashTicket(CPC* ch, const CItemProto* itemproto);
You can just paste it around line ~40 you will see some other functions, just add it under them.
Now we are doing the function (what should happen if the function is called in the code)
For me, it looks like this:
bool do_ItemUse_CashTicket(CPC* ch, const CItemProto* itemproto)
{
mysqldb::connectInfo auth_db_info;
auth_db_info.host_ = gserver->m_config.Find("Auth DB", "IP");
auth_db_info.port_ = 0;
auth_db_info.user_ = gserver->m_config.Find("Auth DB", "User");
auth_db_info.pw_ = gserver->m_config.Find("Auth DB", "Password");
auth_db_info.dbname_ = gserver->m_config.Find("Auth DB", "DBName");
auth_db_info.charsetname_ = "";
mysqldb auth_db_;
auth_db_.connect(auth_db_info);
CLCString TicketQuery(1024);
CDBCmd DBTicket;
DBTicket.Init(auth_db_.getMYSQL());
int userIndex = ch->m_desc->m_index;
TicketQuery.Format("UPDATE bg_user SET cash = cash + 100 WHERE user_code = %d", userIndex);
DBTicket.SetQuery(TicketQuery);
if (!DBTicket.Update())
{
LOG_INFO("CashTicket[100] Failed at USER_INDEX[%d]", userIndex);
return false;
}
LOG_INFO("CashTicket[100] Success at USER_INDEX[%d]", userIndex);
return true;
}
Its simple, but it works fine. You can change the Cash value by changing the TicketQuery "UPDATE bg_user SET cash = cash + 100 WHERE user_code = %d" +100 is the Cash Amount which gets added to the Player and don't forget to add the needed Database information to the newstobm file from GameServer. It requires access to the Auth Database.
If you have done this steps we just need to add the function call which should be an Item after using. We will go around line 7667 which is inside this function for me
bool do_ItemUse_IONCE_ETC(CPC* ch, const CItemProto* itemproto, int nExtar1, CItem* item)
Just add another case like this
case 11111: // Cash Ticket
return do_ItemUse_CashTicket(ch, itemproto);
break;
case 11111 is the ID from the Item which should be your Cash Ticket you can just change it to any Item ID you want (the item need to be type 2 and subtype 9) you can just copy the "Medal of the Mercenary" ID: 10266 and it should work.

