scripthookvdotnet
scripthookvdotnet copied to clipboard
Can mods add console commands?
I was trying to create a Console Command on both v2 and v3 but I ended up finding out that the Console Attribute is part of the ASI and not the DLLs.
Considering that is not possible to access the SHVDN namespace: Is possible to create console commands from our scripts? If so, how?
Yes and no. You don't have to manually add console commands: All script classes are accessible from the console, so any static method can be called already. It is not currently possible to add those to the list printed via Help() though.
E.g. the following:
public class MyScript : Script
{
public static void MyCommand()
{
...
}
};
Can be called by typing MyScript.MyCommand() into the console. The static method doesn't have to be a member of a Script class. It can be anything in the script assembly. As long as it is public static.
I think in the initial version of the console (when it was still in C# userspace) it was possible to add commands by simply adding the ConsoleCommand to a method of a class which inherits Script. I'm not sure if we can easily go back to such functionality with the class being in core. IMO it would be nice, since it would declare some kind of public API for users of a script. Else a user would have to know everything about public static script methods beforehand.
It's still technically possible. There was an implementation that did this, but I removed it before the release in https://github.com/crosire/scripthookvdotnet/commit/7995f3fdd3cb8fcd0583d8a1d23b0d22e691d8a6. Can't really remember why. Probably for simplification. But I guess that could be added back.
Scripts could then add their own Help() command to list there public static methods.
Can be called by typing MyScript.MyCommand() into the console. The static method doesn't have to be a member of a Script class. It can be anything in the script assembly. As long as it is public static.
If the script uses SHVDN 2, is not possible to execute the function because it does not checks what version the assembly needs (v2 vs v3).

It is not currently possible to add those to the list printed via Help() though.
This would be pretty useful to avoid polluting control presses and the input cheat field. Think of the following:
- User writes
Help()on the console - Sees
ConfigureScriptName()with a description ofOpens the configuration options for ScriptName - Enters
ConfigureScriptName()on the console and a NativeUI menu opens up with the options
Enters ConfigureScriptName() on the console and a NativeUI menu opens up with the options
This would make it dependent upon NativeUI which is not maintainable :(
This would make it dependent upon NativeUI which is not maintainable :(
That is just an example showing what I'm trying to do with BulletLines. Calling ConfigureScriptName() would just do UIMenu.Visible = !UIMenu.Visible;.
The point here is that showing the user what he can do with the script in Help() will make it easier if he "forgets" to read the configuration instructions.
Maybe something like a ScriptAttribute[HasHelp] to tell the Console that the Script as a default Script.Help() Method which can then be listed in the Console.Help() options.
Can we write in this console?
Can we write in this console?
I believe that's already possible, just rename ScriptHookVDotNet.asi to *.dll and add reference to it.
Then:
var console = AppDomain.CurrentDomain.GetData("Console") as SHVDN.Console;
console.PrintInfo("Hello");
I believe that's already possible, just rename ScriptHookVDotNet.asi to *.dll and add reference to it.
No need to rename it, you can reference the ASI directly.
Yeah, but only if you edit the project file directly, visual studio won't let you do so in GUI
Weird, both VS and RIder allow me to add the file directly without needing to rename it.
When we add the ability to console commands, I'd like to use the classic syntax [cmd name] [arguments], just like how shells like bash and FiveM console parse commands and arguments. We can keep the ability to invoke public static methods with a dedicated command as long as all of scripts run in a single AppDomain (may be too difficult to achieve if we managed to provide a dedicated AppDomain per script Assembly so we can reload individual script assembly though). We would manage arguments with the classic strings.
Here's part of code how FiveM parses commands in the console: https://github.com/citizenfx/fivem/blob/5979ce4596ddc1f8cdf0a51fcb6c33453f980fc9/code/client/citicore/console/Console.Commands.cpp#L51
https://github.com/citizenfx/fivem/blob/5979ce4596ddc1f8cdf0a51fcb6c33453f980fc9/code/client/citicore/console/Console.cpp#L406