CLASnipe

Member
Hello my server is ServUo I have this nice backpack script but it seems that there is a little bug with them which I would like to fix.

Script works great but if you continue to place bags within bags eventually it can make you lose weight. So I would like to make it to where you cant place this bag in another container or itself other then in the players main inventory If anyone knows how I can do this thank you
 

Attachments

  • BackpackOfReduction.cs
    2.6 KB · Views: 17
  • Like
Reactions: ExX
C#:
public override bool OnDragDrop(Mobile from, Item dropped)

        {

            if (dropped is Container)

            {

                from.SendMessage("That container can not be placed inside another container");

                return false;

            }

        }

Adding that should achieve your goal.
 
C#:
public override bool OnDragDrop(Mobile from, Item dropped)

        {

            if (dropped is Container)

            {

                from.SendMessage("That container can not be placed inside another container");

                return false;

            }

        }

Adding that should achieve your goal.

adding that returns an error

Errors:
+ Custom/Bruiser/BackpackOfReduction.cs:
CS0161: Line 63: 'BackpackOfReduction.OnDragDrop(Mobile, Item)': not all code paths return a value
Scripts: One or more scripts failed to compile or no script files were found.
- Press return to exit, or R to try again.
 
Sorry about that, missed a line.

C#:
                public override bool OnDragDrop(Mobile from, Item dropped)
        {
            if (dropped is Container)
            {
                from.SendMessage("That item is not allowed in this container");
                return false;
            }
            return base.OnDragDrop(from, dropped);
        }

Here's the working file that compiles. Hopefully works as intended. I'm a bit rusty after being gone for a few years.
 

Attachments

  • BackpackOfReduction.cs
    2.9 KB · Views: 5
I am sorry CLASnipe, that's the code I have used in some of my older files that used to work fine. I've been gone for a couple years and it seems something has changed. Hopefully someone can help cause now I will have a couple scripts to update as well. I don't understand why it wouldn't work any longer without tossing an error.
 
The BackpackOfReduction technically is a backpack, which may or may not be considered a Container (I didn't look that far).

You could try changing the check to:
Code:
if (dropped is BackpackOfReduction)

just to see if that gets you closer to your goal. Then you can refine the statement to include Container | Backpack and anything similar.
 
  • Like
Reactions: ExX
Good point, would explain why my bags of weightlessness works fine with the script, but they are just normal bags not backpacks. Keep us posted CLASnipe.
 
ok so making it

if (dropped is BackpackOfReduction)

stops me from drag dropping onto another backpack of reduction. but this doesn't stop me from opening the backpack and just placing it in there
 
There's another function called OnDragDropInto that handles that action and it needs the same set of checks. You should be able to copy and paste the OnDragDrop section you already have, change it to OnDragDropInto, and leave everything else the same.
 
public override bool OnDragDropInto(Mobile from, Item dropped)
{
if (dropped is BackpackOfReduction)
{
from.SendMessage("That item is not allowed in this container");
return false;
}
return base.OnDragDropInto(from, dropped);
}

so something like this if so it leaves me an error

Errors:
+ Custom/Bruiser/BackpackOfReduction.cs:
CS0115: Line 74: 'BackpackOfReduction.OnDragDropInto(Mobile)': no suitable method found to override
Scripts: One or more scripts failed to compile or no script files were found.
 
That override was a little more involved -- that's what I get for making assumptions!

Anyway, here's the working file. I have it set to disallow other BackpackOfReduction and Container, but the other "if" statement is commented out if you want to use just that restriction.
 

Attachments

  • BackpackOfReduction.cs
    3.3 KB · Views: 10
  • Like
Reactions: ExX
Hi,
I've this pack also but never used the reduction so I was curious why putting packs in packs would be a problem.
I think the real problem is not the packs in pack but what the updatetotals code tries to do (its correcting the assumption that added weight results in an weight increase equal to it for all containers that contain the item)
If you set the pack to 80% reduction and add small amounts of apples, then the correction is each time 0.
(0.2+0.2+0.2+0.2+0.2==1, but what if you round 0.2 down to 0?)
But if you remove the total stack of apples, the correction is no longer 0.

The attached code tries to address this by using the delta as seen by the totalweight.
Now it updates by one at the last apple. (0.8(0) to 1)
 

Attachments

  • BackpackOfReduction.cs
    3.5 KB · Views: 22
  • Like
Reactions: ExX

Active Shards

Donations

Total amount
$0.00
Goal
$1,000.00
Back