• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] How to make this code better

Status
Not open for further replies.
Level 10
Joined
Jan 21, 2007
Messages
576
Alright this shouldn't be hard for experienced jass-users out there so all help is appreciated. I made this trigger in gui and want to convert it to jass to optimize, simplify, and make it faster. Rather, I already converted it to jass but it is the choppy editor conversion. So here is the code:

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

function Trig_Masters_Influence_Func002001003 takes nothing returns boolean
    return ( IsUnitType(GetFilterUnit(), UNIT_TYPE_HERO) == false )
endfunction

function Trig_Masters_Influence_Func002Func001C takes nothing returns boolean
    if ( not ( GetPlayerController(GetOwningPlayer(GetEnumUnit())) != MAP_CONTROL_USER ) ) then
        return false
    endif
    return true
endfunction

function Trig_Masters_Influence_Func002A takes nothing returns nothing
    if ( Trig_Masters_Influence_Func002Func001C() ) then
        call IssueTargetOrderBJ( GetEnumUnit(), "attack", GetAttackedUnitBJ() )
        call AddSpecialEffectTargetUnitBJ( "overhead", GetEnumUnit(), "Abilities\\Spells\\Other\\TalkToMe\\TalkToMe.mdl" )
        call DestroyEffectBJ( GetLastCreatedEffectBJ() )
    else
    endif
endfunction

function Trig_Masters_Influence_Actions takes nothing returns nothing
    set udg_p = GetUnitLoc(GetAttacker())
    call ForGroupBJ( GetUnitsInRangeOfLocMatching(250.00, udg_p, Condition(function Trig_Masters_Influence_Func002001003)), function Trig_Masters_Influence_Func002A )
endfunction

//===========================================================================
function InitTrig_Masters_Influence takes nothing returns nothing
    set gg_trg_Masters_Influence = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Masters_Influence, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddCondition( gg_trg_Masters_Influence, Condition( function Trig_Masters_Influence_Conditions ) )
    call TriggerAddAction( gg_trg_Masters_Influence, function Trig_Masters_Influence_Actions )
endfunction

So any ideas to make this simpler? And a reason for why you change this and use that instead would be helpful, I am trying to learn here ;].
 
Level 16
Joined
Feb 22, 2006
Messages
960
so this should work the same way :)

JASS:
function miCond takes nothing returns boolean
    return GetUnitAbilityLevel(GetTriggerUnit(),'B000') > 0
endfunction

function miActions takes nothing returns nothing
  local unit attacker = GetAttacker()
  local unit trigunit = GetTriggerUnit()
  local real x = GetUnitX(attacker)
  local real y = GetUnitY(attacker)
  local group g
  local unit u  
  local effect sfx
    call GroupEnumUnitsInRange(g,x,y,250,null)
    loop
         set u = FirstOfGroup(g)
         exitwhen u == null  
         if ((GetPlayerController(GetOwningPlayer(attacker)) != MAP_CONTROL_USER) and IsUnitType(u, UNIT_TYPE_HERO) == false) then
             set x = GetUnitX(u)
             set y = GetUnitY(u)
             call IssueTargetOrderBJ(attacker, "attack",trigunit) 
             set sfx = AddSpellEffectTarget("Abilities\\Spells\\Other\\TalkToMe\\TalkToMe.mdl",u,"overhead")
             call DestroyEffect(sfx)
             call GroupRemoveUnit(g,u)
         else
             call GroupRemoveUnit(g,u)
         endif
    endloop
  call DestroyGroup(g)
  set attacker = null
  set trigunit = null
  set g = null
  set u = null
  set sfx = null  
endfunction

function InitTrig_Masters_Influence takes nothing returns nothing
  local trigger mi = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(mi, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddCondition(mi,Condition( function miCond))
    call TriggerAddAction(mi,function miActions)
  set mi = null
endfunction
 
Level 10
Joined
Jan 21, 2007
Messages
576
Alright thanks man, +rep. But I'm pretty sure I heard BJ's leak or are bad or something, if thats true is there any better alternitive to the one you have or is that the only way to go about that.

EDIT: Btw your code as of now is semi-broken. The reason I checked if the attacking unit had a buff was because this trigger is only supposed to happen when he has the ability activated, based on immolation, which I detect by checking the buff. So right now units will attack what he attacks wether or not he has it activated.
 
Level 16
Joined
Feb 22, 2006
Messages
960
hm the line
JASS:
return GetUnitAbilityLevel(GetTriggerUnit(),'B000') > 0
should also check if the unit has the specific buff and i see, in my script i used a bj, better use the non bj, i only copied it from yours (BJs are not as fast as nativs, because they are also functions which are executed)
 
Level 8
Joined
Mar 20, 2007
Messages
224
Most BJ's are bad, because they are slow.

How are they slow?

JASS:
function AddItemToStockBJ takes integer itemId, unit whichUnit, integer currentStock, integer stockMax returns nothing
    call AddItemToStock(whichUnit, itemId, currentStock, stockMax)
endfunction

As you can see, all the BJ does is call a native. So you might as well just call the native.

Some BJ's, however, do more then just call natives.
 
Status
Not open for further replies.
Top