Storing custom values in itemdesc

Get Help on scripting in POL with configurations, config setups, script trouble shooting, etc.
Post Reply
User avatar
OldnGrey
POL Expert
Posts: 657
Joined: Sat Feb 04, 2006 6:26 pm

Storing custom values in itemdesc

Post by OldnGrey »

I've been using custom values for items in itemdesc.cfg entries for a while now.
It's not too hard to set and retrieve numbers and strings but how do you set an array (eg as required in the SYSBOOKS distro package)?

Eg in the distro a piece of armour might have:
MedLoss 100
That can be retrieved easily.

But what if you wanted to store an array - eg the Contents of a Sysbook? (I can do it in cprops, but no thanks, I want the array to be stored in the itemdesc.cfg entry once and storing it like a cprop is stored won't work)

Hope someone can help me - otherwise the sysbooks package has a BIG flaw :)
User avatar
OldnGrey
POL Expert
Posts: 657
Joined: Sat Feb 04, 2006 6:26 pm

Post by OldnGrey »

So is this impossible or simply nobody has ever tried to do it?
MuadDib
Former Developer
Posts: 1091
Joined: Sun Feb 12, 2006 9:50 pm

Post by MuadDib »

DataFiles are your friends. There is that, or config files using multiple key entries for each page/array elem, and use GetConfigStringArray or whichever it was, hehe.

DataFiles though, are way underused, even in Distro. I say this because, you can store all that stuff in DataFile, and then make an Ingame editor for it all! You could edit medless entries on the fly, book entries for static books on the fly. All those custom things that are script controllable, could be done that way.

Just an idea :)
User avatar
OldnGrey
POL Expert
Posts: 657
Joined: Sat Feb 04, 2006 6:26 pm

Post by OldnGrey »

MuadDib, have you looked at the distro sysbooks package? :)

I have no issue with using any form of data file, in fact for individual books the distro sysbook package uses the datastore with the key on the serial number of the book. It works fine.

It's just that if the datastore entry is missing it will then try to read cprops on the item and then finally read the itemdesc entry for the objtype looking for the author, title and contents.

Thus the question. Is sysbooks package trying to do something impossible?
User avatar
OldnGrey
POL Expert
Posts: 657
Joined: Sat Feb 04, 2006 6:26 pm

Post by OldnGrey »

Well, I wasn't going to let this one beat me.
Only cprops and datafiles seem to store arrays, so to get them into itemdesc you have to store each element of the array separately and use GetConfigStringArray to get them.

This can be made to work with the sysbooks package from the 097 distro.


In Distro\pkg\items\sysbook\book\methods.src around line 250:

Code: Select all

	//If we got this far.. then lets fall back on the itemdesc.cfg
	//Note its read in as :*: which reads in every itemdesc.cfg
	var cfg := ReadConfigFile(":*:itemdesc");
	cfg := cfg[book.objtype];
	if ( prop_name == "Contents" )
		prop_value := GetConfigStringArray(cfg, prop_name);
	else
		prop_value := GetConfigString(cfg, prop_name);
	endif
	if ( prop_value )
		return prop_value;
	endif
The itemdesc entry for each book is now of the form:

Code: Select all

Item 0x7025
{
	ObjtypeName	newbiebook
	desc		Player guide
	Graphic		0xff2
	CreateScript		book/onCreate
	DestroyScript		book/onDestroy
	Script			book/use
	MethodScript		book/methods
	vendorsellsfor	50
	vendorsellsfor	50
	newbie		1

	ReadOnly	1
	IsBook		1
	NumPages	9
	Author		Me I guess
	Title		Guide to This Shard
	Contents	Welcome to my very
	Contents	own shard. This book will
	Contents	try to explain some of
	Contents	the most basic things
etc etc
So if you want to give out a welcome book to each player, and want to use the disto's book package, this is one way to do it without using the 'orrible cprops on each book.

If this is of any value to the distro, let me know. I know MuadDib is a fan of editable datafiles so this might not meet requirements.
Pierce
Forum Regular
Posts: 420
Joined: Thu Feb 02, 2006 8:33 am

Post by Pierce »

I've been using custom values for items in itemdesc.cfg entries for a while now.
It's not too hard to set and retrieve numbers and strings but how do you set an array (eg as required in the SYSBOOKS distro package)?
If you want to set an array e.g. for the contents of a book to the itemdesc.cfg you better write the book inside the game first and then copy its contents line from the items.txt to your itemdesc.cfg. Otherwise you have to count a lot of letters :)

It looks this way:

Code: Select all

    cprop contents a3:S14:Welcome to theS12:world of UO.S16:At the beginning
To translate the lines:
a3: an array with 3 members
S14: string with 14 letters follow
S12: string with 12 letters follow
...

Edit: Just found that Yukiko already explained that here:
http://forums.polserver.com/ftopic1874.php
User avatar
OldnGrey
POL Expert
Posts: 657
Joined: Sat Feb 04, 2006 6:26 pm

Post by OldnGrey »

Pierce,
I wasn't trying to set cprops, but using itemdesc.cfg for setting arrays on custom entries.
They aren't stored in the same way as cprops or data files. (ie the packed format)

Sorry if I wasn't clear. I think I was getting answers to questions I wasn't asking!
Yukiko
Distro Developer
Posts: 2826
Joined: Thu Feb 02, 2006 1:41 pm

Post by Yukiko »

*** Warning: Slightly off-topic reply! ***

OnG isn't this similar to the way corpseitem (the items placed on corpses after "skinning" them) was stored on NPCDesc entries for the old Distro?

I am looking at using something very similar to your method for storing material requirements for items that are crafted from more than one material eg.

Code: Select all

Item 0x5678
{
Name             anitem
materials        boards cloth ironingot
materialamt    4 5 6
}

I prefer editing stuff in cfg files rather than gumps anyway.

User avatar
OldnGrey
POL Expert
Posts: 657
Joined: Sat Feb 04, 2006 6:26 pm

Post by OldnGrey »

Yukiko,
Yes in that it's custom entries,
but no, what you posted was stored as a string for splitwords to retrieve. My problem was a little different in that I wanted arrays to be stored.

I realise it was a somewhat odd thing to do and normally I wouldn't even worry about it except that the distro sysbooks package tried to use it but was bugged slightly.

I solved the problem after a lot of trial and error (ie no real clue how to do it) and was able to get books stored in itemdesc entries without resorting to cprops. Now that I see it done, it's kinda useful to know for next time. The 097 distro sysbooks package has been modified to use this and has an example of a book written in itemedesc.cfg custom entries. I figured that someday someone might need to know.
Yukiko
Distro Developer
Posts: 2826
Joined: Thu Feb 02, 2006 1:41 pm

Post by Yukiko »

It looks like you stored the data pretty much the same way I was thinking of. It's the retrieval method that differs.

I hadn't thought of using the GetConfigStringArray function to retrieve the "materials" list. I would have probably used SplitWords like the Distro had done.

Your method works well when you need to grab a custom member in an array. I'll definitely keep that tucked away in my memory.
Post Reply