SHOW:
|
|
- or go back to the newest paste.
1 | /* C++ Roulette for Trinity Core | |
2 | - | Made by Crumpets |
2 | + | Made by Crumpets |
3 | - | Idea and LUA version by Crash45 |
3 | + | Idea and LUA version by Crash45 |
4 | - | Error checking and fixed up by Rochet2 */ |
4 | + | Error checking and fixed up by Rochet2*/ |
5 | - | |
5 | + | |
6 | - | |
6 | + | |
7 | class roulette_npc : public CreatureScript | |
8 | { | |
9 | public: | |
10 | - | roulette_npc() : CreatureScript("roulette_npc") { } |
10 | + | roulette_npc() : CreatureScript("roulette_npc") { } |
11 | ||
12 | - | bool OnGossipHello(Player * pPlayer, Creature * pCreature) |
12 | + | bool OnGossipHello(Player * pPlayer, Creature * pCreature) |
13 | - | { |
13 | + | { |
14 | - | pPlayer->ADD_GOSSIP_ITEM(3, "I would like to play", GOSSIP_SENDER_MAIN, 0); |
14 | + | pPlayer->ADD_GOSSIP_ITEM(3, "I would like to play", GOSSIP_SENDER_MAIN, 1); |
15 | - | pPlayer->ADD_GOSSIP_ITEM(1, "Nevermind", GOSSIP_SENDER_MAIN, 100); |
15 | + | pPlayer->ADD_GOSSIP_ITEM(1, "Nevermind", GOSSIP_SENDER_MAIN, 0); |
16 | - | |
16 | + | |
17 | - | pPlayer->PlayerTalkClass->SendGossipMenu(141, pCreature->GetGUID()); //This can be any menu you like :) |
17 | + | pPlayer->PlayerTalkClass->SendGossipMenu(141, pCreature->GetGUID()); //This can be any menu you like :) |
18 | - | return true; |
18 | + | return true; |
19 | - | } |
19 | + | } |
20 | - | |
20 | + | |
21 | - | |
21 | + | bool OnGossipSelect(Player * pPlayer, Creature * pCreature, uint32 sender, uint32 uiAction) |
22 | { | |
23 | - | |
23 | + | pPlayer->PlayerTalkClass->ClearMenus(); |
24 | - | bool TryToSellItem(Player *pPlayer, Creature * pCreature,unsigned int rewardID) |
24 | + | if(uiAction == 1) |
25 | - | |
25 | + | { |
26 | if (pPlayer->isInCombat()) | |
27 | - | pPlayer->CLOSE_GOSSIP_MENU(); |
27 | + | pPlayer->GetSession()->SendNotification("You are in Combat!"); |
28 | else | |
29 | - | uint32 noSpaceForCount = 0; |
29 | + | { |
30 | static std::map<uint32, time_t> PlrCooldowns; // static, so it will stay the same. If it is non static, the type will be auto by default, which means that the map will be destroyed after going out of the "else" statement. | |
31 | - | ItemPosCountVec dest; |
31 | + | if(difftime (time(NULL), PlrCooldowns[pPlayer->GetGUIDLow()]) <= 180) // needs to check if a record for our player exists before using it? |
32 | - | uint8 msg = pPlayer->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, rewardID, 1, &noSpaceForCount ); |
32 | + | |
33 | - | unsigned int count = 1; |
33 | + | switch (urand(1, 1)) |
34 | - | if( msg != EQUIP_ERR_OK ) |
34 | + | { |
35 | - | count -= noSpaceForCount; |
35 | + | case 1: |
36 | if (TryToSellItem(pPlayer, pCreature, 36942)) | |
37 | - | if( count == 0 || dest.empty()) |
37 | + | |
38 | PlrCooldowns[pPlayer->GetGUIDLow()] = time(NULL); | |
39 | - | ChatHandler(pPlayer).PSendSysMessage(LANG_ITEM_CANNOT_CREATE, rewardID, noSpaceForCount ); |
39 | + | pCreature->MonsterSay("This option is on test, But look in your bag!", LANG_UNIVERSAL, NULL); |
40 | - | return false; |
40 | + | |
41 | else | |
42 | - | Item* item = pPlayer->StoreNewItem( dest, rewardID, true, Item::GenerateItemRandomPropertyId(rewardID)); |
42 | + | |
43 | // bags were full, what to do? | |
44 | - | return true; |
44 | + | |
45 | break; | |
46 | } | |
47 | - | bool OnGossipSelect(Player * pPlayer, Creature * pCreature, uint32 sender, uint32 uiAction) |
47 | + | |
48 | - | { |
48 | + | } |
49 | - | |
49 | + | } |
50 | - | pPlayer->PlayerTalkClass->ClearMenus(); |
50 | + | pPlayer->CLOSE_GOSSIP_MENU(); |
51 | - | if(uiAction == 0) |
51 | + | return true; |
52 | - | { |
52 | + | } |
53 | - | std::map<uint32, time_t> PlrCooldowns; |
53 | + | |
54 | - | { |
54 | + | private: |
55 | - | if(difftime (time(NULL), PlrCooldowns[pPlayer->GetGUIDLow()]) <= 180) |
55 | + | bool TryToSellItem(Player* pPlayer, Creature* pCreature, uint32 rewardID) |
56 | - | { |
56 | + | { |
57 | - | if (pPlayer->isInCombat()) |
57 | + | uint32 noSpaceForCount = 0; |
58 | - | { |
58 | + | |
59 | - | pPlayer->GetSession()->SendNotification("You are in Combat!"); |
59 | + | ItemPosCountVec dest; |
60 | - | } |
60 | + | uint8 msg = pPlayer->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, rewardID, 1, &noSpaceForCount ); |
61 | - | else |
61 | + | unsigned int count = 1; |
62 | - | { |
62 | + | if (msg != EQUIP_ERR_OK) |
63 | - | switch (urand(1, 1)) |
63 | + | count -= noSpaceForCount; |
64 | - | { |
64 | + | |
65 | - | case 1: |
65 | + | if (count == 0 || dest.empty()) |
66 | - | PlrCooldowns[pPlayer->GetGUIDLow()] = time(NULL); |
66 | + | { |
67 | - | pCreature->MonsterSay("This option is on test, But look in your bag!", LANG_UNIVERSAL, NULL); |
67 | + | ChatHandler(pPlayer).PSendSysMessage(LANG_ITEM_CANNOT_CREATE, rewardID, noSpaceForCount ); |
68 | - | return TryToSellItem(pPlayer,pCreature, 36942); |
68 | + | return false; |
69 | - | break; |
69 | + | } |
70 | - | } |
70 | + | |
71 | - | } |
71 | + | Item* item = pPlayer->StoreNewItem( dest, rewardID, true, Item::GenerateItemRandomPropertyId(rewardID)); |
72 | - | OnGossipHello(pPlayer, pCreature); |
72 | + | return true; |
73 | - | } |
73 | + | } |
74 | - | else |
74 | + | |
75 | - | { |
75 | + | |
76 | - | pPlayer->CLOSE_GOSSIP_MENU(); |
76 | + | |
77 | - | } |
77 | + | |
78 | - | return true; |
78 | + | new roulette_npc(); |
79 | - | } |
79 | + |