Advertisement
Guest User

EmuDevs - Gambler NPC [3.3.5a]

a guest
May 14th, 2013
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.91 KB | None | 0 0
  1. /*
  2.  *╔═╦═╦═╦╦╦══╦═╦╗─╔╦══╗
  3.  *║╦╣║║║║║╠╗╗║╦╣╚╦╝║══╣
  4.  *║╩╣║║║║║╠╩╝║╩╬╗║╔╬══║
  5.  *╚═╩╩═╩╩═╩══╩═╝╚═╝╚══╝
  6.  *            www.emudevs.com
  7. */
  8. enum GoldVals
  9. {
  10.     GOLD_ONE = 10000,
  11.     GOLD_THREE = 30000,
  12.     GOLD_FIVE = 50000,
  13.     GOLD_TEN = 100000,
  14. };
  15.  
  16. class npc_gamble : public CreatureScript
  17. {
  18. public:
  19.     npc_gamble() : CreatureScript("npc_gamble") { }
  20.  
  21.     bool OnGossipHello(Player* player, Creature* creature)
  22.     {
  23.         if (player->GetMoney() < GOLD_ONE)
  24.         {
  25.             player->GetSession()->SendNotification("You don't have enough gold!");
  26.             return false;
  27.         }
  28.  
  29.         player->ADD_GOSSIP_ITEM(GOSSIP_ICON_VENDOR, "I would like to gamble gold [1g]", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+1);
  30.         player->ADD_GOSSIP_ITEM(GOSSIP_ICON_DOT, "Nevermind", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+2);
  31.         return true;
  32.     }
  33.  
  34.     bool OnGossipSelect(Player* player, Creature* creature, uint32 /*sender*/, uint32 actions)
  35.     {
  36.         player->PlayerTalkClass->ClearMenus();
  37.  
  38.         if (actions == GOSSIP_ACTION_INFO_DEF+1)
  39.         {
  40.             player->ModifyMoney(-GOLD_ONE);
  41.  
  42.             int32 moneyValue = 0;
  43.             bool wonOrLost = false;
  44.  
  45.             switch(rand()%5)
  46.             {
  47.                 case 0:
  48.                     moneyValue = GOLD_ONE;
  49.                     wonOrLost = false;
  50.                     break;
  51.                 case 1:
  52.                     moneyValue = GOLD_THREE;
  53.                     wonOrLost = false;
  54.                     break;
  55.                 case 2:
  56.                     moneyValue = GOLD_TEN;
  57.                     wonOrLost = true;
  58.                     break;
  59.                 case 3:
  60.                     moneyValue = GOLD_FIVE;
  61.                     wonOrLost = false;
  62.                     break;
  63.                 case 4:
  64.                     moneyValue = GOLD_ONE;
  65.                     wonOrLost = true;
  66.                     break;
  67.             }
  68.  
  69.             if (wonOrLost)
  70.             {
  71.                 player->ModifyMoney(moneyValue);
  72.                 ChatHandler(player->GetSession()).PSendSysMessage("You won!");
  73.             }
  74.             else
  75.             {
  76.                 if (player->HasEnoughMoney(moneyValue))
  77.                 {
  78.                     player->ModifyMoney(-moneyValue);
  79.                     ChatHandler(player->GetSession()).PSendSysMessage("You lost %i gold!", moneyValue);
  80.                 }
  81.                 else
  82.                     ChatHandler(player->GetSession()).PSendSysMessage("You lost, but you don't have enough money to lose!");
  83.             }
  84.             player->CLOSE_GOSSIP_MENU();
  85.         }
  86.         else
  87.             player->CLOSE_GOSSIP_MENU();
  88.         return true;
  89.     }
  90. };
  91.  
  92. void AddSC_on_gamble()
  93. {
  94.     new npc_gamble;
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement