Advertisement
yvoms

Gamble npc

Feb 25th, 2013
693
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.08 KB | None | 0 0
  1. /* Gamble npc V1.4
  2. Created By yvoms, Old script not updated,
  3. Just edit the defines and the Item_extended("i want to play with xxxxx" <- The xxxxx to the itemname
  4.  
  5. */
  6.  
  7. #define SOULS 60000
  8. #define UNHOLY_BADGE 29424
  9. #define DAEMON_HEAD 60005
  10.  
  11. class gamble_npc : public CreatureScript
  12. {
  13. public:
  14.     gamble_npc() : CreatureScript("gamble_npc") { }
  15.  
  16.     bool OnGossipHello(Player * player, Creature * creature)
  17.     {
  18.  
  19.         player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to play with Souls!", GOSSIP_SENDER_MAIN, SOULS, "Insert amount of souls", 0, true);
  20.         player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to play with Deamon Heads", GOSSIP_SENDER_MAIN, DAEMON_HEAD, "Insert amount of Deamon Heads", 0, true);
  21.         player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to play with Unholy Badges!", GOSSIP_SENDER_MAIN, UNHOLY_BADGE, "Insert amount of Unholy Badges", 0, true);
  22.         player->ADD_GOSSIP_ITEM(3, "How does this Game work?", GOSSIP_SENDER_MAIN, 0);
  23.  
  24.         player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, creature->GetGUID());
  25.         return true;
  26.     }
  27.  
  28.     bool OnGossipSelect(Player * player, Creature * creature, uint32 sender, uint32 uiAction)
  29.     {
  30.         player->PlayerTalkClass->ClearMenus();
  31.  
  32.         if(uiAction == 0)
  33.         {
  34.             // Check this later on
  35.             player->ADD_GOSSIP_ITEM(7, "Back..", GOSSIP_SENDER_MAIN, 1);
  36.             player->SEND_GOSSIP_MENU(123432, creature->GetGUID());
  37.         }
  38.         else if(uiAction == 1)
  39.         {  
  40.             OnGossipHello(player, creature);
  41.         }
  42.         else if(uiAction == 2)
  43.         {
  44.             player->CLOSE_GOSSIP_MENU();
  45.         }
  46.         return true;
  47.     }
  48.  
  49.     bool OnGossipSelectCode(Player* player, Creature* creature, uint32 sender, uint32 uiAction, const char* code) // happens when an extended gossip item is selected and the code is set to true for the gossip item.
  50.     {
  51.         player->PlayerTalkClass->ClearMenus();
  52.  
  53.         // uiAction is the item ID
  54.         uint32 amount = 0;
  55.         amount = uint32(atol(code));
  56.  
  57.         if(amount < 1 || !player->HasItemCount(uiAction, amount, false)) // && means and, || means or
  58.         {
  59.             player->GetSession()->SendNotification("Invalid amount inserted");
  60.         }
  61.         else
  62.         {
  63.             if(urand(1,2) == 1) // pic a random number between 1 and 2 (50 % chance to get 1)
  64.             {
  65.                 // won, add items
  66.                 // adding items is a bit more complicated than destroying them .. the player might not have enough space in bags etc.
  67.                 GiveItemAmount(player, uiAction, amount);
  68.             }
  69.             else
  70.             {
  71.                 // lost, delete items
  72.                 player->DestroyItemCount(uiAction, amount, true);
  73.             }
  74.         }
  75.         OnGossipSelect(player, creature, sender, 0); // Go to uiAction 0, aka show the selection menu again
  76.         return true;
  77.     }
  78.  
  79.     // You CAN ignore this whole thing for now .. all you need to know is that it adds the item to the player if he has space and returns true, if not enough space it returns false and doesnt add anything
  80.     // this function is pretty much like .additem command. Existing code is very useful .. Whenever I try to do something, I try to remember if there is a command for it and look at it's code.
  81.     bool GiveItemAmount(Player * player, uint32 itemEntry, uint32 amount)
  82.     {
  83.         if (amount < 0)
  84.         {
  85.             player->DestroyItemCount(itemEntry, -amount, true, false);
  86.             return true;
  87.         }
  88.         if (amount == 0)
  89.             amount = 1;
  90.  
  91.         uint32 noSpaceForCount = 0;
  92.  
  93.         ItemPosCountVec dest;
  94.         uint8 msg = player->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, itemEntry, amount, &noSpaceForCount);
  95.  
  96.         if (msg != EQUIP_ERR_OK)
  97.             amount -= noSpaceForCount;
  98.  
  99.         if (amount == 0 || dest.empty())
  100.             return false;
  101.  
  102.         Item* item = player->StoreNewItem(dest, itemEntry, true, Item::GenerateItemRandomPropertyId(itemEntry));
  103.         return true;
  104.     }
  105. };
  106.  
  107. void AddSC_gamble_npc()
  108. {
  109.     new gamble_npc();
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement