Quote
Originally posted by Rubber Ducky:
**At a certain point in my plugin I want to reduce several of the player's attributes (i.e. speed = 2, strength = 30, dexterity = 15, etc.) to simulate the hero being sick in the end-game. I know how to do that much, but what I don't know is how to restore the attributes that he had before he 'got sick'.
...
I know this is done somehow with global checks, but how do you get the original stats back? **
Carefully. The problem with just setting and restoring with globals is that the player's stats can change. Ie, if they have a strength potion in inventory, they get lowered and the immediately quaff a potion, then their strength is now different. When you reset them they will lose that bonus unless you compensate for that.
If you are going to add/remove a constant from the attribute(ie, minus 2) then this is very easy. Just use attribute wizards to remove the constant, and after the effect has worn off you can add it back with the attribute wizard. It doesn't matter what the value has been changed to since you are going to add the same value back when you are finished.
However, if you are going to set the attribute to a specific value(like 5) then we must use globals as we don't know where the attribute started out at.
Here is what I would do(for 1 attribute; just repeat the steps for additional stats):
- Create a global to store current attribute(ie. &&gb;_oldstr)
- Store the current attribute to the global
- Change the current attribute to whatever value you want
At this point the player's attribute is changed. We also have kept track of what their initial attribute was as it is stored in our global. When we return their loss we need to make some additional checks...
- Create a new global to hold a temporary number(ie. &&gb;_tempattribute)
- Use a conditional to check if their current attribute is equal to the value that it was originally set at
- If the current attribute is different then set the value of &&gb;_tempattribute to be equal to the value of that current attribute.
- Subtract the value that that attribute was originally stored as from the temporary global value(ie, if you originally set the player to 15 and it is now 18, you will store in &&gb;_tempattribute the value "18" and then subtract "15" from it, leaving it with the value of 3)
- Add the value of the temporary global value(&&gb;_tempattribute) to the stored attribute holder(&&gb;_oldstr) and store it as &&gb;_oldstr.
- Set the player's attribute to be equal to the value of the stored attribute holder &&gb;_oldstr.
Basically you are going to be looking at the player's current attribute and, if it is different than what you originally set it to be, you will find the difference and add it to the original, then set it to that value. If the player's attribute went down for some reason(set at 15 and was reduced to 14) then there is a net loss of -1 and you will be adding -1 to it, so this should work fine.
Make sense?
------------------
(url="http://"http://stark.evula.net/pogwalkthrough.htm")PoG Walkthrough and Compendium(/url) | (url="http://"http://stark.evula.net/plugins/dev_tools.htm")PoG Dev Tools(/url) | (url="http://"http://stark.evula.net/plugins/spells_expander.htm")Spells Expander(/url)
(url="http://"http://stark.evula.net")Stark.evula.net(/url) | (url="http://"http://www.evula.net")EVula.net(/url) | (url="http://"http://mail.ambrosiasw.com/mailman/listinfo/coldstone_dev")Coldstone-dev mailing list(/url) | (url="http://"http://ucplugs.evula.net/pog.html")PoG Upcoming Plug-Ins Directory(/url)