• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Slotindependant Itemcombining

Status
Not open for further replies.
Level 1
Joined
Apr 22, 2009
Messages
1
Hi guys,

I recently started to get interested in JASS, since I'm feeling kinda limited when using GUI. Luckily I'm not completely new into coding stuff and I had no trouble fixing syntax errors etc. My only problem is: my trigger doesn't do what it's supposed to, in fact it doesn't do anything at all.
So here it is, basic idea is to check for certain items in the inventory, then remove those items and place a new one in the inventory. (You could compare it to creating a fire kit out of a stick, a tinder and a flint as in troll tribes).

JASS:
function Building_Campfire_Condition takes nothing returns boolean
    local unit u = GetTriggerUnit()
    local integer i = 1
    local integer invsize = UnitInventorySize(u) + 1
    local boolean hasitema = false
    local boolean hasitemb = false
    local boolean hasitemc = false
    local boolean isspell = (GetSpellAbilityId() == 'A000')
    //check if items are in inventory
    loop
        if GetItemTypeId(UnitItemInSlot(u, i)) == 'I001' then
            set hasitema = true
        elseif GetItemTypeId(UnitItemInSlot(u, i)) == 'I002' then
            set hasitemb = true
        elseif GetItemTypeId(UnitItemInSlot(u, i)) == 'I000' then
            set hasitemc = true
        endif
        exitwhen i >= invsize
        set i = i + 1
    endloop
    //return true if its the right spell and all items are present
    set u = null
    if (hasitema == false) then
        return false
    elseif (hasitemb == false) then
        return false
    elseif (hasitemc == false) then
        return false
    elseif (isspell == false) then
        return false
    else
        return true
    endif
endfunction


function Building_Campfire_Action takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local integer i = 1
    local integer invsize = UnitInventorySize(u)
    local boolean isremoveda = false
    local boolean isremovedb = false
    local boolean isremovedc = false
    //remove materials from slots
    loop
        if GetItemTypeId(UnitItemInSlot(u, i)) == 'I001' then
            if isremoveda == false then
                call RemoveItem(UnitItemInSlot(u, i))
                set isremoveda = true
            endif
        elseif GetItemTypeId(UnitItemInSlot(u, i)) == 'I002' then
            if isremovedb == false then
                call RemoveItem(UnitItemInSlot(u, i))
                set isremovedb = true
            endif
        elseif GetItemTypeId(UnitItemInSlot(u, i)) == 'I000' then
            if isremovedc == false then
                call RemoveItem(UnitItemInSlot(u, i))
                set isremovedc = true
            endif
        endif
        exitwhen i >= invsize
        set i = i + 1
    endloop
    //place item in inventory
    call UnitAddItemById(u, 'I004')
    set u = null
endfunction


function Inittrig_Building_Campfire takes nothing returns nothing
    local trigger gg_trg_building_campfire = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(gg_trg_building_campfire, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(gg_trg_building_campfire, Condition(function Building_Campfire_Condition))
    call TriggerAddAction(gg_trg_building_campfire, function Building_Campfire_Action)
endfunction

Problem: When I execute the ability on a character, nothing happens (with all required items in the inventory).
 
Status
Not open for further replies.
Top