Jump to content

[LE] Script to change an actors name


Recommended Posts

Here's a script that will change the name of an actor depending on a quest stage.

Useful if you want your character to be called something else until he has introduced himself.

Example: You ask the "Suspicious Bosmer" a bunch of control questions and eventually he'll reveal his real name.

 

This doesn't work with 'Short Name', so you may want to leave that blank on your actor as you create him/her.

Also, I'm a newbie at scripting stuff so if anybody has any suggestions to improve or slim this down then feel free to comment below.

 

*Requires SKSE to work.

Scriptname ChangeNameScript extends Actor

;This script is to be used as a base for eventual name changes in the future.
; Replace the 'RealName' and the 'UnknownName' variables to whatever you want.
; Hook it to the quest you are going to use with it.

;=========================================================
; Variables
Quest Property NameChangeQuest  Auto  ;Hook the Intro Quest

String Property RealName = "Real Name" Auto  ;The Real name of this character.

String Property UnknownName = "Unknown Name" Auto  ;The name to use when this character is unknown to us.

Int Property DefiningStage = 20 Auto  ;The Stage of the quest when our character should switch name.

Float Property UpdateTick = 5.0 Auto  ;The update interval in seconds.
;____________________________________________________________________________
;=========================================================
;The function that handles naming the character.
Function NameIt()

  ;Check if the 'NameChangeQuest' is not completed already, is running - and is on a stage less than 'DefiningStage' or not

  ;If it is less than 'DefiningStage'
  if !NameChangeQuest.IsCompleted() || (NameChangeQuest.IsRunning() &&  (NameChangeQuest.GetStage() < DefiningStage) )

    ;The Character hasn't introduced himself properly yet
    ; so his name should be equal to 'UnknownName'
    GetBaseObject().SetName(UnknownName)

    ;Register an update to check wether he still hasn't introduced himself.
    RegisterForUpdate(UpdateTick)

  ;If it is not less than 'DefiningStage'
  else
     if GetBaseObject().GetName() != RealName

      ;The Character has introduced himself with his real name
      ; and should therefore be referred to as such.
      GetBaseObject().SetName(RealName)
    endIf
  endIf
endFunction
;____________________________________________________________________________
;=========================================================
;Initializing the name of this character.
; NOTE: We probably only need the 'OnInit' event here, but the others are added as fool proof.

Event OnInit()  ;As we initialize this Character.
  NameIt()
EndEvent

Event OnLoad()  ;As we load this Character.
  NameIt()
EndEvent

Event onCellAttach()  ;As attach this Character to a cell.
  NameIt()
EndEvent

Event onLoadGame()  ;As we load a save game.
  NameIt()
EndEvent
;____________________________________________________________________________
;=========================================================
;Handling this Characters name OnUpdate.
; NOTE: We have registered an OnUpdate.
;       The following code should make sure his name gets updated if needed.

;On Update.
Event OnUpdate()  ;This event occurs ever X seconds set by 'UpdateTick'
  ;Check if the introductionary quest is less than 'DefiningStage' or not

  ;If it is less than 'DefiningStage' :
  if (NameChangeQuest.GetStage() < DefiningStage)

    ;Check if his name isn't what it should be.
    if GetBaseObject().GetName() != UnknownName

      ;If it is something else, make sure the Character is referred to by 'UnknownName'.
      GetBaseObject().SetName(UnknownName)
    endIf

  ;If it is not less than 'DefiningStage'
  else
    ;If the character does not have his real name by now :
    if GetBaseObject().GetName() != RealName

      ;The Character has introduced himself with his real name
      ; and should therefore be referred to as such.
      GetBaseObject().SetName(RealName)

    endIf

    ;We'll want to unregister the OnUpdate Event to stop it from firing.
    UnregisterForUpdate()
  endif
EndEvent
;____________________________________________________________________________

 

 

 

Cheers!

Link to comment
Share on other sites

This can be done without SKSE by forcing the actor into an alias with a display name.

Display Name: (optional) Can be used to rename the reference when it is assigned to the alias. The dropdown is a list of Messages - the Message Title will replace the reference's name. Note that this change is permanent - the reference will retain the new Display Name even when it is removed from the alias.

Edited by TheDungeonDweller
Link to comment
Share on other sites

perhaps someone in this thread can help me out. I'm looking for help with SetName/SetDisplayName with a ref alias & text replacement. It's a book for a treasure hunt and when an item is found an "[X]" appears next to the item name/clue. I have the book with text replacement. I have tried using <BaseName> Treasure Item Name: Location Clue, as well as <Alias (equals sign) ItemAliasName> [my equals sign is broke. I created a quest with ref alias for player, the book, and the items. The player alias has a script for addinventoryeventfilter and onitemadded event to capture when the treasures are added to the player inventory. The book has optional, stores text, and uses stored text checked. It is filled with the aliasname, and linked to item(equals)baseobjectid. The item references I have stores text and optional checked, and have tried filling it with alias name, and NONE. I have tried creating a reference to the baseobject and also using item(equals)baseobjectid. The script is below. The addinventoryfilter and onitemadded event work. The script detects the item, but does not rename the refalias so that it displays [X] in the Book.

Scriptname OblivionArtifactsAliasFilter extends ReferenceAlias

FormList Property OblivionArtifactsItemsFormList Auto
ReferenceAlias Property OblivionArtifactRefAlias63 Auto

Event OnInit()   
    AddInventoryEventFilter(OblivionArtifactsItemsFormList)  
	debug.MessageBox("Alias script initialized")
endEvent   

  
Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)   
    int i
	i=OblivionArtifactsItemsFormList.Find(akBaseItem)

	if i==0	;battleaxe of hatred
		debug.MessageBox("Battleaxe of Hatred Added to Inventory")
		akItemReference.SetDisplayName("[X]")
	endif
endEvent 

I have filled the properties in CK.

Link to comment
Share on other sites

 

This can be done without SKSE by forcing the actor into an alias with a display name.

Display Name: (optional) Can be used to rename the reference when it is assigned to the alias. The dropdown is a list of Messages - the Message Title will replace the reference's name. Note that this change is permanent - the reference will retain the new Display Name even when it is removed from the alias.

If you check the option to restore the original name when removed from the alias, it's not permanent.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...