Jump to content

Skyrim Custom Console Commands using Papyrus


milzschnitte

Recommended Posts

Greetings all,

 

after I was sitting around and thought about my Mod BeeingFemale and what is missing, the "Console commands" came up again.

This was something I realy want. One or maybe two years ago I already contact the SKSE Team and asked if there is a way, because they already made a console command to get the SKSE Version, but they couldn't help me.

 

Now I've thought about it again, and there was a new papyrus function in SKSE 1.7.2. With this command you can get the selected ObjectReference that was selected in the console.

And I already knew the UI Script, that was included in SKSE. And I finaly solverd my Console Command problem. I've tested the console commands with the vanilla console and with the MFG Console, and both worked.

But first let me explain the differnet between those two versions. The 'old SKSE' Script does not have a "Get SelectedObject". The support for the selected object came with 1.7.2. The "latest SKSE" does have support for the selected Object.

 

Attached you will find my solutions.

 

 

What do I need?

- SKSE

- Some Papyrus-Script knowledges

 

 

How to use it:

- At first, create a new QuestObject.

- Create a new QuestAlias in this QuestObject, and target the Player as reference. This allows you to use the "Event OnPlayerLoadGame()" Event

- Now include the Code.

 

 

How does it work?

At first, whenever a game was loaded, or when the Object was created (when you start a new Games) it will registrate for the Console Menu.

When registrating, an Event is raised when the console will open or close.

 

That's where we continue. Now we will use the "Event OnMenuOpen(string menuName)" Event that will be triggerd when the console will open

And to make sure, it's the console, we will ask in an If Statement for it.

If it is the console, we will registrate for the keys 28 and 156. Those are Enter and Numpad-Enter. Now we are able to track whenever the Enter or Numpad Enter key was pressed

 

When the console will be closed, we will unregistrate for those keys again. We don't want to use our code when the console is closed.

 

Now the main script part is, when we have pressed Enter in the menu. This is where the main part of the console command script starts.

At first, we will check again if the key was 28 or 156 to make sure it was the enter key (maybe you have registrated some other keys, too)

Now we will fetch the count of already enterd console commands. The last one was our console command.

if the count is greater then 0 we will continue. Otherwise the user opend the console and just pressed enter without a console command

 

Now we get the last typed console command using UI.GetString and will store it in the variable cmdLine

if this is not empty, we will continue again.

Now I've created a new variable named "bSuccess". This is a boolean value that will store, if the console command was handled in your script or not. We need this later again, but whenever your console command was hit, you must set this to true

 

(For 'latestSKSE' a script part will now fetch the selected object and store it in the variable 'a' as an actor. If it's none, we will use the player instead)

 

Now we will split the console command at each space. This allows us to use arguments written next to the console command.

in "cmd[0]" the console command is stored, in cmd[1] the first argument is stored, in cmd[2] the second argument is stored, in cmd[3] the third argument is stored, .....

 

Now we will ask for the console command.

If the Console Commad is "version" a notification will say "This is version 1.0!". After that we set the bSuccess to true, because our script handles this command

If the console command was not "version" check if it was "name" . This will show you how easy it is, to make console commands. If it was name, print a notification that says "Here is the name!"

 

and for a third console command, I've used "gold"

This console command can be written with or without an argument

At first I've created an variable named "c" and set it to 1. Here, the amount of gold will be stored. If there wasn't an argument, use the 1 as default amount.

Now we check if there was an argument written. If so, convert it into an integer, and overwrite "c" with this value.

And at least, add the amount of gold to the Player, or the selected actor, depending on what the SKSE Version you are using

 

Now we have 3 console commands, but there is still the "error message" that the console command does not exist.

That's why we've used our "bSuccess" variable.

If the console comand should be handled with in your script, we want to delete this message.

The script part that will follow now, will delete the last line in the history, if the console command was handeld by your script.

 

 

Knon issue

- If you keep on pressing enter, after you've enterd a console command, it will execute your script anyway. This is because our script makes use of the console command history, not the just typed in console command

- we can't use "." in our console command, ... so "player.mycommand" is not possible. To make use of it, we need more lines to track the last error message.

MyScript (latestSKSE).psc

MyScript (old SKSE).psc

Link to comment
  • 10 months later...

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

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

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. For more information, see our Privacy Policy & Terms of Use