RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

World Announcement on Item Crafted Help

Lord_Velius

Sorceror
I have gotten some help previously from some friends on this and I'm rather stuck still, so I figured I'd ask the community here for a poke in the right direction.

I have a few custom artifacts in my server that are craftable, but I want it to send a worldbroadcast message when one is crafted. It uses a custom craft tool, but I believe its still based on CraftSystem.cs

I was told the best spot to place it in would be the CreateItem section of the craft.

So I put in some code in that section to list said item, and yet on craft I don't get a message, so I'm figuring I'm overlooking something simple. Maybe someone here can help point me in the right direction.

I placed my code under
Code:
if (craftItem != null)
{
}

My code is this:

Code:
                if (type is ItemName)
               {
                   World.Broadcast(38, false, from.Name + " has crafted a ItemName");
               }
 

Khaz

Knight
Do you mean you put the snippet in CraftSystem.CreateItem(...)? If so, maybe the type is not what you're expecting. You can add the following to get the type and see if it's pointing to something else...
Code:
Console.WriteLine("Type crafted: {0}", type.FullName);
(of course, add this before your new if condition)
 

Lord_Velius

Sorceror
Let me give it a go and see what the console says. Good idea, this should help narrow down the faults on this.
I'll post results following.

As to where I put it, yes indeed I put it in craftsystem.cs in the CreateItem(ect ect) section of Craftsystem.cs
 

Lord_Velius

Sorceror
Ok so it looks good on the console.

Type crafted: Server.Items.SkullHammer9

and my if statement is

if (type is SkullHammer9)

Shoudl I redo the if statement? Or make it in a different way?
 

Khaz

Knight
It should be working... try moving the console print inside your if condition - that will tell you if the type check is succeeding or not (hint: it's probably not).

On a side note, you probably want to do all this in CraftItem.CompleteCraft(...) around line 1190. If you don't, then you're broadcasting before the item was successfully crafted, meaning the craft could fail due to lack of skills, resources, etc.
 

Lord_Velius

Sorceror
It should be working... try moving the console print inside your if condition - that will tell you if the type check is succeeding or not (hint: it's probably not).

On a side note, you probably want to do all this in CraftItem.CompleteCraft(...) around line 1190. If you don't, then you're broadcasting before the item was successfully crafted, meaning the craft could fail due to lack of skills, resources, etc.


I'll check the if conditional and see if it's going through.
I'm also thinking it's not going through.
 

Lord_Velius

Sorceror
I put the message in the if statement and its not going through the statement.
No console message.
So that would mean my if statement is invalid.

Since it's invalid, what should I use instead?

**edit**
Making some progress now, I've got it trying to do it.
Now it's crashing me when I craft it, so progress is being made.
I'm running in debug to see exactly whats causing the error so I can go from there.

**edit**
found the crash and its unrelated to
if (type is ItemName)

It's from me changing type to typeRes for the console when I was doing a check of all the variables.
 

daat99

Moderator
Staff member
Can you post your latest code (inside code tags) and describe your issue again?

It's kinda hard to understand what is your current problem from the previous posts.
 

Lord_Velius

Sorceror
Code:
        public void CreateItem(Mobile from, Type type, Type typeRes, BaseTool tool, CraftItem realCraftItem)
        {
            // Verify if the type is in the list of the craftable item
            CraftItem craftItem = this.m_CraftItems.SearchFor(type);
            if (craftItem != null)
            {
                // The item is in the list, try to create it
                // Test code: items like sextant parts can be crafted either directly from ingots, or from different parts
                realCraftItem.Craft(from, this, typeRes, tool);
                //craftItem.Craft( from, this, typeRes, tool );
               
                if (type is itemname)
                    World.Broadcast(38, true, from.Name + " has crafted a itemname!");
                   
                if (type is itemname2)
                    World.Broadcast(38, true, from.Name + " has crafted a itemname2!");
            }
        }

The goal would be to get it to World.Broadcast when said items were created, stating Player.name has created said item.

This is the code I am using inside Craftsystem.cs, within the original code as suggested.

I looked at CraftItem.cs also but the hook in there was for typeRes, I am unfamiliar as to what to do.
What I can do is add
Code:
Console.WriteLine("Type crafted: {0}", type.FullName);
Under any of the code in the if statements and it will show console information: Type crafted: server.items.(whatever the item name is)

My problem is finding a way to world broadcast when said item has been crafted.
 

daat99

Moderator
Staff member
I want to make sure I understand you correctly.

If you are using the following code then you see the message in the console:
Code:
if ( type is itemname )
    Console.WriteLine("Type crafted: {0}", type.FullName);

But if you use this code then nothing happens:
Code:
if ( type is itemname )
    World.Broadcast(38, true, from.Name + " has crafted a itemname!");

Is this correct?

What happens if you have this code:
Code:
if ( type is itemname )
{
    World.Broadcast(38, true, from.Name + " has crafted a itemname!");
    Console.WriteLine("Type crafted: {0}", type.FullName);
}

Do you still see the message in the console but no broadcast?
 

Lord_Velius

Sorceror
#1: Yes this is correct, I see the message in my console window.
#2: This is also correct, nothing happens in game when the item is crafted. No world message at all.
#3: Correct, console shows I created the item, yet the server doesn't broadcast it in game.
 

daat99

Moderator
Staff member
Ok, do you announce your saves to the world?
If so, can you post the script that does the saving and world announcements please?
 

Lord_Velius

Sorceror
It took me a bit but I found the issue.
I simply wasn't handling the command through a namespace.
a simple

using System.IO;
using Server.Commands;

Solved my issue fully. Thanks for the help daat99.
If it wasn't for your save suggestion in the last post I'd have never even thought to look.
 

daat99

Moderator
Staff member
It took me a bit but I found the issue.
I simply wasn't handling the command through a namespace.
a simple

using System.IO;
using Server.Commands;

Solved my issue fully. Thanks for the help daat99.
If it wasn't for your save suggestion in the last post I'd have never even thought to look.

That's why I'm sticking around after all those years :)
 
Top