Custom Script Broken?

Results 1 to 1 of 1
  1. #1
    Newbie Xatmo is offline
    MemberRank
    Nov 2013 Join Date
    1Posts

    Custom Script Broken?

    Can anyone tell my why my custom script wont work it compiles fine with no error or syntax errors in vs 2017 for trinitycore but when i assign it to my custom npc talking to it returns nothing...?

    Code:
    #include "Item.h"
    #include "DBCStores.h"
    #include "Log.h"
    #include "DatabaseEnv.h"
    #include "CharacterDatabase.h"
    #include "Player.h"
    #include "WorldSession.h"
    #include "ScriptedGossip.h"
    #include "ScriptMgr.h"
    #include "ScriptedCreature.h"
    #include "GossipDef.h"
    #include "Creature.h"
    #include "ObjectMgr.h"
    #include "ScriptedCreature.h"
    #include "PassiveAI.h"
    #include "Bag.h"
    #include "Common.h"
    #include "Config.h"
    #include "DBCStructure.h"
    #include "Define.h"
    #include "Field.h"
    #include "GameEventMgr.h"
    #include "ItemTemplate.h"
    #include "Language.h"
    #include "ObjectGuid.h"
    #include "QueryResult.h"
    #include "SharedDefines.h"
    #include "Transaction.h"
    #include <sstream>
    #include <string>
    
    class my_script : public CreatureScript
    {
    public:
        my_script() : CreatureScript("my_script") {}
    
        class my_scriptAI : public ScriptedAI
        {
        public:
            my_scriptAI(Creature* pCreature) : ScriptedAI(pCreature) {}
    
            void RewardItem(Player* pPlayer, Creature* pCreature, int item, int count, int cost)
            {
                QueryResult result;
                result = LoginDatabase.PQuery("SELECT points FROM account WHERE id = '%u'", pPlayer->GetSession()->GetAccountId());
                if (!result) // check
                {
                    pPlayer->GetSession()->SendAreaTriggerMessage("I'm Broken! Contact a gamemaster!");
                    pPlayer->PlayerTalkClass->ClearMenus();
                    OnGossipHello(pPlayer, pCreature);
                    return;
                }
                Field *fields = result->Fetch();
                uint32 points = fields[0].GetUInt32();
    
                if (item == 0)
                {
                    pPlayer->GetSession()->SendAreaTriggerMessage("You got %u voting points!", points);
                }
                else
                {
                    if (points < cost)
                    {
                        pPlayer->GetSession()->SendAreaTriggerMessage("You don't have enough points for this item!");
                    }
                    else
                    {
                        if (pPlayer->AddItem(item, count))
                        {
                            LoginDatabase.PQuery("Update account Set points = points - '%u' WHERE id = '%u'", cost, pPlayer->GetSession()->GetAccountId());
                            pPlayer->GetSession()->SendAreaTriggerMessage("Your points are taken and your item is given!!!");
                        }
                        else
                        {
                            pPlayer->GetSession()->SendAreaTriggerMessage("Item can't be given(your bag is full or you already got the item!)!");
                        }
    
                    }
                }
                pPlayer->PlayerTalkClass->ClearMenus();
                OnGossipHello(pPlayer, pCreature);
            }
    
            bool OnGossipHello(Player* pPlayer, Creature* pCreature)
            {
                AddGossipItemFor(pPlayer, GOSSIP_ICON_CHAT, "Homuch voting points do i have ?", GOSSIP_SENDER_MAIN, 1000);
                AddGossipItemFor(pPlayer, GOSSIP_ICON_CHAT, "Mounts", GOSSIP_SENDER_MAIN, 2000);
                AddGossipItemFor(pPlayer, GOSSIP_ICON_CHAT, "Starter Items", GOSSIP_SENDER_MAIN, 3000);
                AddGossipItemFor(pPlayer, GOSSIP_ICON_CHAT, "Promo 200 Token 250>VP", GOSSIP_SENDER_MAIN, 4000);
                AddGossipItemFor(pPlayer, GOSSIP_ICON_CHAT, "Promo 200 Token 250>VP", GOSSIP_SENDER_MAIN, 5000);
                AddGossipItemFor(pPlayer, GOSSIP_ICON_CHAT, "Goodies", GOSSIP_SENDER_MAIN, 6000);
                SendGossipMenuFor(pPlayer, 600000, pCreature->GetGUID());
                return true;
            }
    
            bool OnGossipSelect(Player* pPlayer, Creature* pCreature, uint32 /*uiSender*/, uint32 uiAction)
            {
                pPlayer->PlayerTalkClass->ClearMenus();
    
                switch (uiAction)
                {
                case 1000:
                    RewardItem(pPlayer, pCreature, 0, 0, 0);
                    break;
                case 2000:
                    pPlayer->PlayerTalkClass->ClearMenus();
                    AddGossipItemFor(pPlayer, GOSSIP_ICON_DOT, "Mechano-hog 50>VP", GOSSIP_SENDER_MAIN, 2001);
                    AddGossipItemFor(pPlayer, GOSSIP_ICON_DOT, "Mekgineer's Chopper 50>VP", GOSSIP_SENDER_MAIN, 2002);
                    AddGossipItemFor(pPlayer, GOSSIP_ICON_DOT, "Celestial Steed 200>VP", GOSSIP_SENDER_MAIN, 2003);
                    AddGossipItemFor(pPlayer, GOSSIP_ICON_DOT, "Invincible's Reins 200>VP", GOSSIP_SENDER_MAIN, 2004);
                    AddGossipItemFor(pPlayer, GOSSIP_ICON_DOT, "Invincible's Reins 200>VP", GOSSIP_SENDER_MAIN, 2003);
                    AddGossipItemFor(pPlayer, GOSSIP_ICON_DOT, "Return", GOSSIP_SENDER_MAIN, 9999);
                    SendGossipMenuFor(pPlayer, 600000, pCreature->GetGUID());
                    return true;
                    break;
                case 2001:
                    RewardItem(pPlayer, pCreature, 41508, 1, 50);
                    break;
                case 2002:
                    RewardItem(pPlayer, pCreature, 44413, 1, 50);
                    break;
                case 2003:
                    RewardItem(pPlayer, pCreature, 54811, 1, 200);
                    break;
                case 2004:
                    RewardItem(pPlayer, pCreature, 50818, 1, 200);
                    break;
                case 2005:
                    RewardItem(pPlayer, pCreature, 50734, 1, 70);
                    break;
                case 2006:
                    RewardItem(pPlayer, pCreature, 50730, 1, 120);
                    break;
                case 2007:
                    RewardItem(pPlayer, pCreature, 50732, 1, 70);
                    break;
                case 2008:
                    RewardItem(pPlayer, pCreature, 50736, 1, 70);
                    break;
                case 2009:
                    RewardItem(pPlayer, pCreature, 50735, 1, 120);
                    break;
                case 3000:
                    pPlayer->PlayerTalkClass->ClearMenus();
                    AddGossipItemFor(pPlayer, GOSSIP_ICON_DOT, "Exp Booster: 30% quest and kill 20>VP", GOSSIP_SENDER_MAIN, 3001);
                    AddGossipItemFor(pPlayer, GOSSIP_ICON_DOT, "Return", GOSSIP_SENDER_MAIN, 999);
                    SendGossipMenuFor(pPlayer, 600000, pCreature->GetGUID());
                    return true;
                    break;
                case 3001:
                    RewardItem(pPlayer, pCreature, 90000, 1, 20);
                    break;
                case 4000:
                    RewardItem(pPlayer, pCreature, 58000, 1, 300);
                    break;
                case 5000:
                    pPlayer->PlayerTalkClass->ClearMenus();
                    AddGossipItemFor(pPlayer, GOSSIP_ICON_DOT, "Murloc Costume 20>VP", GOSSIP_SENDER_MAIN, 5001);
                    AddGossipItemFor(pPlayer, GOSSIP_ICON_DOT, "Muradin's Favor 20>VP", GOSSIP_SENDER_MAIN, 5002);
                    AddGossipItemFor(pPlayer, GOSSIP_ICON_DOT, "Core Hound Pup 15>VP", GOSSIP_SENDER_MAIN, 5003);
                    AddGossipItemFor(pPlayer, GOSSIP_ICON_DOT, "Phoenix Hatchling 15>VP", GOSSIP_SENDER_MAIN, 5004);
                    AddGossipItemFor(pPlayer, GOSSIP_ICON_DOT, "Lil' Ragnaros 15>VP", GOSSIP_SENDER_MAIN, 5005);
                    AddGossipItemFor(pPlayer, GOSSIP_ICON_DOT, "Landro's Lil' XT 15>VP", GOSSIP_SENDER_MAIN, 5006);
                    AddGossipItemFor(pPlayer, GOSSIP_ICON_DOT, "Gryphon Hatchling 15>VP", GOSSIP_SENDER_MAIN, 5007);
                    AddGossipItemFor(pPlayer, GOSSIP_ICON_DOT, "Perky Pug 15>VP", GOSSIP_SENDER_MAIN, 5008);
                    AddGossipItemFor(pPlayer, GOSSIP_ICON_DOT, "Toothy's Bucket 15>VP", GOSSIP_SENDER_MAIN, 5009);
                    AddGossipItemFor(pPlayer, GOSSIP_ICON_DOT, "Warbot Ignition Key 15>VP", GOSSIP_SENDER_MAIN, 5010);
                    AddGossipItemFor(pPlayer, GOSSIP_ICON_DOT, "The Flag of Ownership 20>VP", GOSSIP_SENDER_MAIN, 5011);
                    AddGossipItemFor(pPlayer, GOSSIP_ICON_DOT, "Return", GOSSIP_SENDER_MAIN, 9999);
                    SendGossipMenuFor(pPlayer, 600000, pCreature->GetGUID());
                    return true;
                    break;
                case 5001:
                    RewardItem(pPlayer, pCreature, 33079, 1, 20);
                    break;
                case 5002:
                    RewardItem(pPlayer, pCreature, 52201, 1, 20);
                    break;
                case 5003:
                    RewardItem(pPlayer, pCreature, 49646, 1, 15);
                    break;
                case 5004:
                    RewardItem(pPlayer, pCreature, 49646, 1, 15);
                    break;
                case 5005:
                    RewardItem(pPlayer, pCreature, 68385, 1, 15);
                    break;
                case 5006:
                    RewardItem(pPlayer, pCreature, 67128, 1, 15);
                    break;
                case 5007:
                    RewardItem(pPlayer, pCreature, 49662, 1, 15);
                    break;
                case 5008:
                    RewardItem(pPlayer, pCreature, 49912, 1, 15);
                    break;
                case 5009:
                    RewardItem(pPlayer, pCreature, 33816, 1, 15);
                    break;
                case 5010:
                    RewardItem(pPlayer, pCreature, 46767, 1, 15);
                    break;
                case 5011:
                    RewardItem(pPlayer, pCreature, 38578, 1, 20);
                    break;
                case 9999:
                    pPlayer->PlayerTalkClass->ClearMenus();
                    OnGossipHello(pPlayer, pCreature);
                    break;
                }
    
    
                return true;
            }
        };
    
        CreatureAI* GetAI(Creature* pCreature) const override
        {
            return  new my_scriptAI(pCreature);
        }
    };
    
    void AddSC_my_script()
    {
        new my_script();
    }
    - - - Updated - - -

    Sorry for double post i may have found the issue ill report back!

    - - - Updated - - -

    Got it working with this Enjoy =)
    ps. remove the goodies section as there is no case 6000 and rename the previes menu item as goodies instead

    Code:
    #include "Item.h"
    #include "DBCStores.h"
    #include "Log.h"
    #include "DatabaseEnv.h"
    #include "CharacterDatabase.h"
    #include "Player.h"
    #include "WorldSession.h"
    #include "ScriptedGossip.h"
    #include "ScriptMgr.h"
    #include "ScriptedCreature.h"
    #include "GossipDef.h"
    #include "Creature.h"
    #include "ObjectMgr.h"
    #include "ScriptedCreature.h"
    #include "PassiveAI.h"
    #include "Bag.h"
    #include "Common.h"
    #include "Config.h"
    #include "DBCStructure.h"
    #include "Define.h"
    #include "Field.h"
    #include "GameEventMgr.h"
    #include "ItemTemplate.h"
    #include "Language.h"
    #include "ObjectGuid.h"
    #include "QueryResult.h"
    #include "SharedDefines.h"
    #include "Transaction.h"
    #include <sstream>
    #include <string>
    
    class my_script : public CreatureScript
    {
    public:
        my_script() : CreatureScript("my_script") {}
    
        class my_scriptAI : public ScriptedAI
        {
        public:
            my_scriptAI(Creature* pCreature) : ScriptedAI(pCreature) {}
    
    
            bool GossipHello(Player* pPlayer) override
            {
    
                return OnGossipHello(pPlayer, me);
            }
    
            void RewardItem(Player* pPlayer, Creature* pCreature, int item, int count, int cost)
            {
                QueryResult result;
                result = LoginDatabase.PQuery("SELECT points FROM account WHERE id = '%u'", pPlayer->GetSession()->GetAccountId());
                if (!result) // check
                {
                    pPlayer->GetSession()->SendAreaTriggerMessage("I'm Broken! Contact a gamemaster!");
                    ClearGossipMenuFor(pPlayer);
                    OnGossipHello(pPlayer, pCreature);
                    return;
                }
                Field *fields = result->Fetch();
                uint32 points = fields[0].GetUInt32();
    
                if (item == 0)
                {
                    pPlayer->GetSession()->SendAreaTriggerMessage("You got %u voting points!", points);
                }
                else
                {
                    if (points < cost)
                    {
                        pPlayer->GetSession()->SendAreaTriggerMessage("You don't have enough points for this item!");
                    }
                    else
                    {
                        if (pPlayer->AddItem(item, count))
                        {
                            LoginDatabase.PQuery("Update account Set points = points - '%u' WHERE id = '%u'", cost, pPlayer->GetSession()->GetAccountId());
                            pPlayer->GetSession()->SendAreaTriggerMessage("Your points are taken and your item is given!!!");
                        }
                        else
                        {
                            pPlayer->GetSession()->SendAreaTriggerMessage("Item can't be given(your bag is full or you already got the item!)!");
                        }
    
                    }
                }
                pPlayer->PlayerTalkClass->ClearMenus();
                OnGossipHello(pPlayer, pCreature);
            }
    
            bool GossipSelect(Player* pPlayer, uint32 /*menu_id*/, uint32 gossipListId) override
            {
                uint32 sender = pPlayer->PlayerTalkClass->GetGossipOptionSender(gossipListId);
                uint32 action = pPlayer->PlayerTalkClass->GetGossipOptionAction(gossipListId);
                return OnGossipSelect(pPlayer, me, sender, action);
            }
    
            bool OnGossipHello(Player* pPlayer, Creature* pCreature)
            {
                AddGossipItemFor(pPlayer, GOSSIP_ICON_CHAT, "Homuch voting points do i have ?", GOSSIP_SENDER_MAIN, 1000);
                AddGossipItemFor(pPlayer, GOSSIP_ICON_CHAT, "Mounts", GOSSIP_SENDER_MAIN, 2000);
                AddGossipItemFor(pPlayer, GOSSIP_ICON_CHAT, "Starter Items", GOSSIP_SENDER_MAIN, 3000);
                AddGossipItemFor(pPlayer, GOSSIP_ICON_CHAT, "Promo 200 Token 250>VP", GOSSIP_SENDER_MAIN, 4000);
                AddGossipItemFor(pPlayer, GOSSIP_ICON_CHAT, "Promo 200 Token 250>VP", GOSSIP_SENDER_MAIN, 5000);
                AddGossipItemFor(pPlayer, GOSSIP_ICON_CHAT, "Goodies", GOSSIP_SENDER_MAIN, 6000);
                SendGossipMenuFor(pPlayer, DEFAULT_GOSSIP_MESSAGE, pCreature->GetGUID());
                return true;
            }
    
            bool OnGossipSelect(Player* pPlayer, Creature* pCreature, uint32 /*uiSender*/, uint32 uiAction)
            {
                ClearGossipMenuFor(pPlayer);
    
                switch (uiAction)
                {
                case 1000:
                    RewardItem(pPlayer, pCreature, 0, 0, 0);
                    break;
                case 2000:
                    pPlayer->PlayerTalkClass->ClearMenus();
                    AddGossipItemFor(pPlayer, GOSSIP_ICON_DOT, "Mechano-hog 50>VP", GOSSIP_SENDER_MAIN, 2001);
                    AddGossipItemFor(pPlayer, GOSSIP_ICON_DOT, "Mekgineer's Chopper 50>VP", GOSSIP_SENDER_MAIN, 2002);
                    AddGossipItemFor(pPlayer, GOSSIP_ICON_DOT, "Celestial Steed 200>VP", GOSSIP_SENDER_MAIN, 2003);
                    AddGossipItemFor(pPlayer, GOSSIP_ICON_DOT, "Invincible's Reins 200>VP", GOSSIP_SENDER_MAIN, 2004);
                    AddGossipItemFor(pPlayer, GOSSIP_ICON_DOT, "Invincible's Reins 200>VP", GOSSIP_SENDER_MAIN, 2003);
                    AddGossipItemFor(pPlayer, GOSSIP_ICON_DOT, "Return", GOSSIP_SENDER_MAIN, 9999);
                    SendGossipMenuFor(pPlayer, DEFAULT_GOSSIP_MESSAGE, pCreature->GetGUID());
                    return true;
                    break;
                case 2001:
                    RewardItem(pPlayer, pCreature, 41508, 1, 50);
                    break;
                case 2002:
                    RewardItem(pPlayer, pCreature, 44413, 1, 50);
                    break;
                case 2003:
                    RewardItem(pPlayer, pCreature, 54811, 1, 200);
                    break;
                case 2004:
                    RewardItem(pPlayer, pCreature, 50818, 1, 200);
                    break;
                case 2005:
                    RewardItem(pPlayer, pCreature, 50734, 1, 70);
                    break;
                case 2006:
                    RewardItem(pPlayer, pCreature, 50730, 1, 120);
                    break;
                case 2007:
                    RewardItem(pPlayer, pCreature, 50732, 1, 70);
                    break;
                case 2008:
                    RewardItem(pPlayer, pCreature, 50736, 1, 70);
                    break;
                case 2009:
                    RewardItem(pPlayer, pCreature, 50735, 1, 120);
                    break;
                case 3000:
                    ClearGossipMenuFor(pPlayer);
                    AddGossipItemFor(pPlayer, GOSSIP_ICON_DOT, "Exp Booster: 30% quest and kill 20>VP", GOSSIP_SENDER_MAIN, 3001);
                    AddGossipItemFor(pPlayer, GOSSIP_ICON_DOT, "Return", GOSSIP_SENDER_MAIN, 999);
                    SendGossipMenuFor(pPlayer, DEFAULT_GOSSIP_MESSAGE, pCreature->GetGUID());
                    return true;
                    break;
                case 3001:
                    RewardItem(pPlayer, pCreature, 90000, 1, 20);
                    break;
                case 4000:
                    RewardItem(pPlayer, pCreature, 58000, 1, 300);
                    break;
                case 5000:
                    ClearGossipMenuFor(pPlayer);
                    AddGossipItemFor(pPlayer, GOSSIP_ICON_DOT, "Murloc Costume 20>VP", GOSSIP_SENDER_MAIN, 5001);
                    AddGossipItemFor(pPlayer, GOSSIP_ICON_DOT, "Muradin's Favor 20>VP", GOSSIP_SENDER_MAIN, 5002);
                    AddGossipItemFor(pPlayer, GOSSIP_ICON_DOT, "Core Hound Pup 15>VP", GOSSIP_SENDER_MAIN, 5003);
                    AddGossipItemFor(pPlayer, GOSSIP_ICON_DOT, "Phoenix Hatchling 15>VP", GOSSIP_SENDER_MAIN, 5004);
                    AddGossipItemFor(pPlayer, GOSSIP_ICON_DOT, "Lil' Ragnaros 15>VP", GOSSIP_SENDER_MAIN, 5005);
                    AddGossipItemFor(pPlayer, GOSSIP_ICON_DOT, "Landro's Lil' XT 15>VP", GOSSIP_SENDER_MAIN, 5006);
                    AddGossipItemFor(pPlayer, GOSSIP_ICON_DOT, "Gryphon Hatchling 15>VP", GOSSIP_SENDER_MAIN, 5007);
                    AddGossipItemFor(pPlayer, GOSSIP_ICON_DOT, "Perky Pug 15>VP", GOSSIP_SENDER_MAIN, 5008);
                    AddGossipItemFor(pPlayer, GOSSIP_ICON_DOT, "Toothy's Bucket 15>VP", GOSSIP_SENDER_MAIN, 5009);
                    AddGossipItemFor(pPlayer, GOSSIP_ICON_DOT, "Warbot Ignition Key 15>VP", GOSSIP_SENDER_MAIN, 5010);
                    AddGossipItemFor(pPlayer, GOSSIP_ICON_DOT, "The Flag of Ownership 20>VP", GOSSIP_SENDER_MAIN, 5011);
                    AddGossipItemFor(pPlayer, GOSSIP_ICON_DOT, "Return", GOSSIP_SENDER_MAIN, 9999);
                    SendGossipMenuFor(pPlayer, DEFAULT_GOSSIP_MESSAGE, pCreature->GetGUID());
                    return true;
                    break;
                case 5001:
                    RewardItem(pPlayer, pCreature, 33079, 1, 20);
                    break;
                case 5002:
                    RewardItem(pPlayer, pCreature, 52201, 1, 20);
                    break;
                case 5003:
                    RewardItem(pPlayer, pCreature, 49646, 1, 15);
                    break;
                case 5004:
                    RewardItem(pPlayer, pCreature, 49646, 1, 15);
                    break;
                case 5005:
                    RewardItem(pPlayer, pCreature, 68385, 1, 15);
                    break;
                case 5006:
                    RewardItem(pPlayer, pCreature, 67128, 1, 15);
                    break;
                case 5007:
                    RewardItem(pPlayer, pCreature, 49662, 1, 15);
                    break;
                case 5008:
                    RewardItem(pPlayer, pCreature, 49912, 1, 15);
                    break;
                case 5009:
                    RewardItem(pPlayer, pCreature, 33816, 1, 15);
                    break;
                case 5010:
                    RewardItem(pPlayer, pCreature, 46767, 1, 15);
                    break;
                case 5011:
                    RewardItem(pPlayer, pCreature, 38578, 1, 20);
                    break;
                case 9999:
                    ClearGossipMenuFor(pPlayer);
                    OnGossipHello(pPlayer, pCreature);
                    break;
                }
    
    
                return true;
            }
        };
    
        CreatureAI* GetAI(Creature* pCreature) const override
        {
            return  new my_scriptAI(pCreature);
        }
    };
    
    void AddSC_my_script()
    {
        new my_script();
    }




Advertisement