Welcome to AC Web.
Results 1 to 4 of 4
  1. #1

    Example how to add item by c++


    REGISTER! (FREE)
    Registered members see less ads
    and also gain access to other great features.
    i need little example, how to add item to backpack by gossip menu

  2. #2
    Usage
    Code:
    player->AddItem(ITEM_ENTRY, 1);
    Header
    Code:
    bool AddItem(uint32 itemId, uint32 count);
    - - - Updated - - -

    I'm really rusty with TrinityCore but I believe this template would make it possible for you to make any gossip

    Code:
    #include "ScriptedCreature.h"
    #include "ScriptedGossip.h"
    #include "GameEventMgr.h"
    #include "WorldSession.h"
    #include "DatabaseEnv.h"
    #include "ScriptMgr.h"
    #include "Player.h"
    
    
    class example_gossip : public CreatureScript
    {
    public:
    	example_gossip() : CreatureScript("example_npc") { }
    
    	struct example_gossipAI : public ScriptedAI
    	{
    		example_gossipAI(Creature* creature) : ScriptedAI(creature) { }
                    // Happens when player clicks on the npc
    		bool GossipHello(Player* player) override
    		{
    			return false;
    		}
                    // Happens when player press a menu item
    		bool GossipSelect(Player* player, uint32 /*menuId*/, uint32 gossipListId) override
    		{
                            player->AddItem(55, 1);
    			return false;
    		}
    
                    // Happens if you prompt the player with a codebox
    		bool GossipSelectCode(Player* /*player*/, uint32 /*menuId*/, uint32 /*gossipListId*/, char const* /*code*/)
    		{
    			return false;
    		}
    
    	};
    
    	CreatureAI* GetAI(Creature* creature) const override
    	{
    		return new example_gossipAI(creature);
    	}
    };
    
    void AddSC_BuildNPC()
    {
    	new example_gossip();
    }
    Last edited by remx; 12-05-2018 at 12:29 PM.

  3. #3
    thanks, so how to remove items in bag ???

  4. #4


    Join Date
    Mar 2014
    Location
    http://strong-wow.com
    Posts
    1,117

    REGISTER! (FREE)
    Registered members see less ads
    and also gain access to other great features.
    PHP Code:
    #include "ScriptedCreature.h"
    #include "ScriptedGossip.h"
    #include "WorldSession.h"
    #include "ScriptMgr.h"
    #include "Player.h"


    class example_gossip : public CreatureScript
    {
    public:
        
    example_gossip() : CreatureScript("example_npc") { }

        
    struct example_gossipAI : public ScriptedAI
        
    {
            
    example_gossipAI(Creaturecreature) : ScriptedAI(creature) { }
            
    // Happens when player clicks on the npc
            
    bool GossipHello(Playerplayeroverride
            
    {
                return 
    false;
            }
            
    // Happens when player press a menu item
            
    bool GossipSelect(Playerplayeruint32 /*menuId*/uint32 /*gossipListId*/override
            
    {
                if (
    player->HasItemCount(551false)) //If player has itemid 55 with count of 1 and NOT in bank
                

                    
    player->CLOSE_GOSSIP_MENU();
                    
    player->AddItem(551); //Add item 55 with count of 1
                    
    player->DestroyItemCount(551truefalse); //Destroy item 55, with count of 1 right away
                    
    return true;
                }
                            return 
    false;
                    }
            
    // Happens if you prompt the player with a codebox
            
    bool GossipSelectCode(Player/*player*/uint32 /*menuId*/uint32 /*gossipListId*/char const* /*code*/)
            {
                return 
    false;
            }

        };

        
    CreatureAIGetAI(Creaturecreature) const override
        
    {
            return new 
    example_gossipAI(creature);
        }
    }; 
    PHP Code:
    if (player->HasItemCount(Entry ID1false)) 
    PHP Code:
    player->DestroyItemCount(Entry ID1truefalse); 
    Last edited by XxTryXx; 12-05-2018 at 03:27 PM.

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •