diff --git a/ProjectilesChangeLog.md b/ProjectilesChangeLog.md index 68e01eb..06dcdc8 100644 --- a/ProjectilesChangeLog.md +++ b/ProjectilesChangeLog.md @@ -1,5 +1,8 @@ # projectiles.lua ChangeLog +### Version 0.84 +- Added smart default behavior for UnitTest + ### Version 0.83 - Added additional guards to better handle 'script_reload' diff --git a/ProjectilesReadme.md b/ProjectilesReadme.md index ad4c4be..0b31853 100644 --- a/ProjectilesReadme.md +++ b/ProjectilesReadme.md @@ -15,7 +15,7 @@ **Projectiles Library Functions** ============================= ####**Projectiles:CreateProjectile(projectile)** - This function is used to create ane release the projectile defined by the projectile table passed to the function. The function returns an updated reference to the projectile table on which the Proejctile Table Functions can be called. See the Projectiles Table Format section for more detail on what properties can be used with the projectile table. + This function is used to create ane release the projectile defined by the projectile table passed to the function. The function returns an updated reference to the projectile table on which the Projectile Table Functions can be called. See the Projectiles Table Format section for more detail on what properties can be used with the projectile table. ####**Projectiles:CalcSlope(pos, unit, dir)** @@ -24,6 +24,9 @@ ####**Projectiles:CalcNormal(pos, unit, scale)** This function can be used to get the estimated normal Vector of the ground at the world point Vector 'pos'. The 'unit' parameter is used to specify what unit should be used with GetGroundPosition() in order to handle the ground collision sizing. This function can return odd values when used around sheer vertical edges. +####**Projectiles:DefaultUnitTest(unit)** + This is the default UnitTest function used if none is provided. This test will use the iUnitTargetTeam, iUnitTargetType, and iUnitTargetFlags keys on the projectile, if they're specified. Otherwise, it inherits targeting rules from the ability referenced by the Ability key on the projectile. If none of these keys are available, the test will simply always fail. + **Projectile Table Functions** ============================= @@ -45,6 +48,7 @@ Projectiles are effectively a formatted lua table which is registered with the P | Property | Default | Description | | :------------ | :--------| :-----| +| Ability | <none> | The ability associated with this projectile | | bProvidesVision | false | If set to true, this projectile will provide vision around it as it travels. | | bCutTrees | false | If set to true, this projectile will cut any trees that it comes in contact with. | | bFlyingVision | true | If set to true and, this projectile will provide flying vision as it travels (if bProvidesVision is enabled) | diff --git a/game/dota_addons/barebones/scripts/vscripts/libraries/projectiles.lua b/game/dota_addons/barebones/scripts/vscripts/libraries/projectiles.lua index 61e8950..8db8f12 100644 --- a/game/dota_addons/barebones/scripts/vscripts/libraries/projectiles.lua +++ b/game/dota_addons/barebones/scripts/vscripts/libraries/projectiles.lua @@ -1,4 +1,4 @@ -PROJECTILES_VERSION = "0.83" +PROJECTILES_VERSION = "0.84" PROJECTILES_THINK = 0.01 @@ -99,6 +99,11 @@ function Projectiles:CalcNormal(pos, unit, scale) return Vector(zl - zr, zd - zu, 2*scale):Normalized() end +function Projectiles:DefaultUnitTest(unit) + return (self.iUnitTargetTeam or self.iUnitTargetFlags or self.iUnitTargetType) + and 0 == UnitFilter(unit, self.iUnitTargetTeam or 0, self.iUnitTargetType or 0, self.iUnitTargetFlags or 0, self.Source:GetTeam()) +end + PROJECTILES_NOTHING = 0 PROJECTILES_DESTROY = 1 PROJECTILES_BOUNCE = 2 @@ -128,7 +133,7 @@ function Projectiles:CreateProjectile(projectile) projectile.fGroundOffset = projectile.fGroundOffset or 40 projectile.nChangeMax = projectile.nChangeMax or 1 projectile.fChangeDelay = projectile.fChangeDelay or .1 - projectile.UnitTest = projectile.UnitTest or function() return false end + projectile.UnitTest = projectile.UnitTest or Projectiles.DefaultUnitTest projectile.OnUnitHit = projectile.OnUnitHit or function() return end projectile.OnTreeHit = projectile.OnTreeHit or function() return end projectile.OnWallHit = projectile.OnWallHit or function() return end @@ -139,6 +144,14 @@ function Projectiles:CreateProjectile(projectile) projectile.ControlPointOrientations = projectile.ControlPointOrientations or {} projectile.ControlPointEntityAttaches = projectile.ControlPointEntityAttaches or {} + --derive defaults from Ability, if given. + if projectile.Ability then + projectile.Source = projectile.Source or projectile.Ability:GetCaster() + projectile.iUnitTargetTeam = projectile.iUnitTargetTeam or projectile.Ability:GetAbilityTargetTeam() + projectile.iUnitTargetType = projectile.iUnitTargetType or projectile.Ability:GetAbilityTargetType() + projectile.iUnitTargetFlags = projectile.iUnitTargetFlags or projectile.Ability:GetAbilityTargetFlags() + end + if projectile.bTreeFullCollision == nil then projectile.bTreeFullCollision = false end projectile.bProvidesVision = projectile.bProvidesVision or false if projectile.bFlyingVision == nil then projectile.bFlyingVision = true end @@ -168,7 +181,7 @@ function Projectiles:CreateProjectile(projectile) else projectile.vSpawnOrigin = projectile.vSpawnOrigin or Vector(0,0,0) end - + projectile.rehit = {} projectile.pos = projectile.vSpawnOrigin projectile.vel = projectile.vVelocity / 30