Skip to content

Latest commit

 

History

History
76 lines (53 loc) · 4.08 KB

File metadata and controls

76 lines (53 loc) · 4.08 KB

Using HScript

This guide will walk you through the process of creating a functioning, fully compatible Friday Night Funkin' mod, using the game's official systems for loading custom content and scripts. Once your mod is complete, you will be able to place it in the mods folder in your game install and use its content in-game without overriding the base game content and still maintain compatibility with other mods.

The previous chapters provides for plenty of functionality, and should be sufficient to make your own custom story weeks complete with custom characters, stages with static and animated props, and songs with custom chart events. However, this does not provide for advanced functionality, such as cutscenes, custom mechanics, or other custom behavior. The following chapters describe how to implement your own custom behavior, and this chapter breaks down important fundamentals on how scripting works and how to resolve common issues encountered while scripting.

What is HScript?

HScript is an interpreted scripting language used by Polymod to provide custom functionality to Friday Night Funkin'. The game detects scripts provided in .hxc files, interprets them, and executes them to perform custom functionality in-game.

Mods are not the only thing that utilizes this functionality; the base game itself uses scripts to play animations and cutscenes, manipulate stage props, and even add custom gameplay, in a manner that allows for faster iteration than would be possible without scripts.

HScript is extremely similar to Haxe, and provides access to almost all the variables and classes available in the game, with a few notes:

  • Each scripted class must have a unique name from every other scripted class. If your mod has two scripted classes with the same name, or even if two different mods have scripted classes of the same name, one copy will be completely suppressed, which can result in unexpected behavior.
  • Private variables are simply accessible, be careful what you mess with.
  • Certain classes are blacklisted, to help protect users against malicious scripts.
  • abstract enums (a Haxe language feature which provides values which act like an Enum, but are actually some other type like a String or Integer) are inaccessible. Check the code for the abstract enum you want to use and find the ACTUAL underlying value, and use that instead.
  • abstracts (a Haxe language feature which applies additional methods to an existing class) are inaccessible. You will have to find some workaround to interact with these values.

Examples of HScript

Many examples of working HScript can be found in Funkin's many script files (with the .hxc extenstion), but some easily found ones are stage scripts.

As an example, the Philly Streets1 script file:

 // Top of the file
 import flixel.FlxG;
 import funkin.graphics.shaders.RuntimeRainShader;
 import funkin.modding.base.ScriptedFlxRuntimeShader;
 import funkin.play.PlayState;
 import funkin.play.stage.Stage;

 // ...

 // Line 114
 override function onCreate(event:ScriptEvent):Void
  {
    super.onCreate(event);

    rainShader.scale = FlxG.height / 200; // adjust this value so that the rain looks nice

    FlxG.console.registerObject("rainShader", rainShader);
    switch (PlayState.instance.currentSong.id)
    {
      case "darnell":
        rainShaderStartIntensity = 0;
        rainShaderEndIntensity = 0.1;
      case "lit-up":
        rainShaderStartIntensity = 0.1;
        rainShaderEndIntensity = 0.2;
      case "2hot":
        rainShaderStartIntensity = 0.2;
        rainShaderEndIntensity = 0.4;
    }

    rainShader.intensity = rainShaderStartIntensity;

    rainShaderFilter = new ShaderFilter(rainShader);
    FlxG.camera.filters = [rainShaderFilter];

    resetCar(true, true);
    resetStageValues();
  }

 // ...

As you can see, you can basically use HScript like regular haxe, making it ideal for modding Friday Night Funkin'

Author: EliteMasterEric

Footnotes

  1. https://github.com/FunkinCrew/funkin.assets/blob/main/preload/scripts/stages/phillyStreets.hxc