YaDamageAPI
YaDamageAPI gives the damageable the functionality of being damaged. Here are a few important concepts to understand before you start using this API.Functions
boolean YaDamageAPI.IsDead(YaEntity target)
Code sample
local isDead = YaDamageAPI.IsDead(targetEntity)
-- Returns false if the entity is neither alive nor damageable.
print("Damageable", targetEntity.EntityId, "is dead:", isDead)
targetThe YaEntity to check
boolean YaDamageAPI.IsImmortal(YaEntity target)
Code sample
local isImmortal = YaDamageAPI.IsImmortal(targetEntity)
-- Returns false if the targetEntity is neither immortal nor damageable.
print("Damageable", targetEntity.EntityId, "is immortal:", isImmortal)
targetThe YaEntity to check
void YaDamageAPI.SetImmortal(YaEntity target, boolean immortal)
Sets the damageable entity immortal.
Code sample
-- Set the targetEntity immortal.
YaDamageAPI.SetImmortal(targetEntity, true)
targetThe damageable YaEntityimmortalTrue if the damageable entity is immortal.
boolean YaDamageAPI.IsInvulnerable(YaEntity target)
Code sample
local isInvulnerable = YaDamageAPI.IsInvulnerable(targetEntity)
Returns false if the targetEntity is neither invulnerable nor damageable.
print("Damageable", targetEntity.EntityId, "is invulnerable:", isInvulnerable)
targetThe YaEntity to check
void YaDamageAPI.SetInvulnerable(YaEntity target, boolean invulnerable)
Sets the damageable YaEntity invulnerable.
Code sample
-- set targetEntity invulnerable.
YaDamageAPI.SetInvulnerable(targetEntity, true)
targetThe target YaEntity to setinvulnerableA Boolean value that determines if the YaEntity is invulnerable. Set it true if you want the YaEntity invulnerable.
number YaDamageAPI.GetHitPoints(YaEntity target)
Code sample
-- O is returned if the targetEntity is not damageable.
local hp = YaDamageAPI.GetHitPoints(targetEntity)
targetThe YaEntity from which you want to get HPs
void YaDamageAPI.SetHitPoints(YaEntity target, number amount)
Sets the hit points for the YaEntity. You can only set it within the range between 0 and MaxHitPoints.
Code sample
YaDamageAPI.SetHitPoints(targetEntity, 100)
targetThe YaEntity to set hit points foramountThe value of the hit points
number YaDamageAPI.GetMaxHitPoints(YaEntity target)
Code sample
local maxHp = YaDamageAPI.GetMaxHitPoints(targetEntity)
Get the maximum hit points of the targetEntity. 0 will be returned if the YaEntity is not damageable.
targetThe YaEntity from which you want to get maximum hit points
void YaDamageAPI.SetMaxHitPoints(YaEntity target, number amount)
Sets the maximum hit points (HP) of the YaEntity. The maximum hit points should be no less than 1.
Code sample
-- range: >= 1
-- HitPoints will be set to MaxHitPoints regardless of the current HitPoints is greater than MaxHitPoints.
YaDamageAPI.SetMaxHitPoints(targetEntity, 200)
targetThe YaEntity that you want to set the maximum HP foramountThe value of the maximum HP
void YaDamageAPI.ApplyDamage(YaEntity target, YaDamage damage)
Applies damage to a YaEntity.
Code sample
-- killerEntity deals 100 points of damage to targetEntity.
local damage = YaDamage.New()
damage.Enemy = killerEntity
damage.Amount = 100
YaDamageAPI.ApplyDamage(targetEntity, damage)
targetThe YaEntity to apply the damagedamageInformation of the amount of the damage and where it comes from
void YaDamageAPI.Die(YaEntity target, YaDamage damage)
Code sample
-- killerEntity kills dieEntity.
local damage = YaDamage.New()
damage.Enemy = killerEntity
YaDamageAPI.Die(dieEntity, damage)
The targetEntity won't die if it is invulnerable or immortal.
The targetEntity's hit points will be reduced to 0 if it's immortal.
targetThe YaEntity to killldamageInformation of the amount of the damage and where it comes from
void YaDamageAPI.Revival(YaEntity target, YaRevival revival)
Revives the damageable entity with the full hit points.
Code sample
local revival = YaRevival.New()
revival.Revivaler = revivalerEntity
revival.Position = PositionEntity
YaDamageAPI.Revival(targetEntity, revival)
-- revivalEntity revives targetEntity at positionEntity.
targetThe YaEntity to reviverevivalInformation of the position to revive the YaEntity and who revives it
void YaDamageAPI.Hook(YaEntity target, function actionYaDamageHook)
The hook called before applying damage
Code sample
-- Double the damage in the hook method.
local function DamageHook(damage)
local newDamage = YaDamage.New()
newDamage.Amount = damage.Damage.Amount * 2
newDamage.Enemy = damage.Damage.Enemy
damage.Damage = newDamage
end
YaDamageAPI.Hook(targetEntity, DamageHook)
targetThe YaEntity to be damagedactionThe hook methodYaDamageHookThis object only contains a paramater of YaDamage.
void YaDamageAPI.OnDamage(YaEntity target, function actionYaDamage)
Fired when a damageable entity is damaged.
Code sample
local function OnDamage(damage)
print(targetEntity.EntityId, "get damage", damage.Amount, "from", damage.Enemy.EntityId)
end
YaDamageAPI.OnDamage(targetEntity, OnDamage)
targetThe YaEntity that gets the damageactionThe callback functionYaDamageThe YaEntity who causes the damage and the amount
void YaDamageAPI.OnDead(function callbackYaEntity, YaDamage>, [YaEntity target])
Fired when a damageable entity is dead.
Code sample
YaDamageAPI.OnDie(function (dead, damage)
print(dead.EntityId, "die by entity", damage.Enemy.EntityId)
end)
-- or just listening targetEntity's die event
YaDamageAPI.OnDie(function (dead, damage)
print(dead.EntityId, "die by entity", damage.Enemy.EntityId)
end, targetEntity)
callbackThe callback functionYaEntityThe dead YaEntityYaDamageThe YaEntity who causes the damage and the amount of the damage
targetThe dead YaEntity
void YaDamageAPI.OnRevival(function callbackYaEntity, YaRevival, [YaEntity target])
Fired when a damageable entity is revived.
Code sample
YaDamageAPI.OnRevival(function (target, revivalInfo)
print(target.EntityId, "revivaled by entity", revivalInfo.Revivaler.EntityId, "on position", revivalInfo.Revivaler.EntityId)
end)
-- or just listening targetEntity's revival event
YaDamageAPI.OnRevival(function (target, revivalInfo)
print(target.EntityId, "revivaled by entity", revivalInfo.Revivaler.EntityId, "on position", revivalInfo.Revivaler.EntityId)
end, targetEntity)
callbackThe callback functiontargetThe revived YaEntityrevival infoThe information of who revives it and its position
targetThe revived YaEntity