Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ___ _ ___
- / __\___ __| | _____ __ / __\___ _ __ ___
- / / / _ \ / _` |/ _ \ \/ // / / _ \| '__/ _ \
- / /__| (_) | (_| | __/> </ /__| (_) | | | __/
- \____/\___/ \__,_|\___/_/\_\____/\___/|_| \___|
- conjured directly from the Fists Of anger!
- CodexWoW 2011 - 2013 (C)
- <--------------------------------------------------------------------------->
- - Developer(s): Yvoms
- - Complete: 100%
- - ScriptName: 'teleporter'
- - Comment: Untested
- <--------------------------------------------------------------------------->
- */
- #include "ScriptMgr.h"
- #include "Chat.h"
- ChatCommand* GetCommands() const
- {
- static ChatCommand DevCommandTable[] =
- {
- { "Devadd", SEC_DEV, true, &HandleDevaddCommand, "", NULL },
- { NULL, 0, false, NULL, "", NULL }
- };
- return DevCommandTable;
- }
- };
- class Custom_devadd : public CommandScript
- public:
- Custom_devadd() : CommandScript("Custom_devadd") { }
- static bool HandleDevaddCommand(ChatHandler* handler, char const* args)
- {
- if (!*args)
- return false;
- uint32 itemId = 0;
- if (args[0] == '[') // [name] manual form
- {
- char const* itemNameStr = strtok((char*)args, "]");
- if (itemNameStr && itemNameStr[0])
- {
- std::string itemName = itemNameStr+1;
- WorldDatabase.EscapeString(itemName);
- PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_ITEM_TEMPLATE_BY_NAME);
- stmt->setString(0, itemName);
- PreparedQueryResult result = WorldDatabase.Query(stmt);
- if (!result)
- {
- handler->PSendSysMessage(LANG_COMMAND_COULDNOTFIND, itemNameStr+1);
- handler->SetSentErrorMessage(true);
- return false;
- }
- itemId = result->Fetch()->GetUInt32();
- }
- else
- return false;
- }
- else // item_id or [name] Shift-click form |color|Hitem:item_id:0:0:0|h[name]|h|r
- {
- char const* id = handler->extractKeyFromLink((char*)args, "Hitem");
- if (!id)
- return false;
- itemId = uint32(atol(id));
- }
- char const* ccount = strtok(NULL, " ");
- int32 count = 1;
- if (ccount)
- count = strtol(ccount, NULL, 10);
- if (count == 0)
- count = 1;
- Player* player = handler->GetSession()->GetPlayer();
- Player* playerTarget = handler->getSelectedPlayer();
- if (playerTarget)
- playerTarget = player;
- sLog->outDebug(LOG_FILTER_GENERAL, handler->GetTrinityString(LANG_ADDITEM), itemId, count);
- ItemTemplate const* itemTemplate = sObjectMgr->GetItemTemplate(itemId);
- if (!itemTemplate)
- {
- handler->PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, itemId);
- handler->SetSentErrorMessage(true);
- return false;
- }
- // Subtract
- if (count < 0)
- {
- playerTarget->DestroyItemCount(itemId, -count, true, false);
- handler->PSendSysMessage(LANG_REMOVEITEM, itemId, -count, handler->GetNameLink(playerTarget).c_str());
- return true;
- }
- // Adding items
- uint32 noSpaceForCount = 0;
- // check space and find places
- ItemPosCountVec dest;
- InventoryResult msg = playerTarget->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, itemId, count, &noSpaceForCount);
- if (msg != EQUIP_ERR_OK) // convert to possible store amount
- count -= noSpaceForCount;
- if (count == 0 || dest.empty()) // can't add any
- {
- handler->PSendSysMessage(LANG_ITEM_CANNOT_CREATE, itemId, noSpaceForCount);
- handler->SetSentErrorMessage(true);
- return false;
- }
- Item* item = playerTarget->StoreNewItem(dest, itemId, true, Item::GenerateItemRandomPropertyId(itemId));
- /* remove binding (let GM give it to another player later)
- if (player == playerTarget)
- for (ItemPosCountVec::const_iterator itr = dest.begin(); itr != dest.end(); ++itr)
- if (Item* item1 = player->GetItemByPos(itr->pos))
- item1->SetBinding(false);
- if (count > 0 && item)
- {
- player->SendNewItem(item, count, false, true);
- if (player != playerTarget)
- playerTarget->SendNewItem(item, count, true, false);
- }
- if (noSpaceForCount > 0)
- handler->PSendSysMessage(LANG_ITEM_CANNOT_CREATE, itemId, noSpaceForCount);
- return true;
- }
- */
- void AddSC_Custom_devadd()
- {
- new Custom_devadd();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement