Binding of Isaac - Afterbirth+ Lua Reference/Guide
|
Functions | |
DebugString (string str) | |
EntityPlayer & | GetPlayer (integer playerId) |
int | GetFrameCount () |
Entity & | Spawn (int entityType, int entityVariant, int entitySubtype, Vector position, Vector velocity, Entity Spawner) |
GridEntity & | GridSpawn (GridEntity gridEntityType, int Variant, Vector position, boolean forced) |
RenderText (string str, float X, float Y, float R, float G, float B, float A) | |
RenderScaledText (string str, float X, float Y, float ScaleX, float ScaleY, float R, float G, float B, float A) | |
integer | GetTextWidth (string str) |
Vector | GetRandomPosition () |
Vector | GetFreeNearPosition (Vector pos, float step) |
Explode (Vector pos, Entity source, float damage) | |
integer | AddPillEffectToPool (integer pillEffect) |
returns pill color More... | |
table | GetRoomEntities () |
returns all entities in the room More... | |
integer | GetChallenge () |
integer | GetEntityTypeByName (string entityName) |
integer | GetEntityVariantByName (string entityName) |
integer | GetItemIdByName (string itemName) |
integer | GetPlayerTypeByName (string playerName) |
integer | GetCardIdByName (string cardHudName) |
integer | GetPillEffectByName (string pillEffect) |
integer | GetTrinketIdByName (string trinketName) |
integer | GetChallengeIdByName (string challengeName) |
integer | GetCostumeIdByPath (string path) |
integer | GetCurseIdByName (string curseName) |
integer | GetSoundIdByName (string soundName) |
integer | GetMusicIdByName (string musicName) |
integer | GetTime () |
string | ExecuteCommand (string command) |
ConsoleOutput (string text) | |
Config & | GetItemConfig () |
table | FindInRadius (Vector Position, float Radius, integer Partitions) |
Returns entities in range of Radius from Position filtered by Partitions mask (see EntityPartition enum) (include all = 0xffffffff) More... | |
table | FindByType (integer Type, integer Variant, integer Subtype, boolean Cache, boolean IgnoreFriendly) |
integer | CountEntities (Entity Spawner, integer Type, integer Variant, integer Subtype) |
Counts entities from SpawnerEntity (can be NULL) and/or Type (can be ENTITY_NULL), and/or Variant/Subtype (can be -1) More... | |
integer | CountBosses () |
integer | CountEnemies () |
RegisterMod (table ref, string modName, integer apiVersion) | |
Exposed methods. More... | |
AddCallback (table ref, integer callbackId, table callbackFn, integer entityId) | |
RemoveCallback (table ref, integer callbackId, table callbackFn) | |
SaveModData (table ref, string data) | |
string | LoadModData (table ref) |
boolean | HasModData (table ref) |
RemoveModData (table ref) | |
Vector | ScreenToWorld (Vector pos) |
Vector | WorldToScreen (Vector pos) |
Vector | WorldToScreenDistance (Vector pos) |
Vector | WorldToRenderPosition (Vector pos) |
Vector | ScreenToWorldDistance (Vector pos) |
Isaac::AddCallback | ( | table | ref, |
integer | callbackId, | ||
table | callbackFn, | ||
integer | entityId | ||
) |
integer Isaac::AddPillEffectToPool | ( | integer | pillEffect | ) |
returns pill color
Isaac::ConsoleOutput | ( | string | text | ) |
Prints a string into the Debug Console
Isaac.ConsoleOutput("This is a Test.")
-- Output: This is a Test.
-- Alternatively:
print("This is a Test.")
-- Output: This is a Test.
integer Isaac::CountBosses | ( | ) |
Returns the number of bosses in the current room.
integer Isaac::CountEnemies | ( | ) |
Returns the number of enemies in the current room.
integer Isaac::CountEntities | ( | Entity | Spawner, |
integer | Type, | ||
integer | Variant, | ||
integer | Subtype | ||
) |
Returns the number of entities in the current room that fulfill the specified requirements.
Spawner refers to an entity object (can be nil
)
Type refers to the found entity's type (Can be EntityType.ENTITY_NULL
)
Variant and Subtype refer to the found entitys Variant and Subtype (Can be -1
)
Isaac::DebugString | ( | string | str | ) |
Prints a string into the log file. You can find this file here C:\Users\Jan\Documents\My Games\Binding of Isaac Afterbirth+\log.txt
"This is a Test."
in the log.txt file.
Isaac.DebugString("This is a Test.")
-- Output: Lua Debug: This is a Test.
string Isaac::ExecuteCommand | ( | string | command | ) |
This function executes a debug console command. see [Tutorial] Debug Console for informations on how to use commands.
Spawn an explosion on a specified location.
table Isaac::FindByType | ( | integer | Type, |
integer | Variant, | ||
integer | Subtype, | ||
boolean | Cache, | ||
boolean | IgnoreFriendly | ||
) |
Returns entities based on Type, Variant, Subtype. If Variant and/or Subtype is -1 then everything is included
Use Cache flag for multiple calls per frame.
table Isaac::FindInRadius | ( | Vector | Position, |
float | Radius, | ||
integer | Partitions | ||
) |
Returns entities in range of Radius from Position filtered by Partitions mask (see EntityPartition enum) (include all = 0xffffffff)
This function does not return the entities sorted by nearest first, but based on the order they were loaded.
integer Isaac::GetCardIdByName | ( | string | cardHudName | ) |
Returns the CardID based on its hud value. (File: pocketitems.xml)
Isaac.GetCardIdByName("16_TheTower")
--Returns: 17
integer Isaac::GetChallenge | ( | ) |
Returns the ID of a challenge the player is currently in. Returns 0 if the player is not playing any challenge.
integer Isaac::GetChallengeIdByName | ( | string | challengeName | ) |
Returns the ChallengeID of a challenge based on its name. (File: challenges.xml)
Isaac.GetChallengeIdByName("Aprils fool")
--Returns: 32
integer Isaac::GetCostumeIdByPath | ( | string | path | ) |
Returns the CostumeID of a costume based on its file path. (File: costumes2.xml)
Isaac.GetCostumeIdByPath("gfx/characters/n027_Transformation_Poop.anm2")
--Returns: 27
integer Isaac::GetCurseIdByName | ( | string | curseName | ) |
Returns the CurseID of a curse based on its name. (File: curses.xml)
Isaac.GetCurseIdByName("Curse of the Unknown")
--Returns: 4
integer Isaac::GetEntityTypeByName | ( | string | entityName | ) |
Returns the EntityType of an entity based on its name. (File: entities2.xml)
Isaac.GetEntityTypeByName("Flaming Gaper")
--Returns: 10
integer Isaac::GetEntityVariantByName | ( | string | entityName | ) |
Returns the variant of an entity based on its name. (File: entities2.xml)
Isaac.GetEntityVariantByName("Flaming Gaper")
--Returns: 2
int Isaac::GetFrameCount | ( | ) |
Returns the amount of frames the game as a whole is running. The counter increases even when the game is paused or when you are in the main menu!
1 second equals roughtly 60 frames.
This function therefore works drastically different than Game():GetFrameCount()
Config& Isaac::GetItemConfig | ( | ) |
Returns the ItemConfig::Config object.
integer Isaac::GetItemIdByName | ( | string | itemName | ) |
Returns the ItemID of a Collectible. (File: items.xml)
Isaac.GetItemIdByName("Brimstone")
--Returns: 118
integer Isaac::GetMusicIdByName | ( | string | musicName | ) |
Returns the MusicID of a music track. (File: music.xml)
Isaac.GetMusicIdByName("Title Screen")
--Returns: 61
integer Isaac::GetPillEffectByName | ( | string | pillEffect | ) |
Returns the PillEffectID based on its name. (File: pocketitems.xml)
Isaac.GetPillEffectByName("I can see forever!")
--Returns: 23
EntityPlayer& Isaac::GetPlayer | ( | integer | playerId | ) |
Returns the EntityPlayer which the user is controlling. 0 = Main player. Higher numbers refer to coop babies.
Isaac.GetPlayer(0)
integer Isaac::GetPlayerTypeByName | ( | string | playerName | ) |
Returns the PlayerType of a character based on its name. (File: players.xml)
Isaac.GetPlayerTypeByName("Azazel")
--Returns: 7
Vector Isaac::GetRandomPosition | ( | ) |
Returns a random position inside the current room. The Return value is a Vector containing the position in world coordinates.
table Isaac::GetRoomEntities | ( | ) |
Returns a table containing all entities in the room.
integer Isaac::GetSoundIdByName | ( | string | soundName | ) |
Returns the SoundEffectID of a sound based on its name. (File: sounds.xml)
Isaac.GetSoundIdByName("Custom Sound Effect")
integer Isaac::GetTextWidth | ( | string | str | ) |
Returns the width of the given string in pixels based on the "terminus8" font (same font as used in Isaac.RenderText())
integer Isaac::GetTime | ( | ) |
Returns the current game time in milliseconds. This includes pauses!
integer Isaac::GetTrinketIdByName | ( | string | trinketName | ) |
Returns the TrinketType of a trinket based on its name. (File: items.xml)
Isaac.GetTrinketIdByName("Lucky Toe")
--Returns: 42
GridEntity& Isaac::GridSpawn | ( | GridEntity | gridEntityType, |
int | Variant, | ||
Vector | position, | ||
boolean | forced | ||
) |
Spawn a GridEntity at the given position (world coordinates).
forced
has no effect and will NOT override the grid entity at the given location. Remove a grid entity at the given location if nessesary before spawning something again.
boolean Isaac::HasModData | ( | table | ref | ) |
Returns "true" if your mod has Data stored using the "SaveModData()" function. Aka. if there is a "saveX.dat" file in your mod folder.
There are 3 "saveX.dat" files, one per Savegame. They are stored in the mod's folder next to the "main.lua" file. The number indicates the savegame it corresponds to. The number will be determined automatically by the game.
string Isaac::LoadModData | ( | table | ref | ) |
Returns a JSON array/table that was stored in a "saveX.dat" file using the "SaveModData()" function. If there is no "saveX.dat" file in your mod, this function will return an empty string.
There are 3 "saveX.dat" files, one per Savegame. They are stored in the mod's folder next to the "main.lua" file. The number indicates the savegame it corresponds to. The number will be determined automatically by the game.
local yourMod = RegisterMod("someMod", 1)
local json = require("json")
-- ...
function yourMod:OnGameStart(isSave)
--Loading Moddata--
if yourMod:HasData() then
local myTable = json.decode(Isaac.LoadModData(yourMod))
end
end
yourMod:AddCallback(ModCallbacks.MC_POST_GAME_STARTED, yourMod.OnGameStart)
Isaac::RegisterMod | ( | table | ref, |
string | modName, | ||
integer | apiVersion | ||
) |
Method to define a mod in the game. THIS NEEDS TO BE DEFINED IN EVERY MOD!
local yourMod = RegisterMod("someMod", 1)
Isaac::RemoveCallback | ( | table | ref, |
integer | callbackId, | ||
table | callbackFn | ||
) |
Isaac::RemoveModData | ( | table | ref | ) |
Deletes the stored "saveX.dat" file if it exists.
There are 3 "saveX.dat" files, one per Savegame. They are stored in the mod's folder next to the "main.lua" file. The number indicates the savegame it corresponds to. The number will be determined automatically by the game.
Isaac::RenderScaledText | ( | string | str, |
float | X, | ||
float | Y, | ||
float | ScaleX, | ||
float | ScaleY, | ||
float | R, | ||
float | G, | ||
float | B, | ||
float | A | ||
) |
Renders a scaled text on the Screen. X and Y coordinates need to be in screen coordinates ( x[0,~500) y [0,~350) ). ScaleX, ScaleY, R ,G ,B and A need to be between [0,1]. Some scale values can cause the font to display deformed and pixelated.
local player = Isaac.GetPlayer(0)
local pos = player.Position
Isaac.RenderText("X: "..pos.X.." Y: "..pos.Y, 50, 50, 0.5, 0.5, 1 ,1 ,1 ,1 )
Isaac::RenderText | ( | string | str, |
float | X, | ||
float | Y, | ||
float | R, | ||
float | G, | ||
float | B, | ||
float | A | ||
) |
Renders a text with the default size on the Screen. X and Y coordinates need to be in screen coordinates ( x[0,~500) y [0,~350) ). R,G,B and A need to be between [0,1].
local player = Isaac.GetPlayer(0)
local pos = player.Position
Isaac.RenderText("X: "..pos.X.." Y: "..pos.Y, 50, 50, 1 ,1 ,1 ,1 )
Isaac::SaveModData | ( | table | ref, |
string | data | ||
) |
Stores a JSON array/table in a "saveX.dat" file. The stored Data persists thruout resets and game restart, so its perfect to store persistent data.
There are 3 "saveX.dat" files, one per Savegame. They are stored in the mod's folder next to the "main.lua" file. The number indicates the savegame it corresponds to. The number will be determined automatically by the game.
local yourMod = RegisterMod("someMod", 1)
local json = require("json")
-- ...
--Saving Moddata--
function yourMod:SaveGame()
local table= {1,2,3}
yourMod.SaveData(yourMod, json.encode(table))
end
yourMod:AddCallback(ModCallbacks.MC_PRE_GAME_EXIT, yourMod.SaveGame)
Transfers Screen (aka. Window coordinates) into Worldcoordinates. This can be used to get a specific location in the room in World coordnates The World coordinate system is x[0,inf) y[0,inf).
Entity& Isaac::Spawn | ( | int | entityType, |
int | entityVariant, | ||
int | entitySubtype, | ||
Vector | position, | ||
Vector | velocity, | ||
Entity | Spawner | ||
) |
Spawns the defined entity at the given location. If the position is not free, it spawns it in the nearest free position.
There are two spawn functions. Isaac.Spawn() and Game():Spawn(). If you need to spawn something with a specific seed, then you use Game():Spawn(). If you need to spawn something with a randomly generated seed, then use Isaac.Spawn(). Most of the time, you will probably want to use Isaac.Spawn().
Isaac.Spawn(EntityType.ENTITY_PICKUP, PickupVariant.PICKUP_COLLECTIBLE, 0, Vector(320,280), Vector(0,0), nil)
Transfers world (aka. game coordinates) into Rendercoordinates. This can be used to render things at fixed positions in a room. The Render coordinate system is x[0,inf) y[0,inf). It defines the Position on the rendering-plane in the current room.
Transfers world (aka. game coordinates) into Screen (aka. Window) coordinates. This can be used to render things next to an entity. The Screen coordinate system is x[0,inf) y[0,inf). Normally, it goes till ~500x ~300y. The return vector contains integer values or numbers ending with .5
local player = Isaac.GetPlayer(0)
local screenpos = Isaac.WorldToScreen(player.Position)
Isaac.RenderText("test", screenpos.X, screenpos.Y, 1 ,1 ,1 ,1 )