Jump to content

Mini-Release Coins en c++


Johan™

Recommended Posts

:v
PD: antes de comenzar quiero aclarar que la parte del SQLMsg *msg; - msg = xxx la saque de elitepvpers. D: yo solo realize algunos cambios e.e.
Abrimos char.cpp y al final ponemos:

int 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("pc_update_coins query failed");
		return false;
	}
	return true;
}

Ahora nos vamos a char.h y abajo de bool ItemProcess_Polymorph(LPITEM item);

pegamos esto.

public:
		int	SetCoins(long coins = 0);

Debe quedar asi D:

03b9e98ef250331cd873e5414ea344f2.png

Ahora abrimos char_item.cpp y buscamos switch (item->GetType()) arriba de eso pegamos lo sigiente e.e

switch (item->GetVnum())
	{
		//Coins.
		case 80014:
		case 80015:
		case 80016:
		case 80017:
			int idx[4];
			idx[0] = 100;
			idx[1] = 500;
			idx[2] = 1000;
			idx[3] = 50;
			int idxs;
			if (item->GetVnum() == 80014)
				idxs = 0;
			if (item->GetVnum() == 80015)
				idxs = 1;
			if (item->GetVnum() == 80016)
				idxs = 2;
			if (item->GetVnum() == 80017)
				idxs = 3;
			long val;
			val = idx[idxs];
			if (SetCoins(val))
			{
				ChatPacket(CHAT_TYPE_INFO, "Has cargado %ld coins a tu cuenta.",val);
				item->SetCount(item->GetCount() - 1);
			}
			else
			{
				ChatPacket(CHAT_TYPE_INFO, "Ha ocurrido un error al intentar cambiar tus coins, contacta con el administrador.");
			}
			return 1;
			break;
		default:
			break;
	}

D: tambien pueden usar esta funciona para los lua

solo usen el SetCoins(cantidad e.e)

2b6cd3d39c38fc01aad06837f1871e9f.png

Link to comment
Share on other sites

Una anotación, no pegar esto

public:
        int    SetCoins(long coins = 0);

Debería quedar así: 

public:
        bool ItemProcess_Polymorph(LPITEM item);
        int    SetCoins(long coins = 0);

La razón es que dentro del bloque public: se definen todas las funciones de acceso publico y no hay necesidad de abrir varios bloques.

Link to comment
Share on other sites

Una anotación, no pegar esto

public:
        int    SetCoins(long coins = 0);

Debería quedar así: 

public:
        bool ItemProcess_Polymorph(LPITEM item);
        int    SetCoins(long coins = 0);

La razón es que dentro del bloque public: se definen todas las funciones de acceso publico y no hay necesidad de abrir varios bloques.

asi lo puse yo :v queria mantener el orden los feos deymir tienen varios public :v por categorias :3, solo queria ser popular e.e

Link to comment
Share on other sites

  • 1 year later...

Thanks xD

Small shit from long time ago if someone want: ( sorry for shit code, is from 2014 on my server)

/* 
Ex function call with :
* ExternAppendCoins(this, item);
* ExternAppendCoins(ch, item);
*/
bool ExternAppendCoins(LPCHARACTER ch, LPITEM item)
{	
	#define MYSQL_MAX_COINS 5000
	const int mListVouchers[] = {
		80014,
		80015,
		80016,
		80017
	};
	for (int idx = 0; idx < _countof(mListVouchers); idx++)
	{
		if (item->GetVnum() == mListVouchers[idx] && ch->CountSpecifyItem(mListVouchers[idx]) > 0)
		{	
			if (ch->GetExchange() || ch->IsOpenSafebox() || ch->IsCubeOpen() || ch->GetShop() || ch->GetMyShop())
			{	
				ch->ChatPacket(CHAT_TYPE_INFO, "Have a malicious window open, please close it then you can do this.");
				return false;
			}

			int amount = item->GetValue(0);
			
			if (!ch->CanWarp())

				ch->ChatPacket(CHAT_TYPE_INFO, "You need to wait 10 second.");
				return false; 
			}
					
			if (amount <= 0)
			{
				ch->ChatPacket(CHAT_TYPE_INFO, "Not found value in mysql row value."); /* Put value on player.item_proto->vnum->value0*/
				return false;	
			}
				
			if (amount >= MYSQL_MAX_COINS)
			{
				ch->ChatPacket(CHAT_TYPE_INFO, "Mysql = %d - Max allowed = %d.", amount, MYSQL_MAX_COINS);
				return false;
			}
				
			char buf[CHAT_MAX_LEN + 1];
			snprintf(buf, sizeof(buf), "UPDATE account.account SET coins = coins + %u WHERE id = %u", amount, ch->GetDesc()->GetAccountTable().id));
			std::auto_ptr<SQLMsg> update(DBManager::instance().DirectQuery(buf));
			ch->RemoveSpecifyItem(mListVouchers[idx], 1);
		}
	}
}
Link to comment
Share on other sites

  • 3 months later...

The function to set coins already did by Ymir dudes.

 

Yeah but not all people was used because name of row is called: "cash" and they are used on website/itemshop etc row "coins", but can change in 1 second but they are so bored xD

Here is a small function what used packet of ymir.

//@ svn/Server/game/src/char.cpp
//1.) Search for:
LPITEM CHARACTER::GetInventoryItem(WORD wCell) const
{
	return GetItem(TItemPos(INVENTORY, wCell));
}
//2.) Add after:
#ifdef ENABLE_TICKET_COINS
/*
	* IF YOU HAVE TYPE QUEST ON ITEM JUST RUN THIS QUERY:
	* UPDATE player.item_proto set type = 3 WHERE 80014 <= vnum and vnum <= 80017;
*/
void CHARACTER::InsertCoins(LPITEM item)
{
	typedef std::map<DWORD,DWORD> TMapTicketValues;
	TMapTicketValues cash;
	
	cash[80014] = 100;
	cash[80015] = 500;
	cash[80016] = 1000;
	cash[80017] = 5000;

	DWORD dwVnum = item->GetVnum();
	itertype(cash) iterator = cash.find(dwVnum);

	if (iterator != cash.end())
	{
		TRequestChargeCash p;
		p.dwAID = GetDesc()->GetAccountTable().id;
		p.dwAmount = cash[dwVnum];
		p.eChargeType = ERequestCharge_Cash;
		db_clientdesc->DBPacketHeader(HEADER_GD_REQUEST_CHARGE_CASH, 0, sizeof(TRequestChargeCash));
		db_clientdesc->Packet(&p, sizeof(p));

		RemoveSpecifyItem(dwVnum, 1);
		LogManager::instance().CharLog(this, cash[dwVnum], "USE_TICKET_COINS", "");
		
		if (test_server)
			ChatPacket(CHAT_TYPE_NOTICE, "CHARACTER::InsertCoins: vnum %d | cash %d", dwVnum, cash[dwVnum]);
	}
}
#endif

//1.) Search for:
	sys_log(0, "%s: USE_ITEM %s (inven %d, cell: %d)", GetName(), item->GetName(), window_type, wCell);
//2.) Add after:
#ifdef ENABLE_TICKET_COINS
	InsertCoins(item);
#endif

//@ svn/Server/game/src/char.h
//1.) Search for:
		const char *	GetName() const;
//2.) Add after:
#ifdef ENABLE_TICKET_COINS
		void			InsertCoins(LPITEM item);
#endif

//@ svn/Server/common/service.h
#define ENABLE_TICKET_COINS
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...