Code:
scope Toss
//******************************************************************************************
//*
//* Toss - By emjlr3, Original seen in DotA Allstars
//*
//* Toss a friend or foe from here to there by targeting on a unit, and grabbing
//* a random target in the area, launching them towards the targeted area.
//*
//* Requires:
//* - "TT" trigger copied to your map, if not already there
//* - The "Toss" ability copied to your map
//* - A vJASS Preprocessor
//*
//******************************************************************************************
globals
// Config Globals:
private constant integer abil_id = 'A001' // Toss ability rawcode
private constant integer fly_id = 'Amrf' // Rawcode of ability to use for fly trick, if you have not touched Crow Form, this doesn't need changing
private constant real impact_damage = .20 // Percent of toss damage dealt to tossed unit
private constant real time = 1. // Flight time for tossed unit (seconds)
private constant string fly_sfx = "Abilities\\Spells\\Undead\\Cripple\\CrippleTarget.mdl" // Effect created on target during toss
private constant string end_sfx = "Abilities\\Spells\\Orc\\WarStomp\\WarStompCaster.mdl" // Effect created on target at end of toss
private constant boolean kill_trees = true // Whether trees are destroyed upon target landing
private constant attacktype attack_type = ATTACK_TYPE_NORMAL // Attack type used for damage
private constant damagetype damage_type = DAMAGE_TYPE_DEMOLITION // Damage type used for damage
// Needed Globals:
private group G = CreateGroup()
private unit U = null
private rect R = null
private location L = null
public trigger Trigger = null // Output trigger will be Toss_Trigger, which can be used publically
endglobals
// Config. Functions:
private function Damage takes integer lvl returns real
return 75.*lvl // Damage/lvl
endfunction
private function Area takes integer lvl returns real
return 275. // Area within to grab units and damage units/lvl
endfunction
//========================================================================================
private struct data
unit u
unit targ
player p
real xt
real yt
real xl
real yl
real dist
real ang
real cos
real sin
real speed
real hc
integer lvl
integer count = 1
effect e
static method FiltIsEnemy takes nothing returns boolean
return IsUnitEnemy(GetFilterUnit(), bj_groupEnumOwningPlayer) and GetUnitState(GetFilterUnit(),UNIT_STATE_LIFE)>.405
endmethod
static method DamageGroup takes unit damager, real radius, real x, real y, real amount returns nothing
local unit u
set bj_groupEnumOwningPlayer = GetOwningPlayer(damager)
call GroupClear(G)
call GroupEnumUnitsInRange(G, x, y, radius, Condition(function data.FiltIsEnemy))
loop
set u = FirstOfGroup(G)
exitwhen u == null
call GroupRemoveUnit(G,u)
call UnitDamageTarget(damager,u,amount,false,false,attack_type,damage_type,null)
endloop
endmethod
static method KillTrees_Child takes nothing returns nothing
call KillDestructable(GetEnumDestructable())
endmethod
static method KillTrees takes real x, real y, real radius returns nothing
set R = Rect(x - radius,y - radius,x + radius,y + radius)
call EnumDestructablesInRect(R,null,function data.KillTrees_Child)
call RemoveRect(R)
endmethod
method onDestroy takes nothing returns nothing
call SetUnitFlyHeight(.targ,GetUnitDefaultFlyHeight(.targ),0.)
call PauseUnit(.targ,false)
call SetUnitPathing(.targ,true)
call DestroyEffect(.e)
call UnitDamageTarget(.u,.targ,Damage(.lvl)*impact_damage,false,false,attack_type,damage_type,null)
call DestroyEffect(AddSpecialEffectTarget(end_sfx,.targ,"origin"))
call data.DamageGroup(.u,Area(.lvl),.xl,.yl,Damage(.lvl))
if kill_trees then
call data.KillTrees(.xl,.yl,Area(.lvl))
endif
endmethod
endstruct
private function Conditions takes nothing returns boolean
return GetSpellAbilityId() == abil_id
endfunction
private function Filt takes nothing returns boolean
return GetFilterUnit()!=U and GetWidgetLife(GetFilterUnit())>.405 and not IsUnitType(GetFilterUnit(),UNIT_TYPE_STRUCTURE) and not IsUnitType(GetFilterUnit(),UNIT_TYPE_FLYING)
endfunction
private function GetSpeed takes real dist returns real
return dist/(1./TT_PERIOD)
endfunction
private function GetCountConversion takes integer count returns real
return (50./(time/TT_PERIOD))*count
endfunction
private function Movement takes nothing returns boolean
local data d = TT_GetData()
local real conv
local real height
local real speed
local real x
local real y
if d.count<=time/TT_PERIOD then
set conv = GetCountConversion(d.count)
set height = (conv-25.)*(conv-25.)
set speed = d.count*d.speed
set x = d.xt+speed*d.cos
set y = d.yt+speed*d.sin
call SetUnitX(d.targ,x)
call SetUnitY(d.targ,y)
call SetUnitFlyHeight(d.targ,625.-height,0.)
set d.count = d.count + 1
return false
else
call d.destroy()
return true
endif
endfunction
private function Actions takes nothing returns nothing
local data d = data.create()
set d.u = GetTriggerUnit()
set d.p = GetOwningPlayer(d.u)
set d.lvl = GetUnitAbilityLevel(d.u,abil_id)
call GroupClear(G)
set U = d.u
call GroupEnumUnitsInRange(G,GetUnitX(d.u),GetUnitY(d.u),Area(d.lvl),Condition(function Filt))
set d.targ = GroupPickRandomUnit(G)
if d.targ==null then
call d.destroy()
return
endif
set d.xt = GetUnitX(d.targ)
set d.yt = GetUnitY(d.targ)
set L = GetSpellTargetLoc()
set d.xl = GetLocationX(L)
set d.yl = GetLocationY(L)
set d.ang = Atan2(d.yl-d.yt,d.xl-d.xt)
set d.cos = Cos(d.ang)
set d.sin = Sin(d.ang)
set d.dist = SquareRoot((d.xt-d.xl)*(d.xt-d.xl) + (d.yt-d.yl)*(d.yt-d.yl))
set d.speed = GetSpeed(d.dist)
call PauseUnit(d.targ,true)
call SetUnitPathing(d.targ,false)
call UnitAddAbility(d.targ,fly_id)
call UnitRemoveAbility(d.targ,fly_id)
set d.e = AddSpecialEffectTarget(fly_sfx,d.targ,"origin")
call TT_Start(function Movement,d)
call RemoveLocation(L)
endfunction
//===========================================================================
public function InitTrig takes nothing returns nothing
set Trigger = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( Trigger, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( Trigger, Condition( function Conditions ) )
call TriggerAddAction( Trigger, function Actions )
endfunction
endscope
itu untuk skill
Share This Thread