Warcraft III resources & community, 2003–2006 · archived

Item Combo System

not rated
Submitted by Lord RaszulTriggers0 downloads
This is a script i have created in order to make it easier (for me) to create an AOS- or RPG-Map.

The Script is quite easy to implement, and i hope the comments (even though there aren't that many) help understanding the code.

To implement the script, copy & paste it into your map, as you do with any other script.
The script uses a gamecache wich you need to create on mapinitialisation. Save that "LastCreatedGameCache()" in (udg_)gc_Cache

To add a new combo (of max. 6 items) you need to call
"AddItemCombo()"
the function "AddItemCombo" takes 7 integer values. The first 6 are 0 (if unused) or 'I...' for the items you require for the combo. The 7th value is the item that gets created once a unit has all items required for a combo. - The order in wich you put the items for the combo doesnt matter "call AddItemCombo(0,'I000', 0, 0, 'I001', 0, 'I004)" is as correct as "call AdditemCombo('I000', 'I001', 0, 0, 0, 0, 'I004')"

to check, whether a unit has an item-combo call the function "HasItemCombo". That function takes a unit as parameter and looks, whether that unit has any itemcombo. (even I do not know, in which order the combinations are checked, or to be more exact: i did not want to think about it ^^)

you need only 2 trigger for the whole script:

[b]initiation[/b]
Even: Map nitialisation
Conditions: none
Actions:
game cache - create a GameCachefrom ...
set gc_Cache = LastCreatedGameCache

//this once for every combo
custom code - call AddItemCombo(...)

[b]ComboCheck[/b]
Event: a unit aquires an item
Condition: none
Action: custom code - call HasItemCombo(GetTriggerUnit())

Source

//==========================================================================================
// Item Combo Script
// uses
//   gamecache: udg_gc_Cache
//==========================================================================================

function ItemComboCombine takes integer itemA, integer itemB, integer itemC, integer itemD, integer itemE, integer itemF returns string
  local integer array Items
  local integer tmp
  local integer cnt
  local integer a
  local integer b
  local string TempString

//--------------------------------------------------
//init Array
//--------------------------------------------------

  set cnt = -1
  if (itemA > 0) then
    set cnt = cnt + 1
    set Items[cnt] = itemA
  endif
  if (itemB > 0) then
    set cnt = cnt + 1
    set Items[cnt] = itemB
  endif
  if (itemC > 0) then
    set cnt = cnt + 1
    set Items[cnt] = itemC
  endif
  if (itemD > 0) then
    set cnt = cnt + 1
    set Items[cnt] = itemD
  endif
  if (itemE > 0) then
    set cnt = cnt + 1
    set Items[cnt] = itemE
  endif
  if (itemF > 0) then
    set cnt = cnt + 1
    set Items[cnt] = itemF
  endif

  if (cnt < 1) then
   return "0"
  endif

//--------------------------------------------------
// sort Array
//--------------------------------------------------
  set a = 0
  loop
    set b = 0
    loop
      if(Items[a] < Items[b]) then
        set tmp = Items[b]
        set Items[b] = Items[a]
        set Items[a] = tmp
      endif
      set b = b + 1
      exitwhen (b > cnt)
    endloop
    set a = a + 1
    exitwhen (a > cnt)
  endloop

//--------------------------------------------------
// create combination string
//--------------------------------------------------
  set a = 0
  set TempString = I2S(Items[a])

  loop
    set a = a + 1
    exitwhen (a > cnt)
    set TempString = TempString + "|" + I2S(Items[a])
  endloop

  return TempString
endfunction

function CheckItemCombo takes integer itemA, integer itemB, integer itemC, integer itemD, integer itemE, integer itemF returns string
  local string tempS

  set tempS = ItemComboCombine(itemA, itemB, itemC, itemD, itemE, itemF)
  set tempS = I2S(GetStoredInteger(udg_gc_Cache, "ItemCombo", tempS))

  return tempS
endfunction

function HasItemCombo takes unit Hero returns integer
  local string  tempS
  local integer tempI
  local integer cnt

  local integer a
  local integer b
  local integer c
  local integer d
  local integer e
  local integer f

  local integer itemA
  local integer itemB
  local integer itemC
  local integer itemD
  local integer itemE
  local integer itemF

  local integer array Items
  local integer array ComboItems

//--------------------------------------------------
// get Items
//--------------------------------------------------
  set itemA = GetItemTypeId(UnitItemInSlotBJ(Hero, 1))
  set itemB = GetItemTypeId(UnitItemInSlotBJ(Hero, 2))
  set itemC = GetItemTypeId(UnitItemInSlotBJ(Hero, 3))
  set itemD = GetItemTypeId(UnitItemInSlotBJ(Hero, 4))
  set itemE = GetItemTypeId(UnitItemInSlotBJ(Hero, 5))
  set itemF = GetItemTypeId(UnitItemInSlotBJ(Hero, 6))

//--------------------------------------------------
// init Array
//--------------------------------------------------
  set cnt = -1
  if (itemA > 0) then
    set cnt = cnt + 1
    set Items[cnt] = itemA
  endif
  if (itemB > 0) then
    set cnt = cnt + 1
    set Items[cnt] = itemB
  endif
  if (itemC > 0) then
    set cnt = cnt + 1
    set Items[cnt] = itemC
  endif
  if (itemD > 0) then
    set cnt = cnt + 1
    set Items[cnt] = itemD
  endif
  if (itemE > 0) then
    set cnt = cnt + 1
    set Items[cnt] = itemE
  endif
  if (itemF > 0) then
    set cnt = cnt + 1
    set Items[cnt] = itemF
  endif

//--------------------------------------------------
// Check for combo
//--------------------------------------------------
  set a = 0
  loop
    set b = a +1

    loop  //b-loop
      set c = b +1

      set tempS = CheckItemCombo(Items[a],Items[b],0,0,0,0)
      set ComboItems[0] = Items[a]
      set ComboItems[1] = Items[b]
      set ComboItems[2] = 0
      set ComboItems[3] = 0
      set ComboItems[4] = 0
      set ComboItems[5] = 0
      
      exitwhen StringLength(tempS)>1

      if StringLength(tempS)<=1 then
        loop //c-loop
          set d = c +1

          set tempS = CheckItemCombo(Items[a],Items[b],Items[c],0,0,0)
          set ComboItems[0] = Items[a]
          set ComboItems[1] = Items[b]
          set ComboItems[2] = Items[c]
          set ComboItems[3] = 0
          set ComboItems[4] = 0
          set ComboItems[5] = 0

          exitwhen StringLength(tempS)>1

          if StringLength(tempS)<=1 then
            loop //d-loop
              set e = d +1
 
              set tempS = CheckItemCombo(Items[a],Items[b],Items[c],Items[d],0,0)
              set ComboItems[0] = Items[a]
              set ComboItems[1] = Items[b]
              set ComboItems[2] = Items[c]
              set ComboItems[3] = Items[d]
              set ComboItems[4] = 0
              set ComboItems[5] = 0

              exitwhen StringLength(tempS)>1

              if StringLength(tempS)<=1 then
                loop //e-loop
                  set f = e +1
      
                  set tempS = CheckItemCombo(Items[a],Items[b],Items[c],Items[d],Items[e],0)
                  set ComboItems[0] = Items[a]
                  set ComboItems[1] = Items[b]
                  set ComboItems[2] = Items[c]
                  set ComboItems[3] = Items[d]
                  set ComboItems[4] = Items[e]
                  set ComboItems[5] = 0

                  exitwhen StringLength(tempS)>1

                  if StringLength(tempS)<=1 then
                    loop //f-loop
                      set tempS = CheckItemCombo(Items[a],Items[b],Items[c],Items[d],Items[e],Items[f])
                      set ComboItems[0] = Items[a]
                      set ComboItems[1] = Items[b]
                      set ComboItems[2] = Items[c]
                      set ComboItems[3] = Items[d]
                      set ComboItems[4] = Items[e]
                      set ComboItems[5] = Items[f]

                      exitwhen (StringLength(tempS)>1) or (f > cnt)
                      set f = f + 1
                    endloop
                  endif
  
                  exitwhen (e > cnt) or (StringLength(tempS)>1)
                  set e = e + 1
                endloop
              endif
  
              exitwhen (d > cnt) or (StringLength(tempS)>1)
              set d = d + 1
            endloop
          endif

          exitwhen (c > cnt) or (StringLength(tempS)>1)
          set c = c + 1
        endloop
      endif

      exitwhen (b > cnt) or (StringLength(tempS)>1)
      set b = b + 1
    endloop

    set a = a + 1
    exitwhen (a > cnt) or (StringLength(tempS)>1)
  endloop

//--------------------------------------------------
// remove & add items
//--------------------------------------------------
  if (StringLength(tempS)>1) then
    set a = 0
    loop
      if (ComboItems[a] != 0) then
        call RemoveItem( GetItemOfTypeFromUnitBJ(Hero, ComboItems[a]) )
      endif

      set a = a + 1
      exitwhen a > 5
    endloop

    call UnitAddItemByIdSwapped( S2I(tempS), Hero )
  endif

//--------------------------------------------------
// return the combo-item
//--------------------------------------------------
  return S2I(tempS)
endfunction

function AddItemCombo takes integer itemA, integer itemB, integer itemC, integer itemD, integer itemE, integer itemF, integer itemRes returns nothing
  local string temp

  set temp = ItemComboCombine(itemA, itemB, itemC, itemD, itemE, itemF)

  call StoreInteger(udg_gc_Cache, "ItemCombo", temp, itemRes)
endfunction

Comments

2
Very complex but Cool !

But isn't it more easy with only triggers ?
could DEFINATELY use a little optimizing, and fixing a ton of those BJ calls :?