Making the basics 基礎(chǔ)知識
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.
這是你將要實(shí)現(xiàn)的四個(gè)基本函數(shù):
string getModName() : 此函數(shù)返回mod的ID。 它用于在Mod Manager中識別您的mod。
bool onInitialize() : 游戲開始時(shí),會調(diào)用此函數(shù)
bool onLoadContent() : 當(dāng)游戲加載這個(gè)mod內(nèi)容的時(shí)候,會被調(diào)用此函數(shù)
bool onLoadOS() : 這個(gè)函數(shù)在游戲完成加載并保存時(shí)調(diào)用,并為您提供玩家的權(quán)利,允 許所有類型的修改。
So, first, let's code the first function : getModName().
public override string getModName()
{
return "GuideMod";
}
所以,首先,讓我們編寫第一個(gè)函數(shù):getModName()。
public override string getModName()
{
return "GuideMod";
}
With that, the ID of our mod will be GuideMod.
有了這一個(gè)函數(shù),我們的mod的名稱將會是GuideMod。
Our first command - Introduction 我們的第一個(gè)命令-介紹
We'll start doing our first commands.
First, make sure you've replaced "throw new NotImplementedException();" by "return true;"
我們將要開始做我們的第一個(gè)命令.
首先,確保你已經(jīng)用 "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”。 打開自動(dòng)完成菜單,看看自動(dòng)補(bǔ)全會為我們寫什么。
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.
要?jiǎng)?chuàng)建命令,我們需要使用命令 ModManager.addCommand().
當(dāng)我們輸入它之后,我們將會看到它有三個(gè)聲明。
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.
第一個(gè)參數(shù)總會是是命令的名稱。
第二個(gè)參數(shù)總會是命令的函數(shù),在后面我們會提到。
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.
如果使用第二個(gè)聲明,最后一個(gè)參數(shù)是一個(gè)boolean“true”/“false”,該參數(shù)若被實(shí)現(xiàn)則表示命令是否應(yīng)該自動(dòng)完成狀態(tài)。(true表示自動(dòng)完成,false則否) .而第一個(gè)聲明將不會做自動(dòng)完成。
(譯者注:我們猜測原作者意思如下:
眾所周知,Hacknet原有的指令可用Tab補(bǔ)全,而這一命令則會控制新加的命令是否也可用Tab。這一“開關(guān)”也許是為了防止某些沖突。)
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.
第三個(gè)聲明有四個(gè)參數(shù)。第三個(gè)參數(shù)是命令的描述,在命令幫助中將會出現(xiàn),最后一個(gè)參數(shù)與前面的相同,都是自動(dòng)完成開關(guān)。
Our first command - Implementation 我們的第一個(gè)命令-實(shí)現(xiàn)
Now, we're going to code our command.
Let's create a new static function like so :
現(xiàn)在,我們將要編寫我們的命令。
讓我們用以下代碼創(chuàng)建一個(gè)新的靜態(tài)函數(shù):
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類,而不是電腦操作系統(tǒng)的OS類。
現(xiàn)在,讓我們用命令在終端上打印出“Hello World”。
如果你想用os類自動(dòng)完成這個(gè)命令,你可以使用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()"
我們的第一個(gè)命令完成了。但它不會在游戲中打印出來.我們需要注冊它。
讓我們改寫一下代碼:"public override bool onLoadContent()"
public override bool onLoadContent()
{
ModManager.addCommand("test", testCommand);
return true;
}
瀏覽量:02017-07-19
瀏覽量:02017-03-21
瀏覽量:02017-03-21
瀏覽量:02017-03-21
瀏覽量:02017-03-21