Actor 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.
xActivate⚓︎
Parameters:
referencetarget: What the reference will try to activate.
Returned:
- None
This function allows the forced activation of one reference onto another. Unlike the vanilla Activate function, this allows variable input and will work even when OnActivate hasn't been triggered in the script.
Note
Unlike the vanilla activate function, the reference is the actor that will activate something, rather than the object to activate.
Force the PC to Activate
begin test
long targetRef
long pcRef
; Don't force pickup if we're not sneaking.
if ( GetPCSneaking == 0 )
return
endif
; Get a reference to what the player is looking at.
setx targetRef to xGetPCTarget
if ( targetRef == 0 )
return
endif
; Get a reference to the player, and force them to activate what they are looking at.
setx pcRef to xGetRef "player"
pcRef->xActivate targetRef
end
xAddSpell⚓︎
Parameters:
stringobjectID: The object ID of the spell to add.
Returned:
- None
This is a wrapper for the vanilla AddSpell function that can take variable input.
xAITravel⚓︎
Parameters:
floatx: The position to travel to on the X axis.floaty: The position to travel to on the Y axis.floatz: The position to travel to on the Z axis.
Returned:
- None
This is a wrapper for the vanilla AITravel function that can take variable input.
xDrop⚓︎
Parameters:
stringobjectID: The object ID of the item to drop.longcount: The number of items to drop.
Returned:
- None
This is a wrapper for the vanilla Drop function that can take variable input.
Note
xDrop N+1 items will leave 1 phantom icon plus N real items in the dropping actors inventory. xGetItemCount will not report the 1 phantom icon. However, xRemoveItem will remove the phantom safely. So "safe" procedure for xDrop seems to be to follow up with xRemoveItem of the same count. Additionally for non-player actors in menumode, exit and re-entry to menumode is needed to refresh the icons and avoid phantom icon interaction that could result in permanent item doubling or CTD. This also applies to the standard drop function.
xEquip⚓︎
Parameters:
stringobjectID: The object ID of the item to equip.
Returned:
- None
This is a wrapper for the vanilla Equip function that can take variable input.
xGetAttribute⚓︎
Parameters:
longattributeID: The Attribute ID to get the value of.
Returned:
floatvalue: Current value of the attribute.
Returns the current value of the referenced object's attribute.
Note
This function only supports the player and NPCs.
xGetBaseAttribute⚓︎
Parameters:
longattributeID: The Attribute ID to get the value of.
Returned:
floatvalue: Base value of the attribute.
Returns the base current value of the referenced object's attribute.
Note
This function only supports the player and NPCs.
xGetBaseGold⚓︎
Parameters:
- None
Returned:
longgold: The base amount of bartering gold of the reference.
Returns the base amount of barter gold assigned to the NPC (or creature). This is the value that resets automatically each day.
xGetBaseSkill⚓︎
Parameters:
longskillID: The Skill ID to get the value of.
Returned:
floatvalue: Base value of the skill.
Returns the base value of the referenced object's skill.
Note
This function only supports the player and NPCs.
xGetClass⚓︎
Parameters:
longattributesMask: A bit mask to apply to the attributes value.longmajorMask: A bit mask to apply to the majorSkills value.longminorMask: A bit mask to apply to the minorSkills value.
Returned:
stringclassID: The unique string identifier of the class.stringname: The name of the class.longplayable: 1 if the class can be chosen by the PC, 0 otherwise.longspecialization:0= Combat,1= Magic,2= Stealthlongattributes: A bitmap of the two primary attributes. The result is obtained by adding the values found in the attributes table below.longmajorSkills: A bitmap of the 5 major skills. The result is obtained by adding the values found in the skills table below.longminorSkills: A bitmap of the 5 minor skills. The result is obtained by adding the values found in the skills table below.
Returns info about the class of the target NPC/PC, or 0 if the target is not an NPC or the PC.
For a custom class created at PC creation, the classID is "NEWCLASSID_CHARGEN" and playable is 0.
Attribute and Skill Bitmaps⚓︎
| Value | Attribute |
|---|---|
| 1 | Strength |
| 2 | Intelligence |
| 4 | Willpower |
| 8 | Agility |
| 16 | Speed |
| 32 | Endurance |
| 64 | Personality |
| 128 | Luck |
| Value | Skill |
|---|---|
| 1 | Block |
| 2 | Armorer |
| 4 | Medium Armor |
| 8 | Heavy Armor |
| 16 | Blunt Weapon |
| 32 | Long Blade |
| 64 | Axe |
| 128 | Spear |
| 256 | Athletics |
| 512 | Enchant |
| 1024 | Destruction |
| 2048 | Alteration |
| 4096 | Illusion |
| 8192 | Conjuration |
| 16384 | Mysticism |
| 32768 | Restoration |
| 65536 | Alchemy |
| 131072 | Unarmored |
| 262144 | Security |
| 524288 | Sneak |
| 1048576 | Acrobatics |
| 2097152 | Light Armor |
| 4194304 | Short Blade |
| 8388608 | Marksman |
| 16777216 | Mercantile |
| 33554432 | Speechcraft |
| 67108864 | Hand-to-Hand |
xGetCombat⚓︎
Parameters:
- None
Returned:
referencereference: Reference to the current combat target.
Returns a reference to the reference NPC/creature's combat target, or 0 if the reference is not in combat.
xGetGold⚓︎
Parameters:
- None
Returned:
longgold: The reference's current barter gold.
xGetGold returns the current amount of barter gold possessed by the NPC (or creature). The base gold amount is used if you haven't bartered with the NPC/creature recently.
xGetMagic⚓︎
Parameters:
- None
Returned:
longobjectType: The Object Type of the equipped magical source.stringobjectID: The object ID of the spell or enchantment selected.
Returns the currently equipped spell or enchanted item. This is specifically the object that appears in the equipped magic slot and includes on-use magical items as well as spells.
Note
The returned objectType and objectID will always be associated with a Spell or Enchantment object, not the Weapon, Armor, Clothing, or Book that the magic is placed on.
xGetMaxFatigue⚓︎
Parameters:
- None
Returned:
floatmaxFatigue: The reference's maximum fatigue.
!!! noteReturns maximum fatigue. This function only supports the player and NPCs.
xGetMaxHealth⚓︎
Parameters:
- None
Returned:
floatmaxHealth: The reference's maximum health.
!!! noteReturns maximum health. This function only supports the player and NPCs.
xGetMaxMagicka⚓︎
Parameters:
- None
Returned:
floatmaxMagicka: The reference's maximum magicka.
!!! noteReturns maximum magicka. This function only supports the player and NPCs.
xGetRace⚓︎
Parameters:
shortreturnType: The return pattern desired. See below for details.
Returned (returnType is 0):
stringraceID: The object ID of the target's race.
Returned (returnType is 1):
arrayarrayID: An array ID containing the values of the race.
This function fetches the objectID or complete details about the target's race.
Warning
The arrays returned by this function when returnType is 1 are volatile. They should not be used for custom storage. Whenever xGetRace is called, the arrays are cleared and refilled with up-to-date information.
If returnType is 0, the response is the race's object ID. Otherwise, the returned array contains the following values:
| Index | Type | Contents |
|---|---|---|
| 0 | string |
Object ID. |
| 1 | string |
Name. |
| 2 | array |
Skill bonuses. |
| 3 | array |
Starting attributes. |
| 4 | float |
Male height. |
| 5 | float |
Female height. |
| 6 | float |
Male weight. |
| 7 | float |
Female weight. |
| 8 | long |
Playable flag. |
| 9 | long |
Beast flag. |
The skill bonuses array begins with index 0 holding the number of skill bonuses (a value between 0 and 7). Pairs of values are then returned. The odd indexes hold the Skill while the even indexes hold the bonus to the given skill.
The starting attributes array contains the following values:
| Index | Type | Contents |
|---|---|---|
| 0 | long |
Male strength. |
| 1 | long |
Female strength. |
| 2 | long |
Male intelligence. |
| 3 | long |
Female intelligence. |
| 4 | long |
Male willpower. |
| 5 | long |
Female willpower. |
| 6 | long |
Male agility. |
| 7 | long |
Female agility. |
| 8 | long |
Male speed. |
| 9 | long |
Female speed. |
| 10 | long |
Male endurance. |
| 11 | long |
Female endurance. |
| 12 | long |
Male personality. |
| 13 | long |
Female personality. |
| 14 | long |
Male luck. |
| 15 | long |
Female luck. |
xGetService⚓︎
Parameters:
longmask: A filter to limit the services returned.
Returned:
longservices: The services offered by the reference, limited by mask.
This function returns a bitfield of services offered by a given reference.
The service values are shown in the following table. If an NPC offers more than one service the sum of the service numbers will be returned. The mask parameter can be used as a filter to limit the return value to only consider the services indicated.
| Value | Service |
|---|---|
| 1 | Barters for weapons. |
| 2 | Barters for armor. |
| 4 | Barters for clothing. |
| 8 | Barters for books. |
| 16 | Barters for ingredients. |
| 32 | Barters for lockpicks. |
| 64 | Barters for probes. |
| 128 | Barters for lights. |
| 256 | Barters for alchemical apparatus. |
| 512 | Barters for repair tools. |
| 1024 | Barters for miscellaneous items. |
| 2048 | Offers spells. |
| 4096 | Barters for enchanted items. |
| 8192 | Barters for potions. |
| 16384 | Provides training. |
| 32768 | Provides spellmaking service. |
| 65536 | Provides enchanting service. |
| 131072 | Repairs armor and weapons. |
Note
Previous versions of MWSE made use of xIsTrader, xIsTrainer, and xIsProvider. This function supersedes those. Old scripts that use them will continue to work, but new scripts should make use of xGetService.
xGetSkill⚓︎
Parameters:
longskillID: The Skill ID to get the value of.
Returned:
floatvalue: Current value of the skill.
Returns the current value of the referenced object's skill.
Note
This function only supports the player and NPCs.
xGetSpell⚓︎
Parameters:
stringspellID: The spell ID to search for.
Returned:
longresult:1if the spell was found, otherwise0.
Returns 1 if spellId is present, 0 otherwise. This is not a wrapper for GetSpell; it's a reimplementation. It only works for NPCs and the player.
xGetSpellEffects⚓︎
Parameters:
stringspellID: The spell ID to check for.
Returned:
longresult:1if the object is equipped, otherwise0.
Returns 1 if the calling object is under the effect of the given spell, or 0 otherwise.
xHasItemEquipped⚓︎
Parameters:
stringobjectID: The object ID to check if equipped.
Returned:
longresult:1if the object is equipped, otherwise0.
Returns 1 if the NPC or creature has the object equipped, 0 otherwise.
xIsFemale⚓︎
Parameters:
- None
Returned:
longresult:1if the reference is female, otherwise0.
Returns 1 if the NPC is female and 0 otherwise.
xModAttribute⚓︎
Parameters:
longattributeID: The Attribute ID to modify.floatvalue: The value to modify the attribute by.
Returned:
shortresult: Result of the function.
Modifies the current and base values of the specified attribute. This suffers from the same display issue as xSetLevel. It ignores the 100 max attribute limit.
Note
This function only supports the player and NPCs.
xModService⚓︎
Parameters:
longservices: The combined value of services the reference should offer (positive) or refuse (negative).
Returned:
- None
Uses the services parameter to modify the services offered by an NPC. A positive value adds that service (or set of services) to those already offered. A negative value will remove a service or service. The changes are not permanent.
| Value | Service |
|---|---|
| 1 | Barters for weapons. |
| 2 | Barters for armor. |
| 4 | Barters for clothing. |
| 8 | Barters for books. |
| 16 | Barters for ingredients. |
| 32 | Barters for lockpicks. |
| 64 | Barters for probes. |
| 128 | Barters for lights. |
| 256 | Barters for alchemical apparatus. |
| 512 | Barters for repair tools. |
| 1024 | Barters for miscellaneous items. |
| 2048 | Offers spells. |
| 4096 | Barters for enchanted items. |
| 8192 | Barters for potions. |
| 16384 | Provides training. |
| 32768 | Provides spellmaking service. |
| 65536 | Provides enchanting service. |
| 131072 | Repairs armor and weapons. |
xRemoveSpell⚓︎
Parameters:
stringobjectID: The object ID of the spell to remove.
Returned:
- None
This is a wrapper for the vanilla RemoveSpell function that can take variable input.
xSetBaseGold⚓︎
Parameters:
longgold: New value to set the reference's base barter gold to.
Returned:
- None
Changes the base amount of barter gold assigned to the NPC (or creature). Unfortunately this change won't be saved with the save game so you will need to reset it after each game reload or after the "72-hour bug" affects the merchant.
xSetGold⚓︎
Parameters:
longgold: New value to set the reference's current barter gold to.
Returned:
- None
xSetGold changes the current amount of barter gold possessed by the NPC (or creature). This value is stored in save game files so it will survive a game reload. Setting this will have no effect if you haven't recently bartered with the NPC/creature. But setting both this and the base gold amount at the same time will likely do what you want.
xSetLevel⚓︎
Parameters:
longlevel: New value to set the reference's level to.
Returned:
- None
Sets the level of the given reference. This function is a wrapper for SetLevel, and suffers from the same display issue: when using this function on the player, the character screen does not update with the new level.
xSetService⚓︎
Parameters:
longservices: The combined value of services the reference should offer.
Returned:
- None
xSetService uses the value parameter to change the NPC to offer the set of services represented by the number. The service number values are used and any old services are ignored.
For example using a value of 8 will make the NPC a bookseller. A value of 131587 (1+2+512+131072) is typical for smiths. The values changed by this function are not permanent and may be reset after 72-hours or a game reload.
| Value | Service |
|---|---|
| 1 | Barters for weapons. |
| 2 | Barters for armor. |
| 4 | Barters for clothing. |
| 8 | Barters for books. |
| 16 | Barters for ingredients. |
| 32 | Barters for lockpicks. |
| 64 | Barters for probes. |
| 128 | Barters for lights. |
| 256 | Barters for alchemical apparatus. |
| 512 | Barters for repair tools. |
| 1024 | Barters for miscellaneous items. |
| 2048 | Offers spells. |
| 4096 | Barters for enchanted items. |
| 8192 | Barters for potions. |
| 16384 | Provides training. |
| 32768 | Provides spellmaking service. |
| 65536 | Provides enchanting service. |
| 131072 | Repairs armor and weapons. |
xStartCombat⚓︎
Parameters:
longreference: Target reference for the caller to initiate combat with.
Returned:
- None
xStartCombat is a wrapper for the original StartCombat to take variables.