HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Item Fusion

07-16-2008, 10:37 PM#1
Axzarious
Well, I thought I would not need help for this, but apparantly I do. I can use the recipes or fusion or whatever you want to call it, but, the main problem is this- When a recipe has 2 or more items of the same type it will only use one item.
I will use 2 examples- Recipe- Boomstick- Requires 2 shotguns and a Boomstick recipe. However you only need 1 shotgun and a recipe.
I also want to make a trigger where for certian items, if you buy another so you have 2 the items will fuse into a different one (E.g. you have a mark of intelligence, and you buy another, they fuse and you get a mark of genius).

My basic trigger is like this

Trigger:
Events- Unit aquires an item
Collapse Conditions- And all conditions are true
Collapse Conditions-
((Triggering Unit) has item of type Boomstick Recipe) Equal to True
((Triggering Unit) has item of type Shotgun) Equal to True
((Triggering Unit) has item of type Shotgun) Equal to True
Collapse Actions-
Item - Remove (Item carried by (hero manipulating item) of type Shotgun)
Item - Remove (Item carried by (hero manipulating item) of type Shotgun)
Item - Remove (Item carried by (hero manipulating item) of type Boomstick Recipe)
Hero- Create Boomstick and give it to (Hero manipulating item)
07-16-2008, 11:43 PM#2
FarsalanSX
um im not exactly sure what you need help with but i think if you can just create the same item but different name like name:
shotgun alpha
shotgun beta
and so forth to make the item and then the game might not mistake the trigger for taking 1 item instead of two
or just add a "wait" action between the two removals
07-17-2008, 04:57 AM#3
Anopob
I had this problem before. I had a hope that I fixed it, and I did, except it caused an infinite loop that crashed my game. So instead, I use different items completely. What I would do however is if you're REALLY desperate, make it so the recipe will only combine (or trigger) whenever the recipe is picked up. Then, you can remove one shotgun, check if he has another, remove it if so and then give the output. If not, then give it back (which creates the infinite loop, however with just the recipe item it's okay).
07-17-2008, 06:30 AM#4
Tide-Arc Ephemera
I am very sorry but I'm multitasking so I can't get a 100% whole answer.

http://www.wc3campaigns.net/showthread.php?t=98324

I made a tutorial on this topic, especially made for GUI.
07-17-2008, 07:17 AM#5
d07.RiV
Here's the item system I made for my map (a simplified version, it used to have support for engineering upgrade abilities and class items, plus functions for AI).
Its in jass, just create a script, convert it to custom text and paste this text.
If you don't use vJass you will need to remove the globals..endglobals block and insert every variable into Variables dialog, then replace variable names in the script to udg_<variablename>. Then remove the library/endlibrary lines and rename InitItems function to InitTrig_<triggername>.

Collapse JASS:
library libItems initializer InitItems

globals
  private integer array combo_id
  private integer array comp_1
  private integer array comp_2
  private integer array comp_3
  private integer array comp_4
  private integer array comp_5
  private integer array comp_6
  private integer num_recipes = 0
endglobals

function AddRecipe takes integer combo, integer c1, integer c2, integer c3, integer c4, integer c5, integer c6 returns nothing
  set combo_id[num_recipes] = combo
  set comp_1[num_recipes] = c1
  set comp_2[num_recipes] = c2
  set comp_3[num_recipes] = c3
  set comp_4[num_recipes] = c4
  set comp_5[num_recipes] = c5
  set comp_6[num_recipes] = c6
  set num_recipes = num_recipes + 1
endfunction
function OnGetItem takes nothing returns nothing
  local unit u = GetManipulatingUnit ()
  local item it = GetManipulatedItem ()
  local integer iid = GetItemTypeId (it)
  local integer i = 0
  local integer j
  local integer k
  local integer array req
  local boolean array rem
  loop
    exitwhen i >= num_recipes
    set req[0] = comp_1[i]
    set req[1] = comp_2[i]
    set req[2] = comp_3[i]
    set req[3] = comp_4[i]
    set req[4] = comp_5[i]
    set req[5] = comp_6[i]
    set j = 0
    loop
      exitwhen j > 5
      set it = UnitItemInSlot (u, j)
      set rem[j] = false
      if it != null then
        set iid = GetItemTypeId (it)
        set k = 0
        loop
          exitwhen k > 5
          if iid == req[k] then
            set req[k] = 0
            set rem[j] = true
            set k = 6
          endif
          set k = k + 1
        endloop
      endif
      set j = j + 1
    endloop
    if (req[0] == 0) and (req[1] == 0) and (req[2] == 0) and (req[3] == 0) and (req[4] == 0) and (req[5] == 0) then
      set j = 0
      loop
        exitwhen j > 5
        if rem[j] then
          set it = UnitRemoveItemFromSlot (u, j)
          call RemoveItem (it)
        endif
        set j = j + 1
      endloop
      call UnitAddItemById (u, combo_id[i])
      call DestroyEffect (AddSpecialEffectTarget ("Abilities\\Spells\\Items\\AIem\\AIemTarget.mdl", u, "origin"))
      set i = num_recipes
    endif
    set i = i + 1
  endloop
  set u = null
  set it = null
endfunction

private function InitItems takes nothing returns nothing
  local trigger trg = CreateTrigger ()
  call TriggerRegisterAnyUnitEventBJ (trg, EVENT_PLAYER_UNIT_PICKUP_ITEM)
  call TriggerAddAction (trg, function OnGetItem)
  set trg = null

  // Add your recipes here. First ID is the result, then up to 6 components.
  call AddRecipe ('I009', 'I00B', 'I007', 'I008', 0, 0, 0)
  // etc etc etc
endfunction

endlibrary
07-17-2008, 07:54 AM#6
Tide-Arc Ephemera
I don't think he uses Jass at the moment :P

Trigger:
Combinothinog
Collapse Events
Unit - A unit Acquires an item
Collapse Conditions
(Item-type of (Item being manipulated)) Equal to Recipe
Collapse Actions
Collapse For each (Integer A) from 1 to 6, do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Item-type of (Item carried by (Triggering unit) in slot (Integer A))) Equal to Shotgun
Collapse Then - Actions
Set Counter = (Counter + 1)
Collapse Else - Actions
Do nothing
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
Counter Greater than or equal to 2
Collapse Then - Actions
Item - Remove (Item carried by (Triggering unit) of type Shotgun)
Item - Remove (Item carried by (Triggering unit) of type Shotgun)
Hero - Create Boomstick and give it to (Triggering unit)
Collapse Else - Actions
Do nothing
I just realized my tutorial doesn't have proper support for multiple items of the same type. Quick run down - Counter is just an integer variable, so just go to the variable menu and create an integer. For this recipe, though, it doesn't have to be arrayed.

All Counter does is count the number of Shotguns and it just has to be 2 or greater.

To my knowledge, this trigger should work just fine - though it will only fire when the recipe item is acquired.
07-17-2008, 01:39 PM#7
Anitarf
Quote:
Originally Posted by Tide-Arc Ephemera
I don't think he uses Jass at the moment :P
Doesn't mean he can't start using it.

By the way, you forgot to set your counter to 0 at the start of your trigger.
07-17-2008, 02:14 PM#8
d07.RiV
umm what counter? the global variable? its initialized when it is declared.
the local variables in the combining functions? only i is initialized because all others are initialized inside loops.
07-24-2008, 06:39 AM#9
Axzarious
Thanks for the triggers guys. And for the record, I can read about 40% of JAss, but i cant really code it. I can usually manipulate it though. Im using the jass one. It works great.