• 🏆 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] what is wrong with this code?

Status
Not open for further replies.
Level 3
Joined
Sep 14, 2007
Messages
43
JASS:
function Trig_Transfer_Energy_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A045' ) ) then
        return false
    endif
    return true
endfunction

function MySpell_Stop_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A045' or GetTriggerUnit() == null
endfunction

function MySpell_Stop_Actions takes nothing returns nothing
    local trigger t = GetTriggeringTrigger()
    local unit dummy = GetHandleUnit(t,"dummy") 
    call SetUnitUserData( dummy, 1 )
    set dummy = null
    set t = null
endfunction


function Trig_Transfer_Energy_Actions takes nothing returns nothing
     local real i = 0
    local unit u = GetTriggerUnit()
    local integer level = GetUnitAbilityLevel(u,'A045')
    local trigger t = CreateTrigger()
    local triggeraction ta = TriggerAddAction(t, function MySpell_Stop_Actions)
    local triggercondition tc = TriggerAddCondition(t, Condition(function MySpell_Stop_Conditions))
    local unit dummy = CreateUnit(Player(1),'n02E' ,GetUnitX(u) + Cos(bj_DEGTORAD * GetUnitFacing(u)) * 130, GetUnitY(u) + Sin(bj_DEGTORAD * GetUnitFacing(u)) * 130, GetUnitFacing(u))
    call TriggerRegisterPlayerUnitEvent(t, GetOwningPlayer(u), EVENT_PLAYER_UNIT_SPELL_ENDCAST, null)
    call SetHandleHandle(t,"dummy",dummy)
    loop
    exitwhen(GetBooleanOr(i==6.0,GetUnitUserData(dummy) == 1)) 
    call TriggerSleepAction(0.5)   
    if(level > 1) then
    call SetUnitScale(dummy,0.2 + i * I2R(level) * 0.1,0.2 + i * I2R(level) * 0.1,0.2 + i * I2R(level) * 0.1)
    elseif (level == 1) then
    call SetUnitScale(dummy,0.2 + i * I2R(level) * 0.15,0.2 + i * I2R(level) * 0.15,0.2 + i * I2R(level) * 0.15)
    endif
    set i=i+1.0
    endloop
    if(GetUnitUserData(dummy) != 1) then
    call UnitRemoveAbility(u,'A045')
    call UnitAddAbility(u,'A043')
    call SetUnitAbilityLevel(u,'A043',level)
   endif
    call RemoveUnit(dummy)
    set dummy = null
    set u = null
    call DestroyTrigger(t)
   call TriggerRemoveAction(t,ta)
   call TriggerRemoveCondition(t,tc)
endfunction

//===========================================================================
function InitTrig_Transfer_Energy takes nothing returns nothing
    set gg_trg_Transfer_Energy = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Transfer_Energy, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition( gg_trg_Transfer_Energy, Condition( function Trig_Transfer_Energy_Conditions ) )
    call TriggerAddAction( gg_trg_Transfer_Energy, function Trig_Transfer_Energy_Actions )
endfunction



this code suppose to create something and if the caster moves delete it, everything works fine exept for the deleting the unit part.
if you find leaks please tell me about them also :)
 
Last edited:
Level 3
Joined
Sep 14, 2007
Messages
43
why everytime i edit my post the jass box becomes too small to read? (i posted this to get the code box back to normal)
 
Level 9
Joined
Aug 10, 2007
Messages
92
GetBooleanOr(i==6.0,GetUnitUserData(dummy) == 1))

you could replace that with a simple:

if i==6 or GetUnitUserData(dummy) == 1 then

JASS:
    if ( not ( GetSpellAbilityId() == 'A045' ) ) then
        return false
    endif
    return true

replace that with return GetSpellAbilityId() == 'A045' as you did with the other condition.

Also your trigger action can be deleted if you put its actions inside the condition, just return true or false in the end, works fine as long as you don't have any waits in it.

Use a BJDebugMsg to find out if the unit variable is lost (null), that could be one reason for malfunction.
 
Level 3
Joined
Sep 14, 2007
Messages
43
Thanks, i'll change all that, but my main problem is that the dummy unit doesnt disappear when i press on key 's' and i have no idea why :(
 
Status
Not open for further replies.
Top