Advertisement
yvoms

Untitled

Apr 11th, 2013
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.35 KB | None | 0 0
  1. /*
  2.  
  3.  
  4. ___ _ ___
  5. / __\___ __| | _____ __ / __\___ _ __ ___
  6. / / / _ \ / _` |/ _ \ \/ // / / _ \| '__/ _ \
  7. / /__| (_) | (_| | __/> </ /__| (_) | | | __/
  8. \____/\___/ \__,_|\___/_/\_\____/\___/|_| \___|
  9.  
  10. conjured directly from the Fists Of anger!
  11. CodexWoW 2011 - 2013 (C)
  12. <--------------------------------------------------------------------------->
  13. - Developer(s): Yvoms
  14. - Complete: 100%
  15. - ScriptName: 'teleporter'
  16. - Comment: Untested
  17. <--------------------------------------------------------------------------->
  18. */
  19.  
  20. #include "ScriptMgr.h"
  21. #include "Chat.h"
  22.  
  23. ChatCommand* GetCommands() const
  24. {
  25. static ChatCommand DevCommandTable[] =
  26. {
  27. { "Devadd", SEC_DEV, true, &HandleDevaddCommand, "", NULL },
  28. { NULL, 0, false, NULL, "", NULL }
  29. };
  30. return DevCommandTable;
  31. }
  32. };
  33.  
  34.  
  35. class Custom_devadd : public CommandScript
  36.  
  37. public:
  38. Custom_devadd() : CommandScript("Custom_devadd") { }
  39.  
  40.  
  41. static bool HandleDevaddCommand(ChatHandler* handler, char const* args)
  42. {
  43. if (!*args)
  44. return false;
  45.  
  46. uint32 itemId = 0;
  47.  
  48. if (args[0] == '[') // [name] manual form
  49. {
  50. char const* itemNameStr = strtok((char*)args, "]");
  51.  
  52. if (itemNameStr && itemNameStr[0])
  53. {
  54. std::string itemName = itemNameStr+1;
  55. WorldDatabase.EscapeString(itemName);
  56.  
  57. PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_ITEM_TEMPLATE_BY_NAME);
  58. stmt->setString(0, itemName);
  59. PreparedQueryResult result = WorldDatabase.Query(stmt);
  60.  
  61. if (!result)
  62. {
  63. handler->PSendSysMessage(LANG_COMMAND_COULDNOTFIND, itemNameStr+1);
  64. handler->SetSentErrorMessage(true);
  65. return false;
  66. }
  67. itemId = result->Fetch()->GetUInt32();
  68. }
  69. else
  70. return false;
  71. }
  72. else // item_id or [name] Shift-click form |color|Hitem:item_id:0:0:0|h[name]|h|r
  73. {
  74. char const* id = handler->extractKeyFromLink((char*)args, "Hitem");
  75. if (!id)
  76. return false;
  77. itemId = uint32(atol(id));
  78. }
  79.  
  80. char const* ccount = strtok(NULL, " ");
  81.  
  82. int32 count = 1;
  83.  
  84. if (ccount)
  85. count = strtol(ccount, NULL, 10);
  86.  
  87. if (count == 0)
  88. count = 1;
  89.  
  90. Player* player = handler->GetSession()->GetPlayer();
  91. Player* playerTarget = handler->getSelectedPlayer();
  92. if (playerTarget)
  93. playerTarget = player;
  94.  
  95. sLog->outDebug(LOG_FILTER_GENERAL, handler->GetTrinityString(LANG_ADDITEM), itemId, count);
  96.  
  97. ItemTemplate const* itemTemplate = sObjectMgr->GetItemTemplate(itemId);
  98. if (!itemTemplate)
  99. {
  100. handler->PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, itemId);
  101. handler->SetSentErrorMessage(true);
  102. return false;
  103. }
  104.  
  105. // Subtract
  106. if (count < 0)
  107. {
  108. playerTarget->DestroyItemCount(itemId, -count, true, false);
  109. handler->PSendSysMessage(LANG_REMOVEITEM, itemId, -count, handler->GetNameLink(playerTarget).c_str());
  110. return true;
  111. }
  112.  
  113. // Adding items
  114. uint32 noSpaceForCount = 0;
  115.  
  116. // check space and find places
  117. ItemPosCountVec dest;
  118. InventoryResult msg = playerTarget->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, itemId, count, &noSpaceForCount);
  119. if (msg != EQUIP_ERR_OK) // convert to possible store amount
  120. count -= noSpaceForCount;
  121.  
  122. if (count == 0 || dest.empty()) // can't add any
  123. {
  124. handler->PSendSysMessage(LANG_ITEM_CANNOT_CREATE, itemId, noSpaceForCount);
  125. handler->SetSentErrorMessage(true);
  126. return false;
  127. }
  128.  
  129. Item* item = playerTarget->StoreNewItem(dest, itemId, true, Item::GenerateItemRandomPropertyId(itemId));
  130.  
  131. /* remove binding (let GM give it to another player later)
  132. if (player == playerTarget)
  133. for (ItemPosCountVec::const_iterator itr = dest.begin(); itr != dest.end(); ++itr)
  134. if (Item* item1 = player->GetItemByPos(itr->pos))
  135. item1->SetBinding(false);
  136.  
  137. if (count > 0 && item)
  138. {
  139. player->SendNewItem(item, count, false, true);
  140. if (player != playerTarget)
  141. playerTarget->SendNewItem(item, count, true, false);
  142. }
  143.  
  144. if (noSpaceForCount > 0)
  145. handler->PSendSysMessage(LANG_ITEM_CANNOT_CREATE, itemId, noSpaceForCount);
  146.  
  147. return true;
  148. }
  149. */
  150.  
  151.  
  152. void AddSC_Custom_devadd()
  153. {
  154. new Custom_devadd();
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement