Skip to content

Code Other Functions

dedChar edited this page May 21, 2017 · 3 revisions

Other Functions

Functs that do something

Agony:SaveNow()

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


Agony:redoSpawnList() !!May be deprecated someday when the respawn func is rewritten!!

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


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.


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.


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.


TearProj Functs

Because nicalis failed to make EntityNPC::FireProjectiles() work, we had to write a custom collision detection for EntityTear objects and use those as enemy projectiles.

Agony:TearConf()

Returns a table with the following values:

	t.TearFlags = 0
	t.SpawnerEntity = nil
	t.Height = -23 --default height
	t.FallingAcceleration = 0
	t.FallingSpeed = 0
	t.Color = Color(1,1,1,1,0,0,0)
	t.Data = {} --entity data
	t.Scale = 1 --goes in 1/6 steps for the bigger tearsprite
	t.Functions = {} --supported functions are onDeath, onUpdate and onHit

Agony:fireTearProj(var, sub, pos, vel, tearConf)

Takes a tear variant var, tear subtype sub, a firing position pos, a velocity vel and a tearConf table containing other tear parameters.
Spawns a tearProj according to the passed parameters.

Agony:fireMonstroTearProj(var, sub, pos, vel, tearConf, num, rng, *overrideConf)

Takes the same arguments as Agony:fireTearProj() with addition to an int num, an RNG object rng and optionally an overrideConf table. Spawns num tearProjectiles with randomly rotated velocities, sizes and fallingspeeds. Randomized using the passed rng.
overrideConf can be used to override the default values of a monstro-like shot.

Agony:fireIpecacTearProj(var, sub, pos, vel, tearConf, *overrideConf)

Takes the same arguments as Agony:fireTearProj() and an optional overrideConf table.
Spawns an explosive Ipecac tearProj.
overrideConf can be used to override the default values of a ipecac-like shot.

Agony:fireHomingTearProj(var, sub, pos, vel, tearConf, *overrideConf)

Takes the same arguments as Agony:fireTearProj() and an optional overrideConf table.
Spawns a homing tearProj. Homes to the nearest player from the tear's position.
overrideConf can be used to override the default values of a homing shot.


Agony:makeSplat(Vector pos, int var, float size, *Entity ent)

Spawns a circle of effects of the variant var at the position pos. size determines the size of the circle. ent can be specified as the the spawner.
This is the most useful if var is the variant of a creep effect.
!Do NOT make size too high!

Utility & Calculation shortcut functs

Agony:dataCopy(data originData, data targetData)

Copies all variables from originData to targetData.


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

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


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.


Flag manipulators

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.


Clone this wiki locally