Top / MOD一覧 / MOD製作 / EVENT

MOD製作/EVENT

MOD製作

(英語版Wiki、http://www.paradoxian.org/hoi2wiki/index.php/Modding_eventsより訳出)

戦闘がゲームの心臓、AIがゲームの頭脳とするならば、イベントはすべてを支える骨格であり、来るべき世界大戦のための舞台装置です。これらのイベントを書き換えたり、新しいものを作ったりすることで、ゲームにまったく新しい味わいを加えたり、自分好みに仕立てたりできるのです。

イベントを記述したファイルは、db/eventsフォルダに収められています。

以下、いくつかの手引きや表、それにイベントファイルを変更するための例などをお見せしていきましょう。

簡単な説明とイベント編集例

(英語版Wiki、http://www.paradoxian.org/hoi2wiki/index.php/Simple_Instructions/Examples_on_Event_Editingより訳出)

目標と注意書き

HOI2でイベントを編集するというのはいろいろな目的があってのことでしょう。しかし、実際にファイルを開いて編集するのための知識もしくは技術はそれほど多くありません。ここではイベントファイルを修正するのに必要な、非常に簡単かつ初歩的なやり方で進めていくつもりです。最初に、注意書きからです。

イベントファイルを修正する場合、絶対にまず最初に、編集する前にファイルのバックアップコピーを取っておいてください。ファイルを変更するということは思っていたのと違った動きをゲームにもたらしたりします。ああ、もちろん、もしファイルをどうやってバックアップしたらいいのか分からないのであれば、絶対に編集するな

このガイドの中では疑問に対する解答がなかったら、パラドックスのHOI2 moddingフォーラムで探すべきでしょう。そこで大抵の必要とする答は見つかります。

ありふれたところからはじめる

最初のサンプルとしては、フィンランドのイベントファイル(イベントフォルダのfinland.txt)を使います。短い割にはちょっと複雑なイベントが含まれているからです。ファイルを開いた場合、最初は次のように書かれていると思います。

#
# HoI - Finland Events
#
#		written by Henrik Fahraeus
#

ここで大事なのは、これらの行の最初に半角で#が書いてあることです。イベントファイルの中では、どんなところでも#を入れると、プログラムはその#よりも後に書いてあることは なんでも 無視します。あとでもう少し触れますが、注意書きに使うところです。

......(以下翻訳中)

So we can see that Henrik, in the first 5 lines is telling the program to ignore those 5 lines because he started the line off with the "#". So what purpose do these 5 lines serve? Well the first thing is if you start opening many event files to copy/paste/edit, it's always a good idea to be able to see which file you are working on at any time. By putting the purpose of the file

# HoI - Finland Eventsat the top of the file, we can quickly see where we are. It's just a helpful reminder. In reality, the HOI2.exe couldn't care less about these lines...but don't tell Henrik, he's probably proud of his work. ;)
Obviously you know that Henrik was the programmer of the finland.txt by the this line

# written by Henrik Fahraeus
A good and easy/quick programming practice is that anytime you modify a file to put a new line under the line of the author with your name, the date you COMPLETED the modification of the file and the event number that you worked on. We haven't covered event number yet but stick with me as they'll get clear in a second. You'll also notice that I said completed. Why completed? Because quite frankly most folks don't care how many times you open and modify a file, they just want to know when it was finished and what you did.

Here is an example

#
# HoI - Finland Events
#
#		written by Henrik Fahraeus
#		modified by Chuck U. Farley - 01/14/2005 - 3200
#

Got it? Good...one more thing before we move onward. You'll sometimes come across empty lines. An empty line is basically 2 carriage returns. Here's the finland.txt code that shows a blank line.

#
# HoI - Finland Events
#
#		written by Henrik Fahraeus
#

#########################################################################

6行目:
6行目を見てもらえただろうか。ここには何も、#も、ない。
See line 6? Notice how there is no "#". So what do you think the program does with this line? Did you guess nothing? If so you get a cookie cause this is what happens in the case of an empty line. It ignores it...looks past it...cares nothing about it...

イベント本体

それでは本当のイベントについて、基礎をほんの少し勉強していこう。まずはイベント3200へと入っていこうか。イベント3200って何? って思ったかもしれないが、finland.txtの7行目から44行目に入ってる。まあ見ていこう。

#########################################################################
#  The Winter War
#########################################################################
event = {
	id = 3200
	random = no
	country = FIN

	# Triggered by SOV 2620

	name = "EVT_3200_NAME"
	desc = "EVT_3200_DESC"
	style = 0
	picture = "Winter_War"

	action_a = {
		name = "ACTIONNAME3200A" # Let them come if they dare!
		ai_chance = 99
		command = { type = trigger which = 2621 } #SOV
		command = { type = chiefofstaff which = 29137 }
		command = { type = chiefofarmy which = 29145 }
		command = { type = domestic which = political_left value = -1 }
		command = { type = relation which = SOV value = -10 }
		command = { type = relation which = SWE value = 5 }
		command = { type = relation which = NOR value = 5 }
	}
	action_b = {
		name = "ACTIONNAME3200B" # Fold to Russian Pressure
		ai_chance = 1
		command = { type = secedeprovince which = SOV value = 145 }
		command = { type = secedeprovince which = SOV value = 146 }
		command = { type = domestic which = political_left value = 1 }
		command = { type = relation which = SOV value = 25 }
		command = { type = relation which = GER value = -15 }
		command = { type = relation which = SWE value = -10 }
		command = { type = trigger which = 2622 } #SOV
	}
}

Looks kinda complicated doesn't it? While it is definitely fairly readable and you can quickly get the idea of what Henrik is trying to do, I'm still going to step through it line by line. But before I do that we need to have a quick discussion of braces "{}" and parentheses "()".

When you were in school and taking math, one of the things they taught you early on was the algebraic order of operations. That is, 3-2*4 = 3-(2*4). It isn't (3-2)*4 right? It's the same with programming. But with programming, it's less obvious. It can be really hard to keep track of all of those "()", "{}" and "[]". And just as in math, if you put (3-2x4 with no "closing" parenthesis...you get...junk! Progamming DEMANDS that you put a closing parenthesis when you open a parenthesis, or bracket, quotation-mark or other 'grouping' symbol. If you don't, then your event or program will not work. So make sure you keep up with them! :-)

Now back to the event and lines 7-9.
Lines 7-9:

#########################################################################
#  The Winter War
#########################################################################

Lines 7-9 are additional header information similar to lines 1-5 that we have already spoken about. You'll notice that lines 7 and 9 are basically lots of "#" signs. Henrik didn't put all those "#" signs out there because he really really didn't want the program to run the lines, he basically did it so that you can readily tell when the event starts. Like the first 5 lines it just gives you a marker as to where a certain event starts and it makes for easy reading.
Now for a moment of religion in programming. I personally like it when someone who modifies an event puts some details in the event header about what they changed. Some people don't like it, some do. It's kind of up to the modder.

Line 10:

Yippee for us cause we are now at the start of our event. Line 10 shows us the start of the event.
event = {Gee...somehow I'm just not giddy with excitement. Anyway now that we see the "start" of the event let's move onto the meat.
Lines 11-13:

id = 3200
random = no
country = FIN

11行目が一番大事です。いやもう本当に、致命的に大事です。同じid番号は、一つのイベントでしか使えません。一つのというのは、このfinland.txtの中でという意味にとどまりません。イベントフォルダの中のどのファイルでも、他に3200番を使うことはできません。もし同じイベントidを二回以上使ったとすると、それは機能しなくなります。
そういうわけで、新しいイベントを作るときには、特に気をつけて、イベントidだけはコピーしてしまわないようにしてください。

12行目は簡単です。

random = no

は、プログラムに、このイベントはランダムに、もしくはたまたまで起きるものではない、と指示するものです。

By this I mean that the program will not just arbitrarily decide that it's going to run this event anytime it wants. In order for this event to fire it has to either be triggered by another event (we'll get to triggering in a minute) or it has to be fired/run during a specific timeframe. If you want to create an event or have an event fire at random times during the course of your game, just change the "no" to "yes" and it will. Finally line 13 is a limiter on which country this particular event can be run against. 

country=FINIn this case this event can only be run for Finland and in the event that this event is "triggered" it will only run against Finland. So if you decide to run this via the F12 cheat (i.e. event 3200) and you are any country other than Finland, you don't get any of the benefits. I think....need to verify that tonight but I'm fairly positive.
So let's move onto the next set of lines

Lines 14, 15, 16:
Now we're down to wonderful line 14...which happens to be blank, so we'll do the big skip to line #15. Line #15 is a thing of absolute wonder.

#Triggered by SOV 2620

Of wonder? Why yes...it's a note...which is a great thing in programming. Henrik has left us a wonderful note in his code that simply states that this particular event is only fired/triggered by event 2620 contained in the ussr.txt event file (yes he put SOV and not ussr.txt...bad Henrik...no cookie for you). By the way, in programmer-speak, such notes are called "comments".

Since this event had the "random = no" and from a quick look...no dates for when it kicked off, a casual programmer would have had no idea when or where this event got kicked off. Thanks to Henrik, we now know when this event will be used. So maybe we'll give him a cookie after all. Also he put SOV because this is the country for which USSR is identified by the game. All countries in the game have 3 letter tags which identify that country to the game script.

Note that line 16 is also blank. It is purely a matter of personal taste and style, whether and how, a programmer formats comments. But, whatever the style, it is ever so _good_ to *have* comments!

Lines 17-19:

name = "EVT_3200_NAME"
desc = "EVT_3200_DESC"
style = 0
picture = "Winter_War"

Next we have this

action_a = { name = "ACTIONNAME3200A" # Let them come if they dare!

Every single event in the game has at least one choice. Even events which only have the "OK" option still have that one choice. That means that whenever you make or modify an event you have to put at least one choice in it otherwise the event will not fire.

You start by writing what it is. If it only has one choice, then this would be the first choice: action_a. If its the second choice you write action_b of course in order to have an action_b you have to have an action_a. It's kind of like building blocks. You can have, I believe, an unlimited number of actions (although the most i have ever seen was 6). Next, you have that plain old {which tells the game that there is content it has to read coming up and to get ready to read it.

As far as spacing goes, to my knowledge, it does not matter how much spacing you put between the bracket and the "name". For the events I do for my HOI 2 modification, "the ALEXIS Project", I have action_a = {

                                        name = ******

as compared to what we see above where there is some spacing between the bracket and the name the line below it. It does not really matter how much spacing you put. It differs from modder to modder.

Next, you have the name of the choice which is shown by name = . Then you have to put ACTIONNAME****A or ACTIONNAME****B etc.etc. after the name which is telling the game that this is a choice for that specific event denoted by the **** or in a real event the number. If you mess this up by putting a different event number you are in big trouble because your event will not fire correctly.

Next you type a # sign which tells the game that this is what the event choice should be displayed as in the game. If you goof this part up your event will come up as EVENT_3200. With the choice being ACT_NAME_3200A, or something like that. It wont be pretty, the event will still show and work in game as long as the number is correct, but it wont be "clean" and will surely not look professional.

Now you come to the last tiny bit of information you need to tell the game before you can begin telling the game what to make the event do. The ai_chance, its simple enough, when this event is fired by a country being played by the AI what chance should it have for picking this option? In this particular choice the AI will 99% of the time pick the first option and 1% of the time pick the second option. Its actually quite simple as is all of HOI 2 Programming, once you get the hang of it ;).

Next you come to the juicy stuff which tells the game what the choice should do. There are at least a hundered different commands all available on this site under commands. You merely have to type command = { Put in what you want the event to do or one of the things you want the event to do and close your bracket }Make sure you always close the bracket.

The 'type' part of the command is merly a necessity which will in a few spaces tell the game what type of command this is. For example typing 'trigger' will tell the game to trigger an event which = **** which is ironically how the script in game works. After typing the event number press space once and type a } and you're ready to go down to the next line and do another command!

The event command page will tell you what each command does and from my POV it is self explanatory although if the previous author wishes to come back, revise my work and type up what each line does i will not hold a grudge ;).

Note

You can only do one command to a line and always must do (regardless of what the command is)

command = { type =

that is the only similar part amongst all commands.

After your're done typing the commands, just enter a brace on the next line. This tells the game that this event is finished, and that nothing after this applies to this event.

In my experience, an event will often be missing a brace, and so it will not work. So make sure you double, triple, even quadruple check your braces to make sure that they are all where they need to be and are all braces.

(以下別人による追記1)

イベントトリガーの挙動について

イベントトリガーは、一般的に
A = Xという形で表記されます。(Aが項目名)
引数を複数持つトリガーは
A = { A1 = X A2 = Y }という形になりますが、基本は同じです。

トリガー文の判定とは、その文に示された内容が現状で真か、偽かということです。
たとえば、自国が戦争中の場合に、
atwar = yes のトリガー文は真と評価され、
atwar = no のトリガー文は偽と評価されます。
そして、トリガーセクション全体が真のとき、そのイベントの発動条件を満たしたことになります。
つまり、triggerセクション内に単一のトリガーしかない場合は単純に、そのトリガー文の評価がセクション全体の評価となります。
NOTは内部の論理値の反転、ORが加法でANDが乗法演算です。
つまり、
NOT = { OR = { A B }} ≡ AND = { NOT = { A } NOT = { B } }
NOT = { AND = { A B }} ≡ OR = { NOT = { A } NOT = { B } }
となります。

イベントコマンド小ネタ集

公式でサポートされていない引数に関する小ネタ

relation which = [tag] value = X, set_relation which = [tag] value = Y

tag国家との関係性をX上昇、乃至Yに設定するコマンドです。
ここに、which = -1という引数を与えたときの結果は、周辺国のうちどこか1国(ランダム)の模様です。
なお、周辺国の定義は陸上で国境を接していること、または同地域に属すること、のようです。
以下に実験結果を添付します。

  • フランス編 スペイン・ベルギー・ルクセンブルク・ブラジル・雲南・イギリスなどなど
  • イタリア編 ユーゴ・エチオピア・オーストリア・スイス・ハンガリーなどなど
  • 日本編 ソ連。

Top / MOD一覧 / MOD製作 / EVENT