Northgard Wiki
Advertisement
Northgard Wiki

Northgard Editor - IDE for writing and modifying scripts in Haxe programming language. Used to create Modifications (mods). In combination with Map Editor and CDB allows high-level of mod-ability for Northgard. To use scripts, mod has to have Map first.

FAQ

To set the victory condition to military only.

Place this in the init() call to function:

   function setVictory() {
       // Setup Dom only victory
       state.removeVictory(VictoryKind.VMoney);
       state.removeVictory(VictoryKind.VFame);
       state.removeVictory(VictoryKind.VLore);
   }

Can I choose my clan at start?

No, there is no functionality for that at this time. It will be added in the future.

Can I set teams in the Map Editor?

No, you must use scripts to do so, see: http://northgard.net/doc/api/current/ScriptApi.html#setAlly

Can the number of buildings on a tile be increased?

No, but you might be able to manipulate the map editor by placing/destroying a town hall repeatedly.

My game crashes, and I think it is because my loops are too big, what to do?

Your script has a very small amount of time to execute code before the game crashes. If you must process large numbers of things (all the zones on the map, 100+ units, etc), then you will want to chunk that scanning across multiple calls to regularUpdate(). For example, maybe only scan the even zones when state.time is even, or maybe only 30 zones at a time. Alternatively, store Zones of interest that you need to watch or don't scan Zones you don't care for, therefore reducing the number of lookups.

Reduce the number of times you do things, or alternate what you process on various modulo of state.time to spread out the computation. Since regularUpdate is called every 500ms, a small delay of a few updates won't be noticeable to the player.

Can I change the commercial influence needed to win? What about other default victory conditions?

No, they can not be changed. Instead, you should disable them and implement your own, or manipulate the resources of a player so they are earned slower (for example, take away Fame to make Fame requirement higher, or commercial influence, etc). See the FAQ "How do I make my own victory conditions" for more info.

How do I make my own victory conditions?

You will need to use ScriptObjectives, seen here: http://northgard.net/doc/api/current/ScriptObjectives.html

For example, see below. Note, that all objectives must be created within the init() function call otherwise they will not work. If you want an objective to be seen only later, then you can set visibility to false and then change it to true when desired.

Then, in regular update, you will need to update your objectives to show the player their progress. And once the player has achieve the goal you set, you can call the following to make them win: http://northgard.net/doc/api/current/Player.html#customVictory

I can not check if player has Lighthouse

At this moment (July 2020) check for Lighthouse or RavenLighthouse is not working. You should use "Upgraded Port" instead.

   function hasLighthouse(p : Player) {
       return p.hasBuilding(Building.Port, false, false, true, null) || p.hasBuilding(Building.RavenPort, false, false, true, null);
   }

I want to scan the player units and find PREDICATE

Make this function and use in your code (replace PREDICATE/PREDICATENAME after Copy-Pasting):

   function findUnitsInZonePREDICATENAME(z : Zone) : Array<Unit> {
       var result = [];
       for( unit in z.units )
       {
           if( PREDICATE )
           {
               result.push(unit);
           }
           wait(0);
       }
       return result;
   }
   function findUnitsOfPlayerPREDICATENAME(p : Player) : Array<Unit> {
       var result = [];
       for( unit in p.units )
       {
           if( PREDICATE )
           {
               result.push(unit);
           }
           wait(0);
       }
       return result;
   }

Frequently-used predicates: ownership (unit.owner == p), (unit.owner != p); (non-)military check (unit.isMilitary),(!unit.isMilitary)

How to save time and pre-load tiles that are used often throughout the script?

Put this above all code:

   var bases = [getZone(1), getZone(11), getZone(111), getZone(191)];

Then, when you need to scan through them use generic foreach loop:

   for( zone in bases ) {
       // CODE
   }

Known Issues

  • Entity named player is known to editor, so DO NOT EVER USE IT IN for loops or input arguments. Otherwise, interpreter and IDE will not highlight any errors related to usage of this entity.
  • Cannot set units controllable
    • Even mercenaries, used as the example in Documentation
  • Cannot manipulate values of launched events
  • BSilo and BSiloImproved bonuses don't work
  • drakkar() has the ocean and coastal zones reversed in documentation.
  • Using Objectives API in your script causes all your units and buildings to disappear on loading a save of that map
  • Cannot manipulate Warband. (Whether adjust Training Camp in .diff, or changing Warband as a Resource in script)
  • Can't create Dictionaries/Maps data structures. Only arrays, anon structs, and primitives.
  • Exceptions or failures in the script fail silently and stop execution of the script with no warning.
  • Can't loop over all zones without exceeding the time budget and causing a crash
  • Can't check for the Lighthouse in a tile, must check for an upgraded port
  • You can visually overflow the objective progress bar
    • Setting value more than goal (e.g. 55 for 50 goal) will still display maximum (50/50), but objectives container will grow proportionally
  • No error reporting when game crashes to desktop

Community Wishlist

  • Debug , Output and/or Error log streams (and consequently files) in mod directory. Un-uploadable, please.
  • Want to manipulate the tile geometry (change amount of tiles that surround a tile)
  • Increase number of buildings allowable in a tile
  • Toggle victory conditions within the Map Editor
  • Set Teams within the Map Editor
  • Custom art assets, units
  • Modify more of the values in the DB
Advertisement