Hammerhand

Member
I'm making some training weapons that I want to be craftable using Carpentry, which was the easy part. The only problem I'm having is setting them up to use ONLY RegularWood for the crafting of them. I dont want them with a bunch of attributes, damages & durability (they ARE just training weapons after all). Putting in RegularWood instead of Board or Log in the crafting menu obviously doesnt work. I know they could just be spawned as scripted which I dont want either. Any suggestions?
 
Been a while since I played with daat's or any other OWLTR, but could you just put something in the constructor that would force the Craft Resource Type to be "Regular Wood" no matter how it's crafted? Or, override CraftResource or Resource, or whatever it is?
 
Not sure, but this isnt exactly for OWLTR. I'm thinking this could be for any server. If I can get it to work on a reg server, then I'll tackle any issues with OWLTR it may have.
 
My bad. Still, I think it applies to regular crafting too. CraftResource should be overridable I would think.
 
Tried this in one of the practice weapon scripts..

Code:
public override CraftResource Resource { get { return CraftResource.RegularWood; } }

and got this..

Code:
RunUO - [www.runuo.com] Version 2.2, Build 4782.3756
Core: Running on .NET Framework Version 2.0.50727
Core: Running with arguments: -debug
Core: Optimizing for 6 64-bit processors
Scripts: Compiling C# scripts...failed (1 errors, 0 warnings)
Errors:
+ Customs/Wooden Practice Swords/WoodenBroadsword.cs:
    CS0506: Line 28: 'Server.Items.WoodenBroadsword.Resource.get': cannot overri
de inherited member 'Server.Items.BaseWeapon.Resource.get' because it is not mar
ked virtual, abstract, or override
Scripts: One or more scripts failed to compile or no script files were found.
- Press return to exit, or R to try again.
 
I had a similar problem with bows once, so I ended setting the ressource directly in the constructor.
Probably not what you want, as i only have one type of wood xD
 
*SOLVED* And I aint gonna tell ya' how I dood it either.... Yer just gonna have to look at the scripts when I release em. :p I basically did it Hammerhand style... I added stuff to make them slightly harder to craft with more steps. :D
 
Hey,
I know this thread is old, but I'm struggling with something similar and maybe someone could help.

What I want to achieve is that when there is an item that requires Valorite Ingots to make, you can only make it with those ingots. You can't use Iron, Copper or anything else.

I tried this in DefBlacksmithy.cs, but it doesn't seem to work:

Code:
AddCraft(typeof(Longsword), 1011081, 1023937, 28.0, 78.0, typeof(ValoriteIngot), 1044036, 12, 1044037);

All it does is that it requires Valorite Ingots in your inventory, but then creates the item with whatever material you selected from the resources list in the menu.

I can't figure out how to make it work and it really messes with the idea of our crafting system.
No major changes in crafting were made. The whole idea is about using specific resources for specific items.

Any help, please?
[doublepost=1526945371][/doublepost]It seems that craftable artifacts work with a similar method.
They are always crafted as "Iron" no matter which material you use.

Still, I can't figure out how that works and how to apply it in my own game.
 
tried this in DefBlacksmithy.cs, but it doesn't seem to work:
I think you have a problem with SubRes.
Check this lines in your file:
Code:
            // Set the overridable material
            SetSubRes(typeof(IronIngot), 1044022);

            // Add every material you want the player to be able to choose from
            // This will override the overridable material
            AddSubRes(typeof(IronIngot), 1044022, 00.0, 1044036, 1044267);
            AddSubRes(typeof(DullCopperIngot), 1044023, 65.0, 1044036, 1044268);
            AddSubRes(typeof(ShadowIronIngot), 1044024, 70.0, 1044036, 1044268);
            AddSubRes(typeof(CopperIngot), 1044025, 75.0, 1044036, 1044268);
            AddSubRes(typeof(BronzeIngot), 1044026, 80.0, 1044036, 1044268);
            AddSubRes(typeof(GoldIngot), 1044027, 85.0, 1044036, 1044268);
            AddSubRes(typeof(AgapiteIngot), 1044028, 90.0, 1044036, 1044268);
            AddSubRes(typeof(VeriteIngot), 1044029, 95.0, 1044036, 1044268);
            AddSubRes(typeof(ValoriteIngot), 1044030, 99.0, 1044036, 1044268);

            SetSubRes2(typeof(RedScales), 1060875);

            AddSubRes2(typeof(RedScales), 1060875, 0.0, 1053137, 1044268);
            AddSubRes2(typeof(YellowScales), 1060876, 0.0, 1053137, 1044268);
            AddSubRes2(typeof(BlackScales), 1060877, 0.0, 1053137, 1044268);
            AddSubRes2(typeof(GreenScales), 1060878, 0.0, 1053137, 1044268);
            AddSubRes2(typeof(WhiteScales), 1060879, 0.0, 1053137, 1044268);
            AddSubRes2(typeof(BlueScales), 1060880, 0.0, 1053137, 1044268);
If they are not there, try to add.
 
Hey, thanks for your reply.
I have these lines there, as they are there by default.

The problem seems to lay elsewhere.
No matter which material you assign as main resource for a specific item, it will always create it with the material you chose from the list.
Please take a look at the longsword example in my post above.
It will consume those valorite ingots from your backpack and won't let you craft the item if you don't have them, but the item itself will be created with whatever resource you choose from the list in the blacksmith's menu.

In this case, I want players to be unable to craft Longsword with any other metal than valorite... and I fail to get it to work.

There has to be a workaround... maybe an override to set the item to be always created with a certain metal, no matter what you choose?
Any ideas would be appreciated.
Thanks!
 
Maybe try adding this to the longsword?
Code:
        public override CraftResource DefaultResource
        {
            get
            {
                return CraftResource.ValoriteIngot;
            }
        }
 
BaseArmor.cs has this, maybe try adding it to BaseWeapon?
Code:
        [CommandProperty(AccessLevel.GameMaster)]
        public CraftResource Resource
        {
            get
            {
                return m_Resource;
            }
            set
            {
                if (m_Resource != value || m_Resource == DefaultResource)
                {
                    UnscaleDurability();
                    CraftResource old = m_Resource;

                    m_Resource = value;

                    ApplyResourceResistances(old);

                    if (CraftItem.RetainsColor(GetType()))
                    {
                        Hue = CraftResources.GetHue(m_Resource);
                    }

                    Invalidate();
                    InvalidateProperties();

                    if (Parent is Mobile)
                        ((Mobile)Parent).UpdateResistances();

                    ScaleDurability();
                }
            }
        }
 
I think this is getting way off base.

Take a look at Juzzver's post regarding Sub Resources. He was looking at it backwards, but was actually pointing you to the right place.

What the SetSubRes lines do is allow you to override the resource listed there by using the AddSubRes lines following.

If you want to avoid overrides altogether, all you need to do is remove every "SetSubRes" and "AddSubRes" line. This will force the crafting system to use exactly the resources you have specified in the lines above.

To see an example of this, look at DefCooking. It does not use any SetSubRes or AddSubRes lines because there are not multiple colors of fish and meat that can be substituted for the ones in the recipes. It requires you to use exactly the recipe ingredients specified.
 
Thanks for the tips, I'm still struggling with it.

@Lokai, removing SetSubRes and AddSubRes lines causes the game to crash when using smith's hammer.


Maybe I explained myself incorrectly.

This is the problem:
(don't pay attention to the names, these are just cliloc modifications for easier testing
I don't have any custom resources or heavy changes in crafting)


upload_2018-5-23_16-28-48.png

1. As you can see, the Longsword requires Valorite Ingots to be crafted.
You will not be able to craft it without valorite ingots. You can't use iron, dull copper, bronze or whatever. Only valorite - this is fine and working. So far, so good.


upload_2018-5-23_16-33-46.png

*I only have 100 valorite ingots in my inventory. Nothing else.


2. From the resource list I chose Bronze.

upload_2018-5-23_16-35-54.png


3. I then proceed to craft the longsword.

upload_2018-5-23_16-40-19.png

As you can see, the Resource property on the crafted longsword got replaced by bronze, becouse that's what I chose from the list, even though it consumed valorite ingots.

And basically that's what I'm trying to avoid. That if something is supposed to be crafted with valorite, it can only come out as Resource = Valorite, no matter what you choose. This is important, becouse even if I disable the list, there's always a default metal to craft with (it would be iron I suppose).


Thanks for your attention.
 
Last edited:
Oooookay, I found a work around for this.

Code:
       [Constructable]
       public Longsword()
           : base(0xF61)
       {
           this.Weight = 7.0;
             Timer.DelayCall(TimeSpan.FromSeconds(0.1), delegate { Resource = CraftResource.Bronze; });
       }


Now, each time a longsword is created, it will come out as bronze made.

My issue got officialy fixed.

Thank you all for your input, especially @Juzzver, as you showed me that this function existed ;)
 
This is a horrible approach.

I would go this way with the current crafting system. (that is an better way at least)
If you add an check in the craftitem.cs, inside the Craft method.
like
Code:
if (m_Type != typeof(Longsword) || typeRes == typeof(ValoriteIngot))
and also this part
Code:
    else
   {
       from.EndAction(typeof(CraftSystem));
       from.SendGump(new CraftGump(from, craftSystem, tool, "You need to use the right material for this"));
   }

then it would look like this kinda

Code:
if (!RequiresMechanicalLife || (from is PlayerMobile && ((PlayerMobile)from).MechanicalLife))
{
    if (m_Type != typeof(Longsword) || typeRes == typeof(ValoriteIngot))
    {
        int badCraft = craftSystem.CanCraft(from, tool, m_Type);


        if (badCraft <= 0)
        {
          ...
       }
       else
       {
           from.EndAction(typeof(CraftSystem));
           from.SendGump(new CraftGump(from, craftSystem, tool, badCraft));
       }
   }
    else
   {
       from.EndAction(typeof(CraftSystem));
       from.SendGump(new CraftGump(from, craftSystem, tool, "You need to use the right material for this"));
   }

then you would get the behaviour you want. But the default craft system isnt made to do it that way really so its still hacky.
 
Last edited:
Sorry edited the post a little, so its horrible because for every single item you create that is a longsword, you will then call an timer.

first scenario. you craft the item it and then it will create an timer that will then after some time change its material.
second scenario. you kill monsters that drop a logsword, so you create a timer that changes the material after some time.
third scenario. you do a champion spawn, the monsters from the spawn have loot and they may get a lot of longswords. So you would create a lot of timers just to change the material.
fourth scenario. you add a longsword. It then changes the material type even if you specify it during your creation.

that is just what I had in mind, I am sure there are more of that kind.
 
so its horrible because for every single item you create that is a longsword, you will then call an timer.
The timer is the easiest solution for the user. The timer will terminate immediately after the specified tick, in this case it is 0.1 second. In addition, the timer performs its action in a separate thread, which will not affect the main thread in any way.

I will agree with you only in one that this is a crutch method. But it is the simplest and its load will not affect the server, even in the case of ChampionSpawn and other examples.

If you make dump timers, you'll see that the normal presence of creatures in the game creates a thousand times more load, and each of them is constantly running a cyclic timer.

Anyway, I have given two examples of solving the problem that will not cause the user difficulties in the implementation. The first is a one - line timer, and the second is polymorphism (a more appropriate method if you follow the OOP rules).
https://www.servuo.com/threads/disable-hue-retaining.9498/#post-58320
 
In this case I don't mind it being horrible in that way.
I'm going to use it on some special custom weapons, the longsword was only an example.
Thanks for the tips anyway, I appreciate it.
 
The timer is the easiest solution for the user. The timer will terminate immediately after the specified tick, in this case it is 0.1 second. In addition, the timer performs its action in a separate thread, which will not affect the main thread in any way.

I will agree with you only in one that this is a crutch method. But it is the simplest and its load will not affect the server, even in the case of ChampionSpawn and other examples.

If you make dump timers, you'll see that the normal presence of creatures in the game creates a thousand times more load, and each of them is constantly running a cyclic timer.

Anyway, I have given two examples of solving the problem that will not cause the user difficulties in the implementation. The first is a one - line timer, and the second is polymorphism (a more appropriate method if you follow the OOP rules).
https://www.servuo.com/threads/disable-hue-retaining.9498/#post-58320

You are not wrong that it will not have an huge impact but at the same time the timer itself will create garbage causing the gc to run faster. At least I dont think the timers are actually pooled (could be wrong).

to override the resource itself doesnt make sense either. Lets say he wants to add an longsword himself but made from a different material. Well in that case he cant since its fixed to the overriden value. Still the timer in this case is far from clean and sooner or later will bite you (like when you have a child object of an longsword, wich will get the same timer running since they would call the base constructor)
 
You use a tank track to replace a car wheel, yes it works, but it's an overkill workaround.
It might be better to add an exception directly on the crafting sequence rather than setting it afterward.
 
You are not wrong that it will not have an huge impact but at the same time the timer itself will create garbage causing the gc to run faster. At least I dont think the timers are actually pooled (could be wrong).
If understand how the garbage collector works, then again, there is nothing critical here. All that the collector will do is mark the objects to be deleted with indexes, and cleaning will start only when GC need to free up memory. In addition, in the first two generations (ephemeral), garbage collection is done in the background thread (starting with 4.0 .NET Framework). We're not programming a missile here to go into that kind of detail. :)

to override the resource itself doesnt make sense either. Lets say he wants to add an longsword himself but made from a different material. Well in that case he cant since its fixed to the overriden value.
Everything depends on the task. Smearing dependencies through the Assembly is also not the best solution. The reason is simple, the usual user simply will not find it then.

Still the timer in this case is far from clean and sooner or later will bite you (like when you have a child object of an longsword, wich will get the same timer running since they would call the base constructor)
Here you are right, but the solution is just as simple :)
Code:
            if (this.GetType() == typeof(Longsword))
                Timer.DelayCall(TimeSpan.FromSeconds(0.1), delegate { Resource = CraftResource.Bronze; });

@Piotr, if you are still using this method, you should update it by adding a check for the type of item you are creating. I have given corrections in the same post.
 
I think this is getting way off base.

Take a look at Juzzver's post regarding Sub Resources. He was looking at it backwards, but was actually pointing you to the right place.

What the SetSubRes lines do is allow you to override the resource listed there by using the AddSubRes lines following.

If you want to avoid overrides altogether, all you need to do is remove every "SetSubRes" and "AddSubRes" line. This will force the crafting system to use exactly the resources you have specified in the lines above.

To see an example of this, look at DefCooking. It does not use any SetSubRes or AddSubRes lines because there are not multiple colors of fish and meat that can be substituted for the ones in the recipes. It requires you to use exactly the recipe ingredients specified.

Hi Loki, I tried your suggest but on the another thing, I have not disabled the setsubress and addsubress.
I would like to leave the weapons only for Silver and Golden material, BUT leaving the armors for all materials.
So I create the defcooking addcraft, instead "Ingredients" I putted Gold Weapon and Silver Weapon , and then inside putted the all weapons axes,sword ecc ecc.
Seems works but when I choose a material on blacksmith gump even if I have 0 quantity in this case Mithriel and I craft a Gold Weapon > Broadsword, I craft a Mithriel Broadsword instead the Golden Broadsword… do you know how fix? o someone ?

Thanks!
 

Active Shards

Donations

Total amount
$50.00
Goal
$1,000.00
Back