• 🏆 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!
  • ✅ Time to vote for the top 3 models! The POLL for Hive's 6th HD Modeling Contest: Mechanical is now open! 📅 Poll close on July 16, 2024! 🔗 Cast your vote now!
  • ✅ The POLL for Hive's Texturing Contest #33 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!

[JASS] First JASS spell doesn't work, =(

Status
Not open for further replies.
Level 10
Joined
Nov 28, 2008
Messages
655

JASS:
function Trig_Holy_Light_JASS_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'AHhb' ) ) then
        return false
    endif
    return true
endfunction

function Trig_Holy_Light_JASS_Actions takes nothing returns nothing
    local unit castingunit = GetTriggerUnit()
    local unit targetunit = GetSpellTargetUnit()
    local integer level = GetUnitAbilityLevel(castingunit,'AHhb')
    local real damage = (level * -125.)
    call UnitDamageTarget(castingunit,targetunit,damage,true,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_MAGIC,null)
endfunction

//===========================================================================
function InitTrig_Holy_Light_JASS takes nothing returns nothing
    set gg_trg_Holy_Light_JASS = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Holy_Light_JASS, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Holy_Light_JASS, Condition( function Trig_Holy_Light_JASS_Conditions ) )
    call TriggerAddAction( gg_trg_Holy_Light_JASS, function Trig_Holy_Light_JASS_Actions )
endfunction
Just changed it from GUI to JASS, and tried to make it better...


The Straight GUI to JASS converted code:

JASS:
function Trig_Holy_Light_Copy_Copy_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'AHhb' ) ) then
        return false
    endif
    return true
endfunction

function Trig_Holy_Light_Copy_Copy_Actions takes nothing returns nothing
    set udg_Level = GetUnitAbilityLevelSwapped(GetSpellAbilityId(), GetSpellAbilityUnit())
    call UnitDamageTargetBJ( GetSpellAbilityUnit(), GetSpellTargetUnit(), ( -125.00 * I2R(udg_Level) ), ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL )
endfunction

//===========================================================================
function InitTrig_Holy_Light_Copy_Copy takes nothing returns nothing
    set gg_trg_Holy_Light_Copy_Copy = CreateTrigger(  )
    call DisableTrigger( gg_trg_Holy_Light_Copy_Copy )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Holy_Light_Copy_Copy, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Holy_Light_Copy_Copy, Condition( function Trig_Holy_Light_Copy_Copy_Conditions ) )
    call TriggerAddAction( gg_trg_Holy_Light_Copy_Copy, function Trig_Holy_Light_Copy_Copy_Actions )
endfunction


Am willing to learn, please show me my errors, be as honest as possible, I want to learn the RIGHT way.
 
Level 8
Joined
Feb 15, 2009
Messages
463
You don't need that long variable names, they just block your time

Usual way is
locals single letter e.g. local unit u
globals CAPS_LOCK e.g. private constant real HEAL_PER_LEVEL

Also i suggest getting ,JNGP<-- link because you will use it one day anyways and it also helps learning JASS because of the syntax highlight.

Furthermore:

Such simple spells are still more efficient in the standard hardcoded way. A simple chainheal with 1 target would do this perfectly too.

But this should be what it look like in normal JASS

JASS:
function Trig_Holy_Light_JASS_Conditions takes nothing returns boolean
    local unit u
    local unit t
    local real h

    if  GetSpellAbilityId() == 'AHhb' then 
    
        set u = GetTriggerUnit()
        set t = GetSpellTargetUnit()
        set h = GetUnitAbilityLevel(u , 'AHhb') * 125.
        call SetUnitState( t , UNIT_STATE_LIFE , GetUnitState( t , UNIT_STATE_LIFE) + h )
        set u = null
        set t = null
    endif

   return false
endfunction

//===========================================================================
function InitTrig_Holy_Light_JASS takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( t , EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( t, Condition( function Trig_Holy_Light_JASS_Conditions ) )
endfunction




Here is a vJass version for your further career =D

JASS:
scope Heal initializer Init

globals
    private constant integer ID = 'AHhb'
    //The Id of the Spell press ctrl+D in OE to see it
    private constant real HEAL_PER_LEVEL = 125.
    //How much HP are healed per Abilitylevel
endglobals

private function Conditions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local unit t
    local real h
    
    if GetSpellAbilityId() == ID then
    
        set u = GetTriggerUnit()
        set t = GetSpellTargetUnit()
        set h = GetUnitAbilityLevel(u , ID ) * HEAL_PER_LEVEL
        call SetUnitState( t , UNIT_STATE_LIFE , GetUnitState( t , UNIT_STATE_LIFE) + h )
        set u = null
        set t = null
    endif

    return false
endfunction

private function Init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( t , EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( t, Condition( function Conditions ) )
endfunction
endscope

Only the Eventleak could be improved (too lazy to type now but it's no problem to let it be , I'm also never removing it).
The rest is fine but still remember the standart blizz spells for such things =D
(think this was just training or ? =D)

Gratz and study hard Saia_Djinn
 
Level 10
Joined
Nov 28, 2008
Messages
655
Thanks, few questions though:


1. Could you point out what I did that is the thing that is not working as intended?
2. As GhostWolf said, that works, but is setting the life, what would the syntax be for that? (If mine is not correct)
3. You are setting units to null at the end, but not the real, why are you nulling/not nulling those?


Thanks dudes!
 
Level 8
Joined
Feb 15, 2009
Messages
463
Those function calls do not have the same effect. Setting the state simply sets the state, but damaging actually registers the unit making the damage, aside from having damage types and such.

It's just a simple heal spell and therefore setting the State is better then a negative damage because we don't need to set the unit for anything(or maybe use the return of the damage function is also useless in this simple case)



Thanks, few questions though:


1. Could you point out what I did that is the thing that is not working as intended?
Your version should have been working i just improved

2. As GhostWolf said, that works, but is setting the life, what would the syntax be for that? (If mine is not correct)

I wrote down the correct one :grin:(for me =E ), because it's a heal spell
There are more solution, you can also do negative damage or
JASS:
call SetWidgetLife
it's totally wayne


3. You are setting units to null at the end, but not the real, why are you nulling/not nulling those?


I null the units, because if they are dying the pointer is removed and the restleak is removed through

Integers , reals and booleans can't and don't have to be nulled because they are the only primary types in Wc3
try it and you will get a compile error


Thanks dudes!
No Problem man
 
Status
Not open for further replies.
Top