• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[JASS] This Condition don't work correct! :(

Status
Not open for further replies.
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:

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
recipeIndex is number of this recipe.
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.:ogre_haosis:
 
Last edited:
Status
Not open for further replies.
Top