Lasso v1.00

Toss a magical rope around the target, grabbing it and holding it close.
.Why Dismember sucks:
It has screwy casting distances, and neither the caster nor target can move during the spell.
Why Lasso doesn't suck:
Both the caster and target can move while a unit is lassoed. The user can input a break distance at which point the lasso will snap, a minimum distance required for the lasso to illicit a pull effect, as well as an equation which allows completely unique pulling physics. In other words, this is what Dismember should have been.
Spell Code
JASS:
scope Lasso initializer Init
private keyword data
globals
// Configuration Options:
private integer Abil_ID = 'A000' // Lasso ability rawcode
private real Interval = .04 // Timer interval
private real Height = 30. // Height of lightning
private string Light = "LEAS" // Lightning effect created
private string Sfx = "Abilities\\Weapons\\AncientProtectorMissile\\AncientProtectorMissile.mdl" // Effect created when a untit is pulled
// Needed Globals:
public trigger Trig = null
private timer T = CreateTimer()
private location L1 = null
private location L2 = null
private integer I = 0
private data array D
endglobals
// Configuration Functions:
private function MaxDur takes integer lvl returns real
return 10. // Max duration for spell
endfunction
private function PullEq takes integer lvl, real dist returns real
return dist/50. // Equation for the strength of the pull effect per timer interval
endfunction
private function SlackDist takes integer lvl returns real
return 200. // Distance at which no pull effect is created (all distances under this value)
endfunction
private function BreakDist takes integer lvl returns real
return 800. // Distance at which the lasso snaps
endfunction
//***** No Touching Past This Point *****\\
private struct data
unit u = null
unit targ = null
integer lvl
lightning lasso = null
real time = 0.
method onDestroy takes nothing returns nothing
call DestroyLightning(.lasso)
endmethod
endstruct
private function Update takes nothing returns nothing
local data d
local integer i = 1
local real dist
local real ang
loop
exitwhen i>I
set d = D<i>
set dist = SquareRoot(Pow(GetUnitX(d.u) - GetUnitX(d.targ), 2) + Pow(GetUnitY(d.u)-GetUnitY(d.targ),2))
if GetWidgetLife(d.u)<.405 or GetWidgetLife(d.targ)<.405 or d.time>MaxDur(d.lvl) or dist>BreakDist(d.lvl) then
call d.destroy()
set D<i> = D<i>
set I = I - 1
set i = i - 1
else
if dist>SlackDist(d.lvl) then
set ang = Atan2(GetUnitY(d.targ) - GetUnitY(d.u), GetUnitX(d.targ) - GetUnitX(d.u))
call SetUnitX(d.targ,GetUnitX(d.targ)-PullEq(d.lvl,dist)*Cos(ang))
call SetUnitY(d.targ,GetUnitY(d.targ)-PullEq(d.lvl,dist)*Sin(ang))
call DestroyEffect(AddSpecialEffectTarget(Sfx,d.targ,"origin"))
endif
set L1 = GetUnitLoc(d.u)
set L2 = GetUnitLoc(d.targ)
call MoveLightningEx(d.lasso,true,GetUnitX(d.u),GetUnitY(d.u),GetLocationZ(L1)+Height,GetUnitX(d.targ),GetUnitY(d.targ),GetLocationZ(L2)+Height)
call RemoveLocation(L1)
call RemoveLocation(L2)
set d.time = d.time + Interval
endif
set i = i + 1
endloop
if I==0 then
call PauseTimer(T)
endif
endfunction
private function Conds takes nothing returns boolean
return GetSpellAbilityId()==Abil_ID
endfunction
private function Acts takes nothing returns nothing
local data d = data.create()
set d.u = GetTriggerUnit()
set d.targ = GetSpellTargetUnit()
set d.lvl = GetUnitAbilityLevel(d.u,Abil_ID)
set L1 = GetUnitLoc(d.u)
set L2 = GetUnitLoc(d.targ)
set d.lasso = AddLightningEx(Light,true,GetUnitX(d.u),GetUnitY(d.u),GetLocationZ(L1)+Height,GetUnitX(d.targ),GetUnitY(d.targ),GetLocationZ(L2)+Height)
set I = I + 1
set D<i> = d
if I==1 then
call TimerStart(T,Interval,true,function Update)
endif
call RemoveLocation(L1)
call RemoveLocation(L2)
endfunction
private function Init takes nothing returns nothing
set Trig = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(Trig,EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(Trig,Condition(function Conds))
call TriggerAddAction(Trig,function Acts)
endfunction
endscope</i></i></i></i>
Don't mind the other triggers in the map. All you need to look at is what is contained within the Spells folder, specifically the trigger Lasso.
Enjoy and please comment!
Attachments
-
48.6 KB Views: 435
-
205 KB Views: 686