Advertisement
Rochet2

Roulette - Example

Aug 5th, 2012
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.63 KB | None | 0 0
  1. /* Gamble npc V1.0
  2. Created By yvoms for lostarmywow
  3. V1.0
  4.  
  5. To do's:
  6. Make the Actual Gamble thing,
  7. Make it so they can enter their custom amount and 50% chanse on winning the double,
  8. Checking if they have the Amount they want to gamble with,
  9. Make a how does the game work gossip, with the textID from the database, SQL will be included.
  10. */
  11.  
  12. #define SOULS 60000
  13. #define UNHOLY_BADGE 29424
  14. #define DAEMON_HEAD 60005
  15.  
  16. class gamble_npc : public CreatureScript
  17. {
  18. public:
  19.     gamble_npc() : CreatureScript("gamble_npc") { }
  20.  
  21.     bool OnGossipHello(Player * player, Creature * creature)
  22.     {
  23.         // Note how the uiActions are the item IDs
  24.         player->ADD_GOSSIP_ITEM_EXTENDED(3, "I want to play with Souls!", GOSSIP_SENDER_MAIN, SOULS, "Insert amount of souls", 0, true);
  25.         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);
  26.         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);
  27.         player->ADD_GOSSIP_ITEM(3, "How does this Game work?", GOSSIP_SENDER_MAIN, 0);
  28.         // player->ADD_GOSSIP_ITEM(1, "Nevermind", GOSSIP_SENDER_MAIN, 1000); // Nevermind buttons are usually used when there is only one option in the menu, since if there is only one button, it is automatically clicked.
  29.         player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, creature->GetGUID());
  30.         return true;
  31.     }
  32.  
  33.     bool OnGossipSelect(Player * player, Creature * creature, uint32 sender, uint32 uiAction) // happens when a normal gossip item is selected
  34.     {
  35.         player->PlayerTalkClass->ClearMenus();
  36.  
  37.         if(uiAction == 0)
  38.         {
  39.             // Check this later on
  40.             player->ADD_GOSSIP_ITEM(7, "Back..", GOSSIP_SENDER_MAIN, 1);
  41.             player->SEND_GOSSIP_MENU(123432, creature->GetGUID());
  42.         }
  43.         else if(uiAction == 1)
  44.         {  
  45.             OnGossipHello(player, creature);
  46.         }
  47.         else if(uiAction == 2)
  48.         {
  49.             player->CLOSE_GOSSIP_MENU();
  50.         }
  51.         return true;
  52.     }
  53.  
  54.     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.
  55.     {
  56.         player->PlayerTalkClass->ClearMenus();
  57.  
  58.         // uiAction is the item ID
  59.         uint32 amount = 0;
  60.         amount = uint32(atol(code)); // atol tries to convert code (the inserted thing) into a number.
  61.  
  62.         if(amount < 1 || !player->HasItemCount(uiAction, amount, false)) // && means and, || means or
  63.         {
  64.             player->GetSession()->SendNotification("Invalid amount inserted");
  65.         }
  66.         else
  67.         {
  68.             if(urand(1,2) == 1) // pic a random number between 1 and 2 (50 % chance to get 1)
  69.             {
  70.                 // won, add items
  71.                 // adding items is a bit more complicated than destroying them .. the player might not have enough space in bags etc.
  72.                 GiveItemAmount(player, uiAction, amount);
  73.             }
  74.             else
  75.             {
  76.                 // lost, delete items
  77.                 player->DestroyItemCount(uiAction, amount, true);
  78.             }
  79.         }
  80.         OnGossipSelect(player, creature, sender, 0); // Go to uiAction 0, aka show the selection menu again
  81.         return true;
  82.     }
  83.  
  84.     // 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
  85.     // 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.
  86.     bool GiveItemAmount(Player * player, uint32 itemEntry, uint32 amount)
  87.     {
  88.         if (amount < 0)
  89.         {
  90.             player->DestroyItemCount(itemEntry, -amount, true, false);
  91.             return true;
  92.         }
  93.         if (amount == 0)
  94.             amount = 1;
  95.  
  96.         uint32 noSpaceForCount = 0;
  97.  
  98.         ItemPosCountVec dest;
  99.         uint8 msg = player->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, itemEntry, amount, &noSpaceForCount);
  100.  
  101.         if (msg != EQUIP_ERR_OK)
  102.             amount -= noSpaceForCount;
  103.  
  104.         if (amount == 0 || dest.empty())
  105.             return false;
  106.  
  107.         Item* item = player->StoreNewItem(dest, itemEntry, true, Item::GenerateItemRandomPropertyId(itemEntry));
  108.         return true;
  109.     }
  110. };
  111.  
  112. void AddSC_gamble_npc()
  113. {
  114.     new gamble_npc();
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement