Page 1 of 1

Items and stats

Posted: Thu Mar 16, 2017 7:42 pm
by Donfrow
So it's come to my attention a bug in my mod that I'm not sure how to fix.

I have some items that give stats, for example you put on an amulet that gives + 2 dexterity. If you remove the amulet, it removes 2 dexterity. This is all well and good, until you save the game and quit and restart. What seems to be happening is on a load of a save game, the +2 is being applied again.

So, if you start with base 20 dexterity, put on the amulet, you get 22, if you take it off, you're back to 20. No harm, no foul. This is being triggered by using events readied and unreadied on the object usecode.

If you save the game with 22 dex (20 base + 2 from amulet), you save with 22 dexterity. The next time you load the game, you start with 24 dexterity. (22 from the save, +2 more from the amulet).

I suspect what's happening is when you enter back into the game world, it's re-running the readied usecode, which is in turn causing it to keep going up and up every time you exit.

Does anyone have any thoughts about how to get around this? Is it even possible?

Along the same lines, is there a way to determine the NPC that has the item equipped? Currently I have it hard coded so it only ever works on the Avatar, but it seems like it would be a good idea to work on any equipped NPC's in the party however I can't seem to locate a suitable intrinsic that would return a reference I could use to get the NPC number of the equipped user.

Thanks

Re: Items and stats

Posted: Thu Mar 16, 2017 8:11 pm
by Dominus
without being good with usecode, my first idea is to add a global flag to check against.
For example 0xNNN wear_amulet and make this flag a condition to add dexterity. If you put the amulet on, you check whether that global flag is set, if not, add dexterity, set global flag. If you remove it, unset the global flag.
So the case on reloading the game, will check again, but the global flag is set, so no dexterity is given.
I think the original does something similar with some stuff.

There must be some code to check for the party member, maybe KC can help :)

Re: Items and stats

Posted: Thu Mar 16, 2017 8:49 pm
by Knight Captain
The Silver Seed uses gflags to address this. I've emailed over the Belt of Strength file that you can adapt for your needs. The other boosting items do the same, like the Gauntlets of Quickness, Erinons' Axe, etc.

When the item is READIED the gflag is set, and it checks for that NPC's stat level, and sets the boost granted as the item's quality. For example, if the Avatar has 25 strength, the boost and quality is 5.

When UNREADIED the gflag is unset, and it uses the item's quality for how much to de-boost the stat.

So to do this boost you shouldn't need to check who is wearing the item. I'm not sure how this works in relation to party member deaths. For example, if I give the Belt to Shamino and he gets killed, does that count as (event == UNREADIED) ?

As for how to tell which party member is holding a unique item, I'm not sure. It would require checking that the party has the item, then getting the party list, and checking each member individually after that. I might be able to write this as its own function so you can just do something like:
checkWhoCarries(SHAPE_ARTIFACT, FRAME_AMULET_OF_BALANCE);
to return the NPC.

Doing that to find the right container to place an object, for example to create a designated bag-of-reagents or move Serpent Teeth into the Jawbone, is even more complex.

Re: Items and stats

Posted: Thu Mar 16, 2017 9:14 pm
by Donfrow
Not sure why I didn't think of that. The flag should be straight forward enough.

I imagine with the belt of strength code (so far only skimmed it) it should have something similar in it as well, as I don't believe it was limited to simply the Avatar. Looks like it uses UI_get_container to get the wearer, which is pretty simple if that's the case.

On top of that, I think it contains the logic needed as well not to go over the total stat as well, ie, if you're at 25 strength don't go to 35, go to 30.

Thanks a bunch for that usecode; I think it will be very helpful. It looks like it would work for me with very minor changes. As I fix these bugs that people find in Glimmerscape it will really help to make Glimmerscape2 not quite the mess its predecessor is!

Re: Items and stats

Posted: Mon Apr 03, 2017 1:22 am
by Dale
Just wondering how the progress is going here. Looking very forward to playing this when you fix it.

Re: Items and stats

Posted: Mon Apr 03, 2017 9:50 am
by Donfrow
With the code Knight Captain provided I was able to use with minimal modifications. Waiting now for my latest version of Glimmerscape to be posted so this bug (and a bunch of other bugs people let me know about) is corrected for anyone else.