Difference between revisions of "SetScript"

From the Oblivion ConstructionSet Wiki
Jump to navigation Jump to search
imported>WereWolf
(New page: A command for Oblivion Script Extender Sets the specified script onto the calling object and returns any previous script. '''Syntax:''' (script:re...)
 
imported>Shademe
(→‎Notes: Added method for script activation on items)
 
(10 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{Beta}}
A command for [[:Category:Oblivion Script Extender|Oblivion Script Extender]]
A command for [[:Category:Oblivion Script Extender|Oblivion Script Extender]]

⚫
Sets the specified script onto the calling object and returns any previous script.


'''Syntax:'''
'''Syntax:'''
(script:refID) ''reference.''SetScript scriptID:ref ''targetObjectID:ref''
(script:refID) ''reference.''SetScript scriptID:ref ''targetObjectID:ref''

⚫
Sets the specified script onto the calling object and returns any previous script.


==Notes==
==Notes==
*Note that Oblivion doesn't have a script variable type so you must assign the script to a ref variable for this to work.
*Note that Oblivion doesn't have a script variable type so you must assign the script to a ref variable for this to work.
*It seems that setting the script won't start it up. For instance, if you use '''player.SetScript rScript''' the script will be added to the player ('''player.GetScript''' will be rScript), but no blocks will run (tested GameMode, onHit, onMagicHit) and '''HasVariable''' will falsely return 0.
*'''This function is currently considered a BETA FUNCTION which will get official support after it gets some more testing. For now, please do not use in a shipping mod until further testing is done.'''
**For some scripts, this isn't an issue. For instance, if you set a script to an item and then use '''LocalRef.AddItem Item 1''' the script will run, because '''AddItem''' starts scripts.
***An alternative would be to disable the item and enable it a frame later. This activates the script.
**In the case of the player, however, the only method to start the script is to open the console and type in '''player.ModAV Health 0''', '''player.AddItem F 1''' or even player with the dot '''player.''' Using the functions in a script won't start the script (even '''player.con HairTint 0 0 0''')
***[[RunBatchScript]] works with a text file with a simple '''player.'''.
***For OBSE v16 and later, use '''RunScriptLine "player."'''
**Applying a script directly to NPCs and creatures follow the same rules as when applying it to the player.
***For OBSE v16 and later, use '''RunScriptLine "%q%i%q." NPCRef"'''
*As with all non-cloneform items, when you reload a game the script ref will be reset. If the object didn't have a script, then it won't have a script when you reload. If it had a different script, then it will have the different script once again.
**There is an exception - when reloading a save game in the same area. For instance, if, in your save game, the player doesn't have a script, then you set a script on the player, then reload -> the script will still be on the player.


==See Also==
==See Also==

Latest revision as of 17:08, 9 April 2009


A command for Oblivion Script Extender

Syntax:

(script:refID) reference.SetScript scriptID:ref targetObjectID:ref

Sets the specified script onto the calling object and returns any previous script.

Notes[edit | edit source]

  • Note that Oblivion doesn't have a script variable type so you must assign the script to a ref variable for this to work.
  • It seems that setting the script won't start it up. For instance, if you use player.SetScript rScript the script will be added to the player (player.GetScript will be rScript), but no blocks will run (tested GameMode, onHit, onMagicHit) and HasVariable will falsely return 0.
    • For some scripts, this isn't an issue. For instance, if you set a script to an item and then use LocalRef.AddItem Item 1 the script will run, because AddItem starts scripts.
      • An alternative would be to disable the item and enable it a frame later. This activates the script.
    • In the case of the player, however, the only method to start the script is to open the console and type in player.ModAV Health 0, player.AddItem F 1 or even player with the dot player. Using the functions in a script won't start the script (even player.con HairTint 0 0 0)
      • RunBatchScript works with a text file with a simple player..
      • For OBSE v16 and later, use RunScriptLine "player."
    • Applying a script directly to NPCs and creatures follow the same rules as when applying it to the player.
      • For OBSE v16 and later, use RunScriptLine "%q%i%q." NPCRef"
  • As with all non-cloneform items, when you reload a game the script ref will be reset. If the object didn't have a script, then it won't have a script when you reload. If it had a different script, then it will have the different script once again.
    • There is an exception - when reloading a save game in the same area. For instance, if, in your save game, the player doesn't have a script, then you set a script on the player, then reload -> the script will still be on the player.

See Also[edit | edit source]