| 06-01-2009, 04:18 AM | #1 |
JASS:set r = 0 loop exitwhen r >= d.RCount set d = d.R[r] if RecipeCheck(d,u) then call UnitApplyItem(u,d) endif set r = r + 1 endloop return false endfunction The variables are initialized correctly. JASS:private function RecipeCheck takes bonus d, unit u returns boolean local integer i = 0 local integer array Items local item array ItemRetrieve local integer result = d.result loop exitwhen i > 5 set Items[i] = d.Items[i] set i = i + 1 endloop set i = 0 loop exitwhen i > 5 if UnitHasItemOfType(u,Items[i]) then set Items[i] = 0 set ItemRetrieve[i] = UnitItemInSlot(u,i) endif set i = i + 1 endloop set i = 0 loop exitwhen i > 5 if Items[i] != 0 then return false endif set i = i + 1 endloop set i = 0 loop exitwhen i > 5 call RemoveItem(ItemRetrieve[i]) set ItemRetrieve[i] = null set i = i + 1 endloop call DestroyEffect(AddSpecialEffect(SFX,GetUnitX(u),GetUnitY(u))) call UnitAddItemById(u,d.result) return true endfunction JASS:static method Recipe takes integer i1, integer i2, integer i3,integer i4, integer i5, integer i6, integer result returns bonus local bonus d = bonus.create() local integer i = 0 set d.Items[0] = i1 set d.Items[1] = i2 set d.Items[2] = i3 set d.Items[3] = i4 set d.Items[4] = i5 set d.Items[5] = i6 set d.result = result loop set d.Abilities[i] = 0 set d.AbilityLevels[i] = 1 set i = i+1 exitwhen i >= MAX_ABILITIES endloop set d.R[d.RCount] = d set d.RCount = d.RCount + 1 return d endmethod Creation of the recipe. JASS:set d = bonus.Recipe('I005','I006','I007',0,0,0,'I008') set d.Agi = 5000 Initialization. Again a brief illustration A|B C|0 0|0 During the first time this runs, the items get removed and the recipe result gets applied correctly but during the 2nd time onwards, it adds ingredient B or C instead of A. EDIT: UnitHasItemOfType works properly. |
| 06-01-2009, 08:10 AM | #2 |
Your fallacy is in this line here: JASS:loop exitwhen i > 5 if UnitHasItemOfType(u,Items[i]) then set Items[i] = 0 set ItemRetrieve[i] = UnitItemInSlot(u,i) endif set i = i + 1 endloop JASS:local integer j local item it //... set i = 0 loop exitwhen i > 5 if UnitHasItemOfType(u,Items[i]) then set j = 0 loop exitwhen j > 5 set it = UnitItemInSlot(u, j) if GetItemTypeId(it) == Items[i] then set Items[j] = 0 set ItemRetrieve[i] = it exitwhen true endif set j = j+1 endloop endif set i = i + 1 endloop Or if you changed UnitHasItemOfType to return the index of the item: JASS:local integer slot local boolean array used //initialize indexes 0-5 as false loop exitwhen i > 5 set slot = UnitHasItemOfType(u,Items[i]) if slot >= 0 and not used[slot] then set Items[slot] = 0 set ItemRetrieve[slot] = UnitItemInSlot(u, slot) set used[slot] = true endif set i = i + 1 endloop |
| 06-01-2009, 10:23 AM | #3 |
Doesn't work, discussed at MSN. |
