- Joined
- Jul 20, 2009
- Messages
- 835
I have one function in my system that runs incorrectly. I need to check the recipe's ingredients and also count a permanent item that is picked.
Here it is:
recipeIndex is number of this recipe.
Mean that components can also be the same.
Problems:
I'll give credit to the user who can rewrite/fix this condition.
Here it is:
JASS:
function UnitCountItemsOfType takes unit u, integer itemType returns integer
local integer i = 0
local item slotItem
local integer count = 0
loop
exitwhen i > 5
set slotItem = UnitItemInSlot(u,i)
if GetItemTypeId(slotItem) == itemType then
set count = count + 1
endif
set i = i + 1
endloop
set slotItem = null
return count
endfunction
function GetRecipeComponentCount takes integer compType returns integer
local integer index = GetItemRecipeIndex(compType)
return LoadInteger(udg_RecipeHash,index,compType)
endfunction
function GetFullRecipeId takes unit u, integer pickedType returns integer
local integer i = 1
local integer i2 = 0
local boolean array have
local boolean b
local integer index = 0
local integer currentType
local integer recCount
local integer uCount
loop
exitwhen index > udg_TotalRecipes
loop
exitwhen i > 7
set currentType = LoadInteger(udg_RecipeHash,index,i)
set recCount = GetRecipeComponentCount(currentType)
set uCount = UnitCountItemsOfType(u,currentType)
call BJDebugMsg(" ")
call BJDebugMsg("Rec. Count: " + I2S(recCount))
call BJDebugMsg("Unit Count: " + I2S(uCount))
if currentType == pickedType and b == false then
set uCount = uCount + 1
set b = true
endif
if uCount >= recCount then
set have[i] = true
else
set have[i] = false
endif
if currentType == null then
set b = true
set i2 = 1
loop
exitwhen i2 > i - 1
set b = b and have[i]
set i2 = i2 + 1
endloop
if b then
return index
else
set i = 7
set i2 = 1
loop
exitwhen i2 > i - 1
set b = b and have[i]
set i2 = i2 + 1
endloop
endif
endif
set i = i + 1
endloop
set b = false
set index = index + 1
endloop
return -1
endfunction
Mean that components can also be the same.
Problems:
- This condition is not stackable with full inventory (When a unit have all inventory slots full and buys the last component of the recipe (7th) the owner of this unit receives my custom error message)
- The same components checking works very unstable.
I'll give credit to the user who can rewrite/fix this condition.

Last edited: