//TESH.scrollpos=0
//TESH.alwaysfold=0
Name | Type | is_array | initial_value |
Fear_Data | integer | Yes | 0 |
Fear_Dindex | integer | No | -1 |
Fear_Hash | hashtable | No | |
Fear_Timer | timer | No | |
S_Fear_Effect | effect | Yes | |
S_Fear_StartAt | integer | Yes | |
S_Fear_Steps | integer | Yes | |
S_Fear_Targ | unit | Yes | |
S_Instance | integer | No | 0 |
S_Recycle | integer | No | 0 |
S_Recycle_List | integer | Yes | 0 |
//TESH.scrollpos=0
//TESH.alwaysfold=0
scope Init
globals
private unit u
endglobals
private struct A
static method cond takes nothing returns boolean
call SetFloatGameState(GAME_STATE_TIME_OF_DAY, bj_MELEE_STARTING_TOD)
call BJDebugMsg("Press Esc to winamax a level :3 !")
//call BJDebugMsg("Oh it is fryday ! You want a cookie ? I can't give you this but if you press the up arrow key you'll be full life, full mana and your cooldown will be reset !")
call DestroyTrigger(GetTriggeringTrigger())
return false
endmethod
static method cond2 takes nothing returns boolean
call SetHeroLevel(u, GetHeroLevel(u)+1, true)
return false
endmethod
static method cond3 takes nothing returns boolean
call SetWidgetLife(u, GetUnitState(u, UNIT_STATE_MAX_LIFE))
call SetUnitState(u, UNIT_STATE_MANA, GetUnitState(u, UNIT_STATE_MAX_MANA))
call UnitResetCooldown(u)
return false
endmethod
static method onInit takes nothing returns nothing
local trigger t = CreateTrigger()
local trigger tt = CreateTrigger()
local trigger ttt = CreateTrigger()
call TriggerRegisterTimerEvent(t, 0, false)
call TriggerRegisterPlayerEvent(tt, Player(0), EVENT_PLAYER_END_CINEMATIC)
call TriggerRegisterPlayerEvent(ttt, Player(0), EVENT_PLAYER_ARROW_UP_UP)
call TriggerAddCondition(t, Condition(function thistype.cond))
call TriggerAddCondition(tt, Condition(function thistype.cond2))
call TriggerAddCondition(ttt, Condition(function thistype.cond3))
set u = CreateUnit(Player(0), 'Hblm', 0,0,0)
set t = null
set tt = null
set ttt = null
endmethod
endstruct
endscope
//TESH.scrollpos=220
//TESH.alwaysfold=0
/*********************************************************************************************************************
This is a fear system; use it to remove player
control from a unit temporarily. Units affected
will also be unable to attack.
I - Requirements
You'll need JNGP because it is a vJASS resource.
II - How to import ?
Then you just have to create a trigger called FearSystem then convert it to custom text.
Then remove everything inside the trigger and paste everything inside this. And you're done.
You can also copy and paste this trigger.
Now you have to copy and paste the three abilities called "DISABLE_ATTACK", "BEAR FORM FEAR"
and "MORPH FEAR".
Change the id in the globals block to make it fit to your map.
You're done.
III - Tell me how to use it !
1.) Fear.add
To use this you will have to call the method Fear.add(unit, time, path, attach)
The parameter unit is the unit you want to fear.
The parameter time is how many time the unit have to be feared.
The parameter path : it is the path of the effect you'll add to the feared unit.
The parameter attach : it is the attachment of the effect on the feared unit.
An example : call Fear.add(u, 3, "Abilities\\Spells\\Undead\\Curse\\CurseTarget.mdl","overhead")
The unit u will be feared during 3 seconds and it will have a special effect in the overhead of the target.
2.) Fear.isFeared
To use this you will have to call the method Fear.isFeared(unit).
This will return a boolean that tell if the unit is already feared or not.
Example : if Fear.isFeared(u) then
If the unit is feared so it will return true and the condition will run.
3.) Fear.extend
The last method is Fear.extend(unit,time).
It will extend an already existing fear instance on unit.
Example : Fear.add(u, 3, "Abilities\\Spells\\Undead\\Curse\\CurseTarget.mdl","overhead")
Fear.extend(u,2)
This will result with a fear of 3+2=5 seconds on the same target.
IV- Credits to :
- Vexorian for Table library and vJASS :3
- Maker for the awesome function that disable units.
Give me credits if you use this.
Made by Malhorne
********************************************************************************************************************/
library FearSystem requires optional Table //By Vexorian or By Bribe
//Donut touch this native !
//Comment it if you have already declared it in another scope/library.
native UnitAlive takes unit u returns boolean
globals
//There will be check every FPS second.
private constant real FPS = 0.31250000
//Feared units will change direction every EACH_CHANGE FPS.
private constant integer EACH_CHANGE = 3
//Feared units will go maximum in a circle of 150 around them each time they change direction.
private constant real AROUND = 150.
//The rawcode of the attack disable. Be sure it is the same in the Object Editor.
private constant integer DISABLE_ATTACK = 'W000'
//The rawcode of the morph. Be sure it is the same in the Object Editor.
private constant integer MORPH_ID = 'Z001'
//The rawcode of the bear form. Be sure it is the same in the Object Editor.
private constant integer BEAR_ID = 'Z000'
endglobals
//***********************************************
//DONUT TOUCH ANYTHING BELOW !
//***********************************************
private module Module
static method onInit takes nothing returns nothing
call init()
endmethod
endmodule
static if Table.flush2D.exists then
globals
private HandleTable tab
endglobals
elseif Table.has.exists then
globals
private Table tb
endglobals
else
globals
private hashtable ht = InitHashtable()
endglobals
endif
private function round takes real r returns integer
if r-0.5 > R2I(r) then
return R2I(r+1)
else
return R2I(r)
endif
endfunction
private function modulo takes integer a, integer b returns integer
return a - (a/b)*b
endfunction
//Credits to Maker for this awesum func <3
private function DisableControl takes unit u returns nothing
call UnitAddAbility(u, 'Aloc')
call UnitRemoveAbility(u, 'Aloc')
if IsUnitType(u, UNIT_TYPE_HERO) then
call UnitAddAbility(u,MORPH_ID)
call IssueImmediateOrder(u, "metamorphosis")
call UnitRemoveAbility(u,MORPH_ID)
else
call UnitAddAbility(u, BEAR_ID)
call IssueImmediateOrder(u, "bearform")
call UnitRemoveAbility(u, BEAR_ID)
endif
//I added this line to disable their attack too.
call UnitAddAbility(u,DISABLE_ATTACK)
endfunction
private function EnableControl takes unit u returns nothing
local boolean backup = not IsUnitHidden(u)
call ShowUnit(u,false)
//I added this line to enable their attack.
call UnitRemoveAbility(u,DISABLE_ATTACK)
call ShowUnit(u,true)
call ShowUnit(u,backup)
endfunction
struct Fear extends array
private unit targ
private integer steps
private integer startat
private effect e
private static timer period
private static integer dindex
private static thistype array data
private static integer instanceCount
private static thistype recycle
private thistype recycleNext
static method isFeared takes unit u returns boolean
static if Table.flush2D.exists then
return tab.exists(u)
elseif Table.has.exists then
return tb.has(GetHandleId(u))
else
return HaveSavedInteger(ht,GetHandleId(u),0)
endif
endmethod
private static method periodic takes nothing returns nothing
local thistype this
local real x
local real y
local integer i = 0
loop
exitwhen i > dindex
set this = data[i]
if modulo(this.steps,EACH_CHANGE) == this.startat then
set x = GetUnitX(this.targ)
set y = GetUnitY(this.targ)
call IssuePointOrder(this.targ, "move", GetRandomReal(x-AROUND,x+AROUND), GetRandomReal(y-AROUND, x+AROUND) )
endif
set this.steps = this.steps - 1
if this.steps == 0 or not(UnitAlive(this.targ)) then
set data[i] = data[dindex]
set i = i - 1
set dindex = dindex - 1
call DestroyEffect(this.e)
call IssueImmediateOrder(this.targ,"stop")
call EnableControl(this.targ)
static if Table.flush2D.exists then
call tab.flush(this.targ)
elseif Table.has.exists then
return tb.remove(GetHandleId(this.targ))
else
return FlushChildHashtable(ht,GetHandleId(this.targ))
endif
set this.targ = null
set this.e = null
call this.destroy()
endif
if dindex == -1 then
call PauseTimer(period)
endif
set i = i + 1
endloop
endmethod
static method extend takes unit u, real time returns nothing
local thistype this
if thistype.isFeared(u) then
set this = tab[u]
set this.steps = this.steps + round(time/FPS)
debug else
debug call BJDebugMsg("Fear System Error : You're trying to extend a non-instanciate Fear instance !")
endif
endmethod
static method add takes unit u, real time, string path, string attach returns nothing
local thistype this
if (recycle == 0) then
set instanceCount = instanceCount + 1
set this = instanceCount
else
set this = recycle
set recycle = recycle.recycleNext
endif
call DisableControl(u)
set this.targ = u
set this.e = AddSpecialEffectTarget(path,u,attach)
set this.steps = round(time/FPS)
set this.startat = modulo(this.steps,EACH_CHANGE)
set dindex = dindex + 1
set data[dindex] = this
static if Table.flush2D.exists then
set tab[u] = this
elseif Table.has.exists then
set tb[GetHandleId(u)] = this
else
call SaveInteger(ht,GetHandleId(u),0,this)
endif
if dindex == 0 then
call TimerStart(period, FPS, true, function thistype.periodic)
endif
endmethod
private method destroy takes nothing returns nothing
set recycleNext = recycle
set recycle = this
endmethod
private static method init takes nothing returns nothing
static if Table.flush2D.exists then
set tab = HandleTable.create()
elseif Table.has.exists then
set tb = Table.create()
endif
set period = CreateTimer()
set dindex = -1
set recycle = 0
set instanceCount = 0
endmethod
implement Module
endstruct
endlibrary
//TESH.scrollpos=64
//TESH.alwaysfold=0
scope TestFear
//=============================================================
//=========================SETUP================================
//=============================================================
globals
private constant real DURATION = 3.
private constant real AOE = 350.
private constant integer SPELL_ID = 'P000'
private constant string PATH = "Abilities\\Spells\\Undead\\Curse\\CurseTarget.mdl"
private constant string PATH_2 = "Abilities\\Spells\\NightElf\\BattleRoar\\RoarCaster.mdl"
private constant string ATTACH = "overhead"
endglobals
private function Duration takes integer level returns integer
return 2+level
endfunction
private function Aoe takes integer level returns integer
return 300 + 50*level
endfunction
private function Cond takes nothing returns boolean
local unit FoG
local player p
local real x
local real y
local group g
local integer lvl
local Fear F
if GetSpellAbilityId() == SPELL_ID then
set g = CreateGroup()
set p = GetOwningPlayer(GetTriggerUnit())
set x = GetSpellTargetX()
set y = GetSpellTargetY()
set lvl = GetUnitAbilityLevel(GetTriggerUnit(),SPELL_ID)
call GroupEnumUnitsInRange(g, x, y, Aoe(lvl), null)
call DestroyEffect(AddSpecialEffect(PATH_2,x,y))
loop
set FoG = FirstOfGroup(g)
exitwhen FoG == null
call GroupRemoveUnit(g, FoG)
//I'm using UnitAlive since I declared it in the FearSystem
if not IsUnitAlly(FoG,p) and UnitAlive(FoG) then
if Fear.isFeared(FoG) then
set F = Fear.get(FoG)
set F.time = Duration(lvl)
else
set F = Fear.create()
set F.targ = FoG
set F.path = PATH
set F.attach = ATTACH
set F.time = Duration(lvl)
call F.start()
call F.destroy()
endif
endif
endloop
call DestroyGroup(g)
set g = null
endif
return false
endfunction
private module Module
private static method onInit takes nothing returns nothing
call init()
endmethod
endmodule
private struct A extends array
private static method init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)
call TriggerAddCondition(t, Condition(function Cond))
set bj_lastCreatedUnit = CreateUnit(Player(15),'h000',0,0,0)
call UnitAddAbility(bj_lastCreatedUnit, SPELL_ID)
call KillUnit(bj_lastCreatedUnit)
call Preload(PATH)
call Preload(PATH_2)
set t = null
endmethod
implement Module
endstruct
endscope
//TESH.scrollpos=0
//TESH.alwaysfold=0
library FearSystem /* v3
************************************************************************************
*
* */uses /*
*
* */ Table /* http://www.wc3c.net/showthread.php?t=101246
* //By Vexorian
*
************************************************************************************
*
* struct Fear extends array
*
* Description
* -------------------------
*
* This is a fear system; use it to remove player
* control from a unit temporarily. Units affected
* will also be unable to attack.
*
* Fields
* -------------------------
*
* unit targ -> The unit you want to apply the fear.
*
* string path -> The path of the sfx you want to add to the unit.
*
* string attach -> The attachment string you want the sfx to be on the unit
*
* readonly effect e -> The effect currently applied to the unit.
* Initializes to null
*
* Methods
* -------------------------
*
* static method create takes nothing returns thistype
* method destroy takes nothing returns nothing
*
* method start takes nothing returns nothing
* When you have set every parameters you start your fear instance.
*
* method changeEffect takes string path, string attach returns nothing
* If you already have set the effect of your instance and it is running
* and you want to change it use this.
*
* static method isFeared takes unit u returns boolean
* static method get takes unit u returns thistype
*
* Operators
* -------------------------
*
* method operator time= takes real t returns nothing
* method operator time takes nothing returns real
*
* Credits
* -------------------------
*
* - Vexorian for vJASS and Table
* - Maker for the DisableUnit function
* - Bribe for Table
* - Chobibo for the addition in the DisableUnit function/
*
************************************************************************************/
native UnitAlive takes unit u returns boolean
globals
//There will be check every FPS second.
private constant real FPS = 0.31250000
//Feared units will change direction every EACH_CHANGE FPS.
private constant integer EACH_CHANGE = 3
//Feared units will go maximum in a circle of 150 around them each time they change direction.
private constant real AROUND = 150.
//The rawcode of the attack disable. Be sure it is the same in the Object Editor.
private constant integer DISABLE_ATTACK = 'W000'
//The rawcode of the morph. Be sure it is the same in the Object Editor.
private constant integer MORPH_ID = 'Z001'
//The rawcode of the bear form. Be sure it is the same in the Object Editor.
private constant integer BEAR_ID = 'Z000'
endglobals
//The Table for Vexorian version
globals
private HandleTable tab
endglobals
private function round takes real r returns integer
return R2I(r+0.5)
endfunction
private function modulo takes integer a, integer b returns integer
return a - (a/b)*b
endfunction
//Credits to Maker for this awesum func <3
private function DisableControl takes unit u returns nothing
local boolean b
call UnitAddAbility(u, 'Aloc')
call UnitRemoveAbility(u, 'Aloc')
if IsUnitType(u, UNIT_TYPE_HERO) then
call UnitAddAbility(u,MORPH_ID)
call IssueImmediateOrder(u, "metamorphosis")
call UnitRemoveAbility(u,MORPH_ID)
else
call UnitAddAbility(u, BEAR_ID)
call IssueImmediateOrder(u, "bearform")
call UnitRemoveAbility(u, BEAR_ID)
endif
//Thanks to chobibo for this idea
if GetLocalPlayer() != GetOwningPlayer(u) then
set b = not IsUnitHidden(u)
call ShowUnit(u,false)
call ShowUnit(u,b)
endif
//I added this line to disable their attack too.
call UnitAddAbility(u,DISABLE_ATTACK)
endfunction
private function EnableControl takes unit u returns nothing
local boolean backup = not IsUnitHidden(u)
call ShowUnit(u,false)
//I added this line to enable their attack.
call UnitRemoveAbility(u,DISABLE_ATTACK)
call ShowUnit(u,backup)
endfunction
struct Fear extends array
unit targ
string path
string attach
readonly effect e
readonly boolean b
private integer steps
private integer startat
private static timer period
private static integer dindex
private static thistype array data
private static integer instanceCount
private static thistype recycle
private thistype recycleNext
private static method periodic takes nothing returns nothing
local thistype this
local real x
local real y
local integer i = 0
loop
exitwhen i > dindex
set this = data[i]
if modulo(this.steps,EACH_CHANGE) == this.startat then
set x = GetUnitX(this.targ)
set y = GetUnitY(this.targ)
call IssuePointOrder(this.targ, "move", GetRandomReal(x-AROUND,x+AROUND), GetRandomReal(y-AROUND, x+AROUND) )
endif
set this.steps = this.steps - 1
if this.steps == 0 or not(UnitAlive(this.targ)) then
set data[i] = data[dindex]
set i = i - 1
set dindex = dindex - 1
if this.e != null then
call DestroyEffect(this.e)
set this.e = null
endif
call IssueImmediateOrder(this.targ,"stop")
call EnableControl(this.targ)
call tab.flush(this.targ)
if this.b then
set this.targ = null
set recycleNext = recycle
set recycle = this
endif
endif
if dindex == -1 then
call PauseTimer(period)
endif
set i = i + 1
endloop
endmethod
static method isFeared takes unit u returns boolean
return tab.exists(u)
endmethod
method operator time= takes real t returns nothing
set this.steps = round(t/FPS)
endmethod
method operator time takes nothing returns real
return this.steps*FPS
endmethod
method changeEffect takes string path, string attach returns nothing
call DestroyEffect(this.e)
set this.e = null
set this.e = AddSpecialEffectTarget(path,this.targ,attach)
endmethod
static method get takes unit u returns thistype
if isFeared(u) then
return tab[u]
else
debug call BJDebugMsg("Tryng to get wrong instance")
return 0
endif
endmethod
method start takes nothing returns nothing
debug if this.targ==null or this.steps==0 then
debug call BJDebugMsg("You're instanciating badly ....")
debug return
debug endif
set dindex = dindex + 1
set data[dindex] = this
set this.startat = modulo(this.steps,EACH_CHANGE)
call DisableControl(this.targ)
if this.path != "" and this.attach != "" then
set this.e = AddSpecialEffectTarget(this.path, this.targ, this.attach)
endif
set tab[this.targ] = this
if dindex == 0 then
call TimerStart(period, FPS, true, function thistype.periodic)
endif
endmethod
static method create takes nothing returns thistype
local thistype this
if recycle == 0 then
set instanceCount = instanceCount + 1
set this = instanceCount
else
set this = recycle
set recycle = recycle.recycleNext
endif
set this.path = ""
set this.attach = ""
set this.e = null
set this.b = false
return this
endmethod
method destroy takes nothing returns nothing
set this.b = true
endmethod
private static method onInit takes nothing returns nothing
set tab = HandleTable.create()
set dindex = - 1
set instanceCount = 0
set recycle = 0
set period = CreateTimer()
endmethod
endstruct
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
library FearSystem /* v3
************************************************************************************
*
* */uses /*
*
* */ Table /* http://www.hiveworkshop.com/forums/jass-resources-412/snippet-new-table-188084/
* //By Bribe
*
************************************************************************************
*
* struct Fear extends array
*
* Description
* -------------------------
*
* This is a fear system; use it to remove player
* control from a unit temporarily. Units affected
* will also be unable to attack.
*
* Fields
* -------------------------
*
* unit targ -> The unit you want to apply the fear.
*
* string path -> The path of the sfx you want to add to the unit.
*
* string attach -> The attachment string you want the sfx to be on the unit
*
* readonly effect e -> The effect currently applied to the unit.
* Initializes to null
*
* Methods
* -------------------------
*
* static method create takes nothing returns thistype
* method destroy takes nothing returns nothing
*
* method start takes nothing returns nothing
* When you have set every parameters you start your fear instance.
*
* method changeEffect takes string path, string attach returns nothing
* If you already have set the effect of your instance and it is running
* and you want to change it use this.
*
* static method isFeared takes unit u returns boolean
* static method get takes unit u returns thistype
*
* Operators
* -------------------------
*
* method operator time= takes real t returns nothing
* method operator time takes nothing returns real
*
* Credits
* -------------------------
*
* - Vexorian for vJASS and Table
* - Maker for the DisableUnit function
* - Bribe for Table
* - Chobibo for the addition in the DisableUnit function/
*
************************************************************************************/
native UnitAlive takes unit u returns boolean
globals
//There will be check every FPS second.
private constant real FPS = 0.31250000
//Feared units will change direction every EACH_CHANGE FPS.
private constant integer EACH_CHANGE = 3
//Feared units will go maximum in a circle of 150 around them each time they change direction.
private constant real AROUND = 150.
//The rawcode of the attack disable. Be sure it is the same in the Object Editor.
private constant integer DISABLE_ATTACK = 'W000'
//The rawcode of the morph. Be sure it is the same in the Object Editor.
private constant integer MORPH_ID = 'Z001'
//The rawcode of the bear form. Be sure it is the same in the Object Editor.
private constant integer BEAR_ID = 'Z000'
endglobals
globals
private Table tb
endglobals
private function round takes real r returns integer
return R2I(r+0.5)
endfunction
private function modulo takes integer a, integer b returns integer
return a - (a/b)*b
endfunction
//Credits to Maker for this awesum func <3
private function DisableControl takes unit u returns nothing
local boolean b
call UnitAddAbility(u, 'Aloc')
call UnitRemoveAbility(u, 'Aloc')
if IsUnitType(u, UNIT_TYPE_HERO) then
call UnitAddAbility(u,MORPH_ID)
call IssueImmediateOrder(u, "metamorphosis")
call UnitRemoveAbility(u,MORPH_ID)
else
call UnitAddAbility(u, BEAR_ID)
call IssueImmediateOrder(u, "bearform")
call UnitRemoveAbility(u, BEAR_ID)
endif
//Thanks to chobibo for this idea
if GetLocalPlayer() != GetOwningPlayer(u) then
set b = not IsUnitHidden(u)
call ShowUnit(u,false)
call ShowUnit(u,b)
endif
//I added this line to disable their attack too.
call UnitAddAbility(u,DISABLE_ATTACK)
endfunction
private function EnableControl takes unit u returns nothing
local boolean backup = not IsUnitHidden(u)
call ShowUnit(u,false)
//I added this line to enable their attack.
call UnitRemoveAbility(u,DISABLE_ATTACK)
call ShowUnit(u,backup)
endfunction
struct Fear extends array
unit targ
string path
string attach
readonly effect e
readonly boolean b
private integer steps
private integer startat
private static timer period
private static integer dindex
private static thistype array data
private static integer instanceCount
private static thistype recycle
private thistype recycleNext
private static method periodic takes nothing returns nothing
local thistype this
local real x
local real y
local integer i = 0
loop
exitwhen i > dindex
set this = data[i]
if modulo(this.steps,EACH_CHANGE) == this.startat then
set x = GetUnitX(this.targ)
set y = GetUnitY(this.targ)
call IssuePointOrder(this.targ, "move", GetRandomReal(x-AROUND,x+AROUND), GetRandomReal(y-AROUND, x+AROUND) )
endif
set this.steps = this.steps - 1
if this.steps == 0 or not(UnitAlive(this.targ)) then
set data[i] = data[dindex]
set i = i - 1
set dindex = dindex - 1
if this.e != null then
call DestroyEffect(this.e)
set this.e = null
endif
call IssueImmediateOrder(this.targ,"stop")
call EnableControl(this.targ)
call tb.remove(GetHandleId(this.targ))
if this.b then
set this.targ = null
set recycleNext = recycle
set recycle = this
endif
endif
if dindex == -1 then
call PauseTimer(period)
endif
set i = i + 1
endloop
endmethod
static method isFeared takes unit u returns boolean
return tb.has(GetHandleId(u))
endmethod
method operator time= takes real t returns nothing
set this.steps = round(t/FPS)
endmethod
method operator time takes nothing returns real
return this.steps*FPS
endmethod
method changeEffect takes string path, string attach returns nothing
call DestroyEffect(this.e)
set this.e = null
set this.e = AddSpecialEffectTarget(path,this.targ,attach)
endmethod
static method get takes unit u returns thistype
local thistype this
if isFeared(u) then
return tb[GetHandleId(u)]
else
debug call BJDebugMsg("Tryng to get wrong instance")
return 0
endif
endmethod
method start takes nothing returns nothing
debug if this.targ==null or this.steps==0 then
debug call BJDebugMsg("You're instanciating badly ....")
debug return
debug endif
set dindex = dindex + 1
set data[dindex] = this
set this.startat = modulo(this.steps,EACH_CHANGE)
call DisableControl(this.targ)
if this.path != "" and this.attach != "" then
set this.e = AddSpecialEffectTarget(this.path, this.targ, this.attach)
endif
set tb[GetHandleId(this.targ)] = this
if dindex == 0 then
call TimerStart(period, FPS, true, function thistype.periodic)
endif
endmethod
static method create takes nothing returns thistype
local thistype this
if recycle == 0 then
set instanceCount = instanceCount + 1
set this = instanceCount
else
set this = recycle
set recycle = recycle.recycleNext
endif
set this.path = ""
set this.attach = ""
set this.e = null
set this.b = false
return this
endmethod
method destroy takes nothing returns nothing
set this.b = true
endmethod
private static method onInit takes nothing returns nothing
set tb = Table.create()
set dindex = - 1
set instanceCount = 0
set recycle = 0
set period = CreateTimer()
endmethod
endstruct
endlibrary
//TESH.scrollpos=73
//TESH.alwaysfold=0
constant function Fear_FPS takes nothing returns real
return 0.0312500
endfunction
constant function Fear_EACH_CHANGE takes nothing returns integer
return 3
endfunction
constant function Fear_AROUND takes nothing returns real
return 150.
endfunction
constant function Fear_DISABLE_ATTACK takes nothing returns integer
return 'W000'
endfunction
constant function Fear_MORPH_ID takes nothing returns integer
return 'Z001'
endfunction
constant function Fear_BEAR_ID takes nothing returns integer
return 'Z000'
endfunction
//ALLOCATOR OF STRUCT :
//This could be use to create a struct in GUI/JASS.
function Struct_create takes nothing returns integer
local integer this
if ( udg_S_Recycle == 0 ) then
set udg_S_Instance = udg_S_Instance + 1
set this = udg_S_Instance
else
set this = udg_S_Recycle
set udg_S_Recycle = udg_S_Recycle_List[udg_S_Recycle]
endif
return this
endfunction
function Struct_destroy takes integer this returns nothing
set udg_S_Recycle_List[this] = udg_S_Recycle
set udg_S_Recycle = this
endfunction
function Fear_round takes real r returns integer
if r-0.5 > R2I(r) then
return R2I(r+1)
else
return R2I(r)
endif
endfunction
function Fear_modulo takes integer a, integer b returns integer
return a - (a/b)*b
endfunction
function Fear_DisableControl takes unit u returns nothing
call UnitAddAbility(u, 'Aloc')
call UnitRemoveAbility(u, 'Aloc')
if IsUnitType(u, UNIT_TYPE_HERO) then
call UnitAddAbility(u,Fear_MORPH_ID())
call IssueImmediateOrder(u, "metamorphosis")
call UnitRemoveAbility(u,Fear_MORPH_ID())
else
call UnitAddAbility(u, Fear_BEAR_ID())
call IssueImmediateOrder(u, "bearform")
call UnitRemoveAbility(u, Fear_BEAR_ID())
endif
//I added this line to disable their attack too.
call UnitAddAbility(u,Fear_DISABLE_ATTACK())
endfunction
function Fear_EnableControl takes unit u returns nothing
local boolean backup = not IsUnitHidden(u)
call ShowUnit(u,false)
//I added this line to enable their attack.
call UnitRemoveAbility(u, Fear_DISABLE_ATTACK())
call ShowUnit(u,true)
call ShowUnit(u,backup)
endfunction
function Fear_isFeared takes unit u returns boolean
return HaveSavedInteger(udg_Fear_Hash, 0, GetHandleId(u))
endfunction
function Fear_extend takes unit u, real time returns nothing
local integer this
if Fear_isFeared(u) then
set this = LoadInteger(udg_Fear_Hash, GetHandleId(u),0)
set udg_S_Fear_Steps[this] = udg_S_Fear_Steps[this] + Fear_round(time/Fear_FPS())
else
call BJDebugMsg("Fear System Error : You're trying to extend a non-instanciate Fear instance !")
endif
endfunction
function Fear_periodic takes nothing returns nothing
local integer this
local real x
local real y
local integer i = 0
loop
exitwhen i > udg_Fear_Dindex
set this = udg_Fear_Data[i]
if Fear_modulo(udg_S_Fear_Steps[this], Fear_EACH_CHANGE()) == udg_S_Fear_StartAt[this] then
set x = GetUnitX(udg_S_Fear_Targ[this])
set y = GetUnitY(udg_S_Fear_Targ[this])
call IssuePointOrder(udg_S_Fear_Targ[this], "move", GetRandomReal(x-Fear_AROUND(),x+Fear_AROUND()), GetRandomReal(y-Fear_AROUND(), x+Fear_AROUND()) )
endif
set udg_S_Fear_Steps[this] = udg_S_Fear_Steps[this] - 1
if udg_S_Fear_Steps[this] == 0 or GetWidgetLife(udg_S_Fear_Targ[this])<0.405 then
set udg_Fear_Data[i] = udg_Fear_Data[udg_Fear_Dindex]
set i = i - 1
set udg_Fear_Dindex = udg_Fear_Dindex - 1
call DestroyEffect(udg_S_Fear_Effect[this])
call IssueImmediateOrder(udg_S_Fear_Targ[this],"stop")
call Fear_EnableControl(udg_S_Fear_Targ[this])
call FlushChildHashtable(udg_Fear_Hash, GetHandleId(udg_S_Fear_Targ[this]))
set udg_S_Fear_Targ[this] = null
set udg_S_Fear_Effect[this] = null
call Struct_destroy(this)
endif
if udg_Fear_Dindex == -1 then
call PauseTimer(udg_Fear_Timer)
endif
set i = i + 1
endloop
endfunction
function Fear_add takes unit u, real time, string path, string attach returns nothing
local integer this = Struct_create()
call Fear_DisableControl(u)
set udg_S_Fear_Effect[this] = AddSpecialEffectTarget(path,u,attach)
set udg_S_Fear_Targ[this] = u
set udg_S_Fear_Steps[this] = Fear_round(time/Fear_FPS())
set udg_S_Fear_StartAt[this] = Fear_modulo(udg_S_Fear_Steps[this], Fear_EACH_CHANGE())
set udg_Fear_Dindex = udg_Fear_Dindex + 1
set udg_Fear_Data[udg_Fear_Dindex] = this
call SaveInteger(udg_Fear_Hash,GetHandleId(u),0,this)
if udg_Fear_Dindex == 0 then
call TimerStart(udg_Fear_Timer, Fear_FPS(), true, function Fear_periodic)
endif
endfunction
//===========================================================================
function InitTrig_FearSystemJASS takes nothing returns nothing
set udg_Fear_Hash = InitHashtable()
set udg_Fear_Dindex = -1
set udg_S_Recycle = 0
set udg_S_Instance = 0
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
library Table
//***************************************************************
//* Table object 3.1
//* ------------
//*
//* set t=Table.create() - instanceates a new table object
//* call t.destroy() - destroys it
//* t[1234567] - Get value for key 1234567
//* (zero if not assigned previously)
//* set t[12341]=32 - Assigning it.
//* call t.flush(12341) - Flushes the stored value, so it
//* doesn't use any more memory
//* t.exists(32) - Was key 32 assigned? Notice
//* that flush() unassigns values.
//* call t.reset() - Flushes the whole contents of the
//* Table.
//*
//* call t.destroy() - Does reset() and also recycles the id.
//*
//* If you use HandleTable instead of Table, it is the same
//* but it uses handles as keys, the same with StringTable.
//*
//* You can use Table on structs' onInit if the struct is
//* placed in a library that requires Table or outside a library.
//*
//* You can also do 2D array syntax if you want to touch
//* mission keys directly, however, since this is shared space
//* you may want to prefix your mission keys accordingly:
//*
//* set Table["thisstring"][ 7 ] = 2
//* set Table["thisstring"][ 5 ] = Table["thisstring"][7]
//*
//***************************************************************
//=============================================================
globals
private constant integer MAX_INSTANCES=8100 //400000
//Feel free to change max instances if necessary, it will only affect allocation
//speed which shouldn't matter that much.
//=========================================================
private hashtable ht = InitHashtable()
endglobals
private struct GTable[MAX_INSTANCES]
method reset takes nothing returns nothing
call FlushChildHashtable(ht, integer(this) )
endmethod
private method onDestroy takes nothing returns nothing
call this.reset()
endmethod
endstruct
//Hey: Don't instanciate other people's textmacros that you are not supposed to, thanks.
//! textmacro Table__make takes name, type, key
struct $name$ extends GTable
method operator [] takes $type$ key returns integer
return LoadInteger(ht, integer(this), $key$)
endmethod
method operator []= takes $type$ key, integer value returns nothing
call SaveInteger(ht, integer(this) ,$key$, value)
endmethod
method flush takes $type$ key returns nothing
call RemoveSavedInteger(ht, integer(this), $key$)
endmethod
method exists takes $type$ key returns boolean
return HaveSavedInteger( ht, integer(this) ,$key$)
endmethod
static method flush2D takes string firstkey returns nothing
call $name$(- StringHash(firstkey)).reset()
endmethod
static method operator [] takes string firstkey returns $name$
return $name$(- StringHash(firstkey) )
endmethod
endstruct
//! endtextmacro
//! runtextmacro Table__make("Table","integer","key" )
//! runtextmacro Table__make("StringTable","string", "StringHash(key)" )
//! runtextmacro Table__make("HandleTable","handle","GetHandleId(key)" )
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