logo logo

 Back to main page

The NWNX Community Forum

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
SetPersistentObject
Goto page Previous  1, 2
 
Post new topic   Reply to topic    nwnx.org Forum Index -> Scripts and Modules
View previous topic :: View next topic  
Author Message
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Thu May 01, 2008 14:42    Post subject: Might not be of use Reply with quote

Hi guys,
I recently had a problem of objects loosing their properties when attempting to recreate them via CreateObject, with a resref that was already acquired from the original object.

The problem was that it would rely on resref, and as such would only reproduce the item from the closest matching resref in the pallette.

In order to preserve the properties of the item, I made a code, that would create a loop, that would get each of the item properties, and then copy that property to the new item.

The item might loose its description, but this way, it did preserve item properties. (Charges of spells and such might get refreshed though)


I only did this in a local manner, within the module, but using mysql, it should be easy enough to store itemproperty flags/constants for a particular item in the sql db, then when its respawned, to create a new item, and apply the appropriate properties to that new item.

Let me know if this is helpful or not, as I know this is an old old old topic.
Back to top
View user's profile Send private message
Lugoun



Joined: 18 May 2007
Posts: 36

PostPosted: Mon Jun 30, 2008 19:48    Post subject: Reply with quote

I would definitely find this helpful.

I plan on implementing some persistent storage, but our module makes use of XP_CRAFT which changes the appearance of items and we want to do a system for adding additional enhancements (item properties) onto existing items, so I can't simply store then retrieve res refs and things like stacksizes, etc.

Something like what you have already created would be helpful as a basis to build from.

Thanks,
_________________
Lugoun
www.hotta-rpg.org
Back to top
View user's profile Send private message
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Mon Jan 12, 2009 14:10    Post subject: Ooops Reply with quote

Realise this is an old thread but anyhow.

Code:

//Get the first itemproperty on the item
itemproperty ipLoop=GetFirstItemProperty(oItem);

//Loop for as long as the ipLoop variable is valid
while (GetIsItemPropertyValid(ipLoop))
   {
   //feed the details into the function for going into database
   StoreItemProperty(oItem, ipLoop);

   //Next itemproperty on the list...
   ipLoop=GetNextItemProperty(oItem);
   }


void StoreItemProperty(object oItem, itemproperty itempropertyvariable)
{
string sItemName = GetName(oItem)+"_"+GetTag(oItem); // This is to try and give the item a unique name of sorts for database
int iItemProperty = GetItemPropertyType(ipLoop); // This retrieves the integer value of that particular item property
string sSQL = "INSERT into ItemProperties (itemname, itemproperty, itemowner) VALUES ('"+sItemName+"','"+IntTOString(iItemProperty)+"', '"+GetName(oPC)+"')";

SQLExec(sSQL);

}


This is just a rough plan from my head. I have not had time to check this. It was a while ago as you can see by the date that I wrote this initially.
This script will need you to have a database set up to feed the data into, also you can use timestamps from the database to properly mark items for uniqueness. Eg - Your item gets tagged with a time stamp.


Note - For some item properties, you will need to expand them, to get their item property modifiers. Eg - This script will store a regen type modifyer, but it does not store whether it is +10 or +15 or + 1 type regen.

You need to feed the ipLoop into another function to get the parameters of the item property.
Some item properties can return 0 or nothing, in which case you just have to have your database either have a default value in some fields for such an occasion, or have your script put in N/A for such occasions.

Then when reading the database, it will skip fields reading N/A.
Back to top
View user's profile Send private message
Lugoun



Joined: 18 May 2007
Posts: 36

PostPosted: Fri Jan 16, 2009 0:23    Post subject: Reply with quote

Thanks, originally I was just going to store item resrefs and create those when appropriate, but we do modify items from their original and could also possibly be an issue with any crafting systems.

I still havent implemented our system yet (other priorities have reared up), but an example loop like this will be helpful when the time comes.
_________________
Lugoun
www.hotta-rpg.org
Back to top
View user's profile Send private message
Asparius



Joined: 18 Sep 2007
Posts: 52

PostPosted: Fri Jan 16, 2009 2:13    Post subject: Reply with quote

If there is a separate table for itemlist, I would add an "id" column with autoincrement for making items unique - then use its value for binding property sets to item.

I'd advise to check all GetItemProperty* functions. For instance, a property "damage bonus: 1d4 cold" looks like.

GetItemPropertyType: 16 (property: damage bonus)
GetItemPropertySubType: 7 (damage type:cold)
GetItemPropertyCostTableValue: 6 (d4)

And all values must be restored...

Sorry for leaving this unfinished, but now I am too sleepy. Maybe I will write something more tomorrow...
Back to top
View user's profile Send private message
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Fri Jan 23, 2009 12:37    Post subject: Note Reply with quote

While probably not needed, I think I recall seeing an
ObjectToString function somewhere.


It converts items to hex strings that can be stored in mySQL.
This seems alot easier than storing each individual parameter of the item property.


I am making a forge script of my own at the minute, while it is not storing anything in mySQL, I have learned that the item property variable type, keeps the item property parameters intact, while the item property is loaded as an itemproperty variable type.

Which means, if you store the item, or an item that has the item properties, you can load the item back into the game, and transfer the properties off that item.

It would be a simple matter of

//Storage Item
object oItem1 = GetPersistentObject(INSERT Params here);
//Target Item to copy property onto
object oItem2 = GetObjectByTag("target_item");

itemproperty iProp = GetFirstItemProperty(oItem1);
while (GetIsItemPropertyValid(iProp))
{

AddItemProperty(DURATION_TYPE_PERMANENT, iProp , oItem2 );
iProp =GetNextItemProperty(oItem1);
}

This copies all item properties from Item1 to Item2.

As you can see, it is alot neater to keep the properties self contained, instead of expanding them to have every item property parameter.
(Although, I could see the benefit of such a method - You could alter parameters from the database, then load back an altered item - gives rise to the possibility of Editing Items through your web browser)

If you have exhausted the sql option of StringtoObject and ObjectToString, id recommend creating a dummy object template, that will act as the storer for the itemproperties.

Although, saying that... you could argue that it is just as easy to do a StoreCampaignObject on the item, and just return it.

Either way, if you do choose to export each itemproperty in turn to sql, you could use the above loop to get the itemproperty parameters.

itemproperty iProp = GetFirstItemProperty(oItem1);
while (GetIsItemPropertyValid(iProp))
{

ExamineProperty(iProp);
iProp =GetNextItemProperty(oItem1);
}


void ExamineProperty(itemproperty iProp)
{
int iPropType = GetItemPropertyType(iProp);
int iSubType = GetItemPropertySubType(iProp);
int iCostTable = GetItemPropertyCostTableValue(iProp);
//Anything else.

}

void SendToDB(string blah blah blah blah)
{
Make the database update function here, then you just need to feed all the integers from the ExamineProperties function into it.
}


//Unsure if additional parameters would be required, but I would say YES, especially for items that cast spells, you would need to capture charges, spell id, and stuff. Also, now in 1.69 you can get description, and set description.

All in all, you can pretty much populate this function, and use it to dismantle an itemproperty into its base components. Then you can feed these values into a database, then load them back at a later time.
Back to top
View user's profile Send private message
Zebranky



Joined: 04 Jun 2006
Posts: 415

PostPosted: Fri Jan 23, 2009 15:42    Post subject: Re: Note Reply with quote

Baaleos wrote:
While probably not needed, I think I recall seeing an
ObjectToString function somewhere.


It converts items to hex strings that can be stored in mySQL.
This seems alot easier than storing each individual parameter of the item property.

That wouldn't store the item data, just the object ID. Terrible, terrible things would happen if you then tried to create an item from that Wink

A SCORCO hook would be ideal.
_________________
Win32 SVN builds: http://www.mercuric.net/nwn/nwnx/

<Fluffy-Kooshy> NWNx plugin is to this as nuclear warheads are to getting rid of fire ants.

<ThriWork> whenever I hear nwn extender, I think what does NWN need a penis extender for?
Back to top
View user's profile Send private message Visit poster's website
ShaDoOoW



Joined: 20 Aug 2005
Posts: 584

PostPosted: Sat Jan 24, 2009 13:45    Post subject: Reply with quote

You can store itemproperties as integer with this: item property scripting tool

I didnt tried it but it seems very powerfull.
_________________
Community Patch / NWNX Patch / NWNX Files / NWNX Connect
Back to top
View user's profile Send private message
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Mon Jan 26, 2009 15:29    Post subject: I had a look at that Reply with quote

That ItemPropertyToInt is perfect for what I have planned for my Module.


I am creating a Forge that takes one Item Property from an item, and copies it onto another item, at the cost of destroying the item the property came from.


Eg - Item with Enchanted +4 , and Damage Bonus +2d12 Fire.

It might take Enchanted +4 and copy that onto the new item, destroying the item it came from.

Using the forge, players will be able to scavange, and use their unwanted items to enhance them.



This ItemPropertyToInt function will make it easy to store them.
Also - It gave me an idea to store the item propertys onto Unique Power items.

Eg - Store the item property onto a crystal, then use the crystal to put the property onto an other item at a later time.
Would also promote trading of Item Properties.

No longer just about trading items, but you can trade item properties.
Back to top
View user's profile Send private message
ShaDoOoW



Joined: 20 Aug 2005
Posts: 584

PostPosted: Tue Jan 27, 2009 2:36    Post subject: Re: I had a look at that Reply with quote

Baaleos wrote:
Eg - Item with Enchanted +4 , and Damage Bonus +2d12 Fire.

It might take Enchanted +4 and copy that onto the new item, destroying the item it came from.
This can be done without ItemPropertyToInt

just loop through the ips on first item, and whenever valid itemproperty is found, copy it onto new item and remove on first...

Nevermind, don't forget to vote Wink.
_________________
Community Patch / NWNX Patch / NWNX Files / NWNX Connect
Back to top
View user's profile Send private message
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Tue Jan 27, 2009 11:39    Post subject: Already Reply with quote

Already had a working version working.

However, the one I had, worked on the basis of 2 sequencal loops.

One to find out how many item properties there are,
the second to select a random property from the available ones.


However, sometimes, it returns no properties.



I think IPtoInt might make it easier though, or make it work better.
Also it allows database integration.
Back to top
View user's profile Send private message
Kosmous



Joined: 10 Jan 2005
Posts: 44

PostPosted: Tue Feb 17, 2009 7:20    Post subject: Reply with quote

Hope this thread isn't dead.

Anyway, if I may suggest another approach to this problem which I have found more reliable.

The key to this issue is to really commit the information about the properties during the actual "crafting" procedure. Merely have a string which codes the added properties as a local var which is then referred to when your storing the item or duplicating it.

I have done this automatically since my crafting recipes are stored via database anyway (and hence, recipes can just be retrieved from the db via id number). Doing it this way allows for easy editing of existing recipes without touching the module proper. Only problem with this might be that some people might be using preexisting systems that have been developed using nwscript entirely.
Back to top
View user's profile Send private message
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Tue Feb 17, 2009 10:09    Post subject: The Item Property to Int Reply with quote

The Wonderful ItemProperty to Int function as well as the to string function, has made it possible for my players to purchase item properties from my forum shop.


Yet another method of encouraging forum posting.

The way it works, is that when they buy an item in the smf shop, it gets stored in a database table on my website, the item id is specific for each type of item.


I have a cronjob, that will run through all the forum users, who have a CDKEY (public cdkey) stored on their forum profile, for each CDKEY it finds, it gets the memberid for that person on the forum.

Eg - Mine might be 1

Then the cronjob searches for all items purchased from the forum, that relate to that specific user.

It then performs a mySQL insert statement using this data, but this time, inserting to the mySQL database my game server runs off.


So, the items are now stored alongside the members CDKEY.

Now, they can simply visit the post office I have created, and talk to the manager there. If the person has mail, the manager will give the player the item.

The item itself is a misc object, but it stores a variable on it, which is equivelant to the item property int value, it also gets its description set, to describe what item property it holds.

Using the item, will then run one script, that applies the itemproperty permanently, and in the place of where the item property needs to be specified, it does the int to item property function again, and tada..

Item Properties bought from the forum, and received in the game.

To add more item properties that can be bought from the forum, I need to create the item in the forum shop, and take note of its item id.

Then I need to add that item id to the switch statement in my code, to say that
case:32
ipProperty = ItemPropertyRegenerate(4);
break;

This is sorta what I would do if I wanted item 32 on my forum to be a regenerate +4.
Back to top
View user's profile Send private message
virusman



Joined: 30 Jan 2005
Posts: 1020
Location: Russia

PostPosted: Tue Feb 17, 2009 11:17    Post subject: Reply with quote

Baaleos, great idea and implementation!
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Tue Feb 17, 2009 12:44    Post subject: Thanks Reply with quote

Thanks virusman,
It was fun to code.

I promissed my players something like this, so kinda tied my hands into having to provide it. Lol

Before getting the post office idea running, I did the easier task of implimenting a Forum Bonus Reward Scheme.

Registering on my forum, and adding your public CD rewards you with a small amount of Gold in the game per day. (The daily restart is handled by a cronjob)

The gold reward is based of the players rank on the forum, and rank is determined by their forum post count.

Yet another method of encouraging Forum usage.

Rewards at the minute are gold bonuses which are granted on login (once per day).
Eg - Commoners get 750 Gold per day (0 - 10 posts)
Shop Owners get 1000 Gold Per Day (11-50 Posts)
And so on..

Royal Family Members get 10,000 per day. (over 500 Posts)
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Scripts and Modules All times are GMT + 2 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group