Nitair Posted March 25, 2015 Report Share Posted March 25, 2015 Hello everyone. First of all, my english spelling is nooblike. Dear guest, please login or register to see this content./emoticons/default_wacko.png" alt=":wacko:">I want make a npc with various gossip. He's getting all "options" from a custom database.Thats the main menu (It works)Database is:Entry (int) | Text(string)0 | Mounts Dear guest, please login or register to see this content. And here is the part where i need help. It have to add ONE item. First of all here the table ->Entry | ID | description | reward_id0 | 0 | Monster-Axe 2h | 496450 | 1 | Atiesh | 22632Code: Dear guest, please login or register to see this content. What hes doing (When I click "Monster-Axe 2h") -> What have to do -> When I click on "Monster-Axe 2h" he adds "Monster-Axe 2h". Other information: Latest revision from Trinitycore There is Mounts as section but I tested it with normal items, its a bit weird... Its my first own script, but i dont know how to handle this... Im blind or stupid... :/ - I thinks the issue comes from the for(...) but, when i remove it -> A single line "You dont have any space in your bags". Thanks for taking time to read this. I hope you can help me. - Nitair Dear guest, please login or register to see this content./emoticons/default_smile.png" alt=":)" srcset="https://wowbb.org/uploads/emoticons/smile@2x.png 2x" width="20" height="20"> Quote Link to comment Share on other sites More sharing options...
cyberpro98 Posted March 25, 2015 Report Share Posted March 25, 2015 If you can post full script , because I can't understand what you want ... Quote Link to comment Share on other sites More sharing options...
Nitair Posted March 26, 2015 Author Report Share Posted March 26, 2015 Dear guest, please login or register to see this content. #include "ScriptPCH.h" class Scriptvendor : public CreatureScript { public : Scriptvendor() : CreatureScript("Scriptvendor") { QueryResult category = WorldDatabase.Query("SELECT Entry, Text FROM scriptvendor_categorys WHERE Entry BETWEEN 0 AND 9"); if (category) { do { Field* field = category->Fetch(); uint32 Entry = field[0].GetUInt32(); std::string Text = field[1].GetString(); ItemInfo& data = items[Entry]; data.entry = Entry; data.name = Text; } while (category->NextRow()); } } bool OnGossipHello(Player* player, Creature* creature) { player->PlayerTalkClass->ClearMenus(); for (ItemData::const_iterator it = items.begin(); it != items.end(); ++it) { std::ostringstream oss; oss << " " << it->second.name; player->ADD_GOSSIP_ITEM(10, oss.str(), GOSSIP_SENDER_MAIN, it->second.entry); } player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, creature->GetGUID()); return true; } bool OnGossipSelect(Player* player, Creature* creature, uint32 sender, uint32 uiAction) { if (!player) return false; if (sender == GOSSIP_SENDER_MAIN) { player->PlayerTalkClass->ClearMenus(); switch (uiAction) { case 0: { QueryResult options = WorldDatabase.Query("SELECT ID, description, reward_id FROM scriptvendor_options WHERE Entry = 0 AND ID BETWEEN 0 AND 99"); if (options) { do { Field* field = options->Fetch(); uint32 Entry = field[0].GetUInt32(); std::string Text = field[1].GetString(); uint32 reward_id = field[0].GetUInt32(); MountInfo& data = mounts[Entry]; data.entry = Entry; data.name = Text; data.item_id = reward_id; } while (options->NextRow()); } for (MountData::const_iterator it = mounts.begin(); it != mounts.end(); ++it) { std::ostringstream oss; oss << "Mount - " << it->second.name; player->ADD_GOSSIP_ITEM(10, oss.str(), GOSSIP_SENDER_MAIN, 6); } player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, creature->GetGUID()); } break; case 1: { QueryResult options = WorldDatabase.Query("SELECT ID, description FROM scriptvendor_options WHERE Entry = 1 AND ID BETWEEN 0 AND 99"); if (options) { do { Field* field = options->Fetch(); uint32 Entry = field[0].GetUInt32(); std::string Text = field[1].GetString(); ItemInfo& data = items[Entry]; data.entry = Entry; data.name = Text; } while (options->NextRow()); } for (ItemData::const_iterator it = items.begin(); it != items.end(); ++it) { std::ostringstream oss; oss << "Morpher - " << it->second.name; player->ADD_GOSSIP_ITEM(10, oss.str(), GOSSIP_SENDER_MAIN, it->second.entry); } player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, creature->GetGUID()); } break; case 2: { QueryResult options = WorldDatabase.Query("SELECT ID, description FROM scriptvendor_options WHERE Entry = 2 AND ID BETWEEN 0 AND 99"); if (options) { do { Field* field = options->Fetch(); uint32 Entry = field[0].GetUInt32(); std::string Text = field[1].GetString(); ItemInfo& data = items[Entry]; data.entry = Entry; data.name = Text; } while (options->NextRow()); } for (ItemData::const_iterator it = items.begin(); it != items.end(); ++it) { std::ostringstream oss; oss << "Special-Items - " << it->second.name; player->ADD_GOSSIP_ITEM(10, oss.str(), GOSSIP_SENDER_MAIN, it->second.entry); } player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, creature->GetGUID()); } break; case 3: { QueryResult options = WorldDatabase.Query("SELECT ID, description FROM scriptvendor_options WHERE Entry = 4 AND ID BETWEEN 0 AND 99"); if (options) { do { Field* field = options->Fetch(); uint32 Entry = field[0].GetUInt32(); std::string Text = field[1].GetString(); ItemInfo& data = items[Entry]; data.entry = Entry; data.name = Text; } while (options->NextRow()); } for (ItemData::const_iterator it = items.begin(); it != items.end(); ++it) { std::ostringstream oss; oss << "Titles - " << it->second.name; player->ADD_GOSSIP_ITEM(10, oss.str(), GOSSIP_SENDER_MAIN, it->second.entry); } player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, creature->GetGUID()); } break; case 4: { QueryResult options = WorldDatabase.Query("SELECT ID, description FROM scriptvendor_options WHERE Entry = 5 AND ID BETWEEN 0 AND 99"); if (options) { do { Field* field = options->Fetch(); uint32 Entry = field[0].GetUInt32(); std::string Text = field[1].GetString(); ItemInfo& data = items[Entry]; data.entry = Entry; data.name = Text; } while (options->NextRow()); } for (ItemData::const_iterator it = items.begin(); it != items.end(); ++it) { std::ostringstream oss; oss << "Reputation - " << it->second.name; player->ADD_GOSSIP_ITEM(10, oss.str(), GOSSIP_SENDER_MAIN, it->second.entry); } player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, creature->GetGUID()); } break; case 5: { QueryResult options = WorldDatabase.Query("SELECT ID, description FROM scriptvendor_options WHERE Entry = 6 AND ID BETWEEN 0 AND 99"); if (options) { do { Field* field = options->Fetch(); uint32 Entry = field[0].GetUInt32(); std::string Text = field[1].GetString(); ItemInfo& data = items[Entry]; data.entry = Entry; data.name = Text; } while (options->NextRow()); } for (ItemData::const_iterator it = items.begin(); it != items.end(); ++it) { std::ostringstream oss; oss << "Spells (test) - " << it->second.name; player->ADD_GOSSIP_ITEM(10, oss.str(), GOSSIP_SENDER_MAIN, it->second.entry); } player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, creature->GetGUID()); } break; case 6: //Mounts - Additem { QueryResult result = WorldDatabase.Query("SELECT ID, description, reward_id FROM scriptvendor_options WHERE Entry = 0"); do { Field* field = result->Fetch(); uint32 entry = field[0].GetUInt32(); std::string name = field[1].GetString(); uint32 reward_id = field[2].GetUInt32(); if (!sObjectMgr->GetItemTemplate(reward_id)) continue; ItemInfo& data = items[reward_id]; data.entry = entry; data.name = name; data.item_id = reward_id; } while (result->NextRow()); for (ItemData::const_iterator it = items.begin(); it != items.end(); ++it) { player->AddItem(it->second.item_id, 1); } player->CLOSE_GOSSIP_MENU(); } break; case 7: { } break; case 8: { } break; case 9: { } break; case 10: { } break; case 11: { } break; } } return true; } struct ItemInfo { uint32 entry; std::string name; uint32 item_id; }; typedef std::map<uint32, ItemInfo> ItemData; ItemData items; struct MountInfo { uint32 entry; std::string name; uint32 item_id; }; typedef std::map<uint32, MountInfo> MountData; MountData mounts; }; void AddSC_Scriptvendor() { new Scriptvendor(); } Quote Link to comment Share on other sites More sharing options...
Rykon Posted March 26, 2015 Report Share Posted March 26, 2015 You are making this way too complicated for yourself.Do something like this Dear guest, please login or register to see this content. Quote Link to comment Share on other sites More sharing options...
Nitair Posted March 26, 2015 Author Report Share Posted March 26, 2015 Yeah maybe i think too difficult... Dear guest, please login or register to see this content./emoticons/default_biggrin.png" alt=":D" srcset="https://wowbb.org/uploads/emoticons/biggrin@2x.png 2x" width="20" height="20"> Your script shows me -> Edit: Oh didnt read the "do something like this", sorry Quote Link to comment Share on other sites More sharing options...
Rykon Posted March 26, 2015 Report Share Posted March 26, 2015 while (result->NextRow()){ }; Quote Link to comment Share on other sites More sharing options...
cyberpro98 Posted March 26, 2015 Report Share Posted March 26, 2015 Yep. Quote Link to comment Share on other sites More sharing options...
Nitair Posted March 26, 2015 Author Report Share Posted March 26, 2015 Same error Quote Link to comment Share on other sites More sharing options...
Rykon Posted March 27, 2015 Report Share Posted March 27, 2015 Try while (result->NextRow());{ } Quote Link to comment Share on other sites More sharing options...
Nitair Posted March 27, 2015 Author Report Share Posted March 27, 2015 Tested it too already. It didnt work. All declarations are at this point undefined. while(result->NextRow()); { <- At this point } I did some changes. Now I have only 1 problem to do this what i want -> Dear guest, please login or register to see this content. He's adding now the Item with entry = 0 and id = 0 I guess I should write something like this -> QueryResult result = WorldDatabase.PQuery("SELECT ID, description, reward_id FROM scriptvendor_options WHERE Entry = 0 AND reward_id= %u", item_id); But I dont know how I put the saved variables into the cases. And an another point -> Im sorry - I'm new at trinitycore - hope im not annoying :/ Quote Link to comment Share on other sites More sharing options...
Madness Posted March 27, 2015 Report Share Posted March 27, 2015 Just do this instead: Dear guest, please login or register to see this content. You can use std::string to create the string query and then pass variables to like so: Dear guest, please login or register to see this content. Quote Link to comment Share on other sites More sharing options...
Nitair Posted March 27, 2015 Author Report Share Posted March 27, 2015 Dear guest, please login or register to see this content. What should I type when I want to say -> Add this item what I selected This Code is the menu for all what is written in the database with entry 0 -> Dear guest, please login or register to see this content. When I read this, the Entry and ID have to be set 0 (Like my "just for debug" comment) but I dont have variables where is written "When I select this, so add this".... Nothing where I select Entry 0 and ID 0 Dont know how I can handle this. Thanks anyway for the help. Hope you can understand my question. Dear guest, please login or register to see this content./emoticons/default_smile.png" alt=":)" srcset="https://wowbb.org/uploads/emoticons/smile@2x.png 2x" width="20" height="20"> Quote Link to comment Share on other sites More sharing options...
Madness Posted March 27, 2015 Report Share Posted March 27, 2015 Did you take this script from Rochet2? Have you tried this? Dear guest, please login or register to see this content. Quote Link to comment Share on other sites More sharing options...
Nitair Posted March 27, 2015 Author Report Share Posted March 27, 2015 Yes I already saw it, but it didnt help so much. Hes making a main menu only for items. I did it complicated, cause of i didnt want add only items in a range from ID X to Y. I want specify select when the player goes to "Mounts" ... An another list comes (custom table) and then click on "for example : Spectraltiger" and that adds Spectraltiger I copied some things from rochet2 -> for exmaple : Dear guest, please login or register to see this content. To save the values Quote Link to comment Share on other sites More sharing options...
Madness Posted March 27, 2015 Report Share Posted March 27, 2015 When I finish from work, I'll set this up on my PC so I can see what's actually happening and try fix it for you. Dear guest, please login or register to see this content./emoticons/default_smile.png" alt=":)" srcset="https://wowbb.org/uploads/emoticons/smile@2x.png 2x" width="20" height="20"> Quote Link to comment Share on other sites More sharing options...
Nitair Posted March 27, 2015 Author Report Share Posted March 27, 2015 Yeah nice ! Dear guest, please login or register to see this content./emoticons/default_smile.png" alt=":)" srcset="https://wowbb.org/uploads/emoticons/smile@2x.png 2x" width="20" height="20"> You can add me in Skype and Ill send you the newest code okay? Dear guest, please login or register to see this content./emoticons/default_smile.png" alt=":)" srcset="https://wowbb.org/uploads/emoticons/smile@2x.png 2x" width="20" height="20"> Quote Link to comment Share on other sites More sharing options...
Madness Posted March 27, 2015 Report Share Posted March 27, 2015 Sure man message me your Skype Dear guest, please login or register to see this content./emoticons/default_smile.png" alt=":)" srcset="https://wowbb.org/uploads/emoticons/smile@2x.png 2x" width="20" height="20"> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.