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!

Help with data and include files

Zulu

Wanderer
Help with data and include files

Is it possible to have include files? That way, main parts of code can be used in a bunch of scripts. Like it is done in POL.

Is it possible to read data files and save data files, different than world save.

Can you show us samples.
 

krrios

Administrator
Every part of every script is accessable from every other script, providing you write a using statement:

[code:1]using Server.Scripts.Items; // Access to every script in the Server.Scripts.Items namespace[/code:1]

What type of data files are you wanting to read? The .NET Framework provides file streams, binary readers and writers, text readers and writers, and so on.
 

Zulu

Wanderer
If you look at the cooking script, it seems to have a lot of duplicate code. Could you not put the items that can be cooked in a data file?

The script could read in the items, like something below. (not sure how the file should be setup, hopefully you understand what I mean.) That way the cooking script would be a lot smaller. There are other scripts like tinkering, lumberjack,etc. I am not just picking on cooking;)

datafile for cooking:
item_number,what_it_makes_item_number,how_many_to_use,how_many_make

**or**
Would it be better to make some kind of string array inside of the cooking script?
 

SickLab

Wanderer
Cooking script has been re-scripted as i said. Their is no more duplicated code.

Don't look at the one that is written directly on the forum. You have to download the new file.

All of this is C# related. You can do whatever you want.

The food script was my second script, and it was not really optimized. But i have rescript it and it is now a lot better.

Now, a cookable food is that small:

[code:1]
// ********** RawRibs **********
public class RawRibs : CookableFood
{
[Constructable]
public RawRibs() : base( 0x9f1, 10 )
{
Weight = 1.0;
Stackable = true;
}

public RawRibs( Serial serial ) : base( serial )
{
}

public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );

writer.Write( (int) 0 ); // version
}

public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );

int version = reader.ReadInt();
}

public override Food Cook()
{
return new Ribs();
}
}
[/code:1]


All of the cooking engine is handled by his base class "CookedFood". We simply have to overide the Cook() function to return the item it created when used on firecamp.

I don't think it can be smaller than that. because you actually have to declare a whole class for all the items.

script in RunUO is'nt really script. It's actually real C# code that is compiled into the core at runtime.
 
A

Aahz

Guest
Gah! your making me shudder with code :)
maybe someone can clarify a few things in that code to set my mind at rest. I'm a bit of a newbie but given a few days I'll get hang.

[code:1]
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );

writer.Write( (int) 0 ); // version
}

[/code:1]
What exactly is the purpose of this ?

[code:1]
public override Food Cook()
{
return new Ribs();
}
}
[/code:1]
does that mean all the skill gains and the likes are handled elsewhere ?

Thankyou for your time. Sooner or later I will conquer this masturful language[/code]
 

SickLab

Wanderer
Yes, it is handle in the CookableFood base class.

look at the constructor:

public RawRibs() : base( 0x9f1, 10 )

the 10 at the end is the SkillLevel it needs to cook it. Well, that's the way i code it. It could be something else :)

The serialisation is for the WorldFile saving. We have to put a version in the case that we add some var to serialize to the class. And since we want all of our worldfile to be compatible with all version of RunUO, we have to include version number.
 
Top