• 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.

More Efficient Way To Do This?

Status
Not open for further replies.
Is there a more efficient/better way of doing this?

Basically the skill adds +3 armor for each nearby ally (along with some base armor and hp from a research)

  • Herd
    • Events
      • Unit - A unit Learns a skill
    • Conditions
      • (Learned Hero Skill) Equal to Herd Mentality
    • Actions
      • Set caster = (Triggering unit)
      • Player - Set the current research level of Herd Mentality to (Level of Herd Mentality for caster) for (Owner of caster)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (caster is in HerdGroup) Equal to False
        • Then - Actions
          • Trigger - Turn on Herd Check <gen>
          • Unit - Add Herd (+3) to caster
          • Unit - Set level of Herd (+3) for caster to 1
          • Unit Group - Add caster to HerdGroup
        • Else - Actions
  • Herd Check
    • Events
      • Time - Every 1.50 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in HerdGroup and do (Actions)
        • Loop - Actions
          • Set caster = (Picked unit)
          • Set point1 = (Position of caster)
          • Set i = 1
          • Custom script: set bj_wantDestroyGroup = true
          • Unit Group - Pick every unit in (Units within 400.00 of point1 matching ((((Matching unit) is A Hero) Equal to True) and ((((Matching unit) is alive) Equal to True) and ((((Matching unit) belongs to an ally of (Owner of caster)) Equal to True) and (((Matching unit) is in HerdGroup) Equal to and do (Actions)
            • Loop - Actions
              • Set i = (i + 1)
          • Unit - Set level of Herd (+3) for caster to i
          • Custom script: call RemoveLocation(udg_point1)
It just seems like making a check all the time would cause lag. The spell does work though.
 
Everything always depends on something else ^_^

If you have 480x480 map with high res terrain, very low fps rate and like 25 such like or even more complex triggers with timers running in background of your RPG map this defiantly looks bad. So you need to pause timer when there is no unit with such ability on map and so on.

But if you have all together 10 triggers this is funny even leaks won't mater.

To me the most efficient way is pure jass code with unit within range event.
But you will still need timer to check unit leave event because you need to code this on your own.
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
But be aware that this event is not instant, as you can test yourself with this script :

JASS:
scope TestRangeEvent initializer init

    globals
        private timer Tim = CreateTimer()
        private real Previous = 0
    endglobals
    
    private function Start takes nothing returns nothing
        local real r =  TimerGetElapsed(Tim) - Previous
        
        call BJDebugMsg(R2S(r))
        set Previous = TimerGetElapsed(Tim)
        call CreateUnit(Player(0),'hfoo',0,0,0)      
    endfunction

    private function init takes nothing returns nothing
        local trigger trig = CreateTrigger()
        
        call TriggerRegisterUnitInRange(trig,CreateUnit(Player(0),'Hpal',0,0,0),200,null)
        call TriggerAddAction(trig,function Start)
        call CreateUnit(Player(0),'hfoo',0,0,0)
        call TimerStart(Tim,10,false,null)
    endfunction
    
endscope

It's about 0.125 s , for some reason the first time i takes 0.13 s , maybe it's something related with timers and reals inaccuracy.
It should be enough low for most of things but it's definetely something to know.

Now, i've not made better tests but i suppose there is a permanent check every 0.125 s, and between two ticks unit positions are ignored.
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
Forget what i said about the inaccuracy, nothing really important, we are talking about 0.005 s margin ...
As Mag said i suppose this event acts in fact like a periodic timer of 0.125 to check units distances and eventually fire range events.
But it's far more efficient than doing the same in jass with a timer, because it's directly done inside the wc3 engine.

If you don't have a performance issue it's fine.
Anyway GUI is all but not efficient, you can't really make it more efficient while keeping use GUI.


That script causes a very slow infinite loop :p

No Mag, there is trick, actually the trigger will fire during only few seconds ^^ (assuming you're not doing something else)
 
Status
Not open for further replies.
Top