TShelby

ASD

Nov 23rd, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.22 KB | None | 0 0
  1. // If you use my special storage, and ofc if you want add "ACMD(do_sort_special_storage);" too. ^
  2.  
  3. //////////// CMD.CPP ////////////
  4. Search :
  5. ACMD(do_stun);
  6.  
  7. Add after :
  8. #ifdef ENABLE_SORT_INVENTORY
  9. ACMD(do_sort_items);
  10. ACMD(do_sort_special_storage);
  11. #endif
  12.  
  13. Search:
  14.     {                   "notice",                               do_notice,                          0,                  POS_DEAD,                       GM_LOW_WIZARD                   },
  15.  
  16. Add after :
  17. #ifdef ENABLE_SORT_INVENTORY
  18.     {                   "click_sort_items",                     do_sort_items,                      0,                  POS_DEAD,                       GM_PLAYER                       },
  19.     {                   "click_sort_special_storage",           do_sort_special_storage,            0,                  POS_DEAD,                       GM_PLAYER                       },
  20. #endif
  21.  
  22.  
  23. //////////// CMD_GNERAL.CPP ////////////
  24.  
  25. ADD THIS :
  26. #ifdef ENABLE_SORT_INVENTORY
  27. ACMD (do_sort_items)
  28. {
  29.     if (ch->IsDead() || ch->GetExchange() || ch->IsShop() || ch->IsOpenSafebox() || ch->IsCubeOpen())
  30.     {
  31.         ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("You can't sort your inventory with those windows open."));
  32.         return;
  33.     }
  34.    
  35.     int lastSortInventoryPulse = ch->GetSortInventoryPulse();
  36.     int currentPulse = thecore_pulse();
  37.    
  38.     if (lastSortInventoryPulse > currentPulse) {
  39.         int deltaInSeconds = ((lastSortInventoryPulse / PASSES_PER_SEC(1)) - (currentPulse / PASSES_PER_SEC(1)));
  40.         int minutes = deltaInSeconds / 60;
  41.         int seconds = (deltaInSeconds - (minutes * 60));
  42.         return;
  43.     }
  44.    
  45.     for (int i = 0; i < INVENTORY_MAX_NUM; ++i)
  46.     {
  47.         LPITEM item = ch->GetInventoryItem(i);
  48.        
  49.         if(!item)
  50.             continue;
  51.        
  52.         if(item->isLocked())
  53.             continue;
  54.        
  55.         if(item->GetCount() == g_bItemCountLimit)
  56.             continue;
  57.        
  58.         if (item->IsStackable() && !IS_SET(item->GetAntiFlag(), ITEM_ANTIFLAG_STACK))
  59.         {
  60.             for (int j = i; j < INVENTORY_MAX_NUM; ++j)
  61.             {
  62.                 LPITEM item2 = ch->GetInventoryItem(j);
  63.                
  64.                 if(!item2)
  65.                     continue;
  66.                
  67.                 if(item2->isLocked())
  68.                     continue;
  69.    
  70.                 if (item2->GetVnum() == item->GetVnum())
  71.                 {
  72.                     bool bStopSockets = false;
  73.                    
  74.                     for (int k = 0; k < ITEM_SOCKET_MAX_NUM; ++k)
  75.                     {
  76.                         if (item2->GetSocket(k) != item->GetSocket(k))
  77.                         {
  78.                             bStopSockets = true;
  79.                             break;
  80.                         }
  81.                     }
  82.                    
  83.                     if(bStopSockets)
  84.                         continue;
  85.    
  86.                     BYTE bAddCount = MIN(g_bItemCountLimit - item->GetCount(), item2->GetCount());
  87.    
  88.                     item->SetCount(item->GetCount() + bAddCount);
  89.                     item2->SetCount(item2->GetCount() - bAddCount);
  90.                    
  91.                     continue;
  92.                 }
  93.             }
  94.         }
  95.     }
  96.    
  97.     ch->SetNextSortInventoryPulse(thecore_pulse() + PASSES_PER_SEC(60));
  98. }
  99.  
  100. ACMD (do_sort_special_storage)
  101. {
  102.     if (ch->IsDead() || ch->GetExchange() || ch->IsShop() || ch->IsOpenSafebox() || ch->IsCubeOpen())
  103.     {
  104.         ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("You can't sort your inventory with those windows open."));
  105.         return;
  106.     }
  107.    
  108.     int lastSortSpecialStoragePulse = ch->GetSortSpecialStoragePulse();
  109.     int currentPulse = thecore_pulse();
  110.    
  111.     if (lastSortSpecialStoragePulse > currentPulse) {
  112.         int deltaInSeconds = ((lastSortSpecialStoragePulse / PASSES_PER_SEC(1)) - (currentPulse / PASSES_PER_SEC(1)));
  113.         int minutes = deltaInSeconds / 60;
  114.         int seconds = (deltaInSeconds - (minutes * 60));
  115.  
  116.         ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("You can sort your inventory again in %02d seconds."), seconds);
  117.         return;
  118.     }
  119.    
  120.    
  121.     for (int m = 0; m < 3; m++)
  122.     {
  123.         for (int i = 0; i < SPECIAL_INVENTORY_MAX_NUM; ++i)
  124.         {
  125.             LPITEM item;
  126.            
  127.             switch(m)
  128.             {
  129.                 case 0:
  130.                     item = ch->GetUpgradeInventoryItem(i);
  131.                     break;
  132.                 case 1:
  133.                     item = ch->GetBookInventoryItem(i);
  134.                     break;
  135.                 case 2:
  136.                     item = ch->GetStoneInventoryItem(i);
  137.                     break;
  138.                 default:
  139.                     item = ch->GetUpgradeInventoryItem(i);
  140.                     break;
  141.             }
  142.            
  143.             if(!item)
  144.                 continue;
  145.            
  146.             if(item->isLocked())
  147.                 continue;
  148.            
  149.             if(item->GetCount() == g_bItemCountLimit)
  150.                 continue;
  151.            
  152.             if (item->IsStackable() && !IS_SET(item->GetAntiFlag(), ITEM_ANTIFLAG_STACK))
  153.             {
  154.                 for (int j = i; j < SPECIAL_INVENTORY_MAX_NUM; ++j)
  155.                 {
  156.                    
  157.                     LPITEM item2;
  158.                    
  159.                     switch(m)
  160.                     {
  161.                         case 0:
  162.                             item2 = ch->GetUpgradeInventoryItem(j);
  163.                             break;
  164.                         case 1:
  165.                             item2 = ch->GetBookInventoryItem(j);
  166.                             break;
  167.                         case 2:
  168.                             item2 = ch->GetStoneInventoryItem(j);
  169.                             break;
  170.                         default:
  171.                             item2 = ch->GetUpgradeInventoryItem(j);
  172.                             break;
  173.                     }
  174.            
  175.                     if(!item2)
  176.                         continue;
  177.                    
  178.                     if(item2->isLocked())
  179.                         continue;
  180.        
  181.                     if (item2->GetVnum() == item->GetVnum())
  182.                     {
  183.                         bool bStopSockets = false;
  184.                        
  185.                         for (int k = 0; k < ITEM_SOCKET_MAX_NUM; ++k)
  186.                         {
  187.                             if (item2->GetSocket(k) != item->GetSocket(k))
  188.                             {
  189.                                 bStopSockets = true;
  190.                                 break;
  191.                             }
  192.                         }
  193.                        
  194.                         if(bStopSockets)
  195.                             continue;
  196.        
  197.                         BYTE bAddCount = MIN(g_bItemCountLimit - item->GetCount(), item2->GetCount());
  198.        
  199.                         item->SetCount(item->GetCount() + bAddCount);
  200.                         item2->SetCount(item2->GetCount() - bAddCount);
  201.                        
  202.                         continue;
  203.                     }
  204.                 }
  205.             }
  206.         }
  207.     }
  208.  
  209.     ch->SetNextSortSpecialStoragePulse(thecore_pulse() + PASSES_PER_SEC(60));
  210. }
  211. #endif
  212. //////////// char.cpp ////////////
  213. Search :
  214.     m_iSyncHackCount = 0;
  215.  
  216. Add after:
  217.  
  218. #ifdef ENABLE_SORT_INVENTORY
  219.     m_sortInventoryPulse = 0;
  220.     m_sortSpecialStoragePulse = 0;
  221. #endif
  222.  
  223. //////////// char.h ////////////
  224. Search :
  225. void            GiveGold(INT iAmount);
  226.  
  227. Add after :
  228.  
  229. #ifdef ENABLE_SORT_INVENTORY
  230.         void            SetNextSortInventoryPulse(int pulse) { m_sortInventoryPulse = pulse; }
  231.         int             GetSortInventoryPulse() { return m_sortInventoryPulse; }
  232.        
  233.         void            SetNextSortSpecialStoragePulse(int pulse) { m_sortSpecialStoragePulse = pulse; }
  234.         int             GetSortSpecialStoragePulse() { return m_sortSpecialStoragePulse; }
  235. #endif
  236.  
  237. Search :
  238.  
  239.         LPSHOP          m_pkShop;
  240.         LPSHOP          m_pkMyShop;
  241.         std::string     m_stShopSign;
  242.         LPCHARACTER     m_pkChrShopOwner;
  243.  
  244. Add after :
  245.  
  246. #ifdef ENABLE_SORT_INVENTORY
  247.         int     m_sortInventoryPulse;
  248.         int     m_sortSpecialStoragePulse;
  249. #endif
  250.  
  251. /////// Service.h ////////
  252.  
  253. Add this :
  254. #define ENABLE_SORT_INVENTORY
Advertisement
Add Comment
Please, Sign In to add comment