Magic Functions⚓︎
Warning
The MWSE-mwscript API is deprecated. The documentation found here is for legacy purposes only. None of the following functions can be used directly from Lua.
xAddEffect⚓︎
Parameters:
longobjectType: Object Type value for the target's type.stringobjectID: Object ID of target spell, enchantment, or potion.longeffectID: Magic Effect ID that will be added to the target.longskillAttributeID: Skill or Attribute ID to be used. (Only for absorb/damage/drain/fortify/restore effects - ignored otherwise.)longrangeType: New range type. (0 = SELF, 1 = TOUCH, 2 = TARGET)longarea: Area of effect.longduration: Duration in seconds.longmagMin: Minimum magnitude.longmagMax: Maximum magnitude.
Returned:
longsuccess:1if the effect was added, or0if it wasn't.
Adds a new effect to the given spell, enchantment, or potion.
Example
begin Example_xAddEffect
short result
; Fire Damage (14), On Touch (1), Duration (30), Magnitude (1 to 5)
setx result to xAddEffect 1279610963 "fire bite" 14 0 1 0 30 1 5
if ( result != 0 )
MessageBox "Your 'Fire Bite' spell has been upgraded!"
endif
StopScript Example_xAddEffect
end
xCreateSpell⚓︎
Parameters:
stringID: The object ID of the spell to create.stringname: The name of the spell to create.
Returned:
longwasCreated:1if the spell was successfully created.
Creates a new spell with all flags cleared, origin set to spellmaker (2) and a single Water Breathing effect and adds it to the master spell list.
Note
This function will fail if ID already exists or if either ID or name are longer than 31 characters.
xDeleteEffect⚓︎
Parameters:
longtype: The Object Type to delete an effect from. Must be an alchemy, spell, or enchantment object.stringid: The object ID to remove an effect from.longindex: The index of the effect to remove. Must be between (inclusive)1and8.
Returned:
longresult:1if the effect was deleted.
Removes the effect at index from the given spell or enchantment.
Other effects are reordered, e.g. if effect 1 is removed, effect 2 becomes 1, 3 becomes 2, etc.
xDeleteSpell⚓︎
Parameters:
longtype: The Object Type to delete an effect from. Must be an alchemy, spell, or enchantment object.stringid: The object ID to remove an effect from.longindex: The index of the effect to remove. Must be between (inclusive)1and8.
Returned:
longresult:1if the spell was deleted.
Deletes a spell from the master spell list. It will no longer persist in save games.
Notes: Be very careful using this command. The effect of deleting a spell originating from the CS is undefined. The effect of deleting a spell referenced by other entities (player, npcs, traps, etc.) in undefined. Do not attempt to add a deleted spell with AddSpell. AddSpell will succeed, but leave the game in an indeterminate state. It's not yet clear why this happens, but I hope to fix it in the future.
xGetAlchemyInfo⚓︎
Parameters:
stringid: ID of the alchemy item to get information for.
Returned:
longeffectCount: The number of effects on the alchemy item, between1and8.longflags:1= autocalc,2= PC Start,4= Always Succeeds
Provides information important to a given alchemy object. Unlike the other related functions, there is no associated ability to set this information. The effects themselves can still be retrieved and modified using xGetEffectInfo and xSetEffectInfo.
Tip
Use this function to determine the state of a potion before modifying it with xAddEffect, xDeleteEffect or xSetEffectInfo.
Example
begin Example_xGetAlchemyInfo
long numEffects
long flags
setx numEffects flags to xGetAlchemyInfo "potion_skooma_01"
MessageBox "flags: %g" flags
MessageBox "numEffects: %g" numEffects
MessageBox "potion_skooma_01"
end
xGetBaseEffectInfo⚓︎
Parameters:
longattributeID: The School ID to get the value of.
Returned:
longschool: The School of the effect.floatbaseCost: The base cost of the effect.longflags: The flags of the effect.
Returns the properties of a magic effect.
This function only supports the player and NPCs.
xGetEffectInfo⚓︎
Parameters:
longtype: The Object Type to get the effect of.stringobjectID: The Object ID of the object to get the effect of.longindex: The effect index to get the info from, from 1 to 8.
Returned:
longeffectId: TheEffect ID_ of the effect.longskillAttribId: The Attribute or Skill ID associated with the effect, if applicable.longrangeType:0= self,1= touch,2= targetlongarea: Area of effect.longduration: Duration in seconds.longmagMin: Minimum magnitude.longmagMax: Maximum magnitude.
Returns the properties of an effect on the given alchemy item, spell, or enchantment.
On failure, effectId is set to -1.
xGetEnchantInfo⚓︎
Parameters:
stringobjectID: The Object ID of the enchantment.
Returned:
shorttype:0= Cast Once,1= Cast When Strikes,2= Cast When Used,3= Constantshortcost: The cost of using the enchantment.longmaxCharge: The maximum charge for the enchantment.shortnumEffects: The number of effects on the enchantment.longautocalc:0= off,1= on
Returns info about the given enchantId, or 0 if enchantId is invalid.
xGetIngredientEffect⚓︎
Parameters:
stringid: The id of the ingredient to fetch data for.longeffectIndex: A value between 1 and 4, matching the effect index desired.
Returned:
longeffectType: The Effect Type that the ingredient has at the given effectIndex.longskillAttributeType: The Attribute Type or Skill Type, if the effectType supports one. Otherwise will always be -1.
This function allows scripts to determine the effects of a given ingredient programmatically. Scripts can alter these values as well using xSetIngredientEffect.
Example
begin Example_xGetIngredientEffect
long effect
long skillAttribute
setx effect skillAttribute to xGetIngredientEffect "food_kwama_egg_01" 1
MessageBox "skill / attribute: %g" skillAttribute
MessageBox "effect: %g" effectID
MessageBox "food_kwama_egg_01"
end
xGetSpellInfo⚓︎
Parameters:
stringobjectID: The object ID of the spell to get information from.
Returned:
stringname: The spell's name.shorttype:0= Spell,1= Ability,2= Blight,3= Disease,4= Curse,5= Power.shortcost: The cost to cast the spell.shortnumEffects: The number of effects the spell has.longflags: Bit array of spell flags.1= Auto-Calc,2= PC Starting Spell,4= Always Succeeds.
This function gets information about a spell, given its objectID.
The numEffects value is useful when looping over spell effects using xGetEffectInfo.
xSetBaseEffectInfo⚓︎
Parameters:
longeffectID: The Magic Effect to modify.longschool: New spell School.floatcost: New base cost in magicka.longflags: New Magic Effect Flags. Only spellmaking, enchanting, and negative lighting are valid here. All others are ignored.
Returned:
longresult:1on success,0on failure.
This function changes the properties of the effect for all magic that uses it. Changes to school and flags take effect immediately.
E.g. if you have a spell with a Fire Damage effect and you change the Fire Damage school to Alteration, casting that spell will raise Alteration instead of Destruction. Likewise, if you clear the Spellmaking or Enchanting flags, Fire Damage will no longer be available at the respective crafter. Changes to the base cost take effect on any subsequent spell or magic item creation, but don't affect any spells or items already in the game.
xSetEffectInfo⚓︎
Parameters:
longtype: The Object Type of the object to alter.stringid: The object ID of the object to alter.longindex: The index of the effect to alter.longeffectID: The Effect Type to change to.longskillOrAttributeID: The Attribute or Skill ID to use, if the effectID uses one.longrangeType:0= self,1= touch,2= target.longarea: Area of effect.longduration: Effect duration (in seconds).longminimumMagnitude: Minimum magnitude.longmaximumMagnitude: Maximum magnitude.
Returned:
longresult:1on success,0on failure.
Modifies an existing effect on the given spell or enchantment.
xSetEnchantInfo⚓︎
Parameters:
stringenchantID: Object ID of the enchantment to modify.longtype:0= cast once,1= cast when strikes,2= cast when used,3= constant.longcost: New cost per use.longcharge: New maximum charge.longautoCalc:0= off,1= on.
Returned:
longresult:1on success,0on failure.
Sets the properties of the given enchantId.
xSetIngredientEffect⚓︎
Parameters:
stringid: The id of the ingredient to fetch data for.longeffectIndex: A value between1and4, matching the effect index desired.longeffectType: The Effect Type that the ingredient has at the given effectIndex.longskillAttributeType: The Attribute Type or Skill Type, if the effectType supports one.
Returned:
longsuccess: If the effect was set, this value is1. If it failed, the value is0.
This function allows scripts to modify the effects of an ingredient programmatically.
To instead retrieve these values, use xGetIngredientEffect.
??? example Set an ingredient's first effect.
begin WheatAllergy
long ingred
long index
long effect
long attrib
setx ingred to xStringBuild "ingred_bread_01"
set index to 1 ; First Slot
set effect to 22 ; Damage Attribute
set attrib to 0 ; Strength
xSetIngredientEffect ingred index effect attrib
; in this case, we could've also used literals
xSetIngredientEffect "ingred_bread_01" 1 22 0
; needs to run only once per session
StopScript WheatAllergy
end
xSetSpellInfo⚓︎
Parameters:
stringspellID: The spell ID to modify.stringspellName: New display name. Names longer than 31 characters will be truncated.longtype: New spell type. (0= spell,1= ability,2= blight,3= disease,4= curse,5= power)longcost: New magicka cost.longflags: New flags. (1= autocalc,2= player start,4= always succeeds)longorigin: New origin. (1= module, not saved in .ess;2= spellmaker, saved in .ess;0to leave unmodified)
Returned:
shortresult:1if the function was successfull, other wise0.