Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "ScriptMgr.h"
- const char* DBInfo[] =
- {"127.0.0.1", "account", "passwd", "Webwow"};
- #define PORT 3306
- #define REWARD 25 // reward item
- class example_votepoint_gossip : public CreatureScript
- {
- public:
- example_votepoint_gossip() : CreatureScript("example_votepoint_gossip") { }
- bool OnGossipHello(Player* player, Creature* creature)
- {
- player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, "Claim vote points", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+1);
- player->ADD_GOSSIP_ITEM(GOSSIP_ICON_TALK, "Nevermind", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+2);
- player->PlayerTalkClass->SendGossipMenu(DEFAULT_GOSSIP_MESSAGE, creature->GetGUID());
- return true;
- }
- bool OnGossipSelect(Player* player, Creature* creature, uint32 sender, uint32 action)
- {
- player->PlayerTalkClass->ClearMenus();
- switch(action)
- {
- case GOSSIP_ACTION_INFO_DEF+1:
- {
- uint32 votePoints = GetVotePoints(player->GetSession()->GetAccountId());
- if(votePoints < 1) // vote point amount smaller than 1, send error
- player->GetSession()->SendNotification("Not enough vote points");
- else if(player->AddItem(REWARD, votePoints))
- {
- ResetVotePoints(player->GetSession()->GetAccountId());
- player->GetSession()->SendAreaTriggerMessage("Vote claimed succesfully");
- }
- else
- player->GetSession()->SendNotification("Not enough space for reward");
- OnGossipHello(player, creature);
- } break;
- case GOSSIP_ACTION_INFO_DEF+2: player->CLOSE_GOSSIP_MENU(); break;
- }
- return true;
- }
- private:
- void ResetVotePoints(uint32 accountID)
- {
- MYSQL *conn;
- char sql[256];
- snprintf(sql, 256, "UPDATE Account_more SET vp = 0 WHERE account = %u", accountID);
- conn = mysql_init(NULL);
- mysql_real_connect(conn, DBInfo[0], DBInfo[1], DBInfo[2], DBInfo[3], PORT, NULL, 0);
- mysql_query(conn, sql);
- mysql_close(conn);
- }
- uint32 GetVotePoints(uint32 accountID)
- {
- MYSQL *conn;
- MYSQL_RES *result1;
- MYSQL_FIELD *field;
- uint64 rowCount;
- uint32 fieldCount;
- char sql[256];
- snprintf(sql, 256, "SELECT vp FROM Account_more WHERE account = %u", accountID);
- conn = mysql_init(NULL);
- mysql_real_connect(conn, DBInfo[0], DBInfo[1], DBInfo[2], DBInfo[3], PORT, NULL, 0);
- if(!conn)
- return 0;
- mysql_query(conn, sql);
- result1 = mysql_store_result(conn);
- rowCount = mysql_affected_rows(conn);
- fieldCount = mysql_field_count(conn);
- mysql_close(conn);
- if (!result1)
- return 0;
- if (!rowCount)
- {
- mysql_free_result(result1);
- return 0;
- }
- field = mysql_fetch_fields(result1);
- ResultSet* result2 = new ResultSet(result1, field, rowCount, fieldCount);
- if(!result2)
- return 0;
- if(!result2->NextRow())
- return 0;
- return result2->Fetch()[0].GetUInt32(); // return mysql_fetch_row(result)[0];
- }
- };
- void AddSC_example_votepoint_gossip()
- {
- new example_votepoint_gossip();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement