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

[vJASS] Filter Test

Status
Not open for further replies.
THIS IS SOLVED AND NEEDS TO BE CLOSED

Does this work for you?, well it works for me but when I use this setup in my EngageSystem system, it doesnt, idk why..., tested only for 1 or more units but not all units that is registered wants to engage...

JASS:
scope D

globals
    private hashtable HASH = InitHashtable()
    private group G = CreateGroup()
endglobals

struct D

    static method groupLooper takes nothing returns nothing
        local unit u = GetEnumUnit()
        local unit filter = GetClosestUnit(GetUnitX(u),GetUnitY(u),LoadBooleanExprHandle(HASH,GetHandleId(u),100))
        call BJDebugMsg(GetUnitName(u)+"===ATTACKS==="+GetUnitName(filter))
        call IssuePointOrder(u,"attack",GetUnitX(filter),GetUnitY(filter))
        set u = null
        set filter = null
    endmethod
    
    static method forGroup takes nothing returns nothing
        call ForGroup(G,function thistype.groupLooper)
    endmethod    
    
    static method SetUnitLockTargets takes unit u, boolexpr b returns nothing
        call SaveBooleanExprHandle(HASH,GetHandleId(u),100,b)
    endmethod
    
    static method RegisterHero takes unit u returns nothing
        call GroupAddUnit(G,u)
    endmethod  
    
    static method onInit takes nothing returns nothing
        call TimerStart(CreateTimer(),2.0,true,function thistype.forGroup)    
    endmethod

endstruct

endscope

JASS:
//this is written in the map header
native UnitAlive takes unit u returns boolean

function filterU takes nothing returns boolean
    return UnitAlive(GetFilterUnit()) and IsUnitEnemy(udg_U,GetOwningPlayer(GetFilterUnit()))
endfunction


  • Setup NOT WORKING
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units in (Playable map area)) and do (Actions)
        • Loop - Actions
          • Set U = (Picked unit)
          • Custom script: call D.RegisterHero(udg_U)
          • Custom script: call D.SetUnitLockTargets(udg_U, Filter(function filterU))
  • Setup WORKING
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • -------- This is working but for 1 unit only --------
      • Set U = Mountain King 0006 <gen>
      • Custom script: call D.RegisterHero(udg_U)
      • Custom script: call D.SetUnitLockTargets(udg_U, Filter(function filterU))
EDIT:
Full test code posted...
 

Attachments

  • FilterTest.w3x
    22.9 KB · Views: 57
Last edited:
EngageSystem is in the spell's section, I want to replace the API SetUnitLockTargets to this;
JASS:
static method SetUnitLockTargets takes unit u, boolexpr b, real atkdur returns nothing
   call SaveBooleanExprHandle(HASH,GetHandleId(u),2,b)
   call SaveReal(HASH,GetHandleId(u),3,atkdur)
endmethod

so that I can use like this...
set .target = GetClosestUnit(xAttacker,yAttacker,LoadBooleanExprHandle(HASH,uID,2))

I already tracks it like this and it registers fine;
call BJDebugMsg(GetUnitName(.target))

but still it doesnt work, the units doesnt attack...
 
Level 15
Joined
Jul 6, 2009
Messages
889
Your code looks fine (note, I'm quite blind when reading code). Perhaps the problem is something else? I don't know. You're confusing me. Does the code in the first post work at all? You say it works for you but then fails to work with EngageSystem. So I am inclined to think it is something to do with your EngageSystem, but perhaps if you post the testmap and we take a look at it we can find out the problem of why it "doesn't work, the units doesn't attack".
 
Does the code in the first post work at all?
The first post works, the reason for the boolexpr is changing targets, whether you want the hero to target only structures/heroes/Player1/neutral hostile, etc...
Ima put a sample map here tonight so that you can see what I mean of "doesn't work, the units doesn't attack"...

EDIT:

Map attached
 
Last edited:
All scope globals are private right, there is no need to make them EXTRA private ^_^
Just like you don't need to make onInit private methods in all structs because those are private as well.

Just small notice, also why scopes and structs at first place, especially because I don't see point here.

I had habit to use struct for everything, replaced actions with conditions bla bla bla, but after some time this started to create more errors than good things.

Use regular Jass, libraries and organized code, use structs only where you really need them. That's my advice, cuz I re-coded SotP so many times for nothing >.>
 
no Bribe, this is the order;
- library
- map header
- scopes

afaik, the boolexpr is saved by different parentID's so it shouldnt conflict things and it will be recalled
when you filter the units during the Enum...but idk why this doesnt work, maybe it's another bug?...

structs can make your code semi private by adding a prefix 'D' when compiled, so if I want a function called
'GetDistance' then it would not conflict things if I make 100 of them but different struct names...
unlike functions you cant do that except if you want to put a prefix manually...

Changing it to functions and library doesnt solve this, tested already...
 
Level 15
Joined
Jul 6, 2009
Messages
889
Uh. You do know that your udg_U refers to the unit last set in the initialisation? This unit happens to be the farm. So you will want to set udg_U to the u in groupLooper. That way, the filter will be able to check that the attacking unit is enemy to the filter unit, instead of being a constant unit. I've made the changes and it does work. I mean, you're ordering the Blood Mage to attack itself, wtf?

This has nothing to do with the way things are called. It's merely just error with the values that variables are holding.

JASS:
scope D

globals
    private hashtable HASH = InitHashtable()
    private group G = CreateGroup()
endglobals

struct D

    static method groupLooper takes nothing returns nothing
        local unit u = GetEnumUnit()
        local unit filter
        
        set udg_U = u
        set filter = GetClosestUnit(GetUnitX(u),GetUnitY(u),LoadBooleanExprHandle(HASH,GetHandleId(u),100))
        
        call BJDebugMsg(GetUnitName(u)+"===ATTACKS==="+GetUnitName(filter))
        call IssuePointOrder(u,"attack",GetUnitX(filter),GetUnitY(filter))
        set u = null
        set filter = null
    endmethod
    
    static method forGroup takes nothing returns nothing
        call ForGroup(G,function thistype.groupLooper)
    endmethod    
    
    static method SetUnitLockTargets takes unit u, boolexpr b returns nothing
        call SaveBooleanExprHandle(HASH,GetHandleId(u),100,b)
    endmethod
    
    static method RegisterHero takes unit u returns nothing
        call GroupAddUnit(G,u)
    endmethod  
    
    static method onInit takes nothing returns nothing
        call TimerStart(CreateTimer(),0.5,true,function thistype.forGroup)    
    endmethod

endstruct

endscope
 
Status
Not open for further replies.
Top