• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Trigger] Squad system problem:

Status
Not open for further replies.
Level 4
Joined
Mar 26, 2008
Messages
100
I have been making my own squad system and I got a few questions:

I've using custom values (all members of a squad have the same custom value and so I can select them), is there another way?

When a squad moves, how can I get the offsets of where it should go ?
Like, I don't want them to mass up humping each other while trying to go at a single point, I want to go in a formation or something.
I think this can be accomplished only with JASS, though.

Can someone give me a list of all orders (the unprocessed version,like "move" or "attack") ?

Thanks!
 
Level 4
Joined
Mar 26, 2008
Messages
100
You mean, I should use two indexed variables, one for the angle and the other for the position, and then refer to them in a for loop ?
I've tried and it didn't work because some units blocked off others and made a mess.
 

Cokemonkey11

Spell Reviewer
Level 30
Joined
May 9, 2006
Messages
3,537
No only 1 indexed variable.

Like:
funtion groupmove takes unit array u, integer unitsInGroup returns nothing
local real x
local real y
local real dist
local real angle
loop
exitwhen index>unitsInGroup
set dist=GetRandomReal(100,400)
set angle=index*(360/unitsInGroup)
set x=GetUnitX(u[index])+dist*Cos(angle*bj:DEGTORAD)
set y=GetUnitY(u[index])+dist*Sin(angle*bj:DEGTORAD)
call SetUnitX(u[index],x)
call SetUnitY(u[index],y)
set index=index+1
endloop
endfunction

I don't usually write code without an editor, so that of course is not real code that will work.
 
Level 4
Joined
Mar 26, 2008
Messages
100
No only 1 indexed variable.

Like:
funtion groupmove takes unit array u, integer unitsInGroup returns nothing
local real x
local real y
local real dist
local real angle
loop
exitwhen index>unitsInGroup
set dist=GetRandomReal(100,400)
set angle=index*(360/unitsInGroup)
set x=GetUnitX(u[index])+dist*Cos(angle*bj:DEGTORAD)
set y=GetUnitY(u[index])+dist*Sin(angle*bj:DEGTORAD)
call SetUnitX(u[index],x)
call SetUnitY(u[index],y)
set index=index+1
endloop
endfunction
What's bj ?
 
This should do it:
JASS:
//g is the group you want to move
//targetX is the x point you want the group to move to
//targetY is the y point you want the group to move to
//dist is the distance from the target you want each unit to be

function GroupMove takes group g, real targetX, real targetY, real dist returns nothing
    local integer i = 0
    local unit u
    local real x
    local real y
    local real angle
    local integer numUnits = CountUnitsInGroup(g)
    local group g2 = CreateGroup()
    call GroupAddGroup(g, g2)
    loop
        set u = FirstOfGroup(g2)
        exitwhen u == null
        
        set angle=i*((2*bj_PI)/numUnits)
        set x=targetX+dist*Cos(angle)
        set y=targetY+dist*Sin(angle)
        call IssuePointOrder(u, "move", x, y)
        
        set i = i + 1
        call GroupRemoveUnit(g2, u)
    endloop
    
    set u = null
    call DestroyGroup(g2)
    set g2 = null
endfunction
It puts the units in a circle formation around the target X/Y

EDIT: Oops, declared a local that was taken as a parameter. Fixed.
 
Last edited:
About moving in formation, DSG already once told that is impossible in warcraft because of pathing implementation.

Not using custom value is possible. But it will require a little more time (it shouldn't be so demanding though). Just make a function which cycle through all groups in the array where are the groups stored and it returns the array position in which is the group containing that unit stored.
 
Level 4
Joined
Mar 26, 2008
Messages
100
an array has limited slots though.
Also, I don't really know how to write JASS, I know a few other languages, but not JASS. I'm too lazy to open up the function library and start testing with stuff.
 
Level 4
Joined
Mar 26, 2008
Messages
100
Is it in vjass ?

What the hell, the map makes warcraft 3 crash when I try ordering something.
Apart from the numerous leaks (I will fix them once this is finished), anyone knows why ?
 

Attachments

  • groupsystem_test.w3x
    18.5 KB · Views: 39
No, it's not vJass. I might have got some syntax errors. Let me check it over.

EDIT: I just downloaded the map, I think the reason it gives errors is you put it in a trigger on its own. Unless you use JassNewGenPack it should go in the map header (click on the name of the map in the trigger editor, there is a section you can type into there)

EDIT2: I just looked over your code, and, quite frankly, it fails. It simply won't work at all.
 
Status
Not open for further replies.
Top