| 05-04-2009, 01:47 PM | #1 |
bump. Latest code JASS:library Knockback initializer Init requires DestructableLib, IsTerrainWalkable, GroupUtils, PUI globals private constant real TIME = 0.03 // The timer interval. private constant real CHAINRADIUS = 100.00 // The radius a unit can get chained when near the unit target. private constant real SPEEDFACTOR = 0.75 // How much speed will be reduced when a unit chains another unit. private constant real RADIUS = 128.00 // The radius to check tree. private constant real HEIGHTLEVEL = 200.00 // The default height level that stops chaining or killing trees when in the air. private constant real FACTOR = 0.3333 // Or 0.25 for smoothness. private constant string GROUND = "MDX\\Dust.mdx" // The effect for ground. private constant string WATER = "MDX\\SlideWater.mdx" // The effect for water. private constant string COLLISION = "MDX\\DustAndRocks.mdx" // The effect when at cliff private constant string ATTACHPOINT = "origin" // The attachment point for effects endglobals globals private constant integer INVULNERABLE = 'Avul' private constant integer FLYID = 'Amrf' private rect TreeRect = null private boolexpr TreeCheck = null private boolexpr ChainFilter = null private boolexpr LineFilter = null private real MapMaxX = 0 private real MapMaxY = 0 private real MapMinX = 0 private real MapMinY = 0 endglobals function ParabolaZ takes real h, real d, real x returns real return (4 * h / d) * (d - x) * (x / d) endfunction private function IsPointOutside takes real x, real y returns boolean return (x > MapMaxX or y > MapMaxY or x < MapMinX or y < MapMinY) endfunction private interface face method OnStart takes nothing returns nothing defaults nothing method OnStop takes nothing returns nothing defaults nothing method OnStopCondition takes nothing returns boolean defaults false method OnChain takes nothing returns nothing defaults nothing endinterface struct Knock extends face private static timer Timer = CreateTimer() private static group knocking = CreateGroup() private static Knock data //! runtextmacro PUI() unit source = null unit target = null unit dashtarget = null integer mode = 0 group hit = null real cos = 0 real sin = 0 real speed = 0 real decrement = 0 real distance = 0 real VariableSpeed = 0 real Increment = 0 real positionZ = 0 real LineDamage = 0 location TargetPoint = null effect effects = null boolean terrain = false boolean trees = false boolean chain = false boolean fly = false boolean ToTarget = false boolean Move = false integer Mode = 0 private static method CheckTrees takes nothing returns boolean return IsDestructableTree(GetFilterDestructable()) endmethod private static method Trees takes nothing returns nothing call KillDestructable(GetEnumDestructable()) endmethod private static method ChainCheck takes nothing returns boolean local Knock d = .data return d.target != GetFilterUnit() and IsUnitEnemy(GetFilterUnit(),GetOwningPlayer(d.source)) and IsUnitType(GetFilterUnit(), UNIT_TYPE_GROUND) == true and IsUnitType(GetFilterUnit(), UNIT_TYPE_MECHANICAL) == false and GetWidgetLife(GetFilterUnit()) > 0.405 and GetUnitAbilityLevel(GetFilterUnit(),INVULNERABLE) <= 0 endmethod private static method LineCheck takes nothing returns boolean local Knock d = .data return GetWidgetLife(GetFilterUnit()) > 0.405 and IsUnitEnemy(GetFilterUnit(),GetOwningPlayer(d.source)) and GetFilterUnit() != d.source endmethod method TerrainCheck takes nothing returns integer local real x = GetUnitX(.target) local real y = GetUnitY(.target) local real height = GetUnitFlyHeight(.target) if IsTerrainWalkable(x + 50.00 * .cos,y + 50.00 * .sin) == false then return 3 else if IsTerrainPathable(x,y,PATHING_TYPE_FLOATABILITY) then return 1 elseif not IsTerrainPathable(x,y,PATHING_TYPE_WALKABILITY) then return 2 endif endif return 0 endmethod method KnockbackStop takes unit target returns boolean local Knock d = Knock[target] if d != 0 then call d.release() if FirstOfGroup(Knock.knocking) != null then call GroupRemoveUnit(Knock.knocking, target) else call PauseTimer(Knock.Timer) endif return true endif return false endmethod method IsKnockedBack takes unit target returns boolean return Knock[target] != 0 endmethod static method create takes unit source, unit target, real angle, real speed, real decrement returns Knock local Knock d = Knock.allocate() if target == null or source == null or speed == 0.00 or decrement == 0.00 then call BJDebugMsg("Invalid Values!") call d.destroy() endif set d.source = source set d.target = target set d.trees = false set d.fly = false set d.chain = false set d.ToTarget = false set d.Move = false set d.hit = NewGroup() set d.speed = speed * TIME set d.decrement = decrement * TIME set d.sin = Sin(angle) set d.cos = Cos(angle) set d.distance = -1 * speed * speed / (2 * -decrement / TIME) set d.positionZ = 0. set d.LineDamage = 0 set d.Mode = 0 set d.VariableSpeed = 0 set d.Increment = 0 set d.dashtarget = null set d.TargetPoint = null set d.VariableSpeed = speed if d.fly then call SetUnitPathing(d.target,false) call UnitAddAbility(d.target,FLYID) call UnitRemoveAbility(d.target,FLYID) else set d.mode = d.TerrainCheck() if d.mode == 1 then set d.effects = AddSpecialEffectTarget(GROUND,d.target,ATTACHPOINT) elseif d.mode == 2 then set d.effects = AddSpecialEffectTarget(WATER,d.target,ATTACHPOINT) elseif d.mode == 3 then set d.effects = AddSpecialEffectTarget(COLLISION,d.target,ATTACHPOINT) endif endif set Knock[target] = d if FirstOfGroup(Knock.knocking) == null then call TimerStart(d.Timer,TIME,true,function Knock.Periodic) endif call GroupAddUnit(Knock.knocking, target) if d.OnStart.exists then call d.OnStart() endif return d endmethod static method get takes unit u returns integer return Knock[u] endmethod private method onDestroy takes nothing returns nothing call DestroyEffect(.effects) call ReleaseGroup(.hit) call SetUnitFlyHeight(.target,GetUnitDefaultFlyHeight(.target),0) call SetUnitPathing(.target,true) endmethod private static method action takes nothing returns nothing local Knock d local unit t = GetEnumUnit() local Knock this = Knock[t] local real x = GetUnitX(.target) local real y = GetUnitY(.target) local real cx = 0.00 local real cy = 0.00 local real tx = 0.00 local real ty = 0.00 local integer mode = .mode local real height = GetUnitFlyHeight(.target) local group g = NewGroup() local real angle = 0.00 set .positionZ = .positionZ + .speed if height >= HEIGHTLEVEL then set .chain = false set .trees = false endif if .ToTarget and .TargetPoint == null then set cx = GetUnitX(.dashtarget) set cy = GetUnitY(.dashtarget) // set angle = Atan2(cy-y,cx-x) // set .cos = Cos(angle) // set .sin = Sin(angle) if SquareRoot((cx - x) * (cx - x) + (cy - y) * (cy - y)) <= 125 then if .OnStop.exists then call .OnStop() endif call GroupRemoveUnit(Knock.knocking, .target) call .release() endif endif if .OnStopCondition.exists then call .OnStopCondition() if .OnStop.exists then call .OnStop() endif call GroupRemoveUnit(Knock.knocking, .target) call .release() endif if .TargetPoint != null and not .ToTarget then set tx = GetLocationX(.TargetPoint) set ty = GetLocationY(.TargetPoint) if SquareRoot((tx - x) * (tx - x) + (ty - y) * (ty - y)) <= 128 then if .OnStop.exists then call .OnStop() endif call GroupRemoveUnit(Knock.knocking, .target) call .release() endif endif if .TargetPoint == null and not .ToTarget and not .OnStopCondition.exists then if .speed <= 0 or IsPointOutside(x,y) then if .OnStop.exists then call .OnStop() endif call GroupRemoveUnit(Knock.knocking, .target) call .release() endif endif if .Mode == 0 then set x = x + .speed * .cos set y = y + .speed * .sin elseif .Mode == 1 then set x = x + 5 set y = y + 5 elseif .Mode == 2 then set x = x + .VariableSpeed *.cos set y = y + .VariableSpeed *.sin endif if .Move then call SetUnitX(.target,x) call SetUnitY(.target,y) else call SetUnitPosition(.target,x,y) endif if .LineDamage > 0 then set .data = this call GroupEnumUnitsInRange(g,x,y,100,LineFilter) loop set t = FirstOfGroup(g) exitwhen t == null call UnitDamageTarget(.source,t,.LineDamage,false,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_NORMAL,null) call GroupRemoveUnit(g,t) endloop endif if .trees then call SetRect(TreeRect,x-RADIUS,y-RADIUS,x+RADIUS,y+RADIUS) call EnumDestructablesInRect(TreeRect,TreeCheck,function Knock.Trees) endif if .fly then call SetUnitPathing(.target,false) call UnitAddAbility(.target,FLYID) call UnitRemoveAbility(.target,FLYID) call SetUnitFlyHeight(.target,ParabolaZ(FACTOR*.distance,.distance,.positionZ),0) endif set .mode = .TerrainCheck() set height = GetUnitFlyHeight(.target) if height < 0 then if .mode == 1 and (mode == 2 or mode == 3) then call DestroyEffect(.effects) set .effects = AddSpecialEffectTarget(GROUND,.target,ATTACHPOINT) elseif .mode == 2 and (mode == 1 or mode == 3) then call DestroyEffect(.effects) set .effects = AddSpecialEffectTarget(WATER,.target,ATTACHPOINT) elseif .mode == 3 and (mode == 1 or mode == 2) then call DestroyEffect(.effects) set .effects = AddSpecialEffectTarget(COLLISION,.target,ATTACHPOINT) endif endif if .chain == true then set .data = this call GroupEnumUnitsInRange(ENUM_GROUP,x,y,CHAINRADIUS,ChainFilter) loop set t = FirstOfGroup(ENUM_GROUP) exitwhen t == null if not IsUnitInGroup(t,.hit) then set cx = GetUnitX(t) set cy = GetUnitY(t) call GroupAddUnit(.hit,t) set d = Knock.create(.source,t,Atan2(cy-y,cx-x),(.speed/TIME)*SPEEDFACTOR,(.decrement/TIME)) if .OnChain.exists then call .OnChain() endif call GroupAddUnit(d.hit,.target) call GroupAddUnit(Knock.knocking, t) endif call GroupRemoveUnit(ENUM_GROUP,t) endloop endif set .speed = .speed - .decrement if .Mode == 2 then set .VariableSpeed = .VariableSpeed + .Increment endif endmethod private static method Periodic takes nothing returns nothing call ForGroup(Knock.knocking, function Knock.action) if FirstOfGroup(Knock.knocking) == null then call PauseTimer(.Timer) endif endmethod static method onInit takes nothing returns nothing set TreeRect = Rect(0.00,0.00,1.00,1.00) set TreeCheck = Filter(function Knock.CheckTrees) set ChainFilter = Filter(function Knock.ChainCheck) set LineFilter = Filter(function Knock.LineCheck) endmethod endstruct private function Init takes nothing returns nothing set MapMaxX = GetRectMaxX(bj_mapInitialPlayableArea) set MapMaxY = GetRectMaxY(bj_mapInitialPlayableArea) set MapMinX = GetRectMinX(bj_mapInitialPlayableArea) set MapMinY = GetRectMinY(bj_mapInitialPlayableArea) endfunction endlibrary JASS:scope Overseermight initializer Init globals private constant integer DMGAURA = 'A00F' private constant integer SPELLBOOK = 'A00V' private constant integer SPELL = 'A00U' private constant string EFFECT = "Abilities\\Spells\\Undead\\AbsorbMana\\AbsorbManaBirthMissile.mdl" endglobals private function LConditions takes nothing returns boolean return GetLearnedSkill() == SPELL endfunction private function LActions takes nothing returns nothing local unit u = GetTriggerUnit() local integer i = GetUnitAbilityLevel(u,SPELL) if GetLearnedSkill() > 0 then call UnitAddAbility(u,SPELLBOOK) endif call SetUnitAbilityLevel(u,DMGAURA,i) set u = null endfunction private function Conditions takes nothing returns boolean return GetSpellAbilityId() == SPELL endfunction private function Actions takes nothing returns nothing local Knock d local unit u = GetTriggerUnit() local unit t = GetSpellTargetUnit() local real tx = GetUnitX(t) local real ty = GetUnitY(t) local real x = GetUnitX(u) local real y = GetUnitY(u) local unit dummy = CreateUnit(GetOwningPlayer(u),DUMMY,x,y,0) local real angle = Atan2(ty-y,tx-x) set d = Knock.create(u,dummy,angle,1000,5) set d.dashtarget = t set d.ToTarget = true set d.Mode = 1 endfunction //=========================================================================== private function Init takes nothing returns nothing local trigger t = CreateTrigger() local integer i = 0 loop exitwhen i > 12 call SetPlayerAbilityAvailable(Player(i),SPELLBOOK,false) set i = i + 1 endloop call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_HERO_SKILL) call TriggerAddAction(t, function LActions ) call TriggerAddCondition(t,Condition(function LConditions)) set t = CreateTrigger() call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT) call TriggerAddAction(t, function Actions) call TriggerAddCondition(t,Condition(function Conditions)) endfunction endscope |
| 05-05-2009, 06:56 PM | #2 |
Do you have anything else to add? What does the code do exactly? Can you lead me through the functions? Because I really don't feel like looking throguh all this without a clue what I'm looking for. |
| 05-06-2009, 09:53 AM | #3 |
It's solved, after debugging for 2 days. |
