- Joined
- May 21, 2008
- Messages
- 218
My first vJass spell, is it efficient?
Units caught in the AoE would be affected by a random effect of the following.
1 ~ Stunned for Heroes Level
2 ~ Damage Units by Heroes Level x 50
3 ~ Hero Loses 50% of Max Health (Can kill)
4 ~ Debuffs unit's armor by Heroes Level
5 ~ Debuffs unit's attack speed, damage and movement speed by Heroes Int
This post will be updated as I learn how awful my coding is.
Units caught in the AoE would be affected by a random effect of the following.
1 ~ Stunned for Heroes Level
2 ~ Damage Units by Heroes Level x 50
3 ~ Hero Loses 50% of Max Health (Can kill)
4 ~ Debuffs unit's armor by Heroes Level
5 ~ Debuffs unit's attack speed, damage and movement speed by Heroes Int
JASS:
//===========================================================================\\
//===============================SETUP=======================================\\
//===========================================================================\\
// 1. Copy into your map \\
// 2. Copy ability Armor Debuff (-4) into your map \\
// 3. Set rawcodes for setup data and change to your liking \\
// 4. Enjoy \\
// \\
// Author: Zypher@USeast \\
//===========================================================================\\
scope Random5 initializer Init
globals
private constant integer SPELL_ID = 'ANsi' //the rawcode of the spell
private constant integer DUMMY_ID = 'hf00' //raw code of the dummy unit
private constant integer ARMOR_DEBUFF_ID = 'A000' //rawcode of custom item ability Armor Debuff (-4)
private constant integer ATTACK_SPEED_DEBUFF_ID = 'A001' //rawcode of custom item ability Attack Speed Debuff (-0.3)
private constant integer DAMAGE_DEBUFF_ID = 'A002' //rawcode of custom item ability Damage Debuff (-15)
private constant damagetype D_TYPE = DAMAGE_TYPE_NORMAL //the attack type of the spell
private constant attacktype A_TYPE = ATTACK_TYPE_MAGIC //the damage type of the spell
private constant weapontype W_TYPE = WEAPON_TYPE_WHOKNOWS //default weapontype change if you want to
private constant string AOE_EFFECT = "Units\\NightElf\\Wisp\\WispExplode.mdl" //effect created on cast of Aoe location
private constant string DAMAGE_EFFECT = "Abilities\\Weapons\\Bolt\\BoltImpact.mdl" //effect that will be created when we damage units
private constant string STUN_EFFECT = "Abilities\\Spells\\Human\\Thunderclap\\ThunderclapTarget.mdl" //stun effect path
private constant boolean IS_RANGED = true //spell damage is ranged attack
private constant boolean IS_MELEE = false //spell damage is melee attack.
private constant boolean INT_INCLUDE_BONUSES = true //decides if bonuses should effect hero stats for the spell
endglobals
private function Aoe takes integer level returns real
//returns the Aoe the spell will affect
return I2R(level * 175)
endfunction
private function Stuntime takes integer level returns real
//returns the stun time to enemies
return I2R(level * 1)
endfunction
private function Percenthealthloss takes nothing returns integer
//returns the % of healthloss the caster takes
return 50
endfunction
private function armorloss takes integer level returns integer
//returns the amount of armor lost by target units
return level
endfunction
private function armorlosstime takes integer level returns real
//returns the time armor loss is active on target units
return I2R(20 + (level * 10))
endfunction
private function Damage takes integer level returns real
//returns the damage to enemies
return I2R(level * 50)
endfunction
private function Targets takes nothing returns boolean
//the units the spell will affect
local unit t = GetEnumUnit()
return (GetWidgetLife(t) > 0.405) and (IsUnitType(t, UNIT_TYPE_STRUCTURE) == false) and (IsUnitType(t, UNIT_TYPE_MAGIC_IMMUNE) == false) and (IsUnitType(t, UNIT_TYPE_FLYING) == false)
endfunction
private function debufftime takes integer level returns real
return I2R(20 + (level * 10))
endfunction
private function movespeeddown takes integer Int, real movespeed returns real
//returns the movespeed of the unit minus the intelligence of the hero
return movespeed - I2R(Int)
endfunction
private function movespeedup takes integer Int, real movespeed returns real
//returns the movespeed of the unit plus the intelligence of the hero
return movespeed + I2R(Int)
endfunction
//===========================================================================\\
//=============================SETUP END=====================================\\
//===========================================================================\\
globals
private unit udg_temp_unit
private integer udg_level
private unit udg_caster
private integer INT
endglobals
private function Conditions takes nothing returns boolean
return GetSpellAbilityId() == SPELL_ID
endfunction
private function stun takes nothing returns nothing
local unit u = udg_temp_unit
local effect e = AddSpecialEffectTarget(STUN_EFFECT, u, "overhead")
call PauseUnit(u, true)
call TriggerSleepAction(Stuntime(udg_level))
call PauseUnit(u, false)
call DestroyEffect(e)
set u = null
set e = null
endfunction
private function unitarmorloss takes nothing returns nothing
local unit u = udg_temp_unit
call UnitAddAbility( u, ARMOR_DEBUFF_ID )
call TriggerSleepAction(armorlosstime(udg_level))
call UnitRemoveAbility( u, ARMOR_DEBUFF_ID)
set u = null
endfunction
private function executeunitarmorloss takes nothing returns nothing
local unit u = GetEnumUnit()
set udg_temp_unit = u
call ExecuteFunc("unitarmorloss")
set u = null
endfunction
private function executestun takes nothing returns nothing
local unit u = GetEnumUnit()
set udg_temp_unit = u
call ExecuteFunc("stun")
set u = null
endfunction
private function damage takes nothing returns nothing
local unit u = GetEnumUnit()
call UnitDamageTarget(udg_caster, u, Damage(udg_level), IS_MELEE, IS_RANGED, A_TYPE, D_TYPE, W_TYPE)
set u = null
endfunction
private function killunit takes unit u returns nothing
call KillUnit(u)
call TriggerSleepAction(7.00)
call RemoveUnit(u)
set u = null
endfunction
private function debuff takes nothing returns nothing
local unit u = udg_temp_unit
local real movespeed = GetUnitMoveSpeed(u)
call SetUnitMoveSpeed( u, ( movespeeddown( INT , movespeed )))
call UnitAddAbility( u, ATTACK_SPEED_DEBUFF_ID )
call UnitAddAbility( u, DAMAGE_DEBUFF_ID )
call TriggerSleepAction(debufftime(udg_level))
call SetUnitMoveSpeed( u, ( movespeedup( INT , movespeed )))
call UnitRemoveAbility( u, ATTACK_SPEED_DEBUFF_ID)
call UnitRemoveAbility( u, DAMAGE_DEBUFF_ID )
set u = null
endfunction
private function executedebuff takes nothing returns nothing
local unit u = GetEnumUnit()
set udg_temp_unit = u
call ExecuteFunc("debuff")
set u = null
endfunction
private function Actions takes nothing returns nothing
local location spellLoc = GetSpellTargetLoc()
local real spellX = GetLocationX(spellLoc)
local real spellY = GetLocationY(spellLoc)
local unit caster = GetTriggerUnit()
local integer level = GetUnitAbilityLevel(caster, SPELL_ID)
local group g = CreateGroup()
local real realAoe = Aoe(level)
local integer random = GetRandomInt( 1, 5)
call GroupEnumUnitsInRangeOfLoc( g, Location(spellX, spellY), realAoe, Filter(function Targets))
set udg_level = level
set udg_caster = caster
set INT = GetHeroInt(udg_caster, INT_INCLUDE_BONUSES)
if random == 1 then
call ForGroup(g, function executestun)
endif
if random == 2 then
call ForGroup(g, function damage)
endif
if random == 3 then
if GetUnitStatePercent(udg_caster, UNIT_STATE_LIFE, UNIT_STATE_MAX_LIFE) <= 50 then
call killunit(udg_caster)
call SetUnitState(udg_caster, UNIT_STATE_LIFE, GetUnitState(udg_caster, UNIT_STATE_MAX_LIFE) * RMaxBJ(0,( GetUnitStatePercent(udg_caster, UNIT_STATE_LIFE, UNIT_STATE_MAX_LIFE) - Percenthealthloss() )) * 0.01)
endif
else
endif
if random == 4 then
call ForGroup(g, function executeunitarmorloss)
else
endif
if random == 5 then
call ForGroup(g, function executedebuff)
else
endif
call RemoveLocation(spellLoc)
set spellLoc = null
set caster = null
call DestroyGroup(g)
set g = null
endfunction
private function Init takes nothing returns nothing
local trigger Random5 = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( Random5, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( Random5, Condition( function Conditions ) )
call TriggerAddAction( Random5, function Actions )
set Random5 = null
//preloading effects
call Preload(AOE_EFFECT)
call Preload(DAMAGE_EFFECT)
call Preload(STUN_EFFECT)
//preloading the ability
set bj_lastCreatedUnit = CreateUnit(Player(0), DUMMY_ID, 0, 0, 0)
call UnitAddAbility(bj_lastCreatedUnit, SPELL_ID)
call KillUnit(bj_lastCreatedUnit)
endfunction
endscope
This post will be updated as I learn how awful my coding is.
Last edited: