Skip to content

Instantly share code, notes, and snippets.

@mrowrpurr
Created July 26, 2021 05:36
Show Gist options
  • Save mrowrpurr/9e4f356b909fe08e4fdd5fcf10e58f33 to your computer and use it in GitHub Desktop.
Save mrowrpurr/9e4f356b909fe08e4fdd5fcf10e58f33 to your computer and use it in GitHub Desktop.
Custom Skyrim Console Command
; Credit: milzschnitte
; Source: https://www.loverslab.com/topic/58600-skyrim-custom-console-commands-using-papyrus/
Scriptname MyScript extends ReferenceAlias
Event OnInit()
UnregisterForMenu("Console")
RegisterForMenu("Console")
endEvet
Event OnPlayerLoadGame()
UnregisterForMenu("Console")
RegisterForMenu("Console")
endEvent
Event OnMenuOpen(string menuName)
if menuName=="Console"
RegisterForKey(28)
RegisterForKey(156)
endif
endEvent
Event OnMenuClose(string menuName)
if menuName=="Console"
UnregisterForKey(28)
UnregisterForKey(156)
endif
endEvent
Event OnKeyDown(int keyCode)
if keyCode==28 || keyCode==156
int cmdCount = UI.GetInt("Console", "_global.Console.ConsoleInstance.Commands.length")
if cmdCount>0
cmdCount-=1
string cmdLine = UI.GetString("Console","_global.Console.ConsoleInstance.Commands."+cmdCount)
if cmdLine!=""
bool bSuccess=false
actor a = Game.GetCurrentConsoleRef() as actor
if a==none
a=Game.GetPlayer()
endif
string[] cmd=StringUtil.Split(cmdLine," ")
if cmd[0]=="version"
Debug.Notification("This is version 1.0!")
bSuccess=true
elseif cmd[0]=="name"
Debug.Notification("Here is the name!")
bSuccess=true
elseif cmd[0]=="gold"
int c=1
if cmd.length>1
c=cmd[1] as int
endif
a.AddItem(Game.GetFormFromFile(0xf,"Skyrim.esm",c,true)
bSuccess=true
endif
if bSuccess==true
; Remove last line (error line)
Utility.WaitMenuMode(0.1)
string history = UI.GetString("Console","_global.Console.ConsoleInstance.CommandHistory.text")
int iHistory = StringUtil.GetLength(history) - 1
bool bRunning=true
while iHistory>0 && bRunning==true
if StringUtil.AsOrd(StringUtil.GetNthChar(history,iHistory - 1))==13
bRunning=false
else
iHistory-=1
endif
endWhile
UI.SetString("Console","_global.Console.ConsoleInstance.CommandHistory.text",StringUtil.Substring(history,0,iHistory))
endif
endif
endif
endif
endEvent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment