Jump to content
Sign in to follow this  
You need to play a total of 5 battles to post in this section.
MatroseFuchs

[ModAPI] How-To

4 comments in this topic

Recommended Posts

Administrator
534 posts
41 battles

The first step to a mod

ModsAPI is not active in the client by default. You need to add a "PnFMods" folder to the game directory "World_of_Warships/res_mods/<game_version>" to activate it. Then you need to put an empty Python file "PnFModsLoader.py" to the same directory "World_of_Warships/res_mods/<game_version>":

first_step.png

 

The "PnFMods" folder should contain folders with mods:

mods_folder.png

 

The simplest case is when a mod consists of just one file: "Main.py".

Therefore, the simplest possible mode can be located at: "World_of_Warships/res_mods/<версия_игры>/PnFMods/TestMod/Main.py".

ModsAPI consists of two parts, Python and Flash. The Python part is responsible for loading Main.py, and the Flash part loads a specially prepared Main.swf.

Python and Flash parts of the mod operate separately from the game client. The provided interface is used to receive and send various data.

Share this post


Link to post
Share on other sites
Administrator
534 posts
41 battles

"HelloWorld" Mod on PythonAPI

  1. Open the "PnFMods" folder created earlier and create a folder for the mod called "HelloWorld".
  2. Create a Python file in the mod folder and call it "Main.py".
  3. Open the file in the editor and write the first line API_VERSION = 'API_v1.0', this will allow ModAPI to recognize the file as part of the mod. Then write one more line displaying the message "Hello World!".
  4. Save changes.

files_main.png

imageproxy.png

 

Launch the game client, wait until it loads and then close it. Open a "python.log" file in "World_of_Warships\profile\, you will see something like this there:

imageproxy1.png

Share this post


Link to post
Share on other sites
Administrator
534 posts
41 battles

"HelloWorld" Mod on FlashAPI

Now let’s create a simple Flash mod. Open the project in the editor (see documentation) and rework the script a bit:

mod_hello_flash.png

 

Compile the project file and put the resulting "Main.swf" file in the mod folder.

mod_hello_folder.png

 

Launch the game client to make sure that the mod works.

mod_helloworld.png

Share this post


Link to post
Share on other sites
Administrator
534 posts
41 battles

Interaction between Python and Flash

Let’s take the "Hello World!" mod and look at how its Python and Flash parts interact:

mod_helloworld_code.png

 

Here is a brief explanation:

  1. The mod consists of two files Main.py and Main.swf (a compiled file from the ".as" project). As the mod already has a Flash part, the second file (Main.swf) should also be added to the mod folder (!), where Main.py is located.
  2. In Main.py, create the event handler "events.onFlashReady" that will report that the Flash file has finished loading and you can transfer information to it.
  3. Now let’s pass the line "Hello World!" to Flash using the method "flash.call".
  4. At this time, Flash takes our data using the method "gameAPI.data.addCallBack" and passes it to the handler function subscribed to this callback.
  5. Then the handler function brings the message to the stage and calls a function in a Python file using the method "gameAPI.data.call", but no data is passed in this case.   
  6. The Python file gets a call from Flash using the method "flash.addExternalCallback", calls the handler function.   
  7. And finally, the handler function puts the message about successful work to the log file.

 

Battle Mod

Let’s make the task a little more complicated. Let’s try to change the way a certain game effect is displayed. For example, let’s change the way damage from enemy shells is displayed. Let’s show the damage in a different place, set a different color, different font type and see how it works.

mod_selfDamage_py.pngmod_selfDamage_swf.pngmod_selfDamage.png

 

 

Development comments:

  1. Let’s get our ship’s ID using the method "battle.getPlayersInfo".
  2. The method "events.onReceiveShellInfo" will inform us about the event of damage dealt to our ship and pass this information to the handler function.   
  3. Then the handler function will pass the information to Flash using the same method.
  4. And finally, Flash will display the received damage the way we want it.

As a result, we got a mod displaying dealt damage in the place defined by us, with the message color and font size we want. In this mod, we set the position above the center, the message is bright red and it is displayed for three seconds if it’s not replaced by another message.

 

PS

This mod is just an idea and not the final version. You can use this idea to create your own mod; and maybe it’s your mod that will be included in the official mod pack. Good luck!

 

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  

×