Jump to content

Crash at Items Rewards


Guest asdy

Recommended Posts

I have this script but I want to do for 2.4.3

#include "precompiled.h"
#include "../../../../shared/Config/Config.h"
#include "../../Config.h"
#include "../../../../game/Language.h"
#include "../../../../shared/Database/DatabaseMysql.h" //Wasn't entirely sure if I needed this one so added it just in case
extern DatabaseMysql SD2Database;

bool GossipHello_VoteVendorNPC(Player *player, Creature *_Creature)
{
   Config SD2Config;
   if(!SD2Config.SetSource(_SCRIPTDEV2_CONFIG,true)) //Check if scriptdev2.conf exists
   {
       error_log("SD2: Unable to open configuration file");
   }

   if(SD2Config.GetBoolDefault("VoteVendorNPC.OnlyGMs", false)) // If VoteVendor.OnlyGMs is enabled in scriptdev2.conf
   {
       if(player->GetSession()->GetSecurity() == SEC_PLAYER)
       {
           _Creature->MonsterWhisper("Sorry, I'm only availible to Game Masters.", player->GetGUID());
           return true;
       }
   }

   //Some examples of what can be done:
   player->ADD_GOSSIP_ITEM( 5, "Trade Vote Points for Vote Coins"                    , GOSSIP_SENDER_MAIN, 1000);
   player->ADD_GOSSIP_ITEM( 5, "10 Gold - 20 Vote Coins"                            , GOSSIP_SENDER_MAIN, 2000);
   if(player->getLevel() < 80) //We don't want players to level above 80 
   {
       player->ADD_GOSSIP_ITEM( 5, "1 Level up - 40 Vote Coins"                    , GOSSIP_SENDER_MAIN, 3000);
   }
   player->ADD_GOSSIP_ITEM( 5, "36 Slot bag - 25 Vote Coins"                        , GOSSIP_SENDER_MAIN, 4000);
   player->ADD_GOSSIP_ITEM( 7, "1 item [call GM before paying!] - 60 Vote Coins"    , GOSSIP_SENDER_MAIN, 5000);

   player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE,_Creature->GetGUID());

   return true;
}

void SendDefaultMenu_VoteVendorNPC(Player *player, Creature *_Creature, uint32 action)
{
   QueryResult *result;
   //This query is just an example. I suggest using the account table in the realmd database to store the users
   //vote points. It makes it easier to get the account that belongs to the user ingame.
   result = SD2Database.PQuery("SELECT votepoints FROM realmd.account WHERE id = '%u'", player->GetSession()->GetAccountId());
   Field *Fields = result->Fetch();
   Item* item;
   ItemPosCountVec dest;
   uint32 noSpaceForCount = 0;
   uint32 itemId = 0; //Change 0 to whichever item id your Vote Coins have (do this everywhere in the script where it says //change 0)
   int32 count = Fields[0].GetUInt32(); //Get x Vote Points from database
   uint8 msg = player->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, itemId, count, &noSpaceForCount );

   //When we're going to use multiple item rewards, so we need more variables etc etc
   ItemPosCountVec dest2;
   uint32 itemId2 = 23162;
   int32 count2 = 1;
   uint8 msg2 = player->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest2, itemId2, count2, &noSpaceForCount );

   // Disable npc if in combat
   if(!player->getAttackers().empty())
   {
       player->CLOSE_GOSSIP_MENU();
       _Creature->MonsterSay("You are in combat!", LANG_UNIVERSAL, NULL);
       return;
   }

   switch(action)
   {
       case 6000: //Back to Main Menu
           player->ADD_GOSSIP_ITEM( 5, "Trade Vote Points for Vote Coins"                    , GOSSIP_SENDER_MAIN, 1000);
           player->ADD_GOSSIP_ITEM( 5, "10 Gold - 20 Vote Coins"                            , GOSSIP_SENDER_MAIN, 2000);
           if(player->getLevel() < 80) //We don't want players to level above 80 
           {
               player->ADD_GOSSIP_ITEM( 5, "1 Level up - 40 Vote Coins"                    , GOSSIP_SENDER_MAIN, 3000);
           }
           player->ADD_GOSSIP_ITEM( 5, "36 Slot bag - 25 Vote Coins"                        , GOSSIP_SENDER_MAIN, 4000);
           player->ADD_GOSSIP_ITEM( 7, "1 item [call GM before paying!] - 60 Vote Coins"    , GOSSIP_SENDER_MAIN, 5000);

           player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE,_Creature->GetGUID());
       break;

       case 1000: //Trade Vote Points for Vote Coins
           if(result)
           {
               if( msg2 != EQUIP_ERR_OK ) // convert to possible store amount
                   count2 -= noSpaceForCount;

               if( count2 == 0 || dest.empty()) // If the player doesn't have any vote points
               {
                   player->CLOSE_GOSSIP_MENU();
                   _Creature->MonsterSay("You don't have any vote points!", LANG_UNIVERSAL, NULL);
               }

               item = player->StoreNewItem( dest, itemId, true, Item::GenerateItemRandomPropertyId(itemId));

               if (count2 > 0 && item)
               {
                   player->CLOSE_GOSSIP_MENU();
                   player->SendNewItem(item,count,false,true);
                   //Ofcorse we reset the players Vote Points to 0 in database
                   SD2Database.PExecute("UPDATE realmd.account SET vote_points = '0' WHERE id = '%u'", player->GetSession()->GetAccountId());
                   _Creature->MonsterWhisper("Vote Points reset to 0", player->GetGUID());
               }

               if(noSpaceForCount > 0)
               {
                   player->CLOSE_GOSSIP_MENU();
                   _Creature->MonsterWhisper("Unable to create item", player->GetGUID());
               }
           }
           else //Just in case something went wrong with the first query
           {
               player->CLOSE_GOSSIP_MENU();
               _Creature->MonsterSay("Error: Problem with database data. Please inform a GM about this error.", LANG_UNIVERSAL, NULL);
           }
       break;

       case 2000: //10 Gold - 20 Vote Coins
           if(player->HasItemCount(0, 20)) //change 0
           {
               player->CLOSE_GOSSIP_MENU();
               player->DestroyItemCount(0, 20, true); //change 0
               player->ModifyMoney(100000);
               _Creature->MonsterWhisper("You received 10 Gold", player->GetGUID());
           }
           else
           {
               player->CLOSE_GOSSIP_MENU();
               _Creature->MonsterSay("You don't have enough Vote Coins to purchase that reward!", LANG_UNIVERSAL, NULL);
           }
       break;

       case 3000: //1 Level up - 40 Vote Coins
           if(player->HasItemCount(0, 40)) //change 0
           {
               player->CLOSE_GOSSIP_MENU();
               player->DestroyItemCount(0, 40, true); //change 0
               //Some might question about this one, but it is correct. If you do
               //player->GiveLevel(1);
               //it will reset the players level to 1 instead of adding one
               player->GiveLevel(player->getLevel() + 1);
               _Creature->MonsterWhisper("You received 1 level up", player->GetGUID());
           }
           else
           {
               player->CLOSE_GOSSIP_MENU();
               _Creature->MonsterSay("You don't have enough Vote Coins to purchase that reward!", LANG_UNIVERSAL, NULL);
           }
       break;

       case 4000: //36 Slot bag - 25 Vote Coins
           if(player->HasItemCount(0, 25)) //change 0
           {
               if( msg != EQUIP_ERR_OK ) // convert to possible store amount
                   count2 -= noSpaceForCount;

               if( count2 == 0 || dest.empty()) // If count2 is set 0 for some reason
               {
                   player->CLOSE_GOSSIP_MENU();
                   _Creature->MonsterWhisper("Error: Item count set to 0. Please inform a GM about this error.", player->GetGUID());
               }

               item = player->StoreNewItem( dest2, itemId2, true, Item::GenerateItemRandomPropertyId(itemId2));

               if(count2 > 0 && item)
               {
                   player->CLOSE_GOSSIP_MENU();
                   player->SendNewItem(item,count2,false,true);
                   player->DestroyItemCount(0, 25, true); //change 0
               }

               if(noSpaceForCount > 0)
               {
                   player->CLOSE_GOSSIP_MENU();
                   _Creature->MonsterWhisper("Unable to create item", player->GetGUID());
               }
           }
           else
           {
               player->CLOSE_GOSSIP_MENU();
               _Creature->MonsterSay("You don't have enough Vote Coins to purchase that reward!", LANG_UNIVERSAL, NULL);
           }
       break;

       case 5000: //1 item [call GM before paying!] - 60 Vote Coins
           //An extra little gossip menu for players who click before reading
           //It's impossible to predict which item a player wants to have if you allow them to make their own
           //choice. So in this case a player pays the Coins and the npc says the player has paid for it so the
           //GM can give the item.
           player->ADD_GOSSIP_ITEM( 5, "A GM is with me, pay now"                        , GOSSIP_SENDER_MAIN, 5001);
           player->ADD_GOSSIP_ITEM( 5, "There is no GM with me, return to Main menu"    , GOSSIP_SENDER_MAIN, 6000);
           player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE,_Creature->GetGUID());
       break;

       case 5001:
           if(player->HasItemCount(60004, 60))
           {
               player->CLOSE_GOSSIP_MENU();
               player->DestroyItemCount(60004, 60, true);
               _Creature->MonsterSay("I just received 60 Vote Coins for a Green or Blue item", LANG_UNIVERSAL, NULL);
           }
           else
           {
               player->CLOSE_GOSSIP_MENU();
               _Creature->MonsterSay("You don't have enough Vote Coins to purchase that reward!", LANG_UNIVERSAL, NULL);
           }
       break;
   } //End switch
} //End function

bool GossipSelect_VoteVendorNPC(Player *player, Creature *_Creature, uint32 sender, uint32 action)
{
   // Main menu
   if (sender == GOSSIP_SENDER_MAIN)
   SendDefaultMenu_VoteVendorNPC( player, _Creature, action );

return true;
}

void AddSC_votevendornpc()
{
Script *newscript;

   newscript = new Script;
   newscript->Name = "votevendornpc";
   newscript->pGossipHello = &GossipHello_VoteVendorNPC;
   newscript->pGossipSelect = &GossipSelect_VoteVendorNPC;

m_scripts[nrscripts++] = newscript;
}

I tried to change to make but when compiled vendor and I want to see him give me the menu that appears 5 seconds and then give the Crash mangosd.

I saw a server that Boss had a few drop in an item eg 'Mangos Rune" is like "Badge of Justice" I want to be like that and make trade for "Mangos Token" when I go mangos rune 3 the vendor and give the trade for mangos token and gives me mangos token 1 and at 15-20 mangos token and I can get a bag, etc. or 2 token I take 1 level or 1000 ... honor,arena points etc..

Link to comment
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use