Hello everyone!
For last 2 months working for my own system of circular movement around certain unit.
I want to make it fully automatic and i almost succeed, but now can`t get how to finish it.
For now i`m stuck with system participants death.
If 2 units die in 1 tick - system starts work incorrectly.
Any suggestions how to fix it?
Will be better if u can test it to see my problem - Just use call CircularMovementUnitStart takes unit u, real distance, real speed, unit target
u - spinning unit
distance - radius between target and unit
speed - speed of spinning
target - center of circle
Make trig
I used this trigger to test it
For last 2 months working for my own system of circular movement around certain unit.
I want to make it fully automatic and i almost succeed, but now can`t get how to finish it.
For now i`m stuck with system participants death.
If 2 units die in 1 tick - system starts work incorrectly.
Any suggestions how to fix it?
Will be better if u can test it to see my problem - Just use call CircularMovementUnitStart takes unit u, real distance, real speed, unit target
u - spinning unit
distance - radius between target and unit
speed - speed of spinning
target - center of circle
Make trig
JASS:
key k_Distance
key k_Speed
key k_Offset
key k_Target
key k_Total
key k_Number
key k_PosReset
key k_Group
key k_DestroyedDummy
key k_HowMuchToDecrease
key k_DecreaseCount
library a
function CircularMovementUnitTimer takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer HId = GetHandleId(t)
local unit u = LoadUnitHandle(Hash,HId,k_Unit)
local unit Target = LoadUnitHandle(Hash,HId,k_Target)
local integer TotalDummies = LoadInteger(Hash,GetHandleId(Target),k_Total)
local integer DummyNumber = LoadInteger(Hash,GetHandleId(u),k_Number)
if GetWidgetLife(u)>0.405 then
local real Distance = LoadReal(Hash,HId,k_Distance)
local real Speed = LoadReal(Hash,HId,k_Speed)
local real Offset = LoadReal(Hash,GetHandleId(Target),k_Offset)
local integer DestroyedDummy = LoadInteger(Hash,GetHandleId(Target),k_DestroyedDummy)
call SetUnitState(u,UNIT_STATE_LIFE,DummyNumber)
if DummyNumber>DestroyedDummy and DestroyedDummy!=0 and DummyNumber - DestroyedDummy == 1 then
call SaveInteger(Hash,GetHandleId(u),k_Number,DummyNumber-1)
set DummyNumber = DummyNumber - 1
call SaveInteger(Hash,GetHandleId(Target),k_DestroyedDummy,DestroyedDummy+1)
endif
set Offset = Offset + (Speed/TotalDummies)
local real DistBetweenDummies = 360 / TotalDummies * DummyNumber
if Offset >= 360 then
set Offset = Offset - 360
endif
call SaveReal(Hash,GetHandleId(Target),k_Offset,Offset)
local real x = GetUnitX(Target) + Cos((Offset+DistBetweenDummies)*bj_DEGTORAD) * Distance
local real y = GetUnitY(Target) + Sin((Offset+DistBetweenDummies)*bj_DEGTORAD) * Distance
call SetUnitX(u, x)
call SetUnitY(u, y)
call SetUnitFacing(u, Offset+DistBetweenDummies+90)
else
call PauseTimer(t)
call DestroyTimer(t)
call FlushChildHashtable(Hash,HId)
endif
set Target = null
set u = null
set t = null
endfunction
function CircularMovementUnitStart takes unit u, real distance, real speed, unit target returns nothing
local timer t = CreateTimer()
local integer HId = GetHandleId(t)
local integer count = LoadInteger(Hash,GetHandleId(target),k_Total) + 1
call SaveInteger(Hash,GetHandleId(target),k_Total,count)
call SaveInteger(Hash,GetHandleId(u),k_Number,count)
SaveInteger(Hash,GetHandleId(target),k_DestroyedDummy,LoadInteger(Hash,GetHandleId(target),k_DestroyedDummy)+1)
call SaveBoolean(Hash,GetHandleId(target),k_PosReset,true)
call SaveUnitHandle(Hash,HId,k_Unit,u)
call SaveUnitHandle(Hash,HId,k_Target,target)
call SaveUnitHandle(Hash,GetHandleId(u),k_Target,target)
call SaveReal(Hash,HId,k_Distance,distance)
call SaveReal(Hash,HId,k_Speed,speed)
call TimerStart(t,0.00325,true, function CircularMovementUnitTimer)
set t = null
endfunction
endlibrary
I used this trigger to test it
JASS:
function Trig_____________________________________007_Actions takes nothing returns nothing
local integer j = 0
loop
exitwhen j == 1
local unit u = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE),'hfoo',GetUnitX(gg_unit_Hamg_0000), GetUnitY(gg_unit_Hamg_0000),0)
local effect eff = AddSpecialEffectTarget("Abilities\\Weapons\\FireBallMissile\\FireBallMissile.mdl",u,"chest")
set eff = null
call CircularMovementUnitStart (u,100,0.3, gg_unit_Hamg_0000,1)
set u = null
set j = j+1
endloop
endfunction
//===========================================================================
function InitTrig_____________________________________007 takes nothing returns nothing
set gg_trg_____________________________________007 = CreateTrigger( )
call TriggerRegisterPlayerEventEndCinematic( gg_trg_____________________________________007, Player(0) )
call TriggerAddAction( gg_trg_____________________________________007, function Trig_____________________________________007_Actions )
endfunction