kingkingyyk3
Visitor (Welcome to the Jungle, Baby!)
- Reaction score
- 216
JASS:
Spinning Attachment Tool v1.3.0
present by kingking
What is the function of this tool?
>>It enable users to put some spining attachment around units in an easy way.
Functions provided :
>>SAT_Add takes unit u, integer id, string path, integer count, real range, real speed, real height, real size, integer facingstyle, boolean endeffect, code callback, integer data returns integer
>>SAT_GetData -> integer
>>SAT_Stop(integer)
For Advanced Jassers, you can use struct syntax :
>> Struct Name : SAT
>> static method create takes real x, real y
>> method SetAttachTarget takes unit u
>> method SetRange takes real range
>> method SetSpeed takes real speed
>> method SetEndEffect takes boolean WantEndEffect
>> method SetFacingStyle takes integer Style
>> method CreateEffects takes integer Count, integer id, string ModelPath
>> method SetHeight takes real height
>> method SetSize takes real size
>> method AddCallback takes code callback, integer callback_data
>> method SetXY takes real x, real y//Use this when no unit is attached on the instance.
>> method Start()
>> Change these variables can make it more freedom to spin at multiple style
What is needed?
>>Dummy model by Vexorian.
>>JassHelper 0.9.G.2 or newer. (Lower version may support, but it is untested.)
Provided Facing Style:
1) All effects follow target039;s facing + 90.
2) All effects face outward.
3) All effects have same angle which the angle will change over time.
4) All effects follow target039;s facing.
5) All effects face inward.
**If you put 5 or above value in the Facing Style argument, it will automatically revert it to 1 to prevent bug.
Tricky Info :
1) Put negative in rotate speed value to make effects spin clockwise.
2) Put 0 in rotate speed value to make effects follow the caster without spinning.
3) The callback will stop when returned value is true
4) SetHeight and SetSize will not apply settings if it is called before CreateEffect.
5) ID argument in CreateEffect : Put 0 to use default dummy or put the rawcode of your dummy if the effect of the result is not satisfied.
JASS:
library SAT
/////////////////////////////User defined constant//////////////////////////////////////////
globals
private constant integer DUMMY_ID = 039;h000039;//Dummy's id
private constant integer FLY_HACK = 039;Arav039;//Fly Trick
private constant real HANDLER_SPEED = .03125//Timer's callback speed
private constant integer MAX_ATTACHMENT = 36//Max number of effect on per instance.
endglobals
//////////////////////////////DO NOT TOUCH BELOW THIS LINE//////////////////////////////////
globals
private constant timer t = CreateTimer()
private integer array Data
private integer Counter = 0
private integer bj_lastCallbackData = 0
endglobals
public function GetData takes nothing returns integer
return bj_lastCallbackData
endfunction
public function Add takes unit u, integer id, string path, integer count, real range, real speed, real height, real size, integer facingstyle, boolean endeffect, code c, integer data returns integer
local SAT d = SAT.create(GetUnitX(u),GetUnitY(u))
call d.SetAttachTarget(u)
call d.SetRange(range)
call d.SetSpeed(speed)
call d.SetEndEffect(endeffect)
call d.SetFacingStyle(facingstyle)
call d.CreateEffect(count,id,path)
call d.SetHeight(height)
call d.SetSize(size)
call d.AddCallback(c,data)
//Hook new instance to rotating instances
call d.Start()
return d
endfunction
private function Handler takes nothing returns nothing
local integer i = Counter
loop
//Rotate
exitwhen i == 0
if not SAT(Data<i>).stop then
//Rotate
call SAT(Data<i>).rotate()
else
//If the instance is demanded to destroy...
call SAT(Data<i>).destroy()
set Data<i> = Data[Counter]
//Defragment instance
set Counter = Counter - 1
endif
set i = i - 1
endloop
if Counter == 0 then
call PauseTimer(t)
endif
endfunction
struct SAT
private unit cs
private integer style
private boolean endeffect
private real range
private real rotatespeed
private real size
private unit array dummies[MAX_ATTACHMENT]
private effect array eff[MAX_ATTACHMENT]
private integer count
private real angle
private real currentangle
private integer callbackData
private trigger callback = CreateTrigger()
private triggercondition ta
boolean stop
static method create takes real x, real y returns SAT
local SAT d = SAT.allocate()
set d.endeffect = false
set d.style = 1
set d.currentangle = 0.
set d.stop = false
set d.cs = CreateUnit(Player(15),DUMMY_ID,x,y,0.)
return d
endmethod
method AddCallback takes code c, integer Data returns nothing
if not (c == null) then
set .ta = TriggerAddCondition(.callback,Condition(c))
set .callbackData = Data
endif
endmethod
method SetRange takes real range returns nothing
set .range = range
endmethod
method CreateEffect takes integer count, integer id, string path returns nothing
local integer i = 1
local integer idz
if count > MAX_ATTACHMENT then
set count = MAX_ATTACHMENT//Locks the max effect count to prevent bug occurs
endif
set .count = count
set .angle = 360. / .count
if id == 0 then
set id = DUMMY_ID
endif
loop
exitwhen i > count
set .dummies<i> = CreateUnit(Player(15),id,GetUnitX(.cs),GetUnitY(.cs),.angle * i)
set .eff<i> = AddSpecialEffectTarget(path,.dummies<i>,"origin")
set i = i + 1
endloop
endmethod
method SetHeight takes real h returns nothing
local integer i = 0
loop
exitwhen i > .count
call SetUnitFlyHeight(.dummies<i>,h,0.)
set i = i + 1
endloop
endmethod
method SetSize takes real size returns nothing
local integer i = 0
loop
exitwhen i > .count
call SetUnitScale(.dummies<i>,size,size,size)
set i = i + 1
endloop
endmethod
method SetEndEffect takes boolean b returns nothing
set .endeffect = b
endmethod
method SetSpeed takes real r returns nothing
set .rotatespeed = r * HANDLER_SPEED
endmethod
method SetFacingStyle takes integer i returns nothing
if i > 5 then
set i = 1
endif
set .style = i
endmethod
method SetAttachTarget takes unit u returns nothing
if GetUnitTypeId(.cs) == DUMMY_ID then
call RemoveUnit(.cs)
endif
set .cs = u
endmethod
method SetXY takes real x, real y returns nothing
if GetUnitTypeId(.cs) == DUMMY_ID then
call SetUnitPosition(.cs,x,y)
endif
endmethod
method rotate takes nothing returns nothing
local integer i = 1
local real r = 0.
if .currentangle > 360. then
set .currentangle = .currentangle - 360.
endif
set .currentangle = .currentangle + .rotatespeed
loop
exitwhen i > .count
set r = (.currentangle + (.angle * i )) * .0175
call SetUnitPosition(.dummies<i>,GetUnitX(.cs) + .range * Cos(r),GetUnitY(.cs) + .range * Sin(r))
if .style == 1 then
set r = GetUnitFacing(.cs) + 90.
elseif .style == 2 then
set r = 57.2958 * Atan2(GetUnitY(.dummies<i>) - GetUnitY(.cs),GetUnitX(.dummies<i>) - GetUnitX(.cs))
elseif .style == 3 then
set r = .currentangle
elseif .style == 4 then
set r = GetUnitFacing(.cs)
elseif .style == 5 then
set r = 57.2958 * Atan2(GetUnitY(.cs) - GetUnitY(.dummies<i>),GetUnitX(.cs) - GetUnitX(.dummies<i>))
endif
call SetUnitFacing(.dummies<i>,r)
set i = i + 1
endloop
if not (.ta == null) then
set bj_lastCallbackData = .callbackData
if TriggerEvaluate(.callback) then
call TriggerRemoveCondition(.callback,.ta)
set .ta = null
endif
endif
endmethod
method Start takes nothing returns nothing
if Counter == 0 then
call TimerStart(t,HANDLER_SPEED,true,function Handler)
endif
set Counter = Counter + 1
set Data[Counter] = this
endmethod
//Cleans up all thingy
method onDestroy takes nothing returns nothing
local integer i = 0
set .stop = true
loop
exitwhen i > .count
call DestroyEffect(.eff<i>)
if .endeffect then
call KillUnit(.dummies<i>)
else
call RemoveUnit(.dummies<i>)
endif
set i = i + 1
endloop
if GetUnitTypeId(.cs) == DUMMY_ID then
call RemoveUnit(.cs)
endif
if not (.ta == null) then
call TriggerRemoveCondition(.callback,.ta)
set .ta = null
endif
endmethod
endstruct
public function Stop takes integer i returns nothing
set SAT(i).stop = true
endfunction
endlibrary
</i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i>
JASS:
History :
v1 - First Release
v1.1 - Add some features
v1.2 - Allowing struct syntax
v1.3 - Allowing custom dummies type(I found some effects is ugly when attached on default dummy)
This tool enables users create some spining effects around units.
Screenshot :
http://www.youtube.com/watch?v=QpeTq7LrM20
[YOUTUBE]http://www.youtube.com/watch?v=QpeTq7LrM20[/YOUTUBE]