• 🏆 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!

[JASS] Attempt to make a JASS trigger

Status
Not open for further replies.
Level 8
Joined
Dec 16, 2007
Messages
252
f
JASS:
unction Trig_Nuke_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A009'
endfunction

function Nuke_Effect takes nothing returns nothing
  local timer t = GetExpiredTimer()
  local unit dummy = H2U(GetHandleHandle(t, "dummy"))
  local real ang = GetHandleReal(t, "ang")
  local real i = GetHandleReal(t, "i")
  local location o= GetUnitLoc(dummy)
  call SetUnitPosition(dummy,GetUnitX(dummy) + 20 * Cos(ang * bj_DEGTORAD),GetUnitY(dummy) + 20 * Sin(ang * bj_DEGTORAD))
  set i = i + 1
  call DisplayTextToForce( GetPlayersAll(), R2S(i) )

  if i == 100 then
    //set dummy = CreateUnitAtLoc(GetOwningPlayer(dummy) , 'u004', o, ang )
    call SetUnitPathing(GetLastCreatedUnit(), false)
    call SetUnitFlyHeightBJ( GetLastCreatedUnit(), 0.00, 200.00 )
  endif

  if i == 200 then
    call RemoveUnit(dummy)
    call PauseTimer(t)
call FlushHandleLocals(t)
    call PauseTimer(t)
    call DestroyTimer(t)
  endif

  call RemoveLocation(o)

  set t=null
  set dummy=null
  set o=null
endfunction

function Trig_Nuke_Actions takes nothing returns nothing
  local unit u = GetTriggerUnit()
  local unit dummy
  local unit bomb
  local location l = GetSpellTargetLoc()
  local real x = GetUnitX(u)
  local real y = GetUnitY(u)
  local real xtarg = GetLocationX(l)
  local real ytarg = GetLocationY(l)
  local real ang = bj_RADTODEG * Atan2(ytarg - y, xtarg - x)
  local timer t = CreateTimer()
  local location s = PolarProjectionBJ(Location(xtarg, ytarg), 2000., ang - 180)
  local real i = 0

  set dummy = CreateUnitAtLoc(GetOwningPlayer(u) , 'u003', s, ang )
  call SetUnitPathing(dummy, false)
  set i = 1

  call SetHandleHandle(t, "dummy", dummy)
  call SetHandleHandle(t, "bomb", bomb)
  call SetHandleReal(t, "ang", ang)
  call SetHandleReal(t, "i", i)
  call TimerStart(t, 0.03, true, function Nuke_Effect)

  call RemoveLocation(l)
  call RemoveLocation(s)

  set u=null
  set dummy=null
  set l=null
  set t=null
  set s=null
endfunction

//===========================================================================
function InitTrig_Nuke takes nothing returns nothing
    set gg_trg_Nuke = CreateTrigger( )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Nuke, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Nuke, Condition( function Trig_Nuke_Conditions ) )
    call TriggerAddAction( gg_trg_Nuke, function Trig_Nuke_Actions )
endfunction
 
Last edited:
Level 7
Joined
Jul 20, 2008
Messages
377
I strongly advise against using local timers (destroying timers and nulling timers have a lot of issues). Try to use a stack of global timers so you can recycle timers. I believe there are tutorials on that out there.

I'm curious though, why do you use empty else clauses? Not that it should affect anything - I just think that's weird.

And can you give us a few samples of errors in your code?
 
Level 8
Joined
Dec 16, 2007
Messages
252
The whole function was error

JASS:
function Trig_Nuke_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A009'
endfunction

function Nuke_Effect takes nothing returns nothing
  local timer t = GetExpiredTimer() //Expected A Name
  local unit dummy = H2U(GetHandleHandle(t, "dummy"))//Expected Expression
  local real ang = GetHandleReal(t, "ang"))//Expected Expression
  local real i = GetHandleReal(t, "ang"))
  local location = GetUnitLoc(dummy)
  call SetUnitPosition(dummy,GetUnitX(dummy) + 20 * Cos(ang * bj_DEGTORAD),GetUnitY(dummy) + 20 * Sin(ang * bj_DEGTORAD))
  set i = i + 1

  if i == 100 then
  set dummy = CreateUnitAtLoc(GetOwningPlayer(dummy) , 'u004', o, ang )
  call SetUnitPathing(GetLastCreatedUnit(), false)
  call SetUnitFlyHeightBJ( GetLastCreatedUnit(), 0.00, 200.00 )
  else
  endif

Also this is the Local Handle Vars. I'm not sure if I did it right, but I replaced the InitGameCache("jasslocalvars.w3v") with a global variable - cache, game cache.
JASS:
// ===========================
function H2I takes handle h returns integer
    return h
    return 0
endfunction

// ===========================
function LocalVars takes nothing returns gamecache
    // Replace InitGameCache("jasslocalvars.w3v") with a global variable!!
    return udg_cache
endfunction

function SetHandleHandle takes handle subject, string name, handle value returns nothing
    if value==null then
        call FlushStoredInteger(LocalVars(),I2S(H2I(subject)),name)
    else
        call StoreInteger(LocalVars(), I2S(H2I(subject)), name, H2I(value))
    endif
endfunction

function SetHandleInt takes handle subject, string name, integer value returns nothing
    if value==0 then
        call FlushStoredInteger(LocalVars(),I2S(H2I(subject)),name)
    else
        call StoreInteger(LocalVars(), I2S(H2I(subject)), name, value)
    endif
endfunction

function SetHandleBoolean takes handle subject, string name, boolean value returns nothing
    if value==false then
        call FlushStoredBoolean(LocalVars(),I2S(H2I(subject)),name)
    else
        call StoreBoolean(LocalVars(), I2S(H2I(subject)), name, value)
    endif
endfunction

function SetHandleReal takes handle subject, string name, real value returns nothing
    if value==0 then
        call FlushStoredReal(LocalVars(), I2S(H2I(subject)), name)
    else
        call StoreReal(LocalVars(), I2S(H2I(subject)), name, value)
    endif
endfunction

function SetHandleString takes handle subject, string name, string value returns nothing
    if value==null then
        call FlushStoredString(LocalVars(), I2S(H2I(subject)), name)
    else
        call StoreString(LocalVars(), I2S(H2I(subject)), name, value)
    endif
endfunction

function GetHandleHandle takes handle subject, string name returns handle
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction
function GetHandleInt takes handle subject, string name returns integer
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
endfunction
function GetHandleBoolean takes handle subject, string name returns boolean
    return GetStoredBoolean(LocalVars(), I2S(H2I(subject)), name)
endfunction
function GetHandleReal takes handle subject, string name returns real
    return GetStoredReal(LocalVars(), I2S(H2I(subject)), name)
endfunction
function GetHandleString takes handle subject, string name returns string
    return GetStoredString(LocalVars(), I2S(H2I(subject)), name)
endfunction

function GetHandleUnit takes handle subject, string name returns unit
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction
function GetHandleTimer takes handle subject, string name returns timer
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction
function GetHandleTrigger takes handle subject, string name returns trigger
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction
function GetHandleEffect takes handle subject, string name returns effect
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction
function GetHandleGroup takes handle subject, string name returns group
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction
function GetHandleLightning takes handle subject, string name returns lightning
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction
function GetHandleWidget takes handle subject, string name returns widget
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction

function FlushHandleLocals takes handle subject returns nothing
    call FlushStoredMission(LocalVars(), I2S(H2I(subject)) )
endfunction
 
Maybe like this i don't know :)

custom script
JASS:
// ===========================
function H2I takes handle h returns integer
    return h
    return 0
endfunction
function H2U takes handle h returns unit
    return h
    return null
endfunction

// ===========================
function LocalVars takes nothing returns gamecache
    if udg_cache==null then
        call FlushGameCache(InitGameCache("data.gc"))
        set udg_cache=InitGameCache("data.gc")
    endif
    return udg_cache
endfunction

function SetHandleHandle takes handle subject, string name, handle value returns nothing
    if value==null then
        call FlushStoredInteger(LocalVars(),I2S(H2I(subject)),name)
    else
call StoreInteger(LocalVars(), I2S(H2I(subject)), name, H2I(value))
    endif
endfunction

function SetHandleInt takes handle subject, string name, integer value returns nothing
    if value==0 then
        call FlushStoredInteger(LocalVars(),I2S(H2I(subject)),name)
    else
call StoreInteger(LocalVars(), I2S(H2I(subject)), name, value)
    endif
endfunction

function SetHandleBoolean takes handle subject, string name, boolean value returns nothing
    if value==false then
        call FlushStoredBoolean(LocalVars(),I2S(H2I(subject)),name)
    else
call StoreBoolean(LocalVars(), I2S(H2I(subject)), name, value)
    endif
endfunction

function SetHandleReal takes handle subject, string name, real value returns nothing
    if value==0 then
        call FlushStoredReal(LocalVars(), I2S(H2I(subject)), name)
    else
call StoreReal(LocalVars(), I2S(H2I(subject)), name, value)
    endif
endfunction

function SetHandleString takes handle subject, string name, string value returns nothing
    if value==null then
        call FlushStoredString(LocalVars(), I2S(H2I(subject)), name)
else
        call StoreString(LocalVars(), I2S(H2I(subject)), name, value)
    endif
endfunction

function GetHandleHandle takes handle subject, string name returns handle
return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction
function GetHandleInt takes handle subject, string name returns integer
return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
endfunction
function GetHandleBoolean takes handle subject, string name returns boolean
    return GetStoredBoolean(LocalVars(), I2S(H2I(subject)), name)
endfunction
function GetHandleReal takes handle subject, string name returns real
    return GetStoredReal(LocalVars(), I2S(H2I(subject)), name)
endfunction
function GetHandleString takes handle subject, string name returns string
    return GetStoredString(LocalVars(), I2S(H2I(subject)), name)
endfunction

function GetHandleUnit takes handle subject, string name returns unit
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction
function GetHandleTimer takes handle subject, string name returns timer
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction
function GetHandleTrigger takes handle subject, string name returns trigger
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction
function GetHandleEffect takes handle subject, string name returns effect
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction
function GetHandleGroup takes handle subject, string name returns group
return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction
function GetHandleLightning takes handle subject, string name returns lightning
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction
function GetHandleWidget takes handle subject, string name returns widget
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction

function FlushHandleLocals takes handle subject returns nothing
    call FlushStoredMission(LocalVars(), I2S(H2I(subject)) )
endfunction


Nuke Trigger
JASS:
function Trig_Nuke_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A009'
endfunction

function Nuke_Effect takes nothing returns nothing
  local timer t = GetExpiredTimer()
  local unit dummy = H2U(GetHandleHandle(t, "dummy"))
  local real ang = GetHandleReal(t, "ang")
  local real i = GetHandleReal(t, "ang")
  local location o= GetUnitLoc(dummy)
  call SetUnitPosition(dummy,GetUnitX(dummy) + 20 * Cos(ang * bj_DEGTORAD),GetUnitY(dummy) + 20 * Sin(ang * bj_DEGTORAD))
  set i = i + 1

  if i == 100 then
    set dummy = CreateUnitAtLoc(GetOwningPlayer(dummy) , 'u004', o, ang )
    call SetUnitPathing(GetLastCreatedUnit(), false)
    call SetUnitFlyHeightBJ( GetLastCreatedUnit(), 0.00, 200.00 )
  endif

  if i == 200 then
    call RemoveUnit(dummy)
    call PauseTimer(t)
    call FlushHandleLocals(t)
    call PauseTimer(t)
    call DestroyTimer(t)
  endif
  
  call RemoveLocation(o)
  
  set t=null
  set dummy=null
  set o=null
endfunction

function Trig_Nuke_Actions takes nothing returns nothing
  local unit u = GetTriggerUnit()
  local unit dummy
  local location l = GetSpellTargetLoc()
  local real x = GetUnitX(u)
  local real y = GetUnitY(u)
  local real xtarg = GetLocationX(l)
  local real ytarg = GetLocationY(l)
  local real ang = bj_RADTODEG * Atan2(ytarg - y, xtarg - x)
  local timer t = CreateTimer()
  local location s = PolarProjectionBJ(Location(xtarg, ytarg), 2000., ang - 180)
  local real i = 0
  
  set dummy = CreateUnitAtLoc(GetOwningPlayer(u) , 'u003', s, ang )
  call SetUnitPathing(dummy, false)
  set i = 1

  call SetHandleHandle(t, "dummy", dummy)
  call SetHandleReal(t, "ang", ang)
  call SetHandleReal(t, "i", i)
  call TimerStart(t, 0.03, true, function Nuke_Effect)
  
  call RemoveLocation(l)
  call RemoveLocation(s)
  
  set u=null
  set dummy=null
  set l=null
  set t=null
  set s=null
endfunction

//===========================================================================
function InitTrig_Nuke takes nothing returns nothing
    set gg_trg_Nuke = CreateTrigger( )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Nuke, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Nuke, Condition( function Trig_Nuke_Conditions ) )
    call TriggerAddAction( gg_trg_Nuke, function Trig_Nuke_Actions )
endfunction
 
Level 9
Joined
Apr 5, 2008
Messages
529
First of all.

JASS:
  if i == 100 then
    //set dummy = CreateUnitAtLoc(GetOwningPlayer(dummy) , 'u004', o, ang )
    call SetUnitPathing(GetLastCreatedUnit(), false)
    call SetUnitFlyHeightBJ( GetLastCreatedUnit(), 0.00, 200.00 )
  endif

GetLastCreatedUnit() will return null, since it will only return the last created unit if you did it with the BJ function, CreateNUnits. Why not just use a local unit variable?

JASS:
  if i == 200 then
    call RemoveUnit(dummy)
    call PauseTimer(t)
call FlushHandleLocals(t)
    call PauseTimer(t)
    call DestroyTimer(t)
  endif

Pausing the timer is unnecessary.
I can only recomment TimerUtils. Everyone should use that one.

Why do you convert the coordinates to degrees? You do 2 bj_DEGTORAD calls every 0.03 second. If you just stay with radians you only need to do 2 bj_RADTODEG, the 2 where you create your units.

And don't use locations, they're slow. Just use coordinates instead.

Why do you declare a variable called "bomb" and save store it in the timer? You never use it.

I don't know what the problem is, but your timer will never stop. The problem is, that you store the integer "i", but you never increase the stored value, hench it will stay 0.
 
Status
Not open for further replies.
Top