Skip to content
dedChar edited this page May 20, 2017 · 1 revision

Agony:calcTearVel(Vector sourcePos, Vector targetPos, float multiplier)

Returns a Vector pointing from sourcePos to targetPos with a length of multiplier.

Agony:SaveNow()

Writes the data stored in the saveData table to the savefile.

Agony:AddEternal(int EntityType, int Variant, string Name)

Adds an entry to the EternalsList table.

table Agony:getEternalsList()

Returns the EternalsList table.

Agony:redoSpawnList()

Instructs the game to recreate the respawn tables used for respawning entities.

Entity Agony:getNearestEnemy(Entity sourceEnt, *table whiteList, *table blackList)

Takes a source Entity and two optional tables, a blackList and a whiteList. Each entry of a list consists of an EntityType.
For Example:

whiteList = { 4,
5,
6,
EntityType.ENTITY_CLOTTY
}

The blackList also has a special mode entry that can tell the function to do specific built-in tasks.
Usage of modes:

blackList = { 
mode = "only_same_ent"
}

All currently available modes:

  • only_same_ent: The function will only return the nearest entity that has the same Type, Variant and SubType as the source.
  • only_whitelist: The function will only return the nearest entities that are in the whiteList.

Returns the nearest entity to another entity or, if there is none, the source Entity.

Entity Agony:getFurthestEnemy(Entity sourceEnt, *table whiteList, *table blackList)

Same as Agony:getNearestEnemy(), but returns the furthest away entity.

Agony:AnimGiantBook(string bookSprite, string animName, *string customAnm2)

Plays a Giant Book animation.
Takes the sprite's filename, the name of the animation that should be played and optionally the name of a anm2 file (uses giantbook.anm2 if it's not specified).
All files that are used need to be in /resources/gfx/ui/giantbook/. If they are in a different folder that is in that directory, it needs to be specifies in the argument. For Example:

Agony:AnimGiantBook("examplefolder/examplefile.png", "example", "custom.anm2")

This will play the example animation from /resources/gfx/ui/giantbook/custom.anm2 with /resources/gfx/ui/giantbook/examplefolder/examplefile.png as the sprite.

Sprite, int Agony:addToRender(string anm2, string animName, *Vector pos, *int fps)

Adds an animation to the render queue. Takes a path to an animation file and an animation name. Optional arguments is the position and the fps. Position defaults to Vector(0,0) and the fps to 60.
Returns a Sprite and the index of the animation in the queue.

Agony:dataCopy(data originData, data targetData)

Copies all variables from originData to targetData.

table Agony:getCurrentItems(*table pool)

Takes an optional table with itemIds.
Returns all items the player currently has. If a pool was given, it'll only return items that are also in the pool.

int Agony:AddFlags(int flagSource, int flags)

Adds flags to flagSource and returns the value.

boolean Agony:HasFlags(int flagSource, int flags)

Checks if flagSource has flags.

int Agony:ClearFlags(int flagSource, int flags)

Removes flags from flagSource and returns the value.

string Agony:getItemGfxFromId(int CollectibleType)

Returns the path of the collectible sprite of the item with CollectibleType as its id.

Agony:loadCustomPedestal(Entity Pedestal, int Type, *table data, *int index)

Takes an entity, which should have an id like 5.100.x or else it wouldn't be a pedestal, and a Type.
The Type equals to the frame of the the Alternates animation that will be played from gfx/Items/Pick Ups/Pedestals/animation.anm2. For easier readable code, the enum Agony.Pedestals has entries for these.
The optional arguments are a table that'll get written to the pedestal's EntityData and an index that can be given if you need to target a specific entry in the pedestalsToRender table.
The Pedestal, its EntityData and it's type are added to the pedestalsToRender table to reload the custom animation if it gets unloaded e.g. when a different item is placed on it by the player.

Agony:TransformationUpdate(EntityPlayer player, table trans, table data, boolean hasCostume)

Typically called in a MC_POST_PLAYER_UPDATE callback. Takes the player, the trans table containing the costumeID, hasItem, requireditems and Items variables, the data table which contains the saveData table and a boolean value hasCostume.
If more than 2 items from the trans.requireditems table are in the player's possession, it'll spawn a poof effect and add a NullCostume with the id from trans.costumeID to the player, unless hasCostume equals false.
hasCostume is used in case the code is already done, but the costume doesn't exists yet to avoid errors.

Vector Agony:calcEntVel(Entity ent, Entity target, float mul)

Takes the ent whose velocity should be updated, a target which the ent will try to go to and a mul that is the speed of the ent.
Unlike Agony:calcTearVel() this function makes sure that knockback and the fear status effect work.
Returns a the velocity as a Vector.

Agony:addPickup(int type, int var, int sub, *function pickupF, *function spawnF, *function updateF)

Takes the type information (type, variant, subtype) of the custom pick up and three optional functions.

pickupF is called when the player is close enough to the entity. Proximity detection, entity removal and animation is handled automatically, so this function only needs to contain additional code like e.g. playing a sound.
This function can take a few arguments:

  • player: EntityPlayer object
  • sound: SFXManager object
  • data: EntityData of the PickUp
  • sprite: Sprite object of the PickUp
  • ent: the PickUp as an Entity object

Example:

function example:onPickup(player, sound, data, sprite, ent)
    --do something
    sound:Play(SoundEffect.SOUND_BOSS2_BUBBLES, 1, 0, false, 1)
    player:AnimateHappy()
end

spawnF is called for every entity in the room that does not match the type information of the current pickup and has just appeared.
This function can take two arguments:

  • ent: 'Entity' object of the Entity
  • rng: 'RNG' object of the Entity (DropRNG)

Example:

function example:replacePickup(ent, rng)
	if ent.Type == EntityType.ENTITY_PICKUP and ent.Variant == PickupVariant.PICKUP_COIN and ent.SubType ~= CoinSubType.AGONY_EXAMPLE and ent:GetSprite():IsPlaying("Appear") and rng:RandomFloat() <= (1/22) then
		Isaac.Spawn(ent.Type, ent.Variant, CoinSubType.AGONY_EXAMPLE, ent.Position, ent.Velocity, nil)
		ent:Remove()
	end	
end

updateF gets called every frame for every PickUp of the specified type.
Takes the same arguments as pickupF. For examples, see pickupF.

Then, to add the custom pickup, at the end of the pickup's lua file do:

Agony:addPickup(EntityType.ENTITY_PICKUP, PickupVariant.PICKUP_COIN, CoinSubType.AGONY_EXAMPLE, example.opPickup, example.replacePickup, nil)
Clone this wiki locally