• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Timing Problem

Status
Not open for further replies.
Level 31
Joined
May 3, 2008
Messages
3,155
---problem solved---


JASS:
function Arrow_Split_Conditions takes nothing returns boolean
    return GetSpellAbilityId()=='A62X'
endfunction

function Arrow_Split_Actions takes nothing returns nothing
    local unit caster=GetTriggerUnit()
    local location loc = GetSpellTargetLoc()
    local real x1=GetUnitX(caster)
    local real y1=GetUnitY(caster)
    local real sd=(GetUnitFacing(caster))
    local real x2 = x1 + 100 * Cos(sd*bj_DEGTORAD)
    local real y2 = y1 + 100 * Sin (sd*bj_DEGTORAD)
    local real td
    local real t1=GetLocationX(loc)
    local real t2=GetLocationY(loc)
    local unit lastcreated=CreateUnit(GetOwningPlayer(caster),'n61Q',x2,y2,sd)
    call IssuePointOrder(lastcreated, "move", t1,t2)
    set td=SquareRoot((t1-y2)*(t1-y2)+(t2-x2)*(t2-x2))/522
    call UnitApplyTimedLife(lastcreated,'BTLF',td)
    set caster=null
    set lastcreated=null
    set loc=null
    call RemoveLocation(loc)
endfunction

function Arrow_Death_Conditions takes nothing returns boolean
    return GetUnitTypeId(GetTriggerUnit())=='n61Q'
endfunction

function Arrow_Death_Actions takes nothing returns nothing
    local unit dead=GetTriggerUnit()
    local unit lastcreated=null
    local real x1=GetUnitX(dead)
    local real y1=GetUnitY(dead)
    local integer Arrow_Split=1
    local real SA_real=0
    local real missilefacing=bj_RADTODEG*Atan2(y1,x1) 
    local real newX
    local real newY
    loop
        exitwhen Arrow_Split>12
        set newX=x1+300*Cos(SA_real+.523599)
        set newY=y1+300*Sin(SA_real+.523599)
        set lastcreated=CreateUnit(GetOwningPlayer(dead),'n61R',x1,y1,missilefacing)
        call UnitApplyTimedLife(lastcreated,'BTLF',.30)
        call IssuePointOrder(lastcreated,"shockwave",newX,newY)
        set SA_real=SA_real+.523599
        set Arrow_Split=Arrow_Split+1
    endloop
    set dead=null
    set lastcreated=null
endfunction

//===========================================================================

constant function CSAS takes nothing returns boolean
    return true
endfunction

function InitTrig_Arrow_Split takes nothing returns nothing
    local trigger T=CreateTrigger()
    local trigger T2=CreateTrigger()
    local integer TI=0
    local filterfunc FF=Filter(function CSAS)
    loop
        exitwhen (TI>=bj_MAX_PLAYER_SLOTS)
        call TriggerRegisterPlayerUnitEvent(T,Player(TI),EVENT_PLAYER_UNIT_SPELL_EFFECT,null)
        call TriggerRegisterPlayerUnitEvent(T2,Player(TI),EVENT_PLAYER_UNIT_DEATH,null)
        set TI=TI+1
    endloop
    call DestroyBoolExpr(FF)
    call DestroyFilter(FF)
    call TriggerAddAction(T,function Arrow_Split_Actions)
    call TriggerAddCondition(T,Condition(function Arrow_Split_Conditions))
    call TriggerAddAction(T2,function Arrow_Death_Actions)
    call TriggerAddCondition(T2,Condition(function Arrow_Death_Conditions))
    set FF=null
    set T=null
    set T2=null
endfunction

Now the arrow does travel to the destination. However, it does not dead the moment it reach the destination.

Just where did the carculation goes wrong?

JASS:
set td=SquareRoot((t1-y2)*(t1-y2)+(t2-x2)*(t2-x2))/522
 
Last edited:
Level 19
Joined
Feb 25, 2009
Messages
2,004
JASS:
local location lc = GetUnitLoc(GetTriggerUnit)
local location lt = GetSpellTargetLoc
local real t = DistanceBetweenPoints(lc, lt) / 522
call UnitApplyTimedLife(lastcreated,'BTLF',t)

Or simply said, calculate distance between caster and target point and divide it by the dummy movement speed.
 
Are you talking about my post or his? and did you try mine?

local real t1=GetLocationX(loc) <-- X
local real t2=GetLocationY(loc) <-- Y
set td=SquareRoot((t1-y2) X * Y? YES! *(t1-y2)+(t2-x2)*(t2-x2))/522


local real dx = GetLocationX(locB) - GetLocationX(locA)
local real dy = GetLocationY(locB) - GetLocationY(locA)
return SquareRoot(dx * dx + dy * dy)

Soultion?
set td=SquareRoot((t2-y2)*(t2-y2)+(t1-x2)*(t1-x2))/522 Swap the t1 and t2's.
 
Level 22
Joined
Dec 31, 2006
Messages
2,216
Here, I believe I've fixed your problem, and a few other things in the other functions:


JASS:
function Arrow_Split_Conditions takes nothing returns boolean
    return GetSpellAbilityId()=='A62X'
endfunction

function Arrow_Split_Actions takes nothing returns nothing
    local unit caster=GetTriggerUnit()
    local real x1=GetUnitX(caster)
    local real y1=GetUnitY(caster)
    local real sd=(GetUnitFacing(caster))
    local real x2 = x1 + 100 * Cos(sd*bj_DEGTORAD)
    local real y2 = y1 + 100 * Sin (sd*bj_DEGTORAD)
    local real td
    local real t1=GetSpellTargetX()
    local real t2=GetSpellTargetY()
    local unit lastcreated=CreateUnit(GetOwningPlayer(caster),'n61Q',x2,y2,sd)
    call IssuePointOrder(lastcreated, "move", t1,t2)
    set td=SquareRoot((t1-x2)*(t1-x2)+(t2-y2)*(t2-y2))/522
    call UnitApplyTimedLife(lastcreated,'BTLF',td)
    set caster=null
    set lastcreated=null
endfunction

function Arrow_Death_Conditions takes nothing returns boolean
    return GetUnitTypeId(GetTriggerUnit())=='n61Q'
endfunction

function Arrow_Death_Actions takes nothing returns nothing
    local unit dead=GetTriggerUnit()
    local unit lastcreated
    local real x1=GetUnitX(dead)
    local real y1=GetUnitY(dead)
    local integer Arrow_Split=1
    local real SA_real=0
    local real missilefacing=bj_RADTODEG*Atan2(y1,x1) 
    local real newX
    local real newY
    loop
        exitwhen Arrow_Split>12
        set newX=x1+300*Cos(SA_real+.523599)
        set newY=y1+300*Sin(SA_real+.523599)
        set lastcreated=CreateUnit(GetOwningPlayer(dead),'n61R',x1,y1,missilefacing)
        call UnitApplyTimedLife(lastcreated,'BTLF',.30)
        call IssuePointOrder(lastcreated,"shockwave",newX,newY)
        set SA_real=SA_real+.523599
        set Arrow_Split=Arrow_Split+1
    endloop
    set dead=null
    set lastcreated=null
endfunction

//===========================================================================

function InitTrig_Arrow_Split takes nothing returns nothing
    local trigger T=CreateTrigger()
    local trigger T2=CreateTrigger()
    local integer TI=0
    loop
        exitwhen (TI>=bj_MAX_PLAYER_SLOTS)
        call TriggerRegisterPlayerUnitEvent(T,Player(TI),EVENT_PLAYER_UNIT_SPELL_EFFECT,null)
        call TriggerRegisterPlayerUnitEvent(T2,Player(TI),EVENT_PLAYER_UNIT_DEATH,null)
        set TI=TI+1
    endloop
    call TriggerAddAction(T,function Arrow_Split_Actions)
    call TriggerAddCondition(T,Condition(function Arrow_Split_Conditions))
    call TriggerAddAction(T2,function Arrow_Death_Actions)
    call TriggerAddCondition(T2,Condition(function Arrow_Death_Conditions))
    set T=null
    set T2=null
endfunction
 
Last edited:
Level 31
Joined
May 3, 2008
Messages
3,155
@Septimus: This is unrelated to your coding, but I suggest using Carrion Swarm instead of Shockwave which causes terrain deformations, adding some lag to the map.

Using Shockwaves was part of the intention. The amount of shockwaves cast are at minimal and this spells was ultimate spells that cannot be cast frequently.

To top up with, it was for single player campaign; which naturally it should be fine.
 
Status
Not open for further replies.
Top