The_Kingpin
Member (Who are you and why should I care?)
- Reaction score
- 41
Deflect - Follows JESP standard.
No screenshot available.
(Passive) Gives a percent chance to deflect damage taken and distribute a percentage of it to nearby enemies.
Features:
-vJass (http://wc3campaigns.net/showthread.php?t=90999)
-MUI
-Leakless
-BJ-Free
-Customizable
-Compatible versions for other attachment systems.
Code: (Stand-Alone)
Contains three versions for different attachment systems: Stand-Alone (Nothing extra necessary), HexHandles (The small attachment system I use in my stuff), and ABC / PUI (Systems made by Cohadar).
Constructive criticism is welcome. :shades:
Download:
No screenshot available.
(Passive) Gives a percent chance to deflect damage taken and distribute a percentage of it to nearby enemies.
Features:
-vJass (http://wc3campaigns.net/showthread.php?t=90999)
-MUI
-Leakless
-BJ-Free
-Customizable
-Compatible versions for other attachment systems.
Code: (Stand-Alone)
JASS:
//"Deflect" by The_Kingpin
library SpellDeflect
//
// CONFIGURATION
//
globals
//The id of the ability.
private constant integer Id = 'A000'
//The area of effect that the spell distributes damage to.
private constant real Aoe = 300
//The effect on affected units.
private constant string Effect = "Abilities\\Weapons\\Rifle\\RifleImpact.mdl"
//The area of effect art.
private constant string AoeEffect = "Units\\NightElf\\Wisp\\WispExplode.mdl"
endglobals
//Chance to proc per level. Add another "Level[<LEVEL>]=<VALUE>" for more levels.
private function Chance takes integer lvl returns real
local real array Level
set Level[lvl] = 0.10
set Level[1] = 0.15
set Level[2] = 0.25
set Level[3] = 0.30
return Level[lvl]
endfunction
//The percentage of damage distributed.
private function Percent takes integer lvl returns real
local real array Level
set Level[lvl] = 0.20
set Level[1] = 0.20
set Level[2] = 0.30
set Level[3] = 0.40
return Level[lvl]
endfunction
//This is the condition that the spell will run under. This might not
//need to be changed, unless you want the spell to affect other units.
private function Conditions takes unit caster, unit target returns boolean
return IsUnitEnemy(target,GetOwningPlayer(caster))
endfunction
//
//END CONFIGURATION SECTION
//
//Don't edit anything past here unless you know what you are doing.
//
//
//
globals
private integer array db1
private integer array db2
private integer array db3
private integer array db4
private integer array db5
private integer Hex = 0x100000
private integer Size = 8191
endglobals
private function H2I takes handle h returns integer
return h
return 0
endfunction
private function Store takes handle h, integer s returns nothing
local integer id = H2I(h)-Hex
if id < Size then
set db1[id] = s
elseif id < Size*2 then
set db2[id - Size] = s
elseif id < Size*3 then
set db3[id - Size*2] = s
elseif id < Size*4 then
set db4[id - Size*3] = s
elseif id < Size*5 then
set db5[id - Size*4] = s
else
debug call BJDebugMsg("|cffff2222HexHandles: Too many handles for Store()|r")
endif
endfunction
private function Recall takes handle h returns integer
local integer id = H2I(h)-Hex
if id < Size then
return db1[id]
elseif id < Size*2 then
return db2[id - Size]
elseif id < Size*3 then
return db3[id - Size*2]
elseif id < Size*4 then
return db4[id - Size*3]
elseif id < Size*5 then
return db5[id - Size*4]
else
debug call BJDebugMsg("|cffff2222HexHandles: Nonexistant index for Recall()|r")
endif
return 0
endfunction
private struct SpellEffect
unit Unit
integer Level
real Chance
real Percent
trigger Trigger = CreateTrigger()
static method Damaged takes nothing returns boolean
local SpellEffect this = Recall(GetTriggeringTrigger())
local real damage
local group g
local unit u
if GetRandomReal(0,1) <= this.Chance then
set g = CreateGroup()
set damage = this.Percent*GetEventDamage()
call SetUnitState(this.Unit,UNIT_STATE_LIFE,GetUnitState(this.Unit,UNIT_STATE_LIFE)+GetEventDamage())
call GroupEnumUnitsInRange(g,GetUnitX(this.Unit),GetUnitY(this.Unit),Aoe,null)
call DestroyEffect(AddSpecialEffect(AoeEffect,GetUnitX(this.Unit),GetUnitY(this.Unit)))
loop
set u = FirstOfGroup(g)
exitwhen u == null
if Conditions(this.Unit,u) then
call UnitDamageTarget(this.Unit,u,damage,true,false,ATTACK_TYPE_CHAOS,DAMAGE_TYPE_UNIVERSAL,WEAPON_TYPE_WHOKNOWS)
call DestroyEffect(AddSpecialEffectTarget(Effect,u,"chest"))
endif
call GroupRemoveUnit(g,u)
endloop
call DestroyGroup(g)
endif
set g = null
return false
endmethod
private method onDestroy takes nothing returns nothing
call DestroyTrigger(this.Trigger)
call Store(this.Unit,0)
endmethod
static method create takes unit U, integer L returns SpellEffect
local SpellEffect this = SpellEffect.allocate()
set this.Unit = U
set this.Level = L
set this.Chance = Chance(this.Level)
set this.Percent = Percent(this.Level)
call TriggerRegisterUnitEvent(this.Trigger,this.Unit,EVENT_UNIT_DAMAGED)
call TriggerAddCondition(this.Trigger,Condition(function SpellEffect.Damaged))
call Store(this.Trigger,this)
return this
endmethod
endstruct
function Trig_Spell_Deflect_Conditions takes nothing returns boolean
return GetLearnedSkill() == Id
endfunction
function Trig_Spell_Deflect_Actions takes nothing returns nothing
local SpellEffect this = Recall(GetTriggerUnit())
if this != 0 then
call this.destroy()
endif
set this = SpellEffect.create(GetTriggerUnit(),GetUnitAbilityLevel(GetTriggerUnit(),Id))
call Store(GetTriggerUnit(),this)
endfunction
//===========================================================================
function InitTrig_Spell_Deflect takes nothing returns nothing
set gg_trg_Spell_Deflect = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Spell_Deflect, EVENT_PLAYER_HERO_SKILL )
call TriggerAddCondition( gg_trg_Spell_Deflect, Condition( function Trig_Spell_Deflect_Conditions ) )
call TriggerAddAction( gg_trg_Spell_Deflect, function Trig_Spell_Deflect_Actions )
endfunction
endlibrary
Contains three versions for different attachment systems: Stand-Alone (Nothing extra necessary), HexHandles (The small attachment system I use in my stuff), and ABC / PUI (Systems made by Cohadar).
Constructive criticism is welcome. :shades:
Download:
Attachments
-
55.6 KB Views: 770