- Joined
- Sep 14, 2012
- Messages
- 3,413
Okay Guys Update
library HoT
globals
private constant real FPS = 0.0100
endglobals
struct HoT extends array
private unit target
private real interval
private real during
private real heal
private real temp
private static integer count
private thistype prev
private thistype next
private static timer period
private static method iterate takes nothing returns nothing
local thistype this = thistype(0)
loop
set this = this.next
exitwhen this == 0
set this.temp = this.temp + FPS
if this.temp+FPS >= this.interval then
call SetUnitState(this.target, UNIT_STATE_LIFE, GetUnitState(this.target, UNIT_STATE_LIFE)+this.heal)
set this.temp = 0
endif
set this.during = this.during - FPS
if this.during <= 0 then
call this.destroy()
endif
endloop
endmethod
static method add takes unit targ, real dur, real inter, real amount returns nothing
local thistype this
if thistype(0).prev == 0 then
set count = count + 1
set this = count
else
set this = thistype(0).prev
set thistype(0).prev = thistype(0).prev.prev
endif
if thistype(0).next == 0 then
call TimerStart(period, FPS, true, function thistype.iterate)
else
set thistype(0).next.prev = this
endif
set this.next = thistype(0).next
set thistype(0).next = this
set this.prev = thistype(0)
set this.target = targ
set this.interval = inter
set this.during = dur
set this.heal = amount
set this.temp = 0
endmethod
private method destroy takes nothing returns nothing
if this.next != 0 then
set this.next.prev = this.prev
endif
set this.prev.next = this.next
set this.prev = thistype(0).prev
set thistype(0).prev = this
if thistype(0).next == 0 then
call PauseTimer(period)
endif
set this.target = null
endmethod
private static method onInit takes nothing returns nothing
set count = 0
set period = CreateTimer()
endmethod
endstruct
endlibrary
library Preload requires Table //By Vex atm
globals
//CHANGE THIS LINE TO FIT TO THE MAP WITH YOUR DUMMY_ID
private constant integer DUMMY_ID = 'hfoo'
endglobals
private module Module
static method onInit takes nothing returns nothing
call init()
endmethod
endmodule
private struct slop extends array
string snd
static HandleTable tab
thistype recycleNext
static integer instanceCount
static thistype recycle
static unit dummy
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
return this
endmethod
method destroy takes nothing returns nothing
set recycleNext = recycle
set recycle = this
endmethod
static method init takes nothing returns nothing
set tab = HandleTable.create()
set instanceCount = 0
set recycle = 0
set dummy = CreateUnit(Player(15), DUMMY_ID, 0,0,0)
call UnitApplyTimedLife(dummy, 'BTLF', 2)
endmethod
implement Module
endstruct
private function AfterPreload takes nothing returns nothing
local timer t = GetExpiredTimer()
local slop s = slop.tab[t]
local sound sn = CreateSound(s.snd, false, false, false, 12700, 12700, "" )
call SetSoundVolume(sn, 1)
call StartSound(sn)
call KillSoundWhenDone(sn)
set sn = null
call slop.tab.flush(t)
call DestroyTimer(t)
set t = null
call s.destroy()
endfunction
public function PreloadSound takes string snd returns nothing
local timer t = CreateTimer()
local slop s = slop.create()
set s.snd = snd
set slop.tab[t] = s
call TimerStart( t, 0.01, false, function AfterPreload )
set t = null
endfunction
public function PreloadSpell takes integer id returns nothing
call UnitAddAbility(slop.dummy, id)
endfunction
//The keyword public will be the difference between the BJ func and mine
public function PlaySound takes string s, real x, real y returns nothing
local sound snd = CreateSound(s,false,true,true,12700,12700,"")
call SetSoundVolume(snd,127)
call SetSoundPitch(snd,.88)
call SetSoundPosition(snd,x,y,50.)
call StartSound(snd)
call KillSoundWhenDone(snd)
set snd=null
endfunction
endlibrary
call Preload_PreloadSound(string path)
call Preload_PreloadSpell(integer id)
call Preload_PlaySound(string path, real x, real y)
call Preload_Sound(string path)
call Preload_Spell(integer id)
call Preload_PlaySound(string path, real x, real y)
To Do List
- Stop Time snippet: used for this ability: Dramatically Stops Time all over the game, freezing heroes, timer, day time while keeping the Time Walker unharmed the snippet should do the purposed ability
- A snippet (more of a template) of a looping trigger in vJASS, Linked List, just make a random example that shows a debug msg each 1 s, i'll need it for other things (PS: make it like:
call LoopTest_Debug(string Msg, real FPS)
ok i was excpecting more, but the loop snippet pretty much sums up all of them (instead of letting you make many stuff that are all based on the same thing)
call Time.stop(unit u, real time)
library LLAlloc /*
************************************************************************************
*
* module LL_Alloc
*
* Description
* -------------------------
*
* This is an alternative allocation that allows you to use LinkedList
* in your struct. Linked List for allocation, destruction, iteration.
*
* Fields
* -------------------------
*
* private thistype next
* private thistype prev
*
* private static integer count
*
* debug private boolean check
*
* Methods
* -------------------------
*
* static method allocate takes nothing returns thistype
* method deallocate takes nothing returns nothing
*
* method chain takes nothing returns nothing
* ~Chain the instance in order to make the iteration iterate through it
*
* method unchain takes nothing returns nothing
* ~Unchain the instance in order to make the iteration not iterate anymore through it
*
* method operator first takes nothing returns thistype
* ~Return the first one in the list to iterate
*
* Example of usage
* ~~~~~~~~~~~~~~~~~~
*
* private struct Test extends array
* Your
* Parameters
*
* static timer period = CreateTimer()
* implement LL_Alloc
*
* static method periodic takes nothing returns nothing
* local thistype this = first
* loop
* exitwhen this == 0
*
* Do
* Your
* Stuff
*
* if you have to deallocate then
* Do
* Deallocate
* Stuff
*
* call this.unchain
* call this.deallocate (if you don't need the struct anymore)
* endif
* set this = this.next
* endloop
* endmethod
*
* static method create takes nothing returns thistype
* local thistype this = thistype.allocate()
*
* Perform
* Create
* Stuff
*
* return this
* endmethod
*
* method start takes nothing returns nothing
* if this.empty then
* call TimerStart(period, 0.0312500, true, function thistype.periodic)
* endif
* call this.chain
* endmethod
* endstruct
************************************************************************/
//! textmacro LL_Alloc
private thistype prev
private thistype next
private static integer count = 0
debug private boolean check
private method deallocate takes nothing returns nothing
set this.prev = thistype(0).prev
set thistype(0).prev = this
endmethod
private static method allocate takes nothing returns thistype
local thistype this
if thistype(0).prev == 0 then
set count = count + 1
debug if count > 8190 then
debug call BJDebugMsg("Linked List Module -> You're instanciating too much structs !!!")
debug return 0
debug endif
set this = count
else
set this = thistype(0).prev
set thistype(0).prev = thistype(0).prev.prev
endif
debug set this.check = false
return this
endmethod
private method chain takes nothing returns nothing
debug if this.check then
debug call BJDebugMsg("You're trying to chain an already chained unit")
debug return
debug endif
debug set this.check = true
if thistype(0).next != 0 then
set thistype(0).next.prev = this
endif
set this.next = thistype(0).next
set thistype(0).next = this
set this.prev = thistype(0)
endmethod
private method unchain takes nothing returns nothing
debug if not this.check then
debug call BJDebugMsg("You're tring to unchain a non-chained unit")
debug return
debug endif
debug set this.check = false
if this.next != 0 then
set this.next.prev = this.prev
endif
set this.prev.next = this.next
endmethod
private static method first takes nothing returns thistype
return thistype(0).next
endmethod
private static method empty takes nothing returns boolean
return thistype(0).next == 0
endmethod
//! endtextmacro
endlibrary
* static method periodic takes nothing returns nothing
* local thistype this = first
* loop
* exitwhen this == 0
*
* Do
* Your
* Stuff
*
* set this = this.next
* endloop
* endmethod