《黑客网络》mod开发教程翻译大全

时间:2017/03/21 11:35:38 编辑:杉崎

Making the basics 基础知识

Here are the four basic functions you'll have to write :

string getModName() : This function returns the ID of the mod. It is used for identifying your mod in the Mod Manager.

bool onInitialize() : This function is called when the game starts.

bool onLoadContent() : This function is called when the game loads the content.

bool onLoadOS() : This function is called when the game has finished loading a save, and gives you an instance of the player, allowing for all types of modifications.

这是你将要实现的四个基本函数:

string getModName() : 此函数返回mod的ID。 它用于在Mod Manager中识别您的mod。

bool onInitialize() : 游戏开始时,会调用此函数

bool onLoadContent() : 当游戏加载这个mod内容的时候,会被调用此函数

bool onLoadOS() : 这个函数在游戏完成加载并保存时调用,并为您提供玩家的权利,允 许所有类型的修改

So, first, let's code the first function : getModName().

public override string getModName()

{

return "GuideMod";

}

所以,首先,让我们编写第一个函数:getModName()。

public override string getModName()

{

return "GuideMod";

}

With that, the ID of our mod will be GuideMod.

有了这一个函数,我们的mod的名称将会是GuideMod。

Our first command - Introduction 我们的第一个命令-介绍

We'll start doing our first commands.

First, make sure you've replaced "throw new NotImplementedException();" by "return true;"

我们将要开始做我们的第一个命令.

首先,确保你已经用 "return true;"更换 "throw new NotImplementedException();"

We're going to start working inside onLoadContent().

Let's type "ModManager." to open autocompletion menu and see what we can write.

我们将要开始在”onLoadContent().”里工作.

让我们输入“ModManager”。 打开自动完成菜单,看看自动补全会为我们写什么。

The functions Hackmore lets us use are :

ModManager.addCommand()

ModManager.hasCommand()

ModManager.addCustomComputerXml()

ModManager.addExeProgram()

ModManager.getModType()

ModManager.isModLoaded()

Hackmore让我们使用的方程有:

ModManager.addCommand()

ModManager.hasCommand()

ModManager.addCustomComputerXml()

ModManager.addExeProgram()

ModManager.getModType()

ModManager.isModLoaded()

To create a command, we'll need to use ModManager.addCommand().

When we type it, we see that it has three declarations.

要创建命令,我们需要使用命令 ModManager.addCommand().

当我们输入它之后,我们将会看到它有三个声明。

《黑客网络》mod开发教程翻译大全

The first argument is always the name of the command.

The second argument is always the function of the command, we'll get to that later on.

第一个参数总会是是命令的名称。

第二个参数总会是命令的函数,在后面我们会提到。

If you use the second declaration, the last argument is a boolean "true"/"false" that indicates if the command should be in autocompletion. The first declaration doesn't do autocompletion.

如果使用第二个声明,最后一个参数是一个boolean“true”/“false”,该参数若被实现则表示命令是否应该自动完成状态。(true表示自动完成,false则否) .而第一个声明将不会做自动完成。

(译者注:我们猜测原作者意思如下:

众所周知,Hacknet原有的指令可用Tab补全,而这一命令则会控制新加的命令是否也可用Tab。这一“开关”也许是为了防止某些冲突。)

The third declaration has four arguments. The third one is the description of the command, that appears in the command help, and the last one is the same as above, autocompletion.

第三个声明有四个参数。第三个参数是命令的描述,在命令帮助中将会出现,最后一个参数与前面的相同,都是自动完成开关。

Our first command - Implementation 我们的第一个命令-实现

Now, we're going to code our command.

Let's create a new static function like so :

现在,我们将要编写我们的命令。

让我们用以下代码创建一个新的静态函数:

public static bool testCommand(OS os, string[] args)

{

return true;

}

Make sure to use Hacknet's OS class, and not the system OS class.

Now, let's make so that our command prints out "Hello World" on the terminal.

If you see the autocompletion for os., you'll see that you can use os.write(string text);

So let's write :

确保使用的是Hacknet的OS类,而不是电脑操作系统的OS类。

现在,让我们用命令在终端上打印出“Hello World”。

如果你想用os类自动完成这个命令,你可以使用os.write(string text);

所以,让我们写一段以下代码:

public static bool testCommand(OS os, string[] args)

{

os.write("Hello World");

return true;

}

Our first command is done. But it won't work in game ! We need to register it.

Let's change : "public override bool onLoadContent()"

我们的第一个命令完成了。但它不会在游戏中打印出来.我们需要注册它。

让我们改写一下代码:"public override bool onLoadContent()"

public override bool onLoadContent()

{

ModManager.addCommand("test", testCommand);

return true;

}

相关攻略
相关游戏