• 🏆 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] Spell doesn't seem to work

Status
Not open for further replies.
Level 7
Joined
Oct 8, 2008
Messages
200
JASS:
function attack_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A000' ) ) then
        return false
    endif
    return true
endfunction

function HeartTarget takes integer level returns nothing
local integer heart = 0
if level == 1  then         
loop
exitwhen heart == 20
set heart = ( heart + 1 )
call UnitDamageTargetBJ( GetTriggerUnit(), GetSpellTargetUnit(), 4, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL )
call TriggerSleepAction( 1 )
endloop
else 
if level == 2 then
loop
exitwhen heart == 20
set heart = ( heart + 1 )
call UnitDamageTargetBJ( GetTriggerUnit(), GetSpellTargetUnit(), 6, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL )
call TriggerSleepAction( 1 )
endloop
else
if level == 3 then
loop 
exitwhen   heart == 20
set heart = ( heart + 1 )
call UnitDamageTargetBJ( GetTriggerUnit(), GetSpellTargetUnit(), 8, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL )
call TriggerSleepAction( 1 )
endloop
else
endif
endif
endif   
set heart = null
endfunction

function MuscleTarget takes integer level returns nothing
local integer muscle = 0
if level == 1  then         
loop
exitwhen muscle == 10
set muscle = ( muscle + 2 )
call PauseUnitBJ( true, GetSpellTargetUnit() )
call TriggerSleepAction (0.2)
call PauseUnitBJ( false, GetSpellTargetUnit() )
call TriggerSleepAction( 2 )
endloop
else 
if level == 2 then
loop
exitwhen muscle == 10
set muscle = ( muscle + 2 )
call PauseUnitBJ( true, GetSpellTargetUnit() )
call TriggerSleepAction (0.4)
call PauseUnitBJ( false, GetSpellTargetUnit() )
call TriggerSleepAction( 2 )
endloop
else
if level == 3 then
loop 
exitwhen   muscle == 10
set muscle = ( muscle + 2 )
call PauseUnitBJ( true, GetSpellTargetUnit() )
call TriggerSleepAction (0.6)
call PauseUnitBJ( false, GetSpellTargetUnit() )
call TriggerSleepAction( 2 )
endloop
else
endif
endif
endif  
set muscle = null
endfunction

function ArmorTarget takes integer level returns nothing
endfunction

function attack_Actions takes nothing returns nothing
local integer level
local unit target
local unit caster
set level = GetUnitAbilityLevel ( GetTriggerUnit(),'A001')
    
    if udg_buffselected == 0 then
    call HeartTarget(level)
    else
        if udg_buffselected == 1 then   
        call  MuscleTarget(level)
        
        else
            if udg_buffselected == 2 then
            call ArmorTarget(level)
            else
        endif
    endif
    endif
endfunction
//===========================================================================
function InitTrig_attack takes nothing returns nothing
    local trigger attack = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( attack, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( attack, Condition( function attack_Conditions ) )    
    call TriggerAddAction( attack, function attack_Actions )                      
    set attack = null
endfunction
I can't tell whats wrong with it
 
Level 9
Joined
Apr 5, 2008
Messages
529
There's a few areas you can improve
JASS:
JASS:
set level = GetUnitAbilityLevel ( GetTriggerUnit(),'A001')

JASS:
function attack_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A000' ) ) then
        return false
    endif 
   return true
endfunction
Your condition checks if the spell rawcode is 'A000', your other line checks the level of 'A001'.

This:
JASS:
function attack_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A000' ) ) then
        return false
    endif 
   return true
endfunction
can be shortened to this:
JASS:
function attack_Conditions takes nothing returns boolean
  return GetSpellAbilityId() == 'A000'
endfunction

In your attack_Actions function you declare 2 unit variables, target and caster, but you never use them?



JASS:
if udg_buffselected == 0 then
    call HeartTarget(level)
    else
        if udg_buffselected == 1 then
        call  MuscleTarget(level)
        else
            if udg_buffselected == 2 then
            call ArmorTarget(level)
            else
        endif
    endif
    endif

Can be shortened to:

JASS:
    if udg_buffselected == 0 then
        call HeartTarget(level)
    elseif udg_buffselected == 1 then
        call  MuscleTarget(level)
     elseif udg_buffselected == 2 then
        call ArmorTarget(level)
    endif


The problem with your trigger seems to be the functions you call. You're using
JASS:
GetSpellTargetUnit()
in them. That will return null, since you called the function using the action function. Make the muscle/heart fucntion take an unit parameter and use that one instead.



JASS:
call PauseUnitBJ( false, GetSpellTargetUnit() )

That call is unnecessary, use the native instead.

JASS:
call PauseUniJ( whchUnit false) //whichUnit being the unit the function takes


And a little hint, avoid using TriggerSleepAction at ALL COST! It's an evil function.

I'll rewrite your code tomorow so it's more efficient, shoot me a PM so i don't forget. :wink:
 
Status
Not open for further replies.
Top