Skip to content



FantasyVar is a dynamic variable configuration system that allows easy communication between the SDK and fantasy.moonlight.

With this system, you can accomplish the following:

  • Communicate with other scripts.
  • Directly modify how fantasy.moonlight behaves.
  • Directly change how hard coded features work.
  • Store/Load configuration without worrying about the hassle.

This is prime resource for fantasy.moonlight. It is simply a variable system.

How To Use

There are multiple functions provided by fantasy.moonlight that allow you to manipulate FantasyVars.

  • moonlight.vars.add
  • moonlight.vars.get
  • moonlight.vars.set
  • moonlight.vars.load

To use a FantasyVar, it must be created first. We will make a simple .lua script.

local example = {}

function example.PostInitialize()


return example

This is our base empty script. PostInitialize is called whenever a script is successfully loaded.

Inside the PostInitialize function, we will make our first FantasyVar!

local example = {}

function example.PostInitialize()
    moonlight.vars.add( "hello world", 1337 )

return example

Now any script can access your FantasyVar "hello world". Here is an example:

local example2 = {}

function example2.PostInitialize()
    print( moonlight.vars.get( "hello world" ) )

return example2

If example2.lua is loaded after example.lua, it should print


Manipulating Moonlight

FantasyVars work hand-in-hand with other features, this includes the menu framework and hard-coded FantasyVars.

Next in this documentation, we will look at humanizer.lua.

local humanizer = {
    -- Humanizer On/Off Toggle
    name = "settings_humanizer",

    -- Humanizer Key 
    key_name = "settings_humanizer_key",
    key = 1,


Obviously this is not the full humanizer.lua script. But as you can see, we are naming our FantasyVars to be used later on in PostInitialize.

function humanizer.PostInitialize()
    -- Create variable after cheat & configuration loaded IF it didn't exist already from configuration.
    moonlight.vars.add(, 1 )
    moonlight.vars.add( humanizer.key_name, humanizer.key)


As seen above in local humanizer, the name member is:


Therefore, when we make a variable, we directly access the member and thereby creating a new FantasyVar called "settings_humanizer".

Now ... Take a look at the OnHumanizerReady callback in humanizer.lua:

function humanizer.OnHumanizerReady( target, bone )
    local target_entity = target )

    -- The ST-6 CT Model head bone is slightly off for the humanizer. Change the bone to 8 instead of 9.
    if target_entity["model"] == 338 and (["flags"], FL_DUCKING) ~= 0) and bone == 9 then
        moonlight.vars.set( humanizer.target_bone, 8 )

    -- Sometimes the bone lands next to the head or on their neck. Aim for the head instead.
    if bone == 2 or bone == 7 then 
        moonlight.vars.set( humanizer.target_bone, 8 )

    -- Do not shoot at fingers or arms. Aim for the head instead. Body may be better if headshot % too high.
    if bone >= 10 and bone <= 27 then
        moonlight.vars.set( humanizer.target_bone, 8 )

This is an example of manipulating fantasy.moonlight to change the core function of its features.

As you can see, there is usage of moonlight.vars.set, which changes the value of a FantasyVar. We are changing humanizer.target_bone. Which controls which bone the humanizer aims for. Of course, we change the bone based on conditions shown in the code above.

There are many different examples of this found in the default scripts.