Store: unit creating order

darkbeer

Beer is Good!
Reaction score
84
Hey,
i want to make a spell which summons up to 4 units, but if there are more than 4 units summoned, the first unit summoned should disappear.

well i cant think of any way to make it except doing 4 different unit variables.

since i want to make it mui, i just cant use an array.

Maybe someone of you knows a better way^^

thx for any replies
 

Silvenon

New Member
Reaction score
19
I wanted to do that too, yeah it's kinda screwy.......

Well, you can do an array for each player, because I doubt the same player will have two same heroes.

This is what I did (in vJass), probably isn't completely right because I did it at 1 in the morning, but I think you get the picture :).

JASS:
scope Summon

globals
    private constant SPELL_ID = 'A000'
    private constant UNIT_COUNT = 4
    
    private group array G
    private integer array I
    
    private unit U
    private integer ID
endglobals

//=============================================================

function Summon_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == SPELL_ID
endfunction

function Summon_Execute2 takes nothing returns nothing
    local unit u = GetEnumUnit()
    
    call SetUnitUserData(u, GetUnitUserData(u) + 1)
    
    set u = null
endfunction

function Summon_Execute takes nothing returns nothing
    local unit u = GetEnumUnit()
    
    if GetUnitUserData(u) == UNIT_COUNT - 1 then
        call KillUnit(u)
        call GroupRemoveUnit(G[ID], u)
        call ForGroup(G[ID], function Summon_Execute2)
        call SetUnitUserData(U, 0)
    else
        call SetUnitUserData(u, I[ID])
    endif
    
    set u = null
endfunction

function Summon_Actions takes nothing returns nothing
    local unit c = GetTriggerUnit()
    local unit u1
    local unit u2
    
    if I[ID] > UNIT_COUNT - 1 then
        set I[ID] = null
    endif
    
    set ID = GetPlayerId(GetOwningPlayer(c))
    set U = GetSummonedUnit()
    
    call GroupAddUnit(G[ID], U)
    call ForGroup(G[ID], function Summon_Execute)
    
    
    set I[ID] = I[ID] + 1
    
    set c = null
endfunction

//===============================================
function InitTrig_Summon takes nothing returns nothing
    local trigger t = CreateTrigger()
    local integer i = 0
    
    loop
        exitwhen i == bj_MAX_PLAYER_SLOTS
        call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
        set G<i> = CreateGroup()
        set I<i> = 0
        set i = i + 1
    endloop
    
    call TriggerAddCondition(gg_trg_Summon, Condition(function Trig_Summon_Conditions))
    call TriggerAddAction(gg_trg_Summon, function Trig_Summon_Actions)
    
    set t = null
endfunction

endscope</i></i>
 

darkbeer

Beer is Good!
Reaction score
84
Thx for you reply

unfortunately unit user data is already used for an other sytem in my map

-.-
thx anyway
 

Silvenon

New Member
Reaction score
19
Then just attach the number to the unit via handle vars or something.
JASS:
call SetHandleInt(unit, &quot;i&quot; 1)
 

Technomancer

New Member
Reaction score
14
why not use a linked list? easy to make.

JASS:
struct node
unit u

node prev
node next
endstruct


then just make a global node for each player, and you can fiddle with counting them how you like.
 

Technomancer

New Member
Reaction score
14
a node is a struct of type node that I just created (see the name of the struct)

So then you create a second node, and assign the firstnode.next = secondnode, and secondnode.prev = firstnode. For the third node, the same thing with second node.

Here's a quick method:
JASS:
method addnode takes node add returns nothing
//Set the next node&#039;s .prev value = to the added node.
set this.next.prev = add
//Set the newnode&#039;s next value to our current next
set add.next = this.next
//Then set our next value to the node.
set this.next = add
set add.prev = this
endmethod


So, diagram for easier learning:
Code:
NODE1<->NODE2<->NODE3<->NODE4<->NODE5
//now we add a node to node 3:
call NODE3.addnode(NEWNODE)
//add node sets NODE3.next's (which is node 4) .prev value (currently NODE3) to the new NODE
So
NODE1<->NODE3<->NODE3 ->NODE4
   NEWNODE<- NODE4<->NODE5

then we link NEWNODE to NODE4
NODE1<->NODE3<->NODE3 ->NODE4
   NEWNODE<->NODE4<->NODE5

then we link NODE3 to NEWNODE, erasing our old link to NODE4
NODE1<->NODE3<->NODE3 ->NEWNODE<->NODE4<->NODE5

then we link NEWNODE to NODE3
NODE1<->NODE3<->NODE3<->NEWNODE<->NODE4<->NODE5

and we're good.
 

Silvenon

New Member
Reaction score
19
a node is a struct of type node that I just created (see the name of the struct)

Oh, I didn't see what the struct was called, I was afraid node is some keyword :)

Thanks, that helped. I would've repped you, but I gotta spread first :(
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
> why not use a linked list?

It's overkill?


Unit - Kill Unit1
Set Unit1 = Unit2
Set Unit2 = Unit3
Set Unit3 = Unit4
Set Unit4 = (Summoned unit)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top