Chaosy
Tutorial Reviewer
- Joined
- Jun 9, 2011
- Messages
- 13,239
Hello. Today I made a vjass spell with a struct. (omg!)
The spell works fine, but I want tips/suggestions on how improve my spell code wise.
There are two potential leaks that I am aware of, the special effect and the unitgroups are not cleared. Mainly because I am unsure if they still leak since I don't use the BJ version of them.
Note: a few config variables are not used yet, no need to point that out.
The ability is supposed to make the caster travel to a certain location. Enemies who gets hit while traveling gets knocked backwards and at the end of the path every unit gets knocked up.
The spell works fine, but I want tips/suggestions on how improve my spell code wise.
There are two potential leaks that I am aware of, the special effect and the unitgroups are not cleared. Mainly because I am unsure if they still leak since I don't use the BJ version of them.
Note: a few config variables are not used yet, no need to point that out.
The ability is supposed to make the caster travel to a certain location. Enemies who gets hit while traveling gets knocked backwards and at the end of the path every unit gets knocked up.
JASS:
globals
List l
unit temp
real knockbackDamage = 50
real knockupDamage = 75
constant real strModifier = 0.3
constant real knockbackTime = .75
constant real knockbackDistance = 150
constant real knockupHeight = 300
constant real knockupSpeed = 5
constant real travelSpeed = 6
constant real travelSpeedModifier = 0.3
constant trigger knockupTrigger = gg_trg_KU_prepare
constant trigger knockbackTrigger = gg_trg_Knockback_2D
constant damagetype damageType = DAMAGE_TYPE_FORCE
constant string knockupEffect = "Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.mdl"
constant string travelEffect = "Objects\\Spawnmodels\\Undead\\ImpaleTargetDust\\ImpaleTargetDust.mdl"
constant string knockupAnimation = "Attack"
endglobals
function Knockup takes nothing returns nothing
if IsUnitInGroup(GetEnumUnit(), udg_KUS_group) == false then
set udg_KUS_target = GetEnumUnit()
set udg_KUS_effect = knockupEffect
set udg_KUS_height = knockupHeight
set udg_KUS_speed = knockupSpeed
set udg_KUS_animation = knockupAnimation
call ConditionalTriggerExecute(knockupTrigger)
endif
endfunction
function Knockback takes nothing returns nothing
if GetUnitAbilityLevelSwapped('Aloc', GetEnumUnit()) == 0 then
set udg_CenterPoint = GetUnitLoc(temp)
set udg_TargetPoint = GetUnitLoc(GetEnumUnit())
set udg_Knockback2DAngle = AngleBetweenPoints(udg_CenterPoint, udg_TargetPoint)
set udg_Knockback2DTime = knockbackTime
set udg_Knockback2DDistance = knockbackDistance
set udg_Knockback2DUnit = GetEnumUnit()
call RemoveLocation(udg_CenterPoint)
call RemoveLocation(udg_TargetPoint)
call TriggerExecute(knockbackTrigger)
endif
endfunction
function EnemyFilter takes nothing returns boolean
return IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(temp)) == true
endfunction
struct Underground
unit caster
location targetPos
real speed = travelSpeed
public static method create takes unit u, location targetLoc returns thistype
local thistype this = thistype.allocate()
set caster = u
set targetPos = targetLoc
call l.Add(this)
call SetUnitInvulnerable(u, true)
call SetUnitVertexColor(u, 100, 100, 100, 0)
call SetUnitPathing(u, false)
return this
endmethod
public method Update takes nothing returns nothing
local location loc = GetUnitLoc(caster)
local real angle = AngleBetweenPoints(loc, targetPos)
local real xpos = GetLocationX(loc) + speed * Cos(angle * bj_DEGTORAD)
local real ypos = GetLocationY(loc) + speed * Sin(angle * bj_DEGTORAD)
set speed = speed + travelSpeedModifier
call SetUnitPosition(caster, xpos, ypos)
set loc = Location(xpos, ypos)
set temp = caster
call ForGroupBJ(GetUnitsInRangeOfLocMatching(100, loc, Condition(function EnemyFilter)), function Knockback)
call AddSpecialEffectLoc(travelEffect, loc)
if DistanceBetweenPoints(loc, targetPos) < 50 then
set temp = caster
call ForGroup(GetUnitsInRangeOfLocMatching(200, loc, Condition(function EnemyFilter)), function Knockup)
call l.Remove(this)
call SetUnitVertexColor(caster, 255, 255, 255, 255)
call SetUnitPathing(caster, true)
call this.deallocate()
endif
call RemoveLocation(loc)
endmethod
endstruct