• 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] Unit Group?

Status
Not open for further replies.
Level 11
Joined
Aug 25, 2006
Messages
971
If I don't know how to do something in GUI that I knew in jass, I generally make the GUI command, then change it to jass. Then I find out the code which the BJ function uses, and if necessary I look up the bj's that, that bjfunction calls. I do this until I understand exactly how it works. Then I write it in jass without all the extra BJ junk...
 
Level 19
Joined
Aug 24, 2007
Messages
2,888
Way 1

if you dont use some fishy things like Waits before grouping, you can create a function that retruns boolean well

[jass="Example"]function unitcheck takes nothing returns boolean
return IsUnitEnemy(GetFilterUnit(),GetOwningPlayer(GetTriggerUnit()))
endfunction[/code]

and for grouping
[jass="Example"]local group g = CreateGroup()
call GroupEnumUnitsInRange(g,x,y,area,Filter(function unitcheck))[/code]



Way 2


if not You can group units and remove the not-agreed ones with a code like

[jass="Example"]local unit triggeringone = GetTriggerUnit()
local group g = CreateGroup()
local unit u
call GroupEnumUnitsInRange(g,x,y,area,null)
loop
set u = FirstOfGroup(g)
exitwhen u == null
if IsUnitEnemy(u,GetOwningPlayer(triggeringone)) then
// your actions
endif
call GroupRemoveUnit(g,u)
endloop
call DestroyGroup(g) // removing leak LoL[/code]

As you can get last code groups units in range
picks the first does actions for them if its enemy of triggeringone
and removes them from group so second unit becomes first unit due to removing first unit



Some Additional Information: If you try to use GroupEnumUnits like codes without using CreateGroup() it will cause "thread crash" which means grouping action and other actions after that wont be performed and it will cause also leak
 
Level 12
Joined
Aug 20, 2007
Messages
866
boolexprs

All of the tutorials I have read, the boolexprs are skipped :confused:

A whole mess of explanations of what boolexprs do exactly, and how to use them (*if your gonna use an example I would appreciate extremely simple ones, I just started JASS a week ago) would be just peachy

All of the codes I could understand (long codes i get lost on), the boolexprs were just null-ed :wbored:
 
Level 19
Joined
Aug 24, 2007
Messages
2,888
ah I forgot to tell if you want to use filters so badly after some Trigger Sleep Actions or something
You can store the triggering unit like
set bj_lastCreatedUnit = <your triggering unit local>
and use bj_lastCreatedUnit in filters (for enemy checking etc)
example return IsUnitEnemy(GetFilterUnit(),GetOwningPlayer(bj_lastCreatedUnit))
 
Level 11
Joined
Aug 25, 2006
Messages
971
When you say 'Get all units in location matching condition' the 'matching condition' is a boolexpr. (Meaning it calls a function which says true [add the unit to the group] or false[don't add the unit])
 
Level 7
Joined
Feb 14, 2006
Messages
205
Boolexp, Boolean Expression. Expression that returns true or false.
EG: "IsUnitEnemy(GetFilterUnit(),GetOwningPlayer(bj_lastCreatedUnit))"
If a unit is an enemy, it will return TRUE, if it isn't it returns FALSE

function killenemy takes nothing returns nothing
//called by some trigger. Boolexp is bolded.
if (IsUnitEnemy(GetTriggerUnit(),GetOwningPlayer(udg_somedudesunit))== TRUE) then
call DestroyUnit(GetTriggerUnit())
endif
endfunction
(i did this off the top of my head, excuse the errors)
 
Level 19
Joined
Aug 24, 2007
Messages
2,888
Example
function THISISSPARTAAAAAA takes nothing returns boolean
return IsUnitEnemy(GetFilterUnit(),GetOwningPlayer(GetTriggerUnit())
endfunction

local boolexpr ZOMG = Filter(function THISISSPARTAAAAAA)
 
Last edited:
Level 12
Joined
Aug 20, 2007
Messages
866
Thank You!!!

Thank you so much O2 !!!

That was exactly what I wanted to know (how to use boolexprs in JASS)
I really had no idea that you could set a function as a variable :week:

+rep:wgrin:
 
Level 12
Joined
Aug 20, 2007
Messages
866
You think one of you guys could help me out with this???

JASS:
function Trig_Set_Globals_Actions takes nothing returns nothing
    local group SpawnChoosers = CreateGroup()
    local unit temp
    call GroupEnumUnitsOfType( SpawnChoosers,"Spawn", null)
    //Here is my problem
    loop
      set temp = FirstOfGroup(SpawnChoosers)
      exitwhen temp == null
      call BJDebugMsg("Ok")
      call SetUnitAbilityLevel(temp, 'A000', 21)
      call SetUnitAbilityLevel(temp, 'A001', 21)
      call SetUnitAbilityLevel(temp, 'A002', 21)
      call GroupRemoveUnit(SpawnChoosers, temp)
    endloop
    set udg_TimerInterval = 45.
    set udg_Spawns[0] = GetRectCenter(gg_rct_RedSpawn)
    set udg_Spawns[1] = GetRectCenter(gg_rct_BlueSpawn)
    set udg_Spawns[2] = GetRectCenter(gg_rct_TealSpawn)
    set udg_Spawns[3] = GetRectCenter(gg_rct_PurpleSpawn)
    set udg_Spawns[4] = GetRectCenter(gg_rct_YellowSpawn)
    set udg_Spawns[5] = GetRectCenter(gg_rct_OrangeSpawn)
    set udg_Spawns[6] = GetRectCenter(gg_rct_GreenSpawn)
    set udg_Spawns[7] = GetRectCenter(gg_rct_PinkSpawn)
    set udg_Spawns[8] = GetRectCenter(gg_rct_GraySpawn)
    set udg_Spawns[9] = GetRectCenter(gg_rct_LBSpawn)
    set udg_Spawns[10] = GetRectCenter(gg_rct_DGSpawn)
    set udg_Spawns[11] = GetRectCenter(gg_rct_BrownSpawn)
    call TimerStart(udg_SpawnTimer, udg_TimerInterval, true, null)
    call DestroyGroup(SpawnChoosers)
    set SpawnChoosers = null
endfunction

//===========================================================================
function InitTrig_Set_Globals takes nothing returns nothing
    set gg_trg_Set_Globals = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Set_Globals, function Trig_Set_Globals_Actions )
    call TriggerRegisterTimerEvent( gg_trg_Set_Globals, .01 , false)
endfunction


I made this as a starting setup trigger
The problem is the loop
There is one unit with that name (still testing it), but it doesn't show up with the debug msg

I based the unit off the priest (is a custom unit), I don't know if that matters or not

Please help!!!
 
Level 11
Joined
Aug 25, 2006
Messages
971
I bet you that the unit name string you provided is wrong. Try and check up on that by writing it in Gui and converting to Jass.
 
Level 12
Joined
Aug 20, 2007
Messages
866
Ok hold on now

I just made a string var + set it to the name in GUI

  • Untitled Trigger 001
    • Events
    • Conditions
    • Actions
      • Set xxx = (Name of Spawn 0016 <gen>)

When I converted it to JASS

JASS:
function Trig_Untitled_Trigger_001_Actions takes nothing returns nothing
    set udg_xxx = GetUnitName(gg_unit_h005_0016)
endfunction

//===========================================================================
function InitTrig_Untitled_Trigger_001 takes nothing returns nothing
    set gg_trg_Untitled_Trigger_001 = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Untitled_Trigger_001, function Trig_Untitled_Trigger_001_Actions )
endfunction


Ok, the gg_unit just means its a global unit, and the 0016 means it was the 16th of its kind

That would mean that "h005" is the units name???
____________________________________________

Edit #1

Oooo, does that mean I need to do "afaik:h005" ???
In the object editor it the raw name looks like this

h005:hmpr(Spawn)

I think the 005 = 5th custom unit, h = human class, hmpr = priest's normal, (Spawn) = In-Game name
____________________________________________

Edit #2

WOOT, thnx guys :wgrin::wgrin::wgrin:

Ok i replaced the "Spawn" with "custom_h005", ok so now it works thanks guys!!! :wthumbsup:

+rep Purple Poot cuz that was exactly what I needed (that custom_ in front)

+rep wd40bomber7 as well, because he also gave an excellent explanation :wthumbsup:
(I was figurin it out at the same time he was writin it, n I looked up at his explanation right after I wrote my conclusion, lol)
 
Level 11
Joined
Aug 25, 2006
Messages
971
'h005' is the units type. When it asks for a units type and it wants an integer, you give it the rawcode. A rawcode is converted to a number. So if you said 'h005' it would convert that to an integer. However it doesn't want an integer, it wants a string. So in this case it would be "custom_h005"
To find units/abilities/destructables/etc rawcodes go into the object editor and press ctrl + d This will toggle rawcode display.
 
Status
Not open for further replies.
Top