• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Need help in my own system creation

Status
Not open for further replies.
Level 4
Joined
May 14, 2018
Messages
34
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
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
 
Level 40
Joined
Feb 27, 2007
Messages
5,089
What editor/version are you using to run this code? It has fundamental JASS errors that prevent it from being compiled, so it looks like some JASS with Lua features? Just confused. For example:
  • Shouldn't be able to declare local variables inside of an if block.
  • The CircularMovementUnitStart function definition has 4 arguments, but in the example trigger you supplied you call it with a 5th argument of 1.
I have other questions about how the trigger works, too:
  • What are you trying to do with destroyeddummy?
  • What is supposed to control how long the circular movement happens?
  • Are the units that are being moved in circles also able to move themselves, or are they stationary and only moved by this system?
 
Level 4
Joined
May 14, 2018
Messages
34
What editor/version are you using to run this code? It has fundamental JASS errors that prevent it from being compiled, so it looks like some JASS with Lua features? Just confused. For example:
  • Shouldn't be able to declare local variables inside of an if block.
  • The CircularMovementUnitStart function definition has 4 arguments, but in the example trigger you supplied you call it with a 5th argument of 1.
I have other questions about how the trigger works, too:
  • What are you trying to do with destroyeddummy?
  • What is supposed to control how long the circular movement happens?
  • Are the units that are being moved in circles also able to move themselves, or are they stationary and only moved by this system?
I'm really sorry, I forgot that I use Cjass to localize functions, so I posted a bad version of the code.

I fixed all the bugs in the code, so it should work fine now

Destroyeddummy (in this version I fixed it) describes the last empty dummy number.

So if the 2nd dummy died, the 3rd dummy will be downgraded to number 2, and the Destroyeddummy variable will be incremented by 1.

This is the main problem - it can only detect 1 dead dummy per round.

The movement will continue untill participant death. I believe it`s the best way to controll it`s duration

No, they can`t be moved manually,
For demonstration purposes i use 'hfoo' to test system for now, but in future i`m planning to use dummy with 'aloc'.


Sorry again for bad code. there is correct versions:

All code was written using JNGP 5.0 for Warcraft 1.26a

JASS:
globals
hashtable Hash = InitHashtable()
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_Unit

key k_DestroyedDummy
key k_HowMuchToDecrease
key k_DecreaseCount
endglobals

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)

local real Distance = 0
local real Speed   = 0    
local real Offset  = 0  
local integer DestroyedDummy= 0
local real DistBetweenDummies= 0
local real x= 0
local real y= 0

if GetWidgetLife(u)>0.405 then

  
    set Distance     = LoadReal(Hash,HId,k_Distance)
    set Speed        = LoadReal(Hash,HId,k_Speed)
    set Offset       = LoadReal(Hash,GetHandleId(Target),k_Offset)
  
    set DestroyedDummy = LoadInteger(Hash,GetHandleId(Target),k_DestroyedDummy)
  
    call SetUnitState(u,UNIT_STATE_LIFE,DummyNumber) // Just used for dummy number in system +faster killing for testing
  
    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)

      
        set DistBetweenDummies = 360 / TotalDummies * DummyNumber
      
  

    if Offset >= 360 then
        set Offset = Offset - 360
    endif

    call SaveReal(Hash,GetHandleId(Target),k_Offset,Offset)

  


    set x = GetUnitX(Target) + Cos((Offset+DistBetweenDummies)*bj_DEGTORAD) * Distance
    set 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 SaveInteger(Hash,GetHandleId(Target),k_Total,TotalDummies-1)
    call SaveInteger(Hash,GetHandleId(Target),k_DestroyedDummy,DummyNumber)

    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)

call 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


JASS:
function TestTrigActions takes nothing returns nothing
local integer j = 0
local unit u
local effect eff
loop

exitwhen j == 1
    set u = CreateUnit(Player(PLAYER_NEUTRAL_PASSIVE),'hfoo',GetUnitX(gg_unit_Hamg_0000), GetUnitY(gg_unit_Hamg_0000),0)

    set eff = AddSpecialEffectTarget("Abilities\\Weapons\\FireBallMissile\\FireBallMissile.mdl",u,"chest")
    set eff = null
    call CircularMovementUnitStart (u,100,0.3, gg_unit_Hamg_0000)
    set u = null
set j = j+1
endloop

endfunction

//===========================================================================
function InitTrig_TestTrig takes nothing returns nothing
    set gg_trg_TestTrig = CreateTrigger(  )
    call TriggerRegisterPlayerEventEndCinematic( gg_trg_TestTrig, Player(0) )
    call TriggerAddAction( gg_trg_TestTrig, function TestTrigActions )
endfunction
 
Status
Not open for further replies.
Top