• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

[SOLVED] Openable Bag Script

Status
Not open for further replies.

Visa

Sexy Member
I'm no expert at C++, but if anyone has any helpful hints on how to do the following it's much appreciated.

Basically when you have a /custom/ bag that has /custom/ loot in it that can be opened, it will properly open. But when the bag is stackable to per say 20... right clicking the entire stack of 20 will consume the loot of only 1 actual bag loot.

Per say if we had a script for the bag that would only open 1 of the 20 bags therefore allowing you to spam right click the entire stack and get the loot for all 20 bags.

I know a few functions in c++ and I have tried editing templates of releases relevant to the itemscript but have come up with no luck

Once again, any help is appreciated.


This script is nearly half sufficent, yes I made this but I threw it together sloppy and not knowing which function to replace HasItemCount with to supply the OnUse of the item.


Code:
#include "ScriptPCH.h"

#define bag_id 6000
#define loot1_id 100000
#define loot2_id 100001
#define loot3_id 100002


class bag_script : public ItemScript
{
public:
	bag_script() : ItemScript("bag_script") { }

	bool OnUse(Player* player, Item* item, SpellCastTargets const& /*targets*/)
	{
           if (player->HasItemCount(bag_id, 1, false));
                {
                       player->AddItem(loot1_id, 10);
                       player->AddItem(loot2_id, 10);
                       player->AddItem(loot2_id, 10);
                       return true;
                }
                else
                {
                       player->GetSession->SendNotification("You should not see this");
                       return false;
                }
          }
};

void AddSC_bag_script()
{
	new bag_script();
}

i'm starting to think I don't even need the if else statements, simply
Code:
	bool OnUse(Player* player, Item* item, SpellCastTargets const& /*targets*/)

                       player->AddItem(loot1_id, 10);
                       player->AddItem(loot2_id, 10);
                       player->AddItem(loot2_id, 10);
                       return true;

I have no idea how to register the script to open this 'bag' containing loot


This is for a 3.3.5 TrinityCore
 

Tommy

Founder
Don't have the bags stackable? Pretty simple solution. Why is the bag stackable in the first place? If it's an issue, as I said, don't have the bag stackable and that would lift the point in trying to fix it. Nobody has even brought up this issue so I wouldn't know how to fix it other than not making the bag stack.

I don't see a point in the HasItemCount statement since AddItem is a boolean and if it can/can't add the item you can check like so:

Code:
if (player->AddItem(1, 1))
    // Success
else
    // Could not add the item

However, that's an example. Nothing more. The second way you have it is fine:

Code:
    player->AddItem(loot1_id, 10);
    player->AddItem(loot2_id, 10);
    player->AddItem(loot2_id, 10);
 

Visa

Sexy Member
Yes but I have it set to drop quite a few bags from just one instance, and it would spam the players inventory. Making the bag contain higher loot quantity and less drop rate is always an option, yes but that would depreciate the value of the items contained in the bag.

I know this script exists out there I just don't know how it's done quite yet. I'm very determined.

 

Visa

Sexy Member
Found the correct arguments to call for this function, script works now 100%. Can mark this as solved now

All help was appreciated!
 
Status
Not open for further replies.
Top