Jump to content
WoWBB.org

Need some help with a script


Nitair

Recommended Posts

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_id
0 | 0 | Monster-Axe 2h | 49645
0 | 1 | Atiesh | 22632

Code:
 

Dear guest, please login or register to see this content.

What hes doing (When I click "Monster-Axe 2h") ->
 
5wofz7a585s3.jpg
 
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">

Link to comment
Share on other sites

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();

}

Link to comment
Share on other sites

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 ->

 

2jm2gcyrt4pl.png

 

3ymqwwnnovdb.png

 

Edit: Oh didnt read the "do something like this", sorry

Link to comment
Share on other sites

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 :/

Link to comment
Share on other sites

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">

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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">

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...