Difference between revisions of "Faking Dynamic Variables With Factions"

From the Oblivion ConstructionSet Wiki
Jump to navigation Jump to search
imported>Yarharhar
imported>Khadir
m (Value range for factions is -128 ... 127, actually.)
Line 3: Line 3:
One problem I've run into while scripting mods for Oblivion is the need to set and get values dynamically on actors/creatures.  This could be some sort of value needed to satisfy a condition to play a certain idle animation, how many times they've been hit with a specific spell or effect, etc.  While one can do this for variables that exist in persistent references, dynamic references have no such feature.  What we need is some sort of value that can be accessed by any script, could be added and changed on the fly: Factions!
One problem I've run into while scripting mods for Oblivion is the need to set and get values dynamically on actors/creatures.  This could be some sort of value needed to satisfy a condition to play a certain idle animation, how many times they've been hit with a specific spell or effect, etc.  While one can do this for variables that exist in persistent references, dynamic references have no such feature.  What we need is some sort of value that can be accessed by any script, could be added and changed on the fly: Factions!


Any creature/actor in the game can be part of any number of factions, and even better- factions have different ranks! Note that this doesn't allow us to store fractions or negative numbers directly, though if you were really feeling clever you could use two factions to store a numerator/denominator, or have a positive number faction and negative number faction. Thus, all we need to do for a dynamic variable is create a faction, and then in scripts modify or set the player's rank in the 'custom variable' faction.  
Any creature/actor in the game can be part of any number of factions, and even better- factions have different ranks (in the range of -128 to 127; that is, a signed byte value)! Note that this doesn't allow us to store fractions directly, though if you were really feeling clever you could use two factions to store a numerator/denominator. Thus, all we need to do for a dynamic variable is create a faction, and then in scripts modify or set the player's rank in the 'custom variable' faction.  


Another neat bonus we can get from this method is that any rank we label, if applied to the player, can be viewed in the faction menu.  This is very nifty for debugging without having to add message box or message commands!
Another neat bonus we can get from this method is that any rank we label, if applied to the player, can be viewed in the faction menu.  This is very nifty for debugging without having to add message box or message commands!

Revision as of 06:51, 21 June 2006

Factions: The fake dynamic variable

One problem I've run into while scripting mods for Oblivion is the need to set and get values dynamically on actors/creatures. This could be some sort of value needed to satisfy a condition to play a certain idle animation, how many times they've been hit with a specific spell or effect, etc. While one can do this for variables that exist in persistent references, dynamic references have no such feature. What we need is some sort of value that can be accessed by any script, could be added and changed on the fly: Factions!

Any creature/actor in the game can be part of any number of factions, and even better- factions have different ranks (in the range of -128 to 127; that is, a signed byte value)! Note that this doesn't allow us to store fractions directly, though if you were really feeling clever you could use two factions to store a numerator/denominator. Thus, all we need to do for a dynamic variable is create a faction, and then in scripts modify or set the player's rank in the 'custom variable' faction.

Another neat bonus we can get from this method is that any rank we label, if applied to the player, can be viewed in the faction menu. This is very nifty for debugging without having to add message box or message commands!

A little example

Go to the faction menu and add a new faction. Give it ID NecklaceCount and name "Times equipped increment necklace". Give it a few ranks and label them however you want.

Now make a new amulet (just clone a silver necklace) and label and name it IncrementNecklace. Give it the following script:

scriptname incrementNecklaceScript

ref userRef
float userVal
begin onEquip
	set userRef to getContainer
	if(UserRef.GetInFaction NecklaceCount == 1)
		UserRef.modFactionRank NecklaceCount, 1
	else
		UserRef.setFactionRank NecklaceCount, 0
	endif
	set userVal to UserRef.getFactionRank NecklaceCount
	Message "Necklace Equip Count:%.0f", userVal
end

Then place the necklace in the game world somewhere and then start Oblivion. Whenever someone equips the necklace their 'necklace increment' counter will increase by one. You will see this through both a message, and for any labeled faction ranks, in the player's faction menu.

Hope this is useful for you guys!