Full Version : Making a from check in DefBlacksmithy?
xmlspawner >>Scripting Support >>Making a from check in DefBlacksmithy?
<< Prev | Next >>
Lord Hog Fred- 10-23-2006
How can I make a from check in DefBlacksmithy to a player?
I am trying to add this check to the InitCraftList

CODE
XmlRecipesWeapons wrecipes = (XmlRecipesWeapons)XmlAttach.FindAttachment(from, typeof(XmlRecipesWeapons));

Problem is that there isn't any definition for a mobile from in InitCraftList, how would I add one?
Thanks ,
ArteGordon- 10-24-2006
InitCraft sets up all of the available crafts. To restrict access to crafts for different individuals, I would add the check to the CraftGump methods in CraftGump.cs such as CreateItemList that will allow you to control which items are listed for crafting.
You will still need to initialize all of the possible additional crafts in InitCraft and then you can restrict them for certain individuals in those other methods.
Lord Hog Fred- 10-24-2006

QUOTE (ArteGordon @ October 24, 2006 12:26 pm)
InitCraft sets up all of the available crafts. To restrict access to crafts for different individuals, I would add the check to the CraftGump methods in CraftGump.cs such as CreateItemList that will allow you to control which items are listed for crafting.
You will still need to initialize all of the possible additional crafts in InitCraft and then you can restrict them for certain individuals in those other methods.

Hmm, surely that is much harder than just adding the checks to the InitCraftList? Considering I have a lot of different crafts using the checks.
How would I go about referencing back to a previously defined reference in the script?
I have referenced the XmlAttachment checks in the CanCraft section, is there a way I can reference back to it from the InitCraftList?
ArteGordon- 10-24-2006
the InitCraft method just sets up all of the possible craftable items for a specific crafting skill.
CanCraft will allow you to test for individual crafted items when a player tries to make them. That is where you would make the check.
Since InitCraft sets things up for all players there is no way with the system the way it is designed, to make it player-specific. You just have to restrict the items that can be crafted in CanCraft.
By putting the check into the gump code, you can restrict the craftable items that are listed as well.
Lord Hog Fred- 10-24-2006

QUOTE (ArteGordon @ October 24, 2006 02:51 pm)
the InitCraft method just sets up all of the possible craftable items for a specific crafting skill. CanCraft will allow you to test for individual crafted items when a player tries to make them. That is where you would make the check. Since InitCraft sets things up for all players there is no way with the system the way it is designed, to make it player-specific. You just have to restrict the items that can be crafted in CanCraft.
By putting the check into the gump code, you can restrict the craftable items that are listed as well.

Ah ok, I thoguth by adding the checks to the various AddCrafts would just make them not appear on the craft menu for characters that failed the checks.
On that note, how on earth would I go about adding the checks to the CraftGump?
ArteGordon- 10-24-2006
in CraftGump.cs in the CreateItemList method, you could add a check here

QUOTE
public void CreateItemList( int selectedGroup ) { if ( selectedGroup == 501 ) // 501 : Last 10 { CreateMakeLastList();
return;
}
CraftGroupCol craftGroupCol = m_CraftSystem.CraftGroups;
CraftGroup craftGroup = craftGroupCol.GetAt( selectedGroup );
CraftItemCol craftItemCol = craftGroup.CraftItems;
for ( int i = 0; i < craftItemCol.Count; ++i )
{
int index = i % 10;
CraftItem craftItem = craftItemCol.GetAt( i );
// try adding your check here on the craftItem using m_From as the player calling the gump, m_CraftSystem as the craft system being used, and m_Tool as the tool.
// Something like
if(craftItem is not a valid item for m_Player) continue;

Lord Hog Fred- 10-24-2006

QUOTE (ArteGordon @ October 24, 2006 02:59 pm)
in CraftGump.cs in the CreateItemList method, you could add a check here

QUOTE
public void CreateItemList( int selectedGroup ) { if ( selectedGroup == 501 ) // 501 : Last 10 { CreateMakeLastList();
return;
}
CraftGroupCol craftGroupCol = m_CraftSystem.CraftGroups;
CraftGroup craftGroup = craftGroupCol.GetAt( selectedGroup );
CraftItemCol craftItemCol = craftGroup.CraftItems;
for ( int i = 0; i < craftItemCol.Count; ++i )
{
int index = i % 10;
CraftItem craftItem = craftItemCol.GetAt( i );
// try adding your check here on the craftItem using m_From as the player calling the gump, m_CraftSystem as the craft system being used, and m_Tool as the tool.
// Something like
if(craftItem is not a valid item for m_Player) continue;

Um, can you suggest of any other way to do this?
I'm thinking this is going to make my CraftGump.cs incredibly messy and take a massive amount of time to do.
P.S: I hope I'm not sounding ungrateful for you help as I don't mean to.
Lord Hog Fred- 10-24-2006
Btw, just to let you know, I managed to integrate my new XmlRecipes system into using the RunUO 2.0 distro one. Personally I think it is much better as it gives Admins much greater control over what recipes players do/don't know and it's also much easier to add a new recipe rather than dealing with the old system.
If anyone is interested I'll release what I've done .
And obvious thanks to Arte as without you (as usual) I would be at a total loss .
ArteGordon- 10-24-2006
I wouldnt add all of the detailed checking into the CraftGump.cs script. Make a public static method in your XmlRecipe class that will do all of that and then just call it from CraftGump

CODE
// try adding your check here on the craftItem using m_From as the player calling the gump, m_CraftSystem as the craft system being used, and m_Tool as the tool. // Something like if(!XmlRecipe.AllowCraft(m_From, m_CraftSystem, craftItem, m_Tool)) continue;

where you would have the AllowCraft method defined in your XmlRecipe class like

CODE
public static bool AllowCraft(Mobile from, CraftSystem system, CraftItem item, BaseTool tool) { // add whatever attachment checks you want here and return true/false depending on whether or not you want the item to appear on the list. Return true by default.
return true;
}