//TESH.scrollpos=0
//TESH.alwaysfold=0
Name | Type | is_array | initial_value |
//TESH.scrollpos=558
//TESH.alwaysfold=0
[tabs]
[tab=Foreword]
This is my first ever SpellPack submitted in the spell's section. This is originally from [post=1958167]Hero Contest #4 - Animalistic Nature[/post] contest but some improvements.
[/tab]
[tab=Spell's Description]
[box=Locust Raid]
Throws a magical bottle that has locusts inside. When the bottle breaks, angry locusts follows and attacks nearby enemy unit. If there is no enemy around, the locusts follows the caster.
The locusts are invulnerable and cannot be controlled until the target dies.
|cffffcc00Level 1|r - Maximum of 2 locust, lasts 10 seconds
|cffffcc00Level 2|r - Maximum of 4 locust, lasts 20 seconds
|cffffcc00Level 3|r - Maximum of 6 locust, lasts 30 seconds
|cffffcc00Level 4|r - Maximum of 8 locust, lasts 40 seconds
|cffffcc00Level 5|r - Maximum of 10 locust, lasts 50 seconds
|cffffcc00Locust damage 2-6|r
[/box]
[box=Twin Wolves]
Summons two uncontrollable escort wolves which cannot attack but each one has an individual spell. Each one can damage and heal nearby enemy and allied units respectively.
Wolves lasts for 60 seconds or when the caster dies. You may only summon 2 wolves at a time.
|cffffcc00Level 1|r - Wolves damages 50 or heals 100.
|cffffcc00Level 2|r - Wolves damages 100 or heals 150.
|cffffcc00Level 3|r - Wolves damages 150 or heals 200.
|cffffcc00Level 4|r - Wolves damages 200 or heals 250.
|cffffcc00Level 5|r - Wolves damages 250 or heals 300.
Damage dealt by |cffffcc00chainlightning|r. Cooldown 5 seconds.
Heal is done by |cffffcc00rejuvenation|r for 3 seconds. Cooldown 3 seconds.
[/box]
[box=Enchanted Bottle]
This bottle is enchanted by the locusts inside it so that when it breaks, it gives a chance to poison all nearby enemy organic units.
|cffffcc00Level 1|r - 10% chance, deals 90 damage
|cffffcc00Level 2|r - 15% chance, deals 120 damage
|cffffcc00Level 3|r - 20% chance, deals 150 damage
|cffffcc00Level 4|r - 25% chance, deals 180 damage
|cffffcc00Level 5|r - 30% chance, deals 210 damage
[/box]
[box=Forbidden Wrath]
Outburst the anger of the caster and summons 3 powerful beasts. A Red Dragon, Salamander Lord and a Dragon Turtle. During the entire duration of the spell, the caster dissapears and cannot gain level. The caster will be back to normal when the spell expires or if all 3 beast dies. Beasts life lasts 60 seconds.
[/box]
[/tab]
[tab=Spell Codes]
[tabs]
[tab=Locust Raid]
[jass]
/*
Spell Name: Locust Raid
Made by: mckill2009
REQUIRES:
- Jass New Gen Pack (JNGP) by Vexorian
- CTL by Nesthaurus
- SpellEffectEvent by Bribe
- SummonedEscort by mckill2009
*/
scope LocustRaid
globals
private constant integer SPELL_ID = 'A000' //The Main spell
private constant integer BOTTLE_ID = 'h001'
private constant integer SUMMONED_UNIT_ID = 'h003'
private constant real AOE = 300 //enemy filter for passive and active
private constant real HEIGHT = 300 //bottle height
private constant real SPEED = 10 //bottle speed
//===USED ONLY BY PASSIVE SPELL
private constant integer PASSIVE_SPELL_ID = 'A001' //Passive spell, optional
private constant boolean ENABLE_PASSIVE_SPELL = true
private constant attacktype ATK = ATTACK_TYPE_MAGIC //used only by passive
private constant damagetype DMG = DAMAGE_TYPE_POISON //used only by passive
private constant string SFX = "Abilities\\Weapons\\PhoenixMissile\\Phoenix_Missile.mdl" //used only by passive
//===NON-CONFIGURABLE
private unit TempUnit
private group G = CreateGroup()
endglobals
private function GetChance takes integer level returns integer
return 5 * level + 5 //used by passive only
endfunction
private function GetDamage takes integer level returns real
return 30. * level + 60 //used by passive only
endfunction
private function SummonedCount takes integer level returns integer
return level * 2
endfunction
private function SummonedTimer takes integer level returns real
return level * 10.
endfunction
private function UnitAlive takes unit u returns boolean
return not IsUnitType(u, UNIT_TYPE_DEAD)
endfunction
private function UnitInRange takes nothing returns boolean
return UnitAlive(GetFilterUnit()) and IsUnitEnemy(TempUnit, GetOwningPlayer(GetFilterUnit()))
endfunction
private function EnemyFilter takes unit u returns boolean
return UnitAlive(u) and not IsUnitType(u, UNIT_TYPE_FLYING) and not IsUnitType(u, UNIT_TYPE_STRUCTURE) /*
*/ and not IsUnitType(u, UNIT_TYPE_MECHANICAL) and not IsUnitType(u, UNIT_TYPE_MAGIC_IMMUNE)
endfunction
private struct Engage extends array
unit u
unit target
real interval
implement CTLExpire
if UnitAlive(.target) and UnitAlive(.u) then
set .interval = .interval + 0.03125
if .interval > 1.5 then
call IssueTargetOrder(.u, "attack", .target)
endif
else
call MakeUnitSelectable(.u)
set .u = null
set .target = null
call .destroy()
endif
implement CTLEnd
static method register takes unit caster, unit u returns nothing
local thistype this
local unit first
set TempUnit = u
set first = GetClosestUnitInRange(GetUnitX(u), GetUnitY(u), AOE, Filter(function UnitInRange))
if first==null then
call SE.summoned(caster, u)
else
set this = thistype.create()
set .u = u
set .target = first
set .interval = 0
set first = null
endif
endmethod
endstruct
private struct Cast extends array
unit caster
unit bottle
real xUnit
real yUnit
real xLoc
real yLoc
real damage
real distance
real distX
real angle
real summonedLife
real cos
real sin
integer summonedCount
integer level
player pl
implement CTL
local unit tempUnit
local integer count
local real ht
implement CTLExpire
if .distance > .distX then
set .distX = .distX + SPEED
call SetUnitX(.bottle, .xUnit+.distX * .cos)
call SetUnitY(.bottle, .yUnit+.distX * .sin)
set ht = (4 * HEIGHT / .distance) * (.distance - .distX) * (.distX / .distance)
call SetUnitFlyHeight(.bottle, ht, 0)
else
static if ENABLE_PASSIVE_SPELL then
if UnitAlive(.caster) then
set level = GetUnitAbilityLevel(.caster, PASSIVE_SPELL_ID)
if level > 0 and GetRandomInt(0, 100) < GetChance(.level) then
call GroupEnumUnitsInRange(G, .xLoc, .yLoc, AOE, null)
loop
set tempUnit = FirstOfGroup(G)
exitwhen tempUnit==null
if EnemyFilter(tempUnit) and IsUnitEnemy(tempUnit, .pl) then
call DestroyEffect(AddSpecialEffectTarget(SFX, tempUnit, "origin"))
call UnitDamageTarget(.bottle, tempUnit, GetDamage(level), false, false, ATK, DMG, null)
endif
call GroupRemoveUnit(G, tempUnit)
endloop
endif
endif
endif
call KillUnit(.bottle)
set count = 0
loop
exitwhen count==.summonedCount
set count = count + 1
set tempUnit = CreateUnit(.pl, SUMMONED_UNIT_ID, .xLoc, .yLoc, 0)
call Engage.register(.caster, tempUnit)
call UnitApplyTimedLife(tempUnit, 'BTLF', .summonedLife)
call MakeUnitUnSelectable(tempUnit, 0)
call SetUnitInvulnerable(tempUnit, true)
set tempUnit = null
endloop
set .caster = null
set .bottle = null
set .pl = null
call .destroy()
endif
implement CTLEnd
private static method cast takes nothing returns nothing
local thistype this = create()
local real dx
local real dy
set .caster = GetTriggerUnit()
set .level = GetUnitAbilityLevel(.caster, SPELL_ID)
set .xUnit = GetUnitX(.caster)
set .yUnit = GetUnitY(.caster)
set .xLoc = GetSpellTargetX()
set .yLoc = GetSpellTargetY()
set dx = .xLoc - .xUnit
set dy = .yLoc - .yUnit
set .distance = SquareRoot(dx * dx + dy * dy)
set .distX = 0
set .summonedCount = SummonedCount(.level)
set .summonedLife = SummonedTimer(.level)
set .angle = Atan2(.yLoc-.yUnit, .xLoc-.xUnit)
set .pl = GetTriggerPlayer()
set .bottle = CreateUnit(.pl, BOTTLE_ID , .xUnit, .yUnit, 0)
set .cos = Cos(.angle)
set .sin = Sin(.angle)
call SetUnitFlyHeight(.bottle, GetUnitFlyHeight(.caster)+100, 0)
if UnitAddAbility(.bottle, 'Arav') and UnitRemoveAbility(.bottle, 'Arav') then
endif
endmethod
private static method onInit takes nothing returns nothing
call RegisterSpellEffectEvent(SPELL_ID, function thistype.cast)
endmethod
endstruct
endscope
[/jass]
[/tab]
[tab=Twin Wolves]
[jass]
/*
Spell Name: Twin Wolves
Made by: mckill2009
REQUIRES:
- Jass New Gen Pack (JNGP) by Vexorian
- RegisterPlayerUnitEvent by Magtheridon96
- Table by Bribe
- SimError by Vexorian
- SummonedEscort by mckill2009
*/
scope TwinWolves
globals
private constant integer SPELL_ID = 'A002'
private constant integer WOLF_ID = 'n000'
private constant integer FOR_ALLY_SPELL_ID = 'A004' //rejuvenation
private constant integer FOR_ENEMY_SPELL_ID = 'A005' //chainlightning
private constant integer FOR_ALLY_OID = 852160 //this should match the FOR_ALLY_SPELL_ID
private constant integer FOR_ENEMY_OID = 852119 //this should match the FOR_ENEMY_SPELL_ID
private constant real AOE = 600.
private constant string SFX_APPEAR = "Abilities\\Spells\\Orc\\FeralSpirit\\feralspirittarget.mdl"
private constant real PERIOD = 1.0 //how fast the wolves will cast spells, affected by cooldowns
private constant real WOLF_LIFE = 60.
//===NON-CONFIGURABLE
private Table c
private unit FilterUnit
private unit TempUnit
endglobals
private function UnitAlive takes unit u returns boolean
return not IsUnitType(u, UNIT_TYPE_DEAD)
endfunction
private function UnitAllyInRange takes nothing returns boolean
set FilterUnit = GetFilterUnit()
return UnitAlive(FilterUnit) and not IsUnitEnemy(TempUnit, GetOwningPlayer(FilterUnit)) /*
*/ and not IsUnitType(FilterUnit, UNIT_TYPE_STRUCTURE) and not IsUnitType(FilterUnit, UNIT_TYPE_MECHANICAL) /*
*/ and not IsUnitType(FilterUnit, UNIT_TYPE_MAGIC_IMMUNE) and GetWidgetLife(FilterUnit) < GetUnitState(FilterUnit, UNIT_STATE_MAX_LIFE)
endfunction
private function UnitEnemyInRange takes nothing returns boolean
set FilterUnit = GetFilterUnit()
return UnitAlive(FilterUnit) and IsUnitEnemy(TempUnit, GetOwningPlayer(FilterUnit)) /*
*/ and not IsUnitType(FilterUnit, UNIT_TYPE_STRUCTURE) and not IsUnitType(FilterUnit, UNIT_TYPE_MECHANICAL) /*
*/ and not IsUnitType(FilterUnit, UNIT_TYPE_MAGIC_IMMUNE)
endfunction
struct TW
unit caster
unit healer
unit damager
real duration
private static integer index = 0
private static integer array indexAR
private static timer t = CreateTimer()
private static method periodic takes nothing returns nothing
local thistype this
local integer i = 0
local unit first
loop
set i = i+1
set this = indexAR[i]
if .duration > 0 and UnitAlive(.caster) then
set .duration = .duration - PERIOD
set TempUnit = .caster
if UnitAlive(.damager) then
set first = GetClosestUnitInRange(GetUnitX(.damager), GetUnitY(.damager), AOE, Filter(function UnitEnemyInRange))
if first!=null then
call IssueTargetOrderById(.damager, FOR_ENEMY_OID, first)
endif
endif
if UnitAlive(.healer) then
set first = GetClosestUnitInRange(GetUnitX(.healer), GetUnitY(.healer), AOE, Filter(function UnitAllyInRange))
if first!=null then
call IssueTargetOrderById(.healer, FOR_ALLY_OID, first)
endif
endif
else
call c.remove(GetHandleId(.caster))
call KillUnit(.damager)
call KillUnit(.healer)
set .caster = null
set .damager = null
set .healer = null
call .destroy()
set indexAR[i] = indexAR[index]
set indexAR[index] = this
set index = index - 1
set i = i-1
if index==0 then
call PauseTimer(t)
endif
endif
exitwhen i==index
endloop
set first = null
endmethod
private static method cast takes nothing returns nothing
local unit u
local integer level
local real facing
local real x
local real y
local thistype this
if GetSpellAbilityId()==SPELL_ID then
set u = GetTriggerUnit()
if c.has(GetHandleId(u)) then
call IssueImmediateOrder(u, "stop")
call SimError(GetTriggerPlayer(), "you cant use this spell yet")
else
set this = allocate()
set x = GetUnitX(u)
set y = GetUnitY(u)
set facing = GetUnitFacing(u)*0.017453333
set .caster = u
set level = GetUnitAbilityLevel(u, SPELL_ID)
//===Healer
set .healer = CreateUnit(GetTriggerPlayer(), WOLF_ID, x+150*Cos(facing+1.5708), y+150*Sin(facing+1.5708), GetUnitFacing(u))
call DestroyEffect(AddSpecialEffectTarget(SFX_APPEAR, .healer, "origin"))
call UnitAddAbility(.healer, FOR_ALLY_SPELL_ID)
call SetUnitAbilityLevel(.healer, FOR_ALLY_SPELL_ID, level)
call MakeUnitUnSelectable(.healer, 0)
call SE.summoned(.caster, .healer)
//===Damager
set .damager = CreateUnit(GetTriggerPlayer(), WOLF_ID, x+150*Cos(facing-1.5708), y+150*Sin(facing-1.5708), GetUnitFacing(u))
call DestroyEffect(AddSpecialEffectTarget(SFX_APPEAR, .damager, "origin"))
call UnitAddAbility(.damager, FOR_ENEMY_SPELL_ID)
call SetUnitAbilityLevel(.damager, FOR_ENEMY_SPELL_ID, level)
call MakeUnitUnSelectable(.damager, 0)
call SE.summoned(.caster, .damager)
set .duration = WOLF_LIFE
set c[GetHandleId(u)] = 0
if index==0 then
call TimerStart(t, PERIOD, true, function thistype.periodic)
endif
set index = index + 1
set indexAR[index] = this
endif
set u = null
endif
endmethod
private static method onInit takes nothing returns nothing
local unit u = CreateUnit(Player(15), WOLF_ID, 0,0,0)
call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_SPELL_CAST, function thistype.cast)
set c = Table.create()
//Preloading
call UnitAddAbility(u, FOR_ENEMY_SPELL_ID)
call UnitAddAbility(u, FOR_ALLY_SPELL_ID)
call ShowUnit(u, false)
call RemoveUnit(u)
set u = null
endmethod
endstruct
endscope
[/jass]
[/tab]
[tab=Enchanted Bottle]
[jass]
/*
Spell inside Locust Raid Spell
*/
[/jass]
[/tab]
[tab=Forbidden Wrath]
[jass]
/*
Spell Name: ForbiddenWrath
Made by: mckill2009
REQUIRES:
- Jass New Gen Pack (JNGP) by Vexorian
- SpellEffectEvent by Bribe
- Table by Bribe
*/
scope ForbiddenWrath
globals
private constant integer SPELL_ID = 'A003'
private constant integer MAX_AVATAR = 3
private constant real DURATION = 60.
private constant string SFX_RETAIN = "Abilities\\Spells\\Items\\TomeOfRetraining\\TomeOfRetrainingCaster.mdl"
private constant string SFX_APPEAR = "Abilities\\Spells\\Orc\\FeralSpirit\\feralspirittarget.mdl"
//===NON-CONFIGURABLES:
private integer array avatarID
private TableArray c
endglobals
private struct FW
unit u
real duration
integer check
private static integer array indexAR
private static integer index = 0
static method periodic takes nothing returns nothing
local thistype this
local integer i = 0
local integer count
local integer id
local unit avatar
loop
set i = i+1
set this = indexAR[i]
set .duration = .duration - 0.03125
set id = GetHandleId(.u)
set count = 0
loop
set avatar = c[count].unit[id]
if IsUnitType(avatar, UNIT_TYPE_DEAD) and c[1][GetHandleId(avatar)]==0 then
set .check = .check - 1
set c[1][GetHandleId(avatar)] = 1
endif
set count = count + 1
exitwhen count==MAX_AVATAR
endloop
if 0 > .duration or .check==0 then
set count = 0
loop
set avatar = c[count].unit[id]
if not IsUnitType(avatar, UNIT_TYPE_DEAD) then
call KillUnit(avatar)
endif
set count = count + 1
exitwhen count==MAX_AVATAR
endloop
call SetUnitPropWindow(.u, 1)
call UnitRemoveAbility(.u, 'Abun')
call UnitRemoveAbility(.u, 'Avul')
call SuspendHeroXP(.u, false)
call ShowUnit(.u, true)
call DestroyEffect(AddSpecialEffectTarget(SFX_RETAIN, .u, "origin"))
set .u = null
call .destroy()
set indexAR[i] = indexAR[index]
set indexAR[index] = this
set index = index - 1
set i = i-1
if index==0 then
call PauseTimer(GetExpiredTimer())
call DestroyTimer(GetExpiredTimer())
endif
endif
exitwhen i==index
endloop
set avatar = null
endmethod
static method cast takes nothing returns nothing
local thistype this = allocate()
local integer count = 0
local real angle = 0
local integer id
local real x
local real y
local unit avatar
set .u = GetTriggerUnit()
set .duration = DURATION
set x = GetUnitX(.u)
set y = GetUnitY(.u)
set id = GetHandleId(.u)
loop
set avatar = CreateUnit(GetTriggerPlayer(), avatarID[count], x+150*Cos(angle*0.01745333), y+150*Sin(angle*0.01745333), GetUnitFacing(.u))
set c[count].unit[id] = avatar
call DestroyEffect(AddSpecialEffectTarget(SFX_APPEAR, avatar, "origin"))
set c[1][GetHandleId(avatar)] = 0
set angle = angle + 40
set count = count + 1
set avatar = null
exitwhen count==MAX_AVATAR
endloop
set .check = MAX_AVATAR
call SetUnitPropWindow(.u, 0)
call UnitAddAbility(.u, 'Abun')
call UnitAddAbility(.u, 'Avul')
call SuspendHeroXP(.u, true)
call ShowUnit(.u, false)
if index==0 then
call TimerStart(CreateTimer(), 0.04, true, function thistype.periodic)
endif
set index = index + 1
set indexAR[index] = this
endmethod
static method onInit takes nothing returns nothing
call RegisterSpellEffectEvent(SPELL_ID, function thistype.cast)
set c = TableArray[0x200]
set avatarID[0] = 'nrwm' //red dragon
set avatarID[1] = 'nsll' //salamander lord
set avatarID[2] = 'ntrd' //dragon turtle
endmethod
endstruct
endscope
[/jass]
[/tab]
[/tabs]
[/tab]
[tab=System Used/Credits]
[url=http://www.hiveworkshop.com/forums/jass-resources-412/snippet-constant-timer-loop-32-a-201381/]CTL[/url] by Nesthaurus
[url=http://www.hiveworkshop.com/forums/jass-resources-412/snippet-new-table-188084/]Table[/url] by Bribe
[url=http://www.hiveworkshop.com/forums/jass-resources-412/snippet-registerplayerunitevent-203338/]RegisterPlayerunitEvent[/url] by Magtheridon96
[url=http://www.hiveworkshop.com/forums/jass-resources-412/snippet-getclosestwidget-204217/]GetClosestWidget[/url] by Spinnaker
[url=http://www.hiveworkshop.com/forums/spells-569/summonedescort-v1-4-a-221902/?prev=d%3Dlist%26r%3D20%26u%3Dmckill2009]SummonedEscort[/url] by mckill2009
[url=http://www.hiveworkshop.com/forums/submissions-414/unselectableunit-235882/]UnSelectableUnit[/url] by mckill2009
[url=http://www.wc3c.net/showthread.php?t=101260]SimError[/url] by Vexorian
Skin and Warden Icon by 67chrome
DISPASGreenBottle by Static
[/tab]
[tab=Bugs]
- None ATM
[/tab]
[tab=Changelogs]
v1.2
- Fixed bug that Twin Wolf dont cast chainlightning
- Changes applied
v1.1
- Passive ability and Locust Raid level fixed
- Most suggestion by Maker applied
[/tab]
[/tabs]
//TESH.scrollpos=34
//TESH.alwaysfold=0
library AI uses EngageSystemSimple
globals
private constant player AI_OWNER = Player(1) //player 2 GUI
private constant integer MAX_UNIT_ID = 5
private constant integer MAX_UNIT_GROUP = 3
private constant integer MAX_UNIT_CREATED = 4
private constant integer MAX_COORDINATE = 3
private real array X
private real array Y
private integer array unitID
private timer t = CreateTimer()
private group g = CreateGroup()
private integer count = 0
endglobals
struct AI
private static method grpLoop takes nothing returns nothing
local unit u = GetEnumUnit()
if not IsUnitType(u, UNIT_TYPE_DEAD) then
set count = count + 1
else
call GroupRemoveUnit(g, u)
endif
set u = null
endmethod
private static method run takes nothing returns nothing
local integer random
local integer i
local unit u
set count = 0
call ForGroup(g, function thistype.grpLoop)
if MAX_UNIT_CREATED > count then
set random = GetRandomInt(1,MAX_COORDINATE)
set i = 0
loop
set u = CreateUnit(AI_OWNER, unitID[GetRandomInt(1,MAX_UNIT_ID)], X[random], Y[random], 0)
call GroupAddUnit(g, u)
call SetEngageUnitSimple(u)
set u = null
set i = i + 1
exitwhen i==MAX_UNIT_GROUP
endloop
endif
endmethod
private static method onInit takes nothing returns nothing
set X[1] = -3150
set Y[1] = -2600
set X[2] = 2900
set Y[2] = 2700
set X[3] = 600
set Y[3] = -3431
set unitID[1] = 'ncea' //lvl 2
set unitID[2] = 'ncer' //lvl 2
set unitID[3] = 'ncim' //lvl 4
set unitID[4] = 'ncen' //lvl 4
set unitID[5] = 'ncks' //lvl 5
//set unitID[6] = 'ncnk' //lvl 8
call TimerStart(t, 2.0, true, function thistype.run)
endmethod
endstruct
endlibrary
//TESH.scrollpos=22
//TESH.alwaysfold=0
//System Name: EngageSystemSimple
//Made by: Mckill2009
//===FEATURES:
//- This system will order a unit to engage and search for enemies
//- Allows target random enemy units include creeps
//- Allows target refresh when duration runs out
//- Uses a global timer, which is not going to be destroyed but recycled
//===HOW TO USE:
//- Make a new trigger and convert to custom text via EDIT >>> CONVERT CUSTOM TEXT
//- Copy ALL that is written here (overwrite the existing texts in the trigger)
//===REQUIRES:
//- Jass New Gen Pack (JNGP) by Vexorian
library EngageSystemSimple initializer init
globals
private constant hashtable HASH = InitHashtable() //Do not touch this!
private constant real AOE_FAR_TARGET = 5000
private constant real AOE_NEAR_TARGET = 1000
private constant real AOE_TARGET_BUILDING = 8000
private constant real ATTACK_DURATION = 30.
private constant real ATTACK_INTERVAL = 3 //Recommended setting
private constant real ITEM_PICK_INTERVAL = 1 //Recommended setting
private constant integer ATTACK = 851983
private constant integer MOVE = 851986
private constant timer ENGAGE_TIMER = CreateTimer()
private constant group ENGAGE_GROUP = CreateGroup()
private integer GROUP_COUNTER_ENGAGE = 0
endglobals
private function UnitAlive takes unit u returns boolean
return not IsUnitType(u, UNIT_TYPE_DEAD)
endfunction
private struct Engage
unit hero
unit target
unit ally
real duration
private static thistype DATA
static method onLocateAlly takes nothing returns boolean
local thistype this = DATA
local unit u = GetFilterUnit()
local boolean b = UnitAlive(u) and IsUnitType(u, UNIT_TYPE_STRUCTURE) and not IsUnitEnemy(u, GetOwningPlayer(.hero)) and GetOwningPlayer(u)!=Player(PLAYER_NEUTRAL_PASSIVE)
set u = null
return b
endmethod
static method onRangeAttack takes nothing returns boolean
local thistype this = DATA
local unit u = GetFilterUnit()
local boolean b = UnitAlive(u) and IsUnitEnemy(u, GetOwningPlayer(.hero))
set u = null
return b
endmethod
static method onSearchAttack takes nothing returns boolean
local thistype this = DATA
local unit u = GetFilterUnit()
local integer randomizer = GetRandomInt(1,4)
local boolean b
if randomizer==1 or randomizer==2 then
//Non-Neutral Hostile
set b = UnitAlive(u) and IsUnitEnemy(u, GetOwningPlayer(.hero)) and GetOwningPlayer(u)!=Player(PLAYER_NEUTRAL_AGGRESSIVE)
elseif randomizer==3 then
//Buildings
set b = UnitAlive(u) and IsUnitType(u, UNIT_TYPE_STRUCTURE) and IsUnitEnemy(u, GetOwningPlayer(.hero))
elseif randomizer==4 then
//Creeps
set b = UnitAlive(u) and GetOwningPlayer(u)==Player(PLAYER_NEUTRAL_AGGRESSIVE)
endif
set u = null
return b
endmethod
static method onAttackNow takes nothing returns nothing
local unit u = GetEnumUnit()
local thistype this = LoadInteger(HASH, GetHandleId(u), 1)
local real x = GetUnitX(.hero)
local real y = GetUnitY(.hero)
local rect r
set DATA = this
if .duration > 0 and UnitAlive(.hero) then
set .duration = .duration - ATTACK_INTERVAL
if UnitAlive(.target) and .target != null then
call IssueTargetOrderById(.hero, ATTACK, .target)
call IssuePointOrderById(.hero, ATTACK, GetUnitX(.target), GetUnitY(.target))
else
set r = bj_mapInitialPlayableArea //Playable Map Area
call GroupEnumUnitsInRange(bj_lastCreatedGroup, x, y, AOE_NEAR_TARGET, Filter(function thistype.onSearchAttack))
set .target = FirstOfGroup(bj_lastCreatedGroup)
call IssueTargetOrderById(.hero, ATTACK, .target)
call IssuePointOrderById(.hero, ATTACK, GetUnitX(.target), GetUnitY(.target))
if .target==null then
call GroupEnumUnitsInRect(bj_lastCreatedGroup, r, Filter(function thistype.onSearchAttack))
set .target = FirstOfGroup(bj_lastCreatedGroup)
call IssueTargetOrderById(.hero, ATTACK, .target)
call IssuePointOrderById(.hero, ATTACK, GetUnitX(.target), GetUnitY(.target))
if .target==null then
call GroupEnumUnitsInRect(bj_lastCreatedGroup, r, Filter(function thistype.onLocateAlly))
set .ally = FirstOfGroup(bj_lastCreatedGroup)
call IssuePointOrderById(.hero, MOVE, GetUnitX(.ally), GetUnitY(.ally))
if .ally==null then
call IssueImmediateOrder(.hero, "stop")
endif
endif
endif
endif
else
//call BJDebugMsg(I2S(this))
if UnitAlive(.hero) then
call GroupEnumUnitsInRange(bj_lastCreatedGroup, x, y, AOE_FAR_TARGET, Filter(function thistype.onSearchAttack))
set .target = FirstOfGroup(bj_lastCreatedGroup)
set .duration = ATTACK_DURATION //this action resumes the timer without destroying it
else
call GroupRemoveUnit(ENGAGE_GROUP, .hero)
set GROUP_COUNTER_ENGAGE = GROUP_COUNTER_ENGAGE - 1
call .destroy(this)
endif
endif
set u = null
set r = null
endmethod
static method create takes unit u returns thistype
local thistype this = thistype.allocate()
local real x = GetUnitX(u)
local real y = GetUnitY(u)
set .hero = u
set .duration = ATTACK_DURATION
set DATA = this
call GroupEnumUnitsInRange(bj_lastCreatedGroup, x, y, AOE_FAR_TARGET, Filter(function thistype.onSearchAttack))
set .target = FirstOfGroup(bj_lastCreatedGroup)
call GroupAddUnit(ENGAGE_GROUP, u)
call SaveInteger(HASH, GetHandleId(u), 1, this)
set GROUP_COUNTER_ENGAGE = GROUP_COUNTER_ENGAGE + 1
return this
endmethod
endstruct
function SetEngageUnitSimple takes unit u returns nothing
call Engage.create(u)
endfunction
private function RunAttack takes nothing returns nothing
if GROUP_COUNTER_ENGAGE > 0 then
call ForGroup(ENGAGE_GROUP, function Engage.onAttackNow)
endif
endfunction
private function init takes nothing returns nothing
call TimerStart(ENGAGE_TIMER, ATTACK_INTERVAL, true, function RunAttack)
endfunction
endlibrary
//TESH.scrollpos=236
//TESH.alwaysfold=0
library CTL /* v1.2.0.1
*************************************************************************************
*
* CTL or Constant Timer Loop provides a loop for constant merged timers of timeout .03125
*
* Similar to T32 but pauses timer when no structs have instances and removes structs
* from timer trigger when those structs have no instances.
*
* This can also create new timers after destroying a previous timer and generates less
* code in the module. It also generates no triggers so long as the module is implemented
* at the top of the struct.
*
************************************************************************************
*
* module CTL
*
* Allows creation/destruction of timers in a struct. Provides instancing of those timers.
*
* - static method create takes nothing returns thistype
* - method destroy takes nothing returns nothing
*
* CTL (optional)
* local variables, code before running any timers
* CTLExpire (not optional)
* timer code
* CTLNull (optional)
* null any locals, runs after all timers
* CTLEnd (not optional)
*
* module CT32
*
* Converts struct into a timer group. Allows the timer group to be started and stopped.
* Instancing and looping through active timers is up to the user.
*
* - static method start takes nothing returns nothing
* - static method stop takes nothing returns nothing
*
* CT32 (not optional)
* timer code
* CT32End (not optional)
*
* struct TimerGroup32 extends array
*
* Allows for the creation of timer groups. Timer instancing and looping is entirely up
* to the user.
*
* - static method create takes code func returns thistype
* - method destroy takes nothing returns nothing
* - method start takes nothing returns nothing
* - method stop takes nothing returns nothing
*
************************************************************************************/
globals
private integer tgc = 0 //timer group count
private integer array tgr //timer group recycler
private integer ic=0 //instance count
private integer tc=0 //timer count
private integer array rf //root first
private integer array n //next
private integer array p //previous
private integer array th //timer head
private integer array ns //next stack
private trigger t=CreateTrigger()
private timer m=CreateTimer()
private triggercondition array ct
private conditionfunc array rc
private boolean array e32 //enabled
private integer array i32r //ct32 recycler
private integer i32cr = 0 //ct32 count recycler
private boolean array ir32 //is recycling
private boolean array id32 //is destroying
endglobals
private function E takes nothing returns nothing
local integer i=ns[0]
set ns[0]=0
loop
exitwhen 0==i
if (0==p[i]) then
if (0==n[i]) then
call TriggerRemoveCondition(t,ct[th[i]])
set ct[th[i]]=null
set tc=tc-1
set rf[th[i]]=0
else
set rf[th[i]]=n[i]
set p[n[i]]=0
endif
else
set p[n[i]]=p[i]
set n[p[i]]=n[i]
endif
set n[i]=n[0]
set n[0]=i
set i=ns[i]
endloop
loop
exitwhen 0 == i32cr
set i32cr = i32cr - 1
set i = i32r[i32cr]
if (not e32[i]) then
call TriggerRemoveCondition(t,ct[i])
set ct[i] = null
if (id32[i]) then
set tgr[i] = tgr[0]
set tgr[0] = i
set id32[i] = false
set e32[i] = false
set ir32[i] = false
endif
endif
endloop
if (0==tc) then
call PauseTimer(m)
else
call TriggerEvaluate(t)
endif
endfunction
private function CT takes integer r returns integer
local integer i
local integer f
if (0==n[0]) then
set i=ic+1
set ic=i
else
set i=n[0]
set n[0]=n[i]
endif
set th[i]=r
set ns[i]=-1
set f=rf[r]
if (0==f) then
set n[i]=0
set p[i]=0
set rf[r]=i
set ct[r]=TriggerAddCondition(t,rc[r])
//set ct[r] = null
if (0==tc) then
call TimerStart(m,.031250000,true,function E)
endif
set tc=tc+1
else
set n[i]=f
set p[i]=0
set p[f]=i
set rf[r]=i
endif
return i
endfunction
private function DT takes integer t returns nothing
debug if (0>ns[t]) then
set ns[t]=ns[0]
set ns[0]=t
debug else
debug call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,"TIMER LOOP ERROR: ATTEMPT TO DESTROY NULL TIMER")
debug endif
endfunction
private function A takes code c returns integer
local integer i = tgr[0]
if (0 == i) then
set i = tgc + 1
set tgc = i
else
set tgr[0] = tgr[i]
endif
set rc[i]=Condition(c)
return i
endfunction
private function A32 takes integer i returns nothing
if (not e32[i]) then
if (not ir32[i] and not id32[i]) then
set ct[i] = TriggerAddCondition(t, rc[i])
endif
if (0 == tc) then
call TimerStart(m,.031250000,true,function E)
endif
set tc = tc + 1
set e32[i] = true
endif
endfunction
private function SR32 takes integer i returns nothing
if (e32[i]) then
if (not ir32[i] and not id32[i]) then
set i32r[i32cr] = i
set i32cr = i32cr + 1
set ir32[i] = true
endif
set e32[i] = false
set tc = tc - 1
endif
endfunction
private function DT32 takes integer i returns nothing
if (not id32[i]) then
if (not ir32[i]) then
set ir32[i] = true
set tc = tc - 1
set i32r[i32cr] = i
set i32cr = i32cr + 1
set e32[i] = false
endif
set id32[i] = true
endif
endfunction
private keyword r
private keyword e
module CTL
static integer rctl32
static method create takes nothing returns thistype
return CT(rctl32)
endmethod
method destroy takes nothing returns nothing
call DT(this)
endmethod
static method ectl32 takes nothing returns boolean
local thistype this=rf[rctl32]
endmodule
module CTLExpire
implement CTL
loop
exitwhen 0==this
endmodule
module CTLNull
set this=n[this]
endloop
endmodule
module CTLEnd
implement CTLNull
return false
endmethod
private static method onInit takes nothing returns nothing
set rctl32 = A(function thistype.ectl32)
endmethod
endmodule
module CT32
static integer rctl32
static method ectl32 takes nothing returns boolean
endmodule
module CT32End
return false
endmethod
static method start takes nothing returns nothing
call A32(rctl32)
endmethod
static method stop takes nothing returns nothing
call SR32(rctl32)
endmethod
private static method onInit takes nothing returns nothing
set rctl32 = A(function thistype.ectl32)
endmethod
endmodule
struct TimerGroup32 extends array
static method create takes code c returns thistype
return A(c)
endmethod
method destroy takes nothing returns nothing
call DT32(this)
endmethod
method start takes nothing returns nothing
call A32(this)
endmethod
method stop takes nothing returns nothing
call SR32(this)
endmethod
endstruct
endlibrary
//TESH.scrollpos=30
//TESH.alwaysfold=0
//============================================================================
// SpellEffectEvent
// - Version 1.1.0.0
//
// API
// ---
// RegisterSpellEffectEvent(integer abil, code onCast)
//
// Requires
// --------
// RegisterPlayerUnitEvent: hiveworkshop.com/forums/showthread.php?t=203338
//
// Optional
// --------
// Table: hiveworkshop.com/forums/showthread.php?t=188084
//
library SpellEffectEvent requires RegisterPlayerUnitEvent, optional Table
//============================================================================
private module M
static if LIBRARY_Table then
static Table tb
else
static hashtable ht = InitHashtable()
endif
static method onCast takes nothing returns nothing
static if LIBRARY_Table then
call TriggerEvaluate(.tb.trigger[GetSpellAbilityId()])
else
call TriggerEvaluate(LoadTriggerHandle(.ht, 0, GetSpellAbilityId()))
endif
endmethod
private static method onInit takes nothing returns nothing
static if LIBRARY_Table then
set .tb = Table.create()
endif
call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_SPELL_EFFECT, function thistype.onCast)
endmethod
endmodule
//============================================================================
private struct S extends array
implement M
endstruct
//============================================================================
function RegisterSpellEffectEvent takes integer abil, code onCast returns nothing
static if LIBRARY_Table then
if not S.tb.handle.has(abil) then
set S.tb.trigger[abil] = CreateTrigger()
endif
call TriggerAddCondition(S.tb.trigger[abil], Filter(onCast))
else
if not HaveSavedHandle(S.ht, 0, abil) then
call SaveTriggerHandle(S.ht, 0, abil, CreateTrigger())
endif
call TriggerAddCondition(LoadTriggerHandle(S.ht, 0, abil), Filter(onCast))
endif
endfunction
endlibrary
//TESH.scrollpos=32
//TESH.alwaysfold=0
/**************************************************************
*
* RegisterPlayerUnitEvent
* v5.1.0.0
* By Magtheridon96
*
* I would like to give a special thanks to Bribe, azlier
* and BBQ for improving this library. For modularity, it only
* supports player unit events.
*
* Functions passed to RegisterPlayerUnitEvent must either
* return a boolean (false) or nothing. (Which is a Pro)
*
* Warning:
* --------
*
* - Don't use TriggerSleepAction inside registered code.
* - Don't destroy a trigger unless you really know what you're doing.
*
* API:
* ----
*
* - function RegisterPlayerUnitEvent takes playerunitevent whichEvent, code whichFunction returns nothing
* - Registers code that will execute when an event fires.
* - function RegisterPlayerUnitEventForPlayer takes playerunitevent whichEvent, code whichFunction, player whichPlayer returns nothing
* - Registers code that will execute when an event fires for a certain player.
* - function GetPlayerUnitEventTrigger takes playerunitevent whichEvent returns trigger
* - Returns the trigger corresponding to ALL functions of a playerunitevent.
*
**************************************************************/
library RegisterPlayerUnitEvent // Special Thanks to Bribe and azlier
globals
private trigger array t
endglobals
function RegisterPlayerUnitEvent takes playerunitevent p, code c returns nothing
local integer i = GetHandleId(p)
local integer k = 15
if t[i] == null then
set t[i] = CreateTrigger()
loop
call TriggerRegisterPlayerUnitEvent(t[i], Player(k), p, null)
exitwhen k == 0
set k = k - 1
endloop
endif
call TriggerAddCondition(t[i], Filter(c))
endfunction
function RegisterPlayerUnitEventForPlayer takes playerunitevent p, code c, player pl returns nothing
local integer i = 260 + 16 * GetHandleId(p) + GetPlayerId(pl)
if t[i] == null then
set t[i] = CreateTrigger()
call TriggerRegisterPlayerUnitEvent(t[i], pl, p, null)
endif
call TriggerAddCondition(t[i], Filter(c))
endfunction
function GetPlayerUnitEventTrigger takes playerunitevent p returns trigger
return t[GetHandleId(p)]
endfunction
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library Table /* made by Bribe, special thanks to Vexorian & Nestharus, version 3.1.0.1
One map, one hashtable. Welcome to NewTable 3.1
This library was originally called NewTable so it didn't conflict with
the API of Table by Vexorian. However, the damage is done and it's too
late to change the library name now. To help with damage control, I
have provided an extension library called TableBC, which bridges all
the functionality of Vexorian's Table except for 2-D string arrays &
the ".flush(integer)" method. I use ".flush()" to flush a child hash-
table, because I wanted the API in NewTable to reflect the API of real
hashtables (I thought this would be more intuitive).
API
------------
struct Table
| static method create takes nothing returns Table
| create a new Table
|
| method destroy takes nothing returns nothing
| destroy it
|
| method flush takes nothing returns nothing
| flush all stored values inside of it
|
| method remove takes integer key returns nothing
| remove the value at index "key"
|
| method operator []= takes integer key, $TYPE$ value returns nothing
| assign "value" to index "key"
|
| method operator [] takes integer key returns $TYPE$
| load the value at index "key"
|
| method has takes integer key returns boolean
| whether or not the key was assigned
|
----------------
struct TableArray
| static method operator [] takes integer array_size returns TableArray
| create a new array of Tables of size "array_size"
|
| method destroy takes nothing returns nothing
| destroy it
|
| method flush takes nothing returns nothing
| flush and destroy it
|
| method operator size takes nothing returns integer
| returns the size of the TableArray
|
| method operator [] takes integer key returns Table
| returns a Table accessible exclusively to index "key"
*/
globals
private integer less = 0 //Index generation for TableArrays (below 0).
private integer more = 8190 //Index generation for Tables.
//Configure it if you use more than 8190 "key" variables in your map (this will never happen though).
private hashtable ht = InitHashtable()
private key sizeK
private key listK
endglobals
private struct dex extends array
static method operator size takes nothing returns Table
return sizeK
endmethod
static method operator list takes nothing returns Table
return listK
endmethod
endstruct
private struct handles extends array
method has takes integer key returns boolean
return HaveSavedHandle(ht, this, key)
endmethod
method remove takes integer key returns nothing
call RemoveSavedHandle(ht, this, key)
endmethod
endstruct
private struct agents extends array
method operator []= takes integer key, agent value returns nothing
call SaveAgentHandle(ht, this, key, value)
endmethod
endstruct
//! textmacro NEW_ARRAY_BASIC takes SUPER, FUNC, TYPE
private struct $TYPE$s extends array
method operator [] takes integer key returns $TYPE$
return Load$FUNC$(ht, this, key)
endmethod
method operator []= takes integer key, $TYPE$ value returns nothing
call Save$FUNC$(ht, this, key, value)
endmethod
method has takes integer key returns boolean
return HaveSaved$SUPER$(ht, this, key)
endmethod
method remove takes integer key returns nothing
call RemoveSaved$SUPER$(ht, this, key)
endmethod
endstruct
private module $TYPE$m
method operator $TYPE$ takes nothing returns $TYPE$s
return this
endmethod
endmodule
//! endtextmacro
//! textmacro NEW_ARRAY takes FUNC, TYPE
private struct $TYPE$s extends array
method operator [] takes integer key returns $TYPE$
return Load$FUNC$Handle(ht, this, key)
endmethod
method operator []= takes integer key, $TYPE$ value returns nothing
call Save$FUNC$Handle(ht, this, key, value)
endmethod
endstruct
private module $TYPE$m
method operator $TYPE$ takes nothing returns $TYPE$s
return this
endmethod
endmodule
//! endtextmacro
//Run these textmacros to include the entire hashtable API as wrappers.
//Don't be intimidated by the number of macros - Vexorian's map optimizer is
//supposed to kill functions which inline (all of these functions inline).
//! runtextmacro NEW_ARRAY_BASIC("Real", "Real", "real")
//! runtextmacro NEW_ARRAY_BASIC("Boolean", "Boolean", "boolean")
//! runtextmacro NEW_ARRAY_BASIC("String", "Str", "string")
//! runtextmacro NEW_ARRAY("Player", "player")
//! runtextmacro NEW_ARRAY("Widget", "widget")
//! runtextmacro NEW_ARRAY("Destructable", "destructable")
//! runtextmacro NEW_ARRAY("Item", "item")
//! runtextmacro NEW_ARRAY("Unit", "unit")
//! runtextmacro NEW_ARRAY("Ability", "ability")
//! runtextmacro NEW_ARRAY("Timer", "timer")
//! runtextmacro NEW_ARRAY("Trigger", "trigger")
//! runtextmacro NEW_ARRAY("TriggerCondition", "triggercondition")
//! runtextmacro NEW_ARRAY("TriggerAction", "triggeraction")
//! runtextmacro NEW_ARRAY("TriggerEvent", "event")
//! runtextmacro NEW_ARRAY("Force", "force")
//! runtextmacro NEW_ARRAY("Group", "group")
//! runtextmacro NEW_ARRAY("Location", "location")
//! runtextmacro NEW_ARRAY("Rect", "rect")
//! runtextmacro NEW_ARRAY("BooleanExpr", "boolexpr")
//! runtextmacro NEW_ARRAY("Sound", "sound")
//! runtextmacro NEW_ARRAY("Effect", "effect")
//! runtextmacro NEW_ARRAY("UnitPool", "unitpool")
//! runtextmacro NEW_ARRAY("ItemPool", "itempool")
//! runtextmacro NEW_ARRAY("Quest", "quest")
//! runtextmacro NEW_ARRAY("QuestItem", "questitem")
//! runtextmacro NEW_ARRAY("DefeatCondition", "defeatcondition")
//! runtextmacro NEW_ARRAY("TimerDialog", "timerdialog")
//! runtextmacro NEW_ARRAY("Leaderboard", "leaderboard")
//! runtextmacro NEW_ARRAY("Multiboard", "multiboard")
//! runtextmacro NEW_ARRAY("MultiboardItem", "multiboarditem")
//! runtextmacro NEW_ARRAY("Trackable", "trackable")
//! runtextmacro NEW_ARRAY("Dialog", "dialog")
//! runtextmacro NEW_ARRAY("Button", "button")
//! runtextmacro NEW_ARRAY("TextTag", "texttag")
//! runtextmacro NEW_ARRAY("Lightning", "lightning")
//! runtextmacro NEW_ARRAY("Image", "image")
//! runtextmacro NEW_ARRAY("Ubersplat", "ubersplat")
//! runtextmacro NEW_ARRAY("Region", "region")
//! runtextmacro NEW_ARRAY("FogState", "fogstate")
//! runtextmacro NEW_ARRAY("FogModifier", "fogmodifier")
//! runtextmacro NEW_ARRAY("Hashtable", "hashtable")
struct Table extends array
// Implement modules for intuitive syntax (tb.handle; tb.unit; etc.)
implement realm
implement booleanm
implement stringm
implement playerm
implement widgetm
implement destructablem
implement itemm
implement unitm
implement abilitym
implement timerm
implement triggerm
implement triggerconditionm
implement triggeractionm
implement eventm
implement forcem
implement groupm
implement locationm
implement rectm
implement boolexprm
implement soundm
implement effectm
implement unitpoolm
implement itempoolm
implement questm
implement questitemm
implement defeatconditionm
implement timerdialogm
implement leaderboardm
implement multiboardm
implement multiboarditemm
implement trackablem
implement dialogm
implement buttonm
implement texttagm
implement lightningm
implement imagem
implement ubersplatm
implement regionm
implement fogstatem
implement fogmodifierm
implement hashtablem
method operator handle takes nothing returns handles
return this
endmethod
method operator agent takes nothing returns agents
return this
endmethod
//set this = tb[GetSpellAbilityId()]
method operator [] takes integer key returns Table
return LoadInteger(ht, this, key)
endmethod
//set tb[389034] = 8192
method operator []= takes integer key, Table tb returns nothing
call SaveInteger(ht, this, key, tb)
endmethod
//set b = tb.has(2493223)
method has takes integer key returns boolean
return HaveSavedInteger(ht, this, key)
endmethod
//call tb.remove(294080)
method remove takes integer key returns nothing
call RemoveSavedInteger(ht, this, key)
endmethod
//Remove all data from a Table instance
method flush takes nothing returns nothing
call FlushChildHashtable(ht, this)
endmethod
//local Table tb = Table.create()
static method create takes nothing returns Table
local Table this = dex.list[0]
if this == 0 then
set this = more + 1
set more = this
else
set dex.list[0] = dex.list[this]
call dex.list.remove(this) //Clear hashed memory
endif
debug set dex.list[this] = -1
return this
endmethod
// Removes all data from a Table instance and recycles its index.
//
// call tb.destroy()
//
method destroy takes nothing returns nothing
debug if dex.list[this] != -1 then
debug call BJDebugMsg("Table Error: Tried to double-free instance: " + I2S(this))
debug return
debug endif
call this.flush()
set dex.list[this] = dex.list[0]
set dex.list[0] = this
endmethod
//! runtextmacro optional TABLE_BC_METHODS()
endstruct
//! runtextmacro optional TABLE_BC_STRUCTS()
struct TableArray extends array
//Returns a new TableArray to do your bidding. Simply use:
//
// local TableArray ta = TableArray[array_size]
//
static method operator [] takes integer array_size returns TableArray
local Table tb = dex.size[array_size] //Get the unique recycle list for this array size
local TableArray this = tb[0] //The last-destroyed TableArray that had this array size
debug if array_size <= 0 then
debug call BJDebugMsg("TypeError: Invalid specified TableArray size: " + I2S(array_size))
debug return 0
debug endif
if this == 0 then
set this = less - array_size
set less = this
else
set tb[0] = tb[this] //Set the last destroyed to the last-last destroyed
call tb.remove(this) //Clear hashed memory
endif
set dex.size[this] = array_size //This remembers the array size
return this
endmethod
//Returns the size of the TableArray
method operator size takes nothing returns integer
return dex.size[this]
endmethod
//This magic method enables two-dimensional[array][syntax] for Tables,
//similar to the two-dimensional utility provided by hashtables them-
//selves.
//
//ta[integer a].unit[integer b] = unit u
//ta[integer a][integer c] = integer d
//
//Inline-friendly when not running in debug mode
//
method operator [] takes integer key returns Table
static if DEBUG_MODE then
local integer i = this.size
if i == 0 then
call BJDebugMsg("IndexError: Tried to get key from invalid TableArray instance: " + I2S(this))
return 0
elseif key < 0 or key >= i then
call BJDebugMsg("IndexError: Tried to get key [" + I2S(key) + "] from outside TableArray bounds: " + I2S(i))
return 0
endif
endif
return this + key
endmethod
//Destroys a TableArray without flushing it; I assume you call .flush()
//if you want it flushed too. This is a public method so that you don't
//have to loop through all TableArray indices to flush them if you don't
//need to (ie. if you were flushing all child-keys as you used them).
//
method destroy takes nothing returns nothing
local Table tb = dex.size[this.size]
debug if this.size == 0 then
debug call BJDebugMsg("TypeError: Tried to destroy an invalid TableArray: " + I2S(this))
debug return
debug endif
if tb == 0 then
//Create a Table to index recycled instances with their array size
set tb = Table.create()
set dex.size[this.size] = tb
endif
call dex.size.remove(this) //Clear the array size from hash memory
set tb[this] = tb[0]
set tb[0] = this
endmethod
private static Table tempTable
private static integer tempEnd
//Avoids hitting the op limit
private static method clean takes nothing returns nothing
local Table tb = .tempTable
local integer end = tb + 0x1000
if end < .tempEnd then
set .tempTable = end
call ForForce(bj_FORCE_PLAYER[0], function thistype.clean)
else
set end = .tempEnd
endif
loop
call tb.flush()
set tb = tb + 1
exitwhen tb == end
endloop
endmethod
//Flushes the TableArray and also destroys it. Doesn't get any more
//similar to the FlushParentHashtable native than this.
//
method flush takes nothing returns nothing
debug if this.size == 0 then
debug call BJDebugMsg("TypeError: Tried to flush an invalid TableArray instance: " + I2S(this))
debug return
debug endif
set .tempTable = this
set .tempEnd = this + this.size
call ForForce(bj_FORCE_PLAYER[0], function thistype.clean)
call this.destroy()
endmethod
endstruct
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
/*****************************************************************************
*
* Get Closest Widget
* by Spinnaker v2.0.0.0
*
* Special thanks to Troll-Brain
*
******************************************************************************
*
* This snippet contains several functions which returns closest
* widget to given coordinates and passed filter.
*
******************************************************************************
*
* Requirements:
* Snippet optionaly requires IsDestructableTree,
* enabling user to choose if enumerated should be all destructables
* or only tree-type ones, therefore gives option to get closest tree.
*
******************************************************************************
*
* Important:
* Performance drop depends on amount of objects currently on the map
* Snippet functions are designed to reduce the search time as much as
* posible, although it's recommended to use non specific functions
* wisely, especialy if your map contains large numbers of widgets.
*
******************************************************************************
*
* Functions:
* function GetClosestItem takes real x, real y, boolexpr filter returns item
* - Gets single item, nearest passed coordinates
* function GetClosestItemInRange takes real x, real y, real radius, boolexpr filter returns item
* - Returns single item, closest to coordinates in given range
*
* function GetClosestDestructable takes real x, real y, boolean treeOnly, boolexpr filter returns destructable
* - Gets single destructable, nearest passed coordinates
* function GetClosestDestructableInRange takes real x, real y, real radius, boolean treeOnly, boolexpr filter returns destructable
* - Retrieves single destructable, closest to coordinates in given range
*
* function GetClosestUnit takes real x, real y, boolexpr filter returns unit
* - Returns closest unit matching specific filter
* function GetClosestUnitInRange takes real x, real y, real radius, boolexpr filter returns unit
* - Gets nearest unit in range matching specific filter
* function GetClosestUnitInGroup takes real x, real y, group g returns unit
* - Retrieves closest unit in given group
*
* function GetClosestNUnitsInRange takes real x, real y, real radius, integer n, group g, boolexpr filter returns nothing
* - Returns up to N nearest units in range of passed coordinates
* function GetClosestNUnitsInGroup takes real x, real y, integer n, group sourceGroup, group destGroup returns nothing
* - Retrieves up to N closest units in passed group
*
*****************************************************************************/
library GetClosestWidget uses optional IsDestructableTree
private keyword Init
globals
private unit array Q
private real array V
private integer C=0
endglobals
struct ClosestWidget extends array
readonly static destructable cDest=null
readonly static item cItem=null
readonly static real distance=0
readonly static real cX=0
readonly static real cY=0
readonly static unit cUnit=null
static boolean cTree=false
static rect initRect=null
static method resetData takes real x, real y returns nothing
set cDest=null
set distance=100000
set cItem=null
set cUnit=null
set cX=x
set cY=y
endmethod
static method enumItems takes nothing returns nothing
local item i=GetEnumItem()
local real dx=GetWidgetX(i)-cX
local real dy=GetWidgetY(i)-cY
set dx = (dx*dx+dy*dy)/10000.
if dx<distance then
set cItem=i
set distance=dx
endif
set i =null
endmethod
static method enumDestructables takes nothing returns nothing
local destructable d=GetEnumDestructable()
local real dx
local real dy
static if LIBRARY_IsDestructableTree then
if cTree and not IsDestructableTree(d) then
return
endif
endif
set dx=GetWidgetX(d)-cX
set dy=GetWidgetY(d)-cY
set dx=(dx*dx+dy*dy)/10000.
if dx<distance then
set cDest=d
set distance=dx
endif
set d=null
endmethod
static method enumUnits takes nothing returns nothing
local unit u=GetEnumUnit()
local real dx=GetUnitX(u)-cX
local real dy=GetUnitY(u)-cY
set dx=(dx*dx+dy*dy)/10000.
if dx<distance then
set cUnit=u
set distance=dx
endif
set u=null
endmethod
static method sortUnits takes integer l, integer r returns nothing
local integer i=l
local integer j=r
local real v=V[(l+r)/2]
loop
loop
exitwhen V[i]>=v
set i=i+1
endloop
loop
exitwhen V[j]<=v
set j=j-1
endloop
if i<=j then
set V[0]=V[i]
set V[i]=V[j]
set V[j]=V[0]
set Q[0]=Q[i]
set Q[i]=Q[j]
set Q[j]=Q[0]
set i=i+1
set j=j-1
endif
exitwhen i>j
endloop
if l<j then
call sortUnits(l,j)
endif
if r>i then
call sortUnits(i,r)
endif
endmethod
static method saveGroup takes nothing returns nothing
local real dx
local real dy
set C=C+1
set Q[C]=GetEnumUnit()
set dx=GetUnitX(Q[C])-cX
set dy=GetUnitY(Q[C])-cY
set V[C]=(dx*dx+dy*dy)/10000.
endmethod
implement Init
endstruct
private module Init
private static method onInit takes nothing returns nothing
set thistype.initRect=Rect(0,0,0,0)
endmethod
endmodule
function GetClosestItem takes real x, real y, boolexpr filter returns item
local real r=800.
call ClosestWidget.resetData(x,y)
loop
if r>3200. then
call EnumItemsInRect(bj_mapInitialPlayableArea, filter, function ClosestWidget.enumItems)
exitwhen true
else
call SetRect(ClosestWidget.initRect,x-r,y-r,x+r,y+r)
call EnumItemsInRect(ClosestWidget.initRect, filter, function ClosestWidget.enumItems)
exitwhen ClosestWidget.cItem!=null
endif
set r=2*r
endloop
return ClosestWidget.cItem
endfunction
function GetClosestItemInRange takes real x, real y, real radius, boolexpr filter returns item
call ClosestWidget.resetData(x,y)
if radius>=0 then
call SetRect(ClosestWidget.initRect,x-radius,y-radius,x+radius,y+radius)
call EnumItemsInRect(ClosestWidget.initRect, filter, function ClosestWidget.enumItems)
endif
return ClosestWidget.cItem
endfunction
function GetClosestDestructable takes real x, real y, boolean treeOnly, boolexpr filter returns destructable
local real r=800.
call ClosestWidget.resetData(x,y)
set ClosestWidget.cTree=treeOnly
loop
if r>3200. then
call EnumDestructablesInRect(bj_mapInitialPlayableArea, filter, function ClosestWidget.enumDestructables)
exitwhen true
else
call SetRect(ClosestWidget.initRect,x-r,y-r,x+r,y+r)
call EnumDestructablesInRect(ClosestWidget.initRect, filter, function ClosestWidget.enumDestructables)
exitwhen ClosestWidget.cDest!=null
endif
set r=2*r
endloop
return ClosestWidget.cDest
endfunction
function GetClosestDestructableInRange takes real x, real y, real radius, boolean treeOnly, boolexpr filter returns destructable
call ClosestWidget.resetData(x,y)
if radius>=0 then
set ClosestWidget.cTree=treeOnly
call SetRect(ClosestWidget.initRect,x-radius,y-radius,x+radius,y+radius)
call EnumDestructablesInRect(ClosestWidget.initRect, filter, function ClosestWidget.enumDestructables)
endif
return ClosestWidget.cDest
endfunction
function GetClosestUnit takes real x, real y, boolexpr filter returns unit
local real r=800.
call ClosestWidget.resetData(x,y)
loop
if r>3200. then
call GroupEnumUnitsInRect(bj_lastCreatedGroup, bj_mapInitialPlayableArea, filter)
exitwhen true
else
call GroupEnumUnitsInRange(bj_lastCreatedGroup, x, y, r, filter)
exitwhen FirstOfGroup(bj_lastCreatedGroup)!=null
endif
set r=2*r
endloop
call ForGroup(bj_lastCreatedGroup, function ClosestWidget.enumUnits)
return ClosestWidget.cUnit
endfunction
function GetClosestUnitInRange takes real x, real y, real radius, boolexpr filter returns unit
call ClosestWidget.resetData(x,y)
if radius>=0 then
call GroupEnumUnitsInRange(bj_lastCreatedGroup, x, y, radius, filter)
call ForGroup(bj_lastCreatedGroup, function ClosestWidget.enumUnits)
endif
return ClosestWidget.cUnit
endfunction
function GetClosestUnitInGroup takes real x, real y, group g returns unit
call ClosestWidget.resetData(x,y)
call ForGroup(g, function ClosestWidget.enumUnits)
return ClosestWidget.cUnit
endfunction
function GetClosestNUnitsInRange takes real x, real y, real radius, integer n, group g, boolexpr filter returns nothing
local integer q=n+1
call ClosestWidget.resetData(x,y)
if radius>=0 then
call GroupEnumUnitsInRange(bj_lastCreatedGroup, x, y, radius, filter)
call ForGroup(bj_lastCreatedGroup, function ClosestWidget.saveGroup)
call ClosestWidget.sortUnits(1,C)
loop
exitwhen n==0 or Q[-n+q]==null
call GroupAddUnit(g, Q[-n+q])
set n =n-1
endloop
endif
set C=0
endfunction
function GetClosestNUnitsInGroup takes real x, real y, integer n, group sourceGroup, group destGroup returns nothing
local integer q=n+1
call ClosestWidget.resetData(x,y)
call ForGroup(sourceGroup, function ClosestWidget.saveGroup)
call ClosestWidget.sortUnits(1,C)
loop
exitwhen n==0 or Q[-n+q]==null
call GroupAddUnit(destGroup, Q[-n+q])
set n=n-1
endloop
set C=0
endfunction
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library SimError initializer init
//**************************************************************************************************
//*
//* SimError by Vexorian
//*
//* Mimic an interface error message
//* call SimError(ForPlayer, msg)
//* ForPlayer : The player to show the error
//* msg : The error
//*
//* To implement this function, copy this trigger and paste it in your map.
//* Unless of course you are actually reading the library from wc3c's scripts section, then just
//* paste the contents into some custom text trigger in your map.
//*
//**************************************************************************************************
//==================================================================================================
globals
private sound error
endglobals
//====================================================================================================
function SimError takes player ForPlayer, string msg returns nothing
set msg="\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n|cffffcc00"+msg+"|r"
if (GetLocalPlayer() == ForPlayer) then
call ClearTextMessages()
call DisplayTimedTextToPlayer( ForPlayer, 0.52, 0.96, 2.00, msg )
call StartSound( error )
endif
endfunction
private function init takes nothing returns nothing
set error=CreateSoundFromLabel("InterfaceError",false,false,false,10,10)
//call StartSound( error ) //apparently the bug in which you play a sound for the first time
//and it doesn't work is not there anymore in patch 1.22
endfunction
endlibrary
//TESH.scrollpos=115
//TESH.alwaysfold=0
/*
===SummonedEscort v1.4
===By Mckill2009
Allows your summoned units to follow and guards the summoner, if summoner dies, the summoned unit
searches for a new master or returns to it's original location.
INSTALLATION:
Copy and paste the trigger "SummonedEscort" and "GetClosestWidget" to your map and do:
call SE.summoned(GetSummoningUnit(),GetTriggerUnit())
If AUTO is true, then it will do automatically for you.
API:
static method summoned takes unit summoningUnit, unit summonedUnit returns nothing
CREDITS:
- GetClosestWidget by Spinnaker [http://www.hiveworkshop.com/forums/jass-resources-412/snippet-getclosestwidget-204217/]
*/
library SummonedEscort uses GetClosestWidget
globals
//===CONFIGURABLES:
private constant boolean AUTO = true //auto registers ALL summoned units in map
private constant boolean ALLY_IN_RANGE = true //searches for ally hero if main hero is dead
private constant boolean FOLLOW_ONLY_HEROES = true
private constant real OFFSET = 200
private constant real CLOSEST_ALLY = 600 //ALLY_IN_RANGE must be true
private constant real CLOSEST_ENEMY = 400 //targets closest enemy in range of master
endglobals
struct SE
private unit master
private unit sum
private real xUnit
private real yUnit
private static integer DATA
private static constant integer ATTACK = 851983
private static timer t = CreateTimer()
private static integer instance = 0
private static integer array insAR
private static unit TempUnit = null
private static method UnitAlive takes unit u returns boolean
return not IsUnitType(u,UNIT_TYPE_DEAD) and u!=null
endmethod
private static method closestEnemy takes nothing returns boolean
local thistype this = DATA
set TempUnit = GetFilterUnit()
return UnitAlive(TempUnit) and IsUnitEnemy(TempUnit, GetOwningPlayer(.sum))
endmethod
private static method closestAlly takes nothing returns boolean
local thistype this = DATA
set TempUnit = GetFilterUnit()
if UnitAlive(TempUnit) and GetOwningPlayer(TempUnit)==GetOwningPlayer(.sum) and TempUnit!=.sum /*
*/ and not IsUnitType(TempUnit,UNIT_TYPE_STRUCTURE) and GetUnitMoveSpeed(TempUnit)>0 then
static if FOLLOW_ONLY_HEROES then
return IsUnitType(TempUnit, UNIT_TYPE_HERO)
endif
return true
endif
return false
endmethod
private method destroy takes nothing returns nothing
set .master = null
set .sum = null
call .deallocate()
endmethod
private static method looper takes nothing returns nothing
local thistype this
local unit target
local integer orderSum
local integer index = 0
local real angle
local real xMaster
local real yMaster
local real xSummoned
local real ySummoned
loop
set index = index+1
set this = insAR[index]
if UnitAlive(.sum) then
set angle = GetRandomReal(0,6.28)
set orderSum = GetUnitCurrentOrder(.sum)
if UnitAlive(.master) then
if orderSum==0 then
set xMaster = GetUnitX(.master)+OFFSET*Cos(angle)
set yMaster = GetUnitY(.master)+OFFSET*Sin(angle)
call IssuePointOrderById(.sum,ATTACK,xMaster,yMaster)
set DATA = this
set target = GetClosestUnitInRange(xMaster,yMaster,CLOSEST_ENEMY,Filter(function thistype.closestEnemy))
if target!=null then
if IsUnitType(target,UNIT_TYPE_SLEEPING) then
call IssueTargetOrderById(.sum,ATTACK,target)
else
call IssuePointOrderById(.sum,ATTACK,GetUnitX(target),GetUnitY(target))
endif
set target = null
endif
endif
else
set DATA = this
set xSummoned = GetUnitX(.sum)
set ySummoned = GetUnitY(.sum)
static if ALLY_IN_RANGE then
set .master = GetClosestUnitInRange(xSummoned,ySummoned,CLOSEST_ALLY,Filter(function thistype.closestAlly))
else
set .master = GetClosestUnit(xSummoned,ySummoned,Filter(function thistype.closestAlly))
endif
if .master==null and orderSum==0 then
call IssuePointOrderById(.sum,ATTACK,.xUnit+OFFSET*Cos(angle),.yUnit+OFFSET*Sin(angle))
endif
endif
else
call .destroy()
set insAR[index] = insAR[instance]
set insAR[instance] = this
set index = index - 1
set instance = instance - 1
if instance==0 then
call PauseTimer(t)
endif
endif
exitwhen index==instance
endloop
endmethod
private static method create takes unit summoningUnit, unit summonedUnit returns thistype
local thistype this
if instance==8190 then
call BJDebugMsg("summoned ERROR: Too many instances!")
else
set this = allocate()
set .master = summoningUnit
set .sum = summonedUnit
set .xUnit = GetUnitX(summonedUnit)
set .yUnit = GetUnitY(summonedUnit)
if instance==0 then
call TimerStart(t,1.0,true,function thistype.looper)
endif
set instance = instance + 1
set insAR[instance] = this
call RemoveGuardPosition(summonedUnit)
endif
return this
endmethod
private static method fire takes nothing returns boolean
call thistype.create(GetSummoningUnit(),GetTriggerUnit())
return false
endmethod
private static method onInit takes nothing returns nothing
static if AUTO then
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SUMMON)
call TriggerAddCondition(t,function thistype.fire)
set t = null
endif
endmethod
//API:======================================
static method summoned takes unit summoningUnit, unit summonedUnit returns nothing
call thistype.create(summoningUnit,summonedUnit)
endmethod
endstruct
endlibrary
//TESH.scrollpos=45
//TESH.alwaysfold=0
/*
===UnSelectableUnit v1.3
===by mckill2009
Simple to understand, makes any unit unselectable...
REQUIRES:
- JassNewGenPack by vexorian
API:
function MakeUnitSelectable takes unit u returns nothing
function MakeUnitUnSelectable takes unit u, real duration returns nothing
- put 0 for to the duration for permanent
KNOWN ISSUES:
- Unit can still be attacked, ordered and castable by spells
*/
library UnSelectableUnit
globals
private hashtable ht = InitHashtable()
endglobals
private struct US
unit u
boolean permanent
private static integer index = 0
private static integer array indexAR
private static timer t = CreateTimer()
private static method periodic takes nothing returns nothing
local thistype this
local integer i = 0
local integer id
loop
set i = i+1
set this = indexAR[i]
set id = GetHandleId(.u)
if LoadInteger(ht, id, 1)==2 or IsUnitType(.u, UNIT_TYPE_DEAD) then //reset
call FlushChildHashtable(ht, id)
set .u = null
call .destroy()
set indexAR[i] = indexAR[index]
set indexAR[index] = this
set index = index - 1
set i = i-1
if index==0 then
call PauseTimer(t)
endif
elseif LoadInteger(ht, id, 1)==1 then //permanent
call SelectUnit(.u, false)
else
if LoadReal(ht, id, 2) > 0 and not IsUnitType(.u, UNIT_TYPE_DEAD) then
call SaveReal(ht, id, 2, LoadReal(ht, id, 2)-0.03125)
call SelectUnit(.u, false)
else
call SaveInteger(ht, id, 1, 2)
endif
endif
exitwhen i==index
endloop
endmethod
static method startTimer takes unit u, real d, integer id returns nothing
local thistype this
if LoadBoolean(ht, id, 0) then
if d==0 then
debug call DisplayTimedTextToPlayer(GetOwningPlayer(u), 0, 0, 10, "[UnSelectableUnit][MakeUnitUnSelectable] ERROR: Zero duration is not possible!")
else
call SaveReal(ht, id, 2, LoadReal(ht, id, 2)+d)
endif
else
set this = allocate()
set .u = u
if d==0 then
call SaveInteger(ht, id, 1, 1) //making permanent
endif
call SaveReal(ht, id, 2, d)
call SaveBoolean(ht, id, 0, true)
if index==0 then
call TimerStart(t, 0.03125, true, function thistype.periodic)
endif
set index = index + 1
set indexAR[index] = this
endif
endmethod
endstruct
//API:
function MakeUnitSelectable takes unit u returns nothing
call SaveInteger(ht, GetHandleId(u), 1, 2) //resetting
endfunction
function MakeUnitUnSelectable takes unit u, real duration returns nothing
call US.startTimer(u, duration, GetHandleId(u))
endfunction
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
/*
Spell Name: Locust Raid
Made by: mckill2009
REQUIRES:
- Jass New Gen Pack (JNGP) by Vexorian
- CTL by Nesthaurus
- SpellEffectEvent by Bribe
- SummonedEscort by mckill2009
*/
scope LocustRaid
globals
private constant integer SPELL_ID = 'A000' //The Main spell
private constant integer BOTTLE_ID = 'h001'
private constant integer SUMMONED_UNIT_ID = 'h003'
private constant real AOE = 300 //enemy filter for passive and active
private constant real HEIGHT = 300 //bottle height
private constant real SPEED = 10 //bottle speed
//===USED ONLY BY PASSIVE SPELL
private constant integer PASSIVE_SPELL_ID = 'A001' //Passive spell, optional
private constant boolean ENABLE_PASSIVE_SPELL = true
private constant attacktype ATK = ATTACK_TYPE_MAGIC //used only by passive
private constant damagetype DMG = DAMAGE_TYPE_POISON //used only by passive
private constant string SFX = "Abilities\\Weapons\\PhoenixMissile\\Phoenix_Missile.mdl" //used only by passive
//===NON-CONFIGURABLE
private unit TempUnit
private group G = CreateGroup()
endglobals
private function GetChance takes integer level returns integer
return 5 * level + 5 //used by passive only
endfunction
private function GetDamage takes integer level returns real
return 30. * level + 60 //used by passive only
endfunction
private function SummonedCount takes integer level returns integer
return level * 2
endfunction
private function SummonedTimer takes integer level returns real
return level * 10.
endfunction
private function UnitAlive takes unit u returns boolean
return not IsUnitType(u, UNIT_TYPE_DEAD)
endfunction
private function UnitInRange takes nothing returns boolean
return UnitAlive(GetFilterUnit()) and IsUnitEnemy(TempUnit, GetOwningPlayer(GetFilterUnit()))
endfunction
private function EnemyFilter takes unit u returns boolean
return UnitAlive(u) and not IsUnitType(u, UNIT_TYPE_FLYING) and not IsUnitType(u, UNIT_TYPE_STRUCTURE) /*
*/ and not IsUnitType(u, UNIT_TYPE_MECHANICAL) and not IsUnitType(u, UNIT_TYPE_MAGIC_IMMUNE)
endfunction
private struct Engage extends array
unit u
unit target
real interval
implement CTLExpire
if UnitAlive(.target) and UnitAlive(.u) then
set .interval = .interval + 0.03125
if .interval > 1.5 then
call IssueTargetOrder(.u, "attack", .target)
endif
else
call MakeUnitSelectable(.u)
set .u = null
set .target = null
call .destroy()
endif
implement CTLEnd
static method register takes unit caster, unit u returns nothing
local thistype this
local unit first
set TempUnit = u
set first = GetClosestUnitInRange(GetUnitX(u), GetUnitY(u), AOE, Filter(function UnitInRange))
if first==null then
call SE.summoned(caster, u)
else
set this = thistype.create()
set .u = u
set .target = first
set .interval = 0
set first = null
endif
endmethod
endstruct
private struct Cast extends array
unit caster
unit bottle
real xUnit
real yUnit
real xLoc
real yLoc
real damage
real distance
real distX
real angle
real summonedLife
real cos
real sin
integer summonedCount
integer level
player pl
implement CTL
local unit tempUnit
local integer count
local real ht
implement CTLExpire
if .distance > .distX then
set .distX = .distX + SPEED
call SetUnitX(.bottle, .xUnit+.distX * .cos)
call SetUnitY(.bottle, .yUnit+.distX * .sin)
set ht = (4 * HEIGHT / .distance) * (.distance - .distX) * (.distX / .distance)
call SetUnitFlyHeight(.bottle, ht, 0)
else
static if ENABLE_PASSIVE_SPELL then
if UnitAlive(.caster) then
set level = GetUnitAbilityLevel(.caster, PASSIVE_SPELL_ID)
if level > 0 and GetRandomInt(0, 100) < GetChance(.level) then
call GroupEnumUnitsInRange(G, .xLoc, .yLoc, AOE, null)
loop
set tempUnit = FirstOfGroup(G)
exitwhen tempUnit==null
if EnemyFilter(tempUnit) and IsUnitEnemy(tempUnit, .pl) then
call DestroyEffect(AddSpecialEffectTarget(SFX, tempUnit, "origin"))
call UnitDamageTarget(.bottle, tempUnit, GetDamage(level), false, false, ATK, DMG, null)
endif
call GroupRemoveUnit(G, tempUnit)
endloop
endif
endif
endif
call KillUnit(.bottle)
set count = 0
loop
exitwhen count==.summonedCount
set count = count + 1
set tempUnit = CreateUnit(.pl, SUMMONED_UNIT_ID, .xLoc, .yLoc, 0)
call Engage.register(.caster, tempUnit)
call UnitApplyTimedLife(tempUnit, 'BTLF', .summonedLife)
call MakeUnitUnSelectable(tempUnit, 0)
call SetUnitInvulnerable(tempUnit, true)
set tempUnit = null
endloop
set .caster = null
set .bottle = null
set .pl = null
call .destroy()
endif
implement CTLEnd
private static method cast takes nothing returns nothing
local thistype this = create()
local real dx
local real dy
set .caster = GetTriggerUnit()
set .level = GetUnitAbilityLevel(.caster, SPELL_ID)
set .xUnit = GetUnitX(.caster)
set .yUnit = GetUnitY(.caster)
set .xLoc = GetSpellTargetX()
set .yLoc = GetSpellTargetY()
set dx = .xLoc - .xUnit
set dy = .yLoc - .yUnit
set .distance = SquareRoot(dx * dx + dy * dy)
set .distX = 0
set .summonedCount = SummonedCount(.level)
set .summonedLife = SummonedTimer(.level)
set .angle = Atan2(.yLoc-.yUnit, .xLoc-.xUnit)
set .pl = GetTriggerPlayer()
set .bottle = CreateUnit(.pl, BOTTLE_ID , .xUnit, .yUnit, 0)
set .cos = Cos(.angle)
set .sin = Sin(.angle)
call SetUnitFlyHeight(.bottle, GetUnitFlyHeight(.caster)+100, 0)
if UnitAddAbility(.bottle, 'Arav') and UnitRemoveAbility(.bottle, 'Arav') then
endif
endmethod
private static method onInit takes nothing returns nothing
call RegisterSpellEffectEvent(SPELL_ID, function thistype.cast)
endmethod
endstruct
endscope
//TESH.scrollpos=122
//TESH.alwaysfold=0
/*
Spell Name: Twin Wolves
Made by: mckill2009
REQUIRES:
- Jass New Gen Pack (JNGP) by Vexorian
- RegisterPlayerUnitEvent by Magtheridon96
- Table by Bribe
- SimError by Vexorian
- SummonedEscort by mckill2009
*/
scope TwinWolves
globals
private constant integer SPELL_ID = 'A002'
private constant integer WOLF_ID = 'n000'
private constant integer FOR_ALLY_SPELL_ID = 'A004' //rejuvenation
private constant integer FOR_ENEMY_SPELL_ID = 'A005' //chainlightning
private constant integer FOR_ALLY_OID = 852160 //this should match the FOR_ALLY_SPELL_ID
private constant integer FOR_ENEMY_OID = 852119 //this should match the FOR_ENEMY_SPELL_ID
private constant real AOE = 600.
private constant string SFX_APPEAR = "Abilities\\Spells\\Orc\\FeralSpirit\\feralspirittarget.mdl"
private constant real PERIOD = 1.0 //how fast the wolves will cast spells, affected by cooldowns
private constant real WOLF_LIFE = 60.
//===NON-CONFIGURABLE
private Table c
private unit FilterUnit
private unit TempUnit
endglobals
private function UnitAlive takes unit u returns boolean
return not IsUnitType(u, UNIT_TYPE_DEAD)
endfunction
private function UnitAllyInRange takes nothing returns boolean
set FilterUnit = GetFilterUnit()
return UnitAlive(FilterUnit) and not IsUnitEnemy(TempUnit, GetOwningPlayer(FilterUnit)) /*
*/ and not IsUnitType(FilterUnit, UNIT_TYPE_STRUCTURE) and not IsUnitType(FilterUnit, UNIT_TYPE_MECHANICAL) /*
*/ and not IsUnitType(FilterUnit, UNIT_TYPE_MAGIC_IMMUNE) and GetWidgetLife(FilterUnit) < GetUnitState(FilterUnit, UNIT_STATE_MAX_LIFE)
endfunction
private function UnitEnemyInRange takes nothing returns boolean
set FilterUnit = GetFilterUnit()
return UnitAlive(FilterUnit) and IsUnitEnemy(TempUnit, GetOwningPlayer(FilterUnit)) /*
*/ and not IsUnitType(FilterUnit, UNIT_TYPE_STRUCTURE) and not IsUnitType(FilterUnit, UNIT_TYPE_MECHANICAL) /*
*/ and not IsUnitType(FilterUnit, UNIT_TYPE_MAGIC_IMMUNE)
endfunction
struct TW
unit caster
unit healer
unit damager
real duration
private static integer index = 0
private static integer array indexAR
private static timer t = CreateTimer()
private static method periodic takes nothing returns nothing
local thistype this
local integer i = 0
local unit first
loop
set i = i+1
set this = indexAR[i]
if .duration > 0 and UnitAlive(.caster) then
set .duration = .duration - PERIOD
set TempUnit = .caster
if UnitAlive(.damager) then
set first = GetClosestUnitInRange(GetUnitX(.damager), GetUnitY(.damager), AOE, Filter(function UnitEnemyInRange))
if first!=null then
call IssueTargetOrderById(.damager, FOR_ENEMY_OID, first)
endif
endif
if UnitAlive(.healer) then
set first = GetClosestUnitInRange(GetUnitX(.healer), GetUnitY(.healer), AOE, Filter(function UnitAllyInRange))
if first!=null then
call IssueTargetOrderById(.healer, FOR_ALLY_OID, first)
endif
endif
else
call c.remove(GetHandleId(.caster))
call KillUnit(.damager)
call KillUnit(.healer)
set .caster = null
set .damager = null
set .healer = null
call .destroy()
set indexAR[i] = indexAR[index]
set indexAR[index] = this
set index = index - 1
set i = i-1
if index==0 then
call PauseTimer(t)
endif
endif
exitwhen i==index
endloop
set first = null
endmethod
private static method cast takes nothing returns nothing
local unit u
local integer level
local real facing
local real x
local real y
local thistype this
if GetSpellAbilityId()==SPELL_ID then
set u = GetTriggerUnit()
if c.has(GetHandleId(u)) then
call IssueImmediateOrder(u, "stop")
call SimError(GetTriggerPlayer(), "you cant use this spell yet")
else
set this = allocate()
set x = GetUnitX(u)
set y = GetUnitY(u)
set facing = GetUnitFacing(u)*0.017453333
set .caster = u
set level = GetUnitAbilityLevel(u, SPELL_ID)
//===Healer
set .healer = CreateUnit(GetTriggerPlayer(), WOLF_ID, x+150*Cos(facing+1.5708), y+150*Sin(facing+1.5708), GetUnitFacing(u))
call DestroyEffect(AddSpecialEffectTarget(SFX_APPEAR, .healer, "origin"))
call UnitAddAbility(.healer, FOR_ALLY_SPELL_ID)
call SetUnitAbilityLevel(.healer, FOR_ALLY_SPELL_ID, level)
call MakeUnitUnSelectable(.healer, 0)
call SE.summoned(.caster, .healer)
//===Damager
set .damager = CreateUnit(GetTriggerPlayer(), WOLF_ID, x+150*Cos(facing-1.5708), y+150*Sin(facing-1.5708), GetUnitFacing(u))
call DestroyEffect(AddSpecialEffectTarget(SFX_APPEAR, .damager, "origin"))
call UnitAddAbility(.damager, FOR_ENEMY_SPELL_ID)
call SetUnitAbilityLevel(.damager, FOR_ENEMY_SPELL_ID, level)
call MakeUnitUnSelectable(.damager, 0)
call SE.summoned(.caster, .damager)
set .duration = WOLF_LIFE
set c[GetHandleId(u)] = 0
if index==0 then
call TimerStart(t, PERIOD, true, function thistype.periodic)
endif
set index = index + 1
set indexAR[index] = this
endif
set u = null
endif
endmethod
private static method onInit takes nothing returns nothing
local unit u = CreateUnit(Player(15), WOLF_ID, 0,0,0)
call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_SPELL_CAST, function thistype.cast)
set c = Table.create()
//Preloading
call UnitAddAbility(u, FOR_ENEMY_SPELL_ID)
call UnitAddAbility(u, FOR_ALLY_SPELL_ID)
call ShowUnit(u, false)
call RemoveUnit(u)
set u = null
endmethod
endstruct
endscope
//TESH.scrollpos=0
//TESH.alwaysfold=0
/*
Spell inside Locust Raid Spell
*/
//TESH.scrollpos=83
//TESH.alwaysfold=0
/*
Spell Name: ForbiddenWrath
Made by: mckill2009
REQUIRES:
- Jass New Gen Pack (JNGP) by Vexorian
- SpellEffectEvent by Bribe
- Table by Bribe
*/
scope ForbiddenWrath
globals
private constant integer SPELL_ID = 'A003'
private constant integer MAX_AVATAR = 3
private constant real DURATION = 60.
private constant string SFX_RETAIN = "Abilities\\Spells\\Items\\TomeOfRetraining\\TomeOfRetrainingCaster.mdl"
private constant string SFX_APPEAR = "Abilities\\Spells\\Orc\\FeralSpirit\\feralspirittarget.mdl"
//===NON-CONFIGURABLES:
private integer array avatarID
private TableArray c
endglobals
private struct FW
unit u
real duration
integer check
private static integer array indexAR
private static integer index = 0
static method periodic takes nothing returns nothing
local thistype this
local integer i = 0
local integer count
local integer id
local unit avatar
loop
set i = i+1
set this = indexAR[i]
set .duration = .duration - 0.03125
set id = GetHandleId(.u)
set count = 0
loop
set avatar = c[count].unit[id]
if IsUnitType(avatar, UNIT_TYPE_DEAD) and c[1][GetHandleId(avatar)]==0 then
set .check = .check - 1
set c[1][GetHandleId(avatar)] = 1
endif
set count = count + 1
exitwhen count==MAX_AVATAR
endloop
if 0 > .duration or .check==0 then
set count = 0
loop
set avatar = c[count].unit[id]
if not IsUnitType(avatar, UNIT_TYPE_DEAD) then
call KillUnit(avatar)
endif
set count = count + 1
exitwhen count==MAX_AVATAR
endloop
call SetUnitPropWindow(.u, 1)
call UnitRemoveAbility(.u, 'Abun')
call UnitRemoveAbility(.u, 'Avul')
call SuspendHeroXP(.u, false)
call ShowUnit(.u, true)
call DestroyEffect(AddSpecialEffectTarget(SFX_RETAIN, .u, "origin"))
set .u = null
call .destroy()
set indexAR[i] = indexAR[index]
set indexAR[index] = this
set index = index - 1
set i = i-1
if index==0 then
call PauseTimer(GetExpiredTimer())
call DestroyTimer(GetExpiredTimer())
endif
endif
exitwhen i==index
endloop
set avatar = null
endmethod
static method cast takes nothing returns nothing
local thistype this = allocate()
local integer count = 0
local real angle = 0
local integer id
local real x
local real y
local unit avatar
set .u = GetTriggerUnit()
set .duration = DURATION
set x = GetUnitX(.u)
set y = GetUnitY(.u)
set id = GetHandleId(.u)
loop
set avatar = CreateUnit(GetTriggerPlayer(), avatarID[count], x+150*Cos(angle*0.01745333), y+150*Sin(angle*0.01745333), GetUnitFacing(.u))
set c[count].unit[id] = avatar
call DestroyEffect(AddSpecialEffectTarget(SFX_APPEAR, avatar, "origin"))
set c[1][GetHandleId(avatar)] = 0
set angle = angle + 40
set count = count + 1
set avatar = null
exitwhen count==MAX_AVATAR
endloop
set .check = MAX_AVATAR
call SetUnitPropWindow(.u, 0)
call UnitAddAbility(.u, 'Abun')
call UnitAddAbility(.u, 'Avul')
call SuspendHeroXP(.u, true)
call ShowUnit(.u, false)
if index==0 then
call TimerStart(CreateTimer(), 0.04, true, function thistype.periodic)
endif
set index = index + 1
set indexAR[index] = this
endmethod
static method onInit takes nothing returns nothing
call RegisterSpellEffectEvent(SPELL_ID, function thistype.cast)
set c = TableArray[0x200]
set avatarID[0] = 'nrwm' //red dragon
set avatarID[1] = 'nsll' //salamander lord
set avatarID[2] = 'ntrd' //dragon turtle
endmethod
endstruct
endscope