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

[JASS] Inlining

Status
Not open for further replies.
Level 6
Joined
Aug 1, 2009
Messages
159
I just wanted to learn how to inline triggers :(. But I cant just get it to work, when I delete the BJs or turn them to natives, script errors occur.

This is just an converted text :p.

JASS:
function Trig_AP_Start_Conditions takes nothing returns boolean
    if ( not ( UnitHasBuffBJ(GetAttackedUnitBJ(), 'B000') == true ) ) then
        return false
    endif
    return true
endfunction

function Trig_AP_Start_Func013002003 takes nothing returns boolean
    return ( IsUnitAliveBJ(GetFilterUnit()) == true )
endfunction

function Trig_AP_Start_Func017Func002A takes nothing returns nothing
    call UnitDamageTargetBJ( udg_AP_Caster, GetEnumUnit(), udg_AP_Damage, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_SONIC )
    call AddSpecialEffectTargetUnitBJ( "overhead", GetEnumUnit(), "Abilities\\Spells\\Other\\CrushingWave\\CrushingWaveDamage.mdl" )
    call DestroyEffectBJ( GetLastCreatedEffectBJ() )
endfunction

function Trig_AP_Start_Func017C takes nothing returns boolean
    if ( not ( udg_AP_Chance <= 10 ) ) then
        return false
    endif
    return true
endfunction

function Trig_AP_Start_Actions takes nothing returns nothing
    // -----------------------------------------------------------------------------------------------------------------
    // ----------------------------------------------- Variables --------------------------------------------------
    // -----------------------------------------------------------------------------------------------------------------
    set udg_AP_Caster = GetAttackedUnitBJ()
    // -----------------------------------------------------------------------------------------------------------------
    set udg_AP_Loc[0] = GetUnitLoc(udg_AP_Caster)
    // -----------------------------------------------------------------------------------------------------------------
    set udg_AP_Damage = 150.00
    set udg_AP_Aoe = 300.00
    // -----------------------------------------------------------------------------------------------------------------
    set udg_AP_Chance = GetRandomInt(0, 100)
    // -----------------------------------------------------------------------------------------------------------------
    set udg_AP_Group = GetUnitsInRangeOfLocMatching(udg_AP_Aoe, udg_AP_Loc[0], Condition(function Trig_AP_Start_Func013002003))
    // -----------------------------------------------------------------------------------------------------------------
    // ------------------------------------------------- Actions --------------------------------------------------
    // -----------------------------------------------------------------------------------------------------------------
    if ( Trig_AP_Start_Func017C() ) then
        set bj_forLoopAIndex = 1
        set bj_forLoopAIndexEnd = 6
        loop
            exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
            set udg_AP_Loc[1] = PolarProjectionBJ(udg_AP_Loc[0], ( udg_AP_Aoe - ( udg_AP_Aoe / 10.00 ) ), ( 60.00 * I2R(GetForLoopIndexA()) ))
            set udg_AP_Loc[2] = PolarProjectionBJ(udg_AP_Loc[0], 100.00, ( 60.00 * I2R(GetForLoopIndexA()) ))
            call AddSpecialEffectLocBJ( udg_AP_Loc[1], "Objects\\Spawnmodels\\Naga\\NagaDeath\\NagaDeath.mdl" )
            call DestroyEffectBJ( GetLastCreatedEffectBJ() )
            call AddSpecialEffectLocBJ( udg_AP_Loc[2], "Objects\\Spawnmodels\\Naga\\NagaDeath\\NagaDeath.mdl" )
            call DestroyEffectBJ( GetLastCreatedEffectBJ() )
            // -----------------------------------------------------------------------------------------------------------------
            // --------------------------------------------Clearing Leaks----------------------------------------------
            // -----------------------------------------------------------------------------------------------------------------
            call RemoveLocation(udg_AP_Loc[1])
            call RemoveLocation(udg_AP_Loc[2])
            set bj_forLoopAIndex = bj_forLoopAIndex + 1
        endloop
        call ForGroupBJ( udg_AP_Group, function Trig_AP_Start_Func017Func002A )
        // -----------------------------------------------------------------------------------------------------------------
        // --------------------------------------------Clearing Leaks----------------------------------------------
        // -----------------------------------------------------------------------------------------------------------------
        set udg_AP_Caster = null
        // -----------------------------------------------------------------------------------------------------------------
        call RemoveLocation(udg_AP_Loc[0])
        // -----------------------------------------------------------------------------------------------------------------
        call DestroyGroup(udg_AP_Group)
    else
    endif
endfunction

//===========================================================================
function InitTrig_AP_Start takes nothing returns nothing
    set gg_trg_AP_Start = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_AP_Start, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddCondition( gg_trg_AP_Start, Condition( function Trig_AP_Start_Conditions ) )
    call TriggerAddAction( gg_trg_AP_Start, function Trig_AP_Start_Actions )
endfunction

I know how to turn the condition of an spell that is (ability being casted) but this is attacked unit.
 
Level 14
Joined
Nov 18, 2007
Messages
1,084
The easiest way to inline code is to have a JNGP since you can look up BJ functions easily with Function List and replace them with what they refer to.

Since it's easier to explain with an example, I inlined your code and put comments.

JASS:
function Trig_AP_Start_Conditions takes nothing returns boolean
    //GetTriggerUnit() refers to the unit that has been attacked
    //UnitHasBuffBJ basically does this check
    return GetUnitAbilityLevel(GetTriggerUnit(),'B000') > 0
endfunction

function Trig_AP_Start_Func013002003 takes nothing returns boolean
    //Alternative way to check if a unit is alive
    return not IsUnitType(GetFilterUnit(),UNIT_TYPE_DEAD) and GetUnitTypeId(GetFilterUnit()) != 0
endfunction

function Trig_AP_Start_Func017Func002A takes nothing returns nothing
    //Just inlined functions
    call UnitDamageTarget(udg_AP_Caster,GetEnumUnit(),udg_AP_Damage,false,false,ATTACK_TYPE_NORMAL,DAMAGE_TYPE_SONIC,null)
    //Since you destroy this effect once it's created, you can do this:
    call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Other\\CrushingWave\\CrushingWaveDamage.mdl",GetEnumUnit(),"overhead"))
endfunction

function Trig_AP_Start_Actions takes nothing returns nothing
    //Better to use coordinates instead of locations
    local real x
    local real y
    local real px //Used to replace polar functions
    local real py
    local integer chance = GetRandomInt(0, 100) //You don't need a global for this.
    local integer index = 1 //Use this for looping instead of a global to avoid conflicting
    // -----------------------------------------------------------------------------------------------------------------
    // ----------------------------------------------- Variables --------------------------------------------------
    // -----------------------------------------------------------------------------------------------------------------
    set udg_AP_Caster = GetTriggerUnit()
    // -----------------------------------------------------------------------------------------------------------------
    set x = GetUnitX(udg_AP_Caster)
    set y = GetUnitY(udg_AP_Caster)
    // -----------------------------------------------------------------------------------------------------------------
    set udg_AP_Damage = 150.00
    set udg_AP_Aoe = 300.00
    // -----------------------------------------------------------------------------------------------------------------
    set udg_AP_Group = GroupEnumUnitsInRange(udg_AP_Group,x,y,udg_AP_Aoe,Condition(function Trig_AP_Start_Func013002003))
    // -----------------------------------------------------------------------------------------------------------------
    // ------------------------------------------------- Actions --------------------------------------------------
    // -----------------------------------------------------------------------------------------------------------------
    if chance <= 10 then //Can use the conditional directly
        loop
            exitwhen index > 6
            //Using Coordinates instead of location
            set px = x + (udg_AP_Aoe - (udg_AP_Aoe / 10.00 ))*Cos(index*60.*bj_DEGTORAD)
            set py = y + (udg_AP_Aoe - (udg_AP_Aoe / 10.00 ))*Sin(index*60.*bj_DEGTORAD)
            call DestroyEffect(AddSpecialEffect("Objects\\Spawnmodels\\Naga\\NagaDeath\\NagaDeath.mdl",px,py))
            set px = x + 100*Cos(index*60*bj_DEGTORAD)
            set py = y + 100*Sin(index*60*bj_DEGTORAD)
            call DestroyEffect(AddSpecialEffect("Objects\\Spawnmodels\\Naga\\NagaDeath\\NagaDeath.mdl",px,py))
            // -----------------------------------------------------------------------------------------------------------------
            // --------------------------------------------Clearing Leaks----------------------------------------------
            // -----------------------------------------------------------------------------------------------------------------
            set index = index + 1
        endloop
        call ForGroup(udg_AP_Group, function Trig_AP_Start_Func017Func002A)
        // -----------------------------------------------------------------------------------------------------------------
        // --------------------------------------------Clearing Leaks----------------------------------------------
        // -----------------------------------------------------------------------------------------------------------------
        //You don't really need to do this since it's a global
        //set udg_AP_Caster = null 
        // -----------------------------------------------------------------------------------------------------------------
        //It's kind of bad to destroy groups... It might be better to just use GroupClear on that variable and then use that variable in all your group enum functions
        call DestroyGroup(udg_AP_Group)
    //Don't need an else if you don't do anything there
    endif
endfunction

//===========================================================================
function InitTrig_AP_Start takes nothing returns nothing
    //Better to use a local variable instead of global
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddCondition( t, Condition( function Trig_AP_Start_Conditions ) )
    call TriggerAddAction( t, function Trig_AP_Start_Actions )
endfunction
 
Level 6
Joined
Aug 1, 2009
Messages
159
Ohh so thats why, How do you know when to use
JASS:
*bj_DEGTORAD
since I see that you always replace the I2R part (Integer to String)
 
Level 6
Joined
Aug 1, 2009
Messages
159
You mentioned JNGP I have that but how do I use TESH like what you said the Function List.
 
Level 14
Joined
Nov 18, 2007
Messages
1,084
You can use Function List whenever you're doing Jass in the Trigger Editor.

Edit: Geez, I only provided a picture to help X3n0nX.
Stop making fun of my ugly style. >_<
 

Attachments

  • Function List.PNG
    Function List.PNG
    18.4 KB · Views: 117
Last edited:
Level 6
Joined
Aug 1, 2009
Messages
159
Your styles are good, but, how do I use them. For example, replacing the IsUnitAliveBJ to not an BJ since I dont really know how to use the Function List.
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
PurgeandFire111 said:
@Berb: Your style reminds me of JASSCraft. :p

I prefer light text on a dark background, it's easier on the eyes. Also I find it so lame that natives are purple. I sort of like how Bribe's keywords are blue but I like my style the very best, that is of course besides PurgeandFire111's style which is so easy to read it can only be read by the mentally and physically impaired.
 
Status
Not open for further replies.
Top