Console

Also known as a Developer Console. Part of Code diving.

The Console is a command prompt that allows one to run Lua commands, or even multiple commands that form a script. It is a useful tool for getting acquainted with game's API, as well as prototyping and debugging scripts that will later be used in making actual mods.

Using any command disables "Hardcore" (Immortal) mode, and consequently the ability to gain Achievements as well. A new savefile would be made that is effectively a "Classic" game mode difficulty version of your Immortal run. The last save from before using the console is kept as Immortal.

The Console isn't going to be of much use without at least a surface knowledge of game's API, as well as Lua syntax. For the purpose of retrieving lost single issue items (like the Legacy of Taiyi, Universe Spirit Crystal, or the Taiyi Scroll), trying out game mechanics, fixing consequences of known bugs, or just plain cheating, the MODModifier (Mod) will prove to be a more beginner-friendly tool. Unlike console, using MODModifier won't trigger anti-cheat.

This article's information/formatting is messy and needs a cleanup**Reason:** *unformatted sections*. **Click here to edit.**

## Enabling the Console

The in-game console is enabled from the Settings menu, then pressing Ctrl+F8

## Using the console

During a loaded game, it can be used to send Lua commands

## Available commands

To see what all the available, or "touchable" parts are, you can run a command to show you the Global variable namespace.

```
for k,v in pairs(\_G) do
	print(k, " => ", v)
end

```

## Important Variables

Immediately, we see things like World => XiaWorld.World

This can both be seen in <ACS Install Directory>/Scripts/main.lua,

and in the C# Website (Modding API): http://api.gsqstudio.com

The big things like this, or NpcMgr, we can also find in the top level of MODModifier (Mod).

## Examples

### Enabling 4th option of 3rd Golden Casket

World flags are viewable by using the print command. For example:

```
print(world:GetWorldFlag(95))

```
(you can thank iguana for this command :D )
They are also settable with

```
world:SetWorldFlag(95,1)

```

Replace 95 with whichever flag number you want. And 1 with whichever number you want (presumably, 0 of "off", and 1 for "on")

For the 3rd Golden Casket's 4th hidden story option, MODMod currently doesn't work for setting this flag for some reason. But the console command works just fine.

### Get Npc IDs on the map

To run any command that does something to Npc you need a way to point to that Npc. This could be done with IDs.

To get the list of all Npcs on the map run this code first:

```
for k,v in pairs(Map.Things.m\_lisNpcs) do
    print(Map.Things.m\_lisNpcs[k].Name, Map.Things.m\_lisNpcs[k].ID)
end

```

Now you can reference any Npc with FindThingByID command. An example I'm using to probe into Npc's data:

```
local n = ThingMgr:FindThingByID(Insert\_ID\_Here)

print(n.Name, n.Key)
print(n.PropertyMgr.Practice.Gong.DisplayName)
print(n.PropertyMgr.Practice.CurStage.DisplayName, n.PropertyMgr.Practice.StageValue)

```

### Working with Tiles

Sometimes there's a need to point to specific tile rather than an object. Internally tiles are called Grids and are part of the Map. Each Grid is assigned a number called "key" that could be used to point to that Grid when running a function.

So how do we know the key of a certain Grid?

One method is to place an Npc on that Grid (by ordering him to go there) and use the above technique to get the ID of that Npc. One of the data fields you can read off the Npc is the key of the Grid he's currently in (Npc.Key). See the code below:

```
local n = ThingMgr:FindThingByID(Insert\_Npc\_ID\_here)

print(n.Name, "is in Grid with Key:" , n.Key)

print("Qi:", Map:GetLing(n.Key))
print("Fertility:", Map:GetFertility(n.Key))
print("Beauty:", Map:GetBeauty(n.Key))
print("Light:", Map:GetLight(n.Key))
print("Temperature:", Map:GetTemperature(n.Key))

print("Earth:", Map:GetElementPower(n.Key, "Tu"))
print("Metal:", Map:GetElementPower(n.Key, "Jin"))
print("Water:", Map:GetElementPower(n.Key, "Shui"))
print("Wood:", Map:GetElementPower(n.Key, "Mu"))
print("Fire:", Map:GetElementPower(n.Key, "Huo"))

```

The code basically probes into certain Grid-related values, like the MoreGridInfo mod.

### List Items on the Map

Similar to NPCs one can make a printout of all items on the map. See the code below:

```
for k,v in pairs(Map.Things.m\_Things:GetExistDataKeys()) do
    if ( Map.Things:GetItemAtGrid(v) ~= nil ) then
        print(v, Map.Things:GetItemAtGrid(v))
    end
end

```

The code first retrieves the list of valid keys (pointers towards the grids on the map), then checks if the grid that the key points to has an item, in which case it prints the key and the item data).

### Spawning Items on the Map

To spawn an Item with console you would need to know it's internal name, as well as specify a grid to serve as it's spawning point. An internal name could be learnt directly from the game's xml files, or alternatively you could find it on this very wiki (check the page of item in question, if it exists). As for the grid a simple way would be using Map.BornCenter, which points to the place where your starting items get spawned. It doesn't matter if the grid is occupied, the item will be pushed to the closest vacant grid.

```
-- this spawns 500 Spirit Stones
Map:DropItems("Item\_LingStone", nil, 500, Map.BornCenter)

```

### Unlocking a Supreme Law

To unlock a law you would need to know the internal name of the law. The internal names for each law could be found on Law page. Here's an example for Sixteen Supreme Steps Law:

```
SchoolMgr:UnLockGong("Gong\_1\_Shui")

```